:root {
  --brand-primary: #2563eb;
  --brand-primary-pressed: #1d4ed8;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --surface-background: #f7f9fc;
  --surface-primary: #ffffff;
  --border-subtle: #e5e7eb;
  --state-success: #16a34a;
  --state-warning: #d97706;
  --state-error: #dc2626;
  --state-info-surface: #eff6ff;
  --sidebar: #111d31;
  --sidebar-muted: #93a4bd;
  --radius-control: 10px;
  --radius-panel: 12px;
  --focus-ring: 0 0 0 3px rgb(37 99 235 / 18%);
  font-family: "Source Han Sans SC", "Noto Sans CJK SC", "Microsoft YaHei UI", system-ui, sans-serif;
  color: var(--text-primary);
  background: var(--surface-background);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-width: 320px; min-height: 100%; }

body {
  min-height: 100vh;
  background: var(--surface-background);
  font-size: 14px;
  line-height: 1.55;
}

button, input { font: inherit; }

button { cursor: pointer; }

button:disabled { cursor: not-allowed; opacity: .48; }

[hidden] { display: none !important; }

:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.notice {
  position: fixed;
  z-index: 20;
  top: 16px;
  left: 50%;
  width: min(520px, calc(100% - 32px));
  transform: translateX(-50%);
  padding: 12px 16px;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-control);
  background: var(--state-info-surface);
  color: #1e40af;
  box-shadow: 0 12px 28px rgb(15 23 42 / 12%);
}

.notice.error { border-color: #fecaca; background: #fef2f2; color: #991b1b; }
.notice.success { border-color: #bbf7d0; background: #f0fdf4; color: #166534; }

.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 32px 16px;
  background:
    linear-gradient(90deg, transparent 0, transparent 49.9%, rgb(229 231 235 / 40%) 50%, transparent 50.1%) 0 0 / 80px 80px,
    var(--surface-background);
}

.auth-panel {
  width: min(440px, 100%);
  padding: 36px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-panel);
  background: var(--surface-primary);
  box-shadow: 0 18px 50px rgb(15 23 42 / 8%);
}

.brand-mark, .sidebar-logo {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 11px;
  background: var(--brand-primary);
  color: white;
  font-size: 20px;
  font-weight: 700;
}

.brand-name { margin: 16px 0 2px; color: var(--brand-primary); font-weight: 600; }
.auth-panel h1 { margin: 0; font-size: 26px; line-height: 36px; }
.supporting { margin: 8px 0 24px; color: var(--text-secondary); }

.form-stack { display: grid; gap: 16px; }

.field { display: grid; gap: 7px; color: var(--text-primary); font-weight: 500; }

.field input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-control);
  background: white;
  color: var(--text-primary);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.field input:focus { border-color: var(--brand-primary); outline: none; box-shadow: var(--focus-ring); }
.field input[readonly] { background: #f8fafc; color: #475569; }
.field input::placeholder { color: #94a3b8; }

.button {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  font-size: 14px;
  font-weight: 600;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

.button.primary { background: var(--brand-primary); color: white; }
.button.primary:hover { background: var(--brand-primary-pressed); }
.button.secondary { border-color: #cbd5e1; background: white; color: #334155; }
.button.secondary:hover { border-color: #94a3b8; background: #f8fafc; }
.button.danger { border-color: #fecaca; background: white; color: var(--state-error); }
.button.danger:hover { background: #fef2f2; }
.button.text { min-height: 40px; padding: 0 8px; background: transparent; color: var(--brand-primary); }
.button.full { width: 100%; min-height: 48px; }
.button.compact { min-height: 36px; padding: 0 12px; font-size: 13px; }

.security-footnote { margin: 22px 0 0; color: var(--text-secondary); font-size: 12px; text-align: center; }

.info-panel { padding: 14px 16px; border-radius: var(--radius-panel); background: var(--state-info-surface); }
.info-panel p { margin: 4px 0 0; color: #475569; font-size: 13px; }
.info-panel code { overflow-wrap: anywhere; }

.secret-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 10px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-control);
  background: #f8fafc;
}

.secret-line code { flex: 1; overflow-wrap: anywhere; font-size: 13px; letter-spacing: .06em; }

.app-shell { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  padding: 20px 12px;
  background: var(--sidebar);
  color: white;
}

.sidebar-brand {
  display: grid;
  grid-template-columns: 42px 1fr;
  grid-template-rows: 23px 19px;
  column-gap: 10px;
  align-items: center;
  padding: 0 8px 22px;
  font-size: 16px;
  font-weight: 700;
}

.sidebar-brand .sidebar-logo { grid-row: 1 / 3; width: 40px; height: 40px; }
.sidebar-brand small { color: var(--sidebar-muted); font-size: 11px; font-weight: 400; }
.sidebar nav { display: grid; gap: 6px; }

.nav-item {
  display: flex;
  width: 100%;
  min-height: 46px;
  align-items: center;
  gap: 11px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
}

.nav-item svg { width: 20px; height: 20px; fill: currentColor; }
.nav-item:hover { background: rgb(255 255 255 / 7%); color: white; }
.nav-item.selected { background: var(--brand-primary); color: white; }

.sidebar-safety {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding: 12px;
  color: var(--sidebar-muted);
  font-size: 12px;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px rgb(34 197 94 / 14%); }

.workspace { min-width: 0; }

.topbar {
  display: flex;
  min-height: 80px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border-subtle);
  background: white;
}

.breadcrumb { margin: 0 0 2px; color: var(--text-secondary); font-size: 12px; }
.topbar h1 { margin: 0; font-size: 20px; line-height: 28px; }
.admin-menu { display: flex; align-items: center; gap: 9px; color: #334155; }
.avatar { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 50%; background: #e2e8f0; color: #334155; font-weight: 700; }

.content { width: min(1080px, 100%); margin: 0 auto; padding: 28px; }

.status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
  padding: 16px 18px;
  border: 1px solid #dbeafe;
  border-radius: var(--radius-panel);
  background: var(--state-info-surface);
}

.status-strip > div { display: flex; align-items: center; gap: 12px; }
.status-strip strong { display: block; }
.status-strip p { margin: 2px 0 0; color: #475569; font-size: 13px; }
.status-icon { width: 12px; height: 12px; border-radius: 50%; background: var(--state-success); box-shadow: 0 0 0 5px rgb(22 163 74 / 13%); }
.status-icon.disabled { background: #94a3b8; box-shadow: 0 0 0 5px rgb(148 163 184 / 14%); }
.key-mask { color: #334155; font-family: ui-monospace, "Cascadia Mono", monospace; font-size: 13px; font-variant-numeric: tabular-nums; }

.settings-panel {
  margin-top: 16px;
  padding: 22px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-panel);
  background: white;
}

.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.section-heading h2 { margin: 0; font-size: 16px; line-height: 24px; }
.section-heading p { margin: 3px 0 0; color: var(--text-secondary); font-size: 13px; }
.revision { color: var(--text-secondary); font-size: 12px; font-variant-numeric: tabular-nums; }
.settings-form { display: grid; gap: 14px; margin-top: 20px; }
.horizontal-field { grid-template-columns: 150px minmax(0, 1fr); align-items: start; }
.horizontal-field > span:first-child { padding-top: 11px; }
.input-with-help { display: grid; gap: 5px; }
.input-with-help small { color: var(--text-secondary); font-size: 12px; font-weight: 400; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 6px; border-top: 1px solid var(--border-subtle); margin-top: 4px; padding-top: 16px; }

.health-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; margin-top: 20px; border-top: 1px solid var(--border-subtle); }
.health-row > div { padding: 16px 20px 0 0; }
.health-row > div + div { padding-left: 20px; border-left: 1px solid var(--border-subtle); }
.health-label { display: block; color: var(--text-secondary); font-size: 12px; }
.health-row strong { display: block; margin-top: 4px; font-size: 14px; font-variant-numeric: tabular-nums; }

.page-section-heading { margin-bottom: 16px; }
.audit-table-wrap { overflow: hidden; border: 1px solid var(--border-subtle); border-radius: var(--radius-panel); background: white; }
.audit-table { width: 100%; border-collapse: collapse; }
.audit-table th, .audit-table td { padding: 13px 16px; border-bottom: 1px solid var(--border-subtle); text-align: left; vertical-align: middle; }
.audit-table th { background: #f8fafc; color: #475569; font-size: 12px; font-weight: 600; }
.audit-table td { color: #334155; font-size: 13px; }
.audit-table tbody tr:last-child td { border-bottom: 0; }
.outcome { font-weight: 600; }
.outcome.success { color: var(--state-success); }
.outcome.failure { color: var(--state-error); }
.empty-state { padding: 48px 20px; color: var(--text-secondary); text-align: center; }

.modal {
  width: min(460px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-panel);
  color: var(--text-primary);
  box-shadow: 0 24px 70px rgb(15 23 42 / 24%);
}

.modal::backdrop { background: rgb(15 23 42 / 46%); }
.modal form { display: grid; gap: 16px; padding: 24px; }
.modal-heading h2 { margin: 0; font-size: 18px; }
.modal-heading p { margin: 5px 0 0; color: var(--text-secondary); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.compact-modal { width: min(420px, calc(100% - 32px)); }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 12px 16px; }
  .sidebar-brand { grid-template-columns: 36px 1fr; grid-template-rows: 19px 16px; padding: 0; }
  .sidebar-brand .sidebar-logo { width: 34px; height: 34px; font-size: 17px; }
  .sidebar nav { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 12px; }
  .sidebar-safety { display: none; }
  .topbar { padding: 14px 20px; }
  .content { padding: 20px; }
}

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metric-card { padding: 20px; border: 1px solid var(--border-subtle); border-radius: var(--radius-panel); background: white; }
.metric-card span, .metric-card small { display: block; color: var(--text-secondary); font-size: 12px; }
.metric-card strong { display: block; margin: 8px 0 3px; color: var(--text-primary); font-size: 28px; font-variant-numeric: tabular-nums; }
.boundary-list { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.boundary-list span { padding: 8px 12px; border-radius: 999px; background: var(--state-info-surface); color: #334155; font-size: 13px; }
.user-toolbar { display: grid; grid-template-columns: minmax(240px, 1fr) 180px auto; align-items: end; gap: 12px; margin-bottom: 16px; }
.field select { min-height: 44px; padding: 0 12px; border: 1px solid #cbd5e1; border-radius: var(--radius-control); background: white; color: var(--text-primary); }
.user-name { display: block; color: var(--text-primary); font-weight: 600; }
.user-email, .user-meta { display: block; margin-top: 3px; color: var(--text-secondary); font-size: 12px; }
.status-pill { display: inline-flex; padding: 4px 8px; border-radius: 999px; background: #dcfce7; color: #15803d; font-size: 12px; font-weight: 600; }
.status-pill.disabled { background: #f1f5f9; color: #64748b; }
.table-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.table-actions .button { min-height: 32px; padding: 0 9px; font-size: 12px; }
.credential-value { padding: 14px; border: 1px solid #bfdbfe; border-radius: var(--radius-control); background: var(--state-info-surface); text-align: center; }
.credential-value code { font-size: 18px; letter-spacing: .06em; overflow-wrap: anywhere; }
.credential-expiry { margin: 0; color: var(--text-secondary); font-size: 13px; }

@media (max-width: 860px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav-item { justify-content: center; padding: 0 6px; }
  .nav-item svg { display: none; }
}

@media (max-width: 620px) {
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric-card { padding: 14px; }
  .metric-card strong { font-size: 23px; }
  .user-toolbar { grid-template-columns: 1fr; }
  .user-table th:nth-child(3), .user-table td:nth-child(3),
  .user-table th:nth-child(4), .user-table td:nth-child(4),
  .user-table th:nth-child(5), .user-table td:nth-child(5) { display: none; }
  .user-table-wrap { overflow-x: auto; }
}

@media (max-width: 620px) {
  .auth-panel { padding: 26px 20px; }
  .topbar { align-items: flex-start; }
  .admin-menu #admin-name { display: none; }
  .content { padding: 16px; }
  .status-strip, .section-heading { align-items: stretch; flex-direction: column; }
  .settings-panel { padding: 18px 16px; }
  .horizontal-field { grid-template-columns: 1fr; gap: 6px; }
  .horizontal-field > span:first-child { padding-top: 0; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .button, .section-heading .button { width: 100%; }
  .health-row { grid-template-columns: 1fr; }
  .health-row > div { padding: 14px 0; }
  .health-row > div + div { padding-left: 0; border-top: 1px solid var(--border-subtle); border-left: 0; }
  .audit-table th:nth-child(2), .audit-table td:nth-child(2),
  .audit-table th:nth-child(4), .audit-table td:nth-child(4) { display: none; }
  .audit-table th, .audit-table td { padding: 12px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
