:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --ink: #0f172a;
  --ink-muted: #64748b;
  --primary: #0f766e;
  --primary-hover: #0d9488;
  --primary-soft: #ccfbf1;
  --accent: #0284c7;
  --accent-soft: #e0f2fe;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --sidebar-w: 236px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: #0f172a;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 0.3px;
}
.sidebar-brand p {
  margin: 4px 0 0;
  font-size: 11px;
  color: #94a3b8;
}

.nav-list {
  padding: 12px 10px;
  flex: 1;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-group + .nav-group {
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  margin-top: 8px;
  padding-top: 8px;
}

.nav-group-title {
  padding: 4px 12px 2px;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 8px;
  color: #cbd5e1;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-size: 13.5px;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255,255,255,0.07); color: #ffffff; }
.nav-item.active { background: var(--primary); color: #ffffff; font-weight: 600; }

.main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.topbar-title { font-size: 16px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.content {
  padding: 20px 24px;
  flex: 1;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.card-title { margin: 0; font-size: 15px; font-weight: 600; }

.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 16px; }

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.kpi-label { font-size: 12px; color: var(--ink-muted); }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 6px; color: var(--ink); }
.kpi-sub { font-size: 12px; color: var(--ink-muted); margin-top: 4px; }

.overview-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 285px), 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.overview-card { margin-bottom: 0; }
.overview-period { margin: 4px 0 10px; }

.overview-distribution {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 14px;
  min-height: 126px;
}

.overview-ring {
  flex: 0 0 min(108px, 40%);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ring-fill);
}

.overview-ring-center {
  width: 74%;
  height: 74%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface);
  font-size: 12px;
  color: var(--ink-muted);
}

.overview-ring-center strong { font-size: 25px; line-height: 1.15; color: var(--ink); }

.overview-legend {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
}

.overview-legend li {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) max-content;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
}

.overview-legend li::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--legend-color);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}
.btn:hover { background: var(--surface-alt); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #ffffff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #ffffff; }
.btn-warn { background: var(--warn); border-color: var(--warn); color: #ffffff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: var(--success-soft); color: #15803d; }
.badge-warn { background: var(--warn-soft); color: #b45309; }
.badge-danger { background: var(--danger-soft); color: #b91c1c; }
.badge-info { background: var(--accent-soft); color: #0369a1; }
.badge-muted { background: #e2e8f0; color: #475569; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
th { font-weight: 600; color: var(--ink-muted); background: var(--surface-alt); font-size: 12px; }
tr:hover td { background: #f8fafc; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 12px; font-weight: 600; color: #334155; }
.field input, .field select, .field textarea {
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  font-size: 13px;
  font-family: inherit;
  background: #ffffff;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid rgba(15, 118, 110, 0.25);
  border-color: var(--primary);
}

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tab-btn {
  padding: 8px 14px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-muted);
  border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .toolbar select {
  padding: 7px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  font-size: 13px;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #0f766e 100%);
  padding: 20px;
}
.login-box {
  width: 100%;
  max-width: 420px;
  background: #ffffff;
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 20px 45px rgba(0,0,0,0.25);
}
.demo-accounts {
  margin-top: 16px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-alt);
  border: 1px dashed #cbd5e1;
  font-size: 12px;
}
.demo-chip {
  display: inline-block;
  margin: 4px 6px 0 0;
  padding: 4px 8px;
  border-radius: 6px;
  background: #e2e8f0;
  cursor: pointer;
  font-weight: 500;
}
.demo-chip:hover { background: var(--primary-soft); color: var(--primary); }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 1000;
}
.modal {
  background: #ffffff;
  border-radius: 12px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border);
}

.toast-root {
  position: fixed; right: 20px; bottom: 20px;
  display: flex; flex-direction: column; gap: 8px; z-index: 1200;
}
.toast {
  padding: 10px 14px;
  border-radius: 8px;
  background: #0f172a;
  color: #ffffff;
  font-size: 13px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.2);
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--primary); }

.muted { color: var(--ink-muted); font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.alert-box {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}
.alert-warn { background: var(--warn-soft); color: #92400e; border: 1px solid #fde68a; }
.alert-danger { background: var(--danger-soft); color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: var(--accent-soft); color: #075985; border: 1px solid #bae6fd; }

.quiz-wrap { max-width: 820px; margin: 0 auto; }
.patient-quiz-page .quiz-wrap { padding: 16px; }
.quiz-progress-bar {
  height: 8px; background: #e2e8f0; border-radius: 999px; overflow: hidden; margin: 10px 0 18px;
}
.quiz-progress-fill { height: 100%; background: var(--primary); transition: width 0.2s ease; }
.quiz-q-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px; margin-bottom: 14px;
}
.quiz-q-title { font-weight: 600; font-size: 15px; margin-bottom: 10px; color: var(--ink); }
.quiz-opt-list { display: flex; flex-direction: column; gap: 8px; }
.quiz-opt {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; border: 1.5px solid #cbd5e1; border-radius: 8px;
  cursor: pointer; background: #ffffff; transition: all 0.15s; text-align: left; font-size: 13.5px;
}
.quiz-opt:hover { border-color: var(--primary); background: #f0fdfa; }
.quiz-opt.selected {
  border-color: var(--primary); background: #ccfbf1; color: #0f766e; font-weight: 600;
}
.quiz-result-hero {
  background: linear-gradient(135deg, #0f766e 0%, #0284c7 100%);
  color: #ffffff; border-radius: 12px; padding: 22px; margin-bottom: 16px;
}
