:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #5f6f86;
  --line: #dfe4ee;
  --brand: #2563eb;
  --brand-strong: #1d4ed8;
  --sidebar: #0f172a;
  --sidebar-soft: #1e293b;
  --success: #15803d;
  --warning: #b45309;
  --danger: #b91c1c;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  font-size: 14px;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }
p { color: var(--muted); line-height: 1.65; }

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.side {
  background: var(--sidebar);
  color: #cbd5e1;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  color: #fff;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: #2563eb;
  display: grid;
  place-items: center;
  font-weight: 900;
}

.brand-title { font-size: 19px; font-weight: 800; }
.brand-sub { color: #94a3b8; font-size: 12px; margin-top: 2px; }
.nav-title { color: #94a3b8; font-size: 12px; margin: 18px 0 6px 8px; }

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 12px;
  background: transparent;
  color: #cbd5e1;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
}

.nav-item span {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: rgba(255,255,255,.08);
  display: grid;
  place-items: center;
  font-size: 12px;
}

.nav-item:hover,
.nav-item:focus-visible {
  outline: 0;
  background: rgba(255,255,255,.08);
  color: #fff;
}

.nav-item.active {
  background: var(--brand);
  color: #fff;
}

.nav-item.active span { background: rgba(255,255,255,.18); }

.side-foot {
  margin-top: auto;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--radius);
  background: rgba(255,255,255,.04);
  padding: 13px;
  display: grid;
  gap: 6px;
  color: #b6c3d6;
  font-size: 12px;
  line-height: 1.65;
}

.side-foot b { color: #fff; }

.main {
  min-width: 0;
  padding: 28px 32px 44px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 22px;
  margin-bottom: 16px;
}

.eyebrow {
  color: var(--brand);
  font-size: 13px;
  font-weight: 750;
  margin-bottom: 6px;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
  margin-bottom: 8px;
}

.server-summary {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.token-panel {
  display: flex;
  align-items: end;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 640px;
}

.token-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.token-panel input,
.field input,
.field select,
.field textarea {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  min-height: 38px;
  padding: 9px 11px;
  width: 100%;
}

.token-panel input { width: 220px; }

.field input:focus,
.field select:focus,
.field textarea:focus,
.token-panel input:focus {
  outline: 3px solid #dbeafe;
  border-color: #93c5fd;
}

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius);
  min-height: 38px;
  padding: 0 13px;
  font-weight: 700;
  background: #eef2ff;
  color: #1e40af;
}

.btn:hover,
.btn:focus-visible {
  outline: 3px solid rgba(37,99,235,.18);
  outline-offset: 1px;
}

.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-strong); }
.btn.secondary { background: #e0e7ff; color: #1e3a8a; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.danger { background: #fee2e2; color: var(--danger); }
.btn.small { min-height: 30px; padding: 0 9px; font-size: 12px; }

.notice {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--muted);
  padding: 10px 12px;
  margin-bottom: 16px;
}

.notice.ok { color: var(--success); border-color: #bbf7d0; background: #f0fdf4; }
.notice.warn { color: var(--warning); border-color: #fde68a; background: #fffbeb; }
.notice.error { color: var(--danger); border-color: #fecaca; background: #fef2f2; }

.view-panel { display: none; }
.view-panel.active { display: grid; gap: 16px; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.metric-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric-grid.compact { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.card,
.metric {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  min-width: 0;
}

.card { padding: 16px; }
.metric { padding: 15px; min-height: 92px; }

.metric .label {
  color: var(--muted);
  font-size: 13px;
}

.metric .num {
  font-size: 28px;
  line-height: 1.15;
  margin-top: 7px;
  font-weight: 850;
}

.metric .trend {
  color: var(--muted);
  font-size: 12px;
  margin-top: 7px;
}

.section-title {
  font-size: 18px;
  line-height: 1.3;
  margin-bottom: 12px;
}

.section-line {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.split-grid,
.license-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.filter-grid,
.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
}

.rule-form {
  grid-template-columns: minmax(180px, 260px) minmax(320px, 1fr) auto;
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field textarea {
  min-height: 128px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.field.is-hidden { display: none; }
.span-2 { grid-column: span 1; }
.form-stack { display: grid; gap: 14px; }
.form-action { white-space: nowrap; }
.help, .mini { color: var(--muted); font-size: 12px; line-height: 1.65; }

.setting-status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0 4px;
}

.setting-status-grid > div {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fafc;
}

.setting-status-grid span { color: var(--muted); font-size: 12px; }
.setting-status-grid b { overflow-wrap: anywhere; }
.interview-llm-form .span-2 { grid-column: span 2; }

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.codebox {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--radius);
  padding: 13px;
  word-break: break-all;
  line-height: 1.6;
}

.codebox.small {
  min-height: 38px;
  padding: 9px 11px;
}

.note {
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  border-radius: var(--radius);
  padding: 12px;
  color: #1e3a8a;
  line-height: 1.65;
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 14px 0;
}

.result-box {
  margin: 12px 0 0;
  min-height: 40px;
  max-height: 160px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fafc;
  padding: 10px;
  color: #334155;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
}

.table-wrap.tall {
  max-height: 560px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

table {
  width: 100%;
  min-width: 780px;
  border-collapse: separate;
  border-spacing: 0 8px;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-align: left;
  padding: 0 10px;
}

td {
  background: #fff;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: #263244;
  padding: 12px 10px;
  text-align: left;
  vertical-align: middle;
}

td:first-child { border-left: 1px solid var(--line); border-radius: var(--radius) 0 0 var(--radius); }
td:last-child { border-right: 1px solid var(--line); border-radius: 0 var(--radius) var(--radius) 0; }

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.muted { color: var(--muted); }

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
  background: #eef2ff;
  color: #1e3a8a;
}

.tag.active,
.tag.success,
.tag.published,
.tag.generated { background: #dcfce7; color: #166534; }
.tag.pending,
.tag.medium { background: #fef3c7; color: #92400e; }
.tag.blocked,
.tag.revoked,
.tag.expired,
.tag.high { background: #fee2e2; color: #991b1b; }
.tag.low { background: #e0f2fe; color: #075985; }

.bar-list { display: grid; gap: 10px; }
.bar-row {
  display: grid;
  grid-template-columns: minmax(90px, 150px) 1fr minmax(34px, auto);
  gap: 10px;
  align-items: center;
}

.bar-track {
  height: 8px;
  border-radius: 999px;
  background: #e8edf5;
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--brand);
}

.empty {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--muted);
  background: #f8fafc;
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .metric-grid.cols-4,
  .split-grid,
  .license-grid,
  .filter-grid,
  .form-grid,
  .rule-form { grid-template-columns: 1fr; }
  .setting-status-grid { grid-template-columns: 1fr; }
  .interview-llm-form .span-2 { grid-column: auto; }
}

@media (max-width: 760px) {
  .main { padding: 20px 16px 32px; }
  .topbar,
  .section-line {
    align-items: stretch;
    flex-direction: column;
  }
  .token-panel { justify-content: stretch; }
  .token-panel input { width: min(100%, 360px); }
}
