:root {
  --paper: #FAF8F5;
  --surface: #FFFFFF;
  --surface-muted: #F2EFEA;
  --line: #ECE8E2;
  --line-strong: #C9C2B8;
  --ink: #1A1A1A;
  --ink-sub: #6B6762;
  --ink-invert: #FFFFFF;

  --accent: #3DDC97;
  --accent-tint: #E5F8EE;
  --accent-border: #9EE2C0;
  --accent-ring: rgba(61, 220, 151, 0.25);

  --warn: #F7C948;
  --warn-tint: #FEF6DA;
  --danger: #D63A3F;
  --danger-tint: #FDECEC;

  --r-tag: 8px;
  --r-input: 12px;
  --r-card: 16px;
  --r-pill: 999px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Noto Sans SC", sans-serif;
  background-color: var(--paper);
  background-image: radial-gradient(#E5DFD6 1px, transparent 1px);
  background-size: 20px 20px;
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

/* Layout */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 248px;
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--accent);
  box-shadow: 0 6px 16px var(--accent-ring);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.brand-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}

.brand-sub {
  font-size: 12px;
  color: var(--ink-sub);
  margin-top: 2px;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-btn {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--ink-sub);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background 140ms, color 140ms;
  text-align: left;
}

.nav-btn:hover {
  background: var(--surface-muted);
  color: var(--ink);
}

.nav-btn.active {
  background: var(--ink);
  color: var(--ink-invert);
  font-weight: 600;
}

.nav-ic {
  width: 18px;
  height: 18px;
  flex: none;
}

.nav-pill {
  margin-left: auto;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-muted);
  color: var(--ink);
}

.nav-pill.pass { background: var(--accent-tint); color: var(--ink); }
.nav-pill.warn { background: var(--warn-tint); color: var(--ink); }
.nav-pill.fail { background: var(--danger); color: #FFFFFF; }

.sidebar-foot {
  padding: 12px 10px 0;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.server-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.dot-live {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring);
}

.sidebar-meta {
  font-size: 12px;
  color: var(--ink-sub);
  line-height: 1.5;
}

/* Main area */
.main-area {
  flex: 1;
  min-width: 0;
  padding: 28px 36px 56px;
  max-width: 1280px;
}

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

.page-title {
  font-size: 26px;
  font-weight: 600;
  line-height: 1.25;
}

.page-sub {
  font-size: 13px;
  color: var(--ink-sub);
  margin-top: 4px;
}

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

/* Buttons */
.btn {
  height: 40px;
  padding: 0 18px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: opacity 140ms, transform 120ms;
}

.btn:hover { opacity: 0.88; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--ink);
  color: var(--ink-invert);
}

.btn-accent {
  background: var(--accent);
  color: var(--ink);
  box-shadow: 0 4px 12px var(--accent-ring);
}

.btn-subtle {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
}

.btn-danger {
  background: var(--danger-tint);
  color: var(--danger);
  border: 1px solid rgba(214, 58, 63, 0.35);
}

.btn-sm {
  height: 34px;
  padding: 0 13px;
  font-size: 12px;
  border-radius: 10px;
}

/* Cards & Grids */
.content-mount {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 20px 22px;
}

.empty-loading {
  text-align: center;
  color: var(--ink-sub);
  padding: 48px 24px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kpi-label {
  font-size: 12px;
  color: var(--ink-sub);
  font-weight: 500;
}

.kpi-val {
  font-size: 28px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.2;
}

.kpi-foot {
  font-size: 12px;
  color: var(--ink-sub);
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.section-h {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}

.section-cap {
  font-size: 12px;
  color: var(--ink-sub);
}

/* Status Pills & Tags */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.pill-pass, .pill-ok { background: var(--accent-tint); color: var(--ink); }
.pill-warn { background: var(--warn-tint); color: var(--ink); }
.pill-fail, .pill-missing, .pill-danger { background: var(--danger); color: #FFFFFF; }
.pill-muted { background: var(--surface-muted); color: var(--ink-sub); font-weight: 500; }
.pill-ink { background: var(--ink); color: #FFFFFF; }

/* Self-Check Banner & Cards */
.health-banner {
  border-radius: var(--r-card);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}

.health-banner.pass { background: var(--accent-tint); border: 1px solid var(--accent-border); }
.health-banner.warn { background: var(--warn-tint); border: 1px solid rgba(247, 201, 72, 0.7); }
.health-banner.fail { background: var(--danger-tint); border: 1px solid rgba(214, 58, 63, 0.4); }

.health-title {
  font-size: 18px;
  font-weight: 600;
}

.health-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.check-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.check-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 15px 18px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.check-item.is-fail {
  border-color: rgba(214, 58, 63, 0.45);
  background: #FFFBFB;
}

.check-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

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

.check-name {
  font-size: 14px;
  font-weight: 600;
}

.check-summary {
  font-size: 13px;
  color: var(--ink);
}

.check-detail {
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink-sub);
  background: var(--paper);
  padding: 10px 12px;
  border-radius: 10px;
  white-space: pre-wrap;
  word-break: break-all;
}

.check-fix {
  font-size: 12px;
  color: var(--ink);
  background: var(--warn-tint);
  padding: 8px 12px;
  border-radius: 10px;
}

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-sub);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  line-height: 1.5;
}

tr:last-child td {
  border-bottom: none;
}

.code-chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  background: var(--surface-muted);
  padding: 2px 7px;
  border-radius: 6px;
  color: var(--ink);
}

/* Forms & Inputs */
.input-std, .select-std {
  height: 40px;
  padding: 0 13px;
  border-radius: var(--r-input);
  border: 1px solid var(--line-strong);
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-sub);
}

.code-block {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.65;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  overflow-x: auto;
  white-space: pre;
  color: var(--ink);
}

/* Segmented Tabs inside Cards */
.sub-tabs {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-muted);
}

.sub-tab {
  height: 34px;
  padding: 0 14px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--ink-sub);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.sub-tab.active {
  background: var(--ink);
  color: #FFFFFF;
}

/* QA Lab */
.qa-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.qa-bar .input-std {
  flex: 1;
  min-width: 240px;
}

.qa-samples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.chip-btn {
  height: 32px;
  padding: 0 12px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}

.chip-btn:hover {
  background: var(--surface-muted);
}

.qa-answer-box {
  margin-top: 14px;
  padding: 16px 18px;
  border-radius: 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Logs list */
.log-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.log-row:last-child { border-bottom: none; }

/* Toast & Modal */
.toast-mount {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast-item {
  background: var(--ink);
  color: #FFFFFF;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 28px rgba(26, 26, 26, 0.18);
}

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 26, 0.45);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 20px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-title { font-size: 18px; font-weight: 600; }
.modal-desc { font-size: 13px; color: var(--ink-sub); line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* System Admin Login Gate */
.login-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 20px;
}

.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 30px 28px;
  box-shadow: 0 18px 48px rgba(26, 26, 26, 0.08);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.login-title {
  font-size: 19px;
  font-weight: 600;
  color: var(--ink);
}

.login-sub {
  font-size: 13px;
  color: var(--ink-sub);
  margin-top: 3px;
}

.login-hint {
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--accent-tint);
  border: 1px solid var(--accent-border);
  padding: 10px 14px;
  border-radius: 12px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.input-pwd-wrap {
  display: flex;
  gap: 8px;
}

.input-pwd-wrap .input-std {
  flex: 1;
}

.btn-eye {
  height: 40px;
  padding: 0 12px;
  border-radius: var(--r-input);
  border: 1px solid var(--line-strong);
  background: var(--surface-muted);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.login-submit {
  width: 100%;
  height: 44px;
  font-size: 14px;
}

.login-error {
  font-size: 12px;
  line-height: 1.5;
  color: var(--danger);
  background: var(--danger-tint);
  border: 1px solid rgba(214, 58, 63, 0.3);
  border-radius: 10px;
  padding: 10px 12px;
}

.login-foot {
  font-size: 12px;
  color: var(--ink-sub);
  line-height: 1.55;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

/* Filter Bar */
.filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-bar .input-std {
  min-width: 240px;
  flex: 1;
  max-width: 360px;
}

.tag-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

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

/* Slide-Over Drawer */
.drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 26, 0.42);
  z-index: 2500;
  display: flex;
  justify-content: flex-end;
}

.drawer-panel {
  width: 100%;
  max-width: 620px;
  height: 100vh;
  background: var(--paper);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  box-shadow: -16px 0 40px rgba(26, 26, 26, 0.14);
}

.drawer-header {
  padding: 18px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.drawer-title {
  font-size: 18px;
  font-weight: 600;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 22px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

@media (max-width: 960px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--line); }
  .nav-list { flex-direction: row; overflow-x: auto; }
  .nav-btn { width: auto; white-space: nowrap; }
  .main-area { padding: 20px 16px 40px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col { grid-template-columns: 1fr; }
}
