/* ============================================================
   康程 PHMS · Design Tokens & Base
   Theme: 现代消费级健康 — 柔和绿/蓝, 温暖人性化
   ============================================================ */

/* ----- Themes ----- */
:root,
[data-theme="warm"] {
  /* surfaces */
  --bg:           #F6F4EE;
  --bg-sub:       #EFEBE1;
  --surface:      #FFFFFF;
  --surface-2:    #FAF8F3;
  --surface-3:    #F1ECE0;
  --border:       #E6DFD1;
  --border-2:     #D6CEBC;
  --border-strong:#B8AE99;
  /* text */
  --text:         #1F2421;
  --text-2:       #44483F;
  --text-3:       #75786D;
  --text-4:       #A6A89C;
  /* brand */
  --primary:      #4F7D5C;   /* sage */
  --primary-2:    #3F6749;
  --primary-soft: #E7EFE7;
  --accent:       #5C7FA8;   /* dusty blue */
  --accent-soft:  #E5ECF4;
  /* status (rgb / 红绿橙黄) */
  --st-normal:    #4D9E6F;
  --st-mild:      #C9A33D;
  --st-mod:       #D17A38;
  --st-crit:      #C44B5C;
  --st-review:    #888A82;
  --st-normal-bg: #E4F0E7;
  --st-mild-bg:   #F6EED4;
  --st-mod-bg:    #F6E0D0;
  --st-crit-bg:   #F4DBDE;
  --st-review-bg: #ECECE8;
}

[data-theme="medical"] {
  --bg:           #F2F5F8;
  --bg-sub:       #E7ECF2;
  --surface:      #FFFFFF;
  --surface-2:    #F7F9FC;
  --surface-3:    #ECF0F5;
  --border:       #DCE3EB;
  --border-2:     #C5CFDA;
  --border-strong:#9AA8B8;
  --text:         #15202B;
  --text-2:       #3B4956;
  --text-3:       #6E7B89;
  --text-4:       #9DA8B4;
  --primary:      #2F6EAE;
  --primary-2:    #235789;
  --primary-soft: #DEE9F4;
  --accent:       #2E8C9D;
  --accent-soft:  #DDEDEF;
  --st-normal:    #2E8C5E;
  --st-mild:      #C28E1E;
  --st-mod:       #C76B2D;
  --st-crit:      #B83A4E;
  --st-review:    #7C8693;
}

[data-theme="chinese"] {
  --bg:           #F5EFE4;
  --bg-sub:       #ECE2CE;
  --surface:      #FFFBF1;
  --surface-2:    #F8F1DE;
  --surface-3:    #EFE4CB;
  --border:       #DDCFB0;
  --border-2:     #C9B68F;
  --border-strong:#A38860;
  --text:         #2B1F12;
  --text-2:       #4F3E29;
  --text-3:       #80684B;
  --text-4:       #B09779;
  --primary:      #8C2E1E;   /* 朱砂 */
  --primary-2:    #6F2113;
  --primary-soft: #F0DDD0;
  --accent:       #2F5F4F;   /* 松绿 */
  --accent-soft:  #DCE7DF;
  --st-normal:    #2F6B45;
  --st-mild:      #B58311;
  --st-mod:       #B36523;
  --st-crit:      #9C2B1A;
  --st-review:    #847458;
}

[data-theme="dark"] {
  --bg:           #11141A;
  --bg-sub:       #181C24;
  --surface:      #1B1F28;
  --surface-2:    #232834;
  --surface-3:    #2D3340;
  --border:       #2C3240;
  --border-2:     #3B4252;
  --border-strong:#525A6B;
  --text:         #E8EAEF;
  --text-2:       #C5C9D2;
  --text-3:       #8B91A0;
  --text-4:       #5C6373;
  --primary:      #6BAA88;
  --primary-2:    #88C2A2;
  --primary-soft: #233027;
  --accent:       #7B9DC9;
  --accent-soft:  #1F2A38;
  --st-normal:    #5DC489;
  --st-mild:      #E2B952;
  --st-mod:       #E08A4C;
  --st-crit:      #DF6B7D;
  --st-review:    #9CA1AC;
  --st-normal-bg: #1F2A24;
  --st-mild-bg:   #2C2820;
  --st-mod-bg:    #2C2521;
  --st-crit-bg:   #2C2123;
  --st-review-bg: #21242B;
}

/* status default bgs for non-warm light themes */
[data-theme="medical"],
[data-theme="chinese"] {
  --st-normal-bg: color-mix(in oklab, var(--st-normal) 14%, var(--surface));
  --st-mild-bg:   color-mix(in oklab, var(--st-mild)   14%, var(--surface));
  --st-mod-bg:    color-mix(in oklab, var(--st-mod)    14%, var(--surface));
  --st-crit-bg:   color-mix(in oklab, var(--st-crit)   14%, var(--surface));
  --st-review-bg: color-mix(in oklab, var(--st-review) 12%, var(--surface));
}

/* Status colors — gradient variant (单色梯度: 浅→深 蓝绿) */
[data-status="gradient"] {
  --st-normal:    #4F9C8B;
  --st-mild:      #79A89F;
  --st-mod:       #BD8F69;
  --st-crit:      #8E3F4F;
  --st-review:    #8E928A;
  --st-normal-bg: #E5EFEC;
  --st-mild-bg:   #ECF1EE;
  --st-mod-bg:    #F1E6DA;
  --st-crit-bg:   #EAD4D8;
}

/* ----- Type ramp ----- */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Helvetica Neue", "Segoe UI", sans-serif;
  --font-data: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;

  --shadow-sm: 0 1px 2px rgba(20,24,20,.04);
  --shadow:    0 2px 8px rgba(20,24,20,.05), 0 1px 2px rgba(20,24,20,.03);
  --shadow-md: 0 6px 18px rgba(20,24,20,.08), 0 2px 4px rgba(20,24,20,.04);
  --shadow-lg: 0 18px 48px rgba(20,24,20,.14), 0 4px 10px rgba(20,24,20,.06);

  --t-fast: 120ms cubic-bezier(.2,.7,.3,1);
  --t-base: 200ms cubic-bezier(.2,.7,.3,1);
}

[data-theme="dark"] {
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow:    0 2px 10px rgba(0,0,0,.45), 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 8px 22px rgba(0,0,0,.5);
  --shadow-lg: 0 24px 60px rgba(0,0,0,.55);
}

/* ----- Reset / base ----- */
*,*::before,*::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: var(--base-font-size, 14px);
  line-height: 1.5;
  font-feature-settings: "ss01","cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
button { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
input, textarea, select { font: inherit; color: inherit; }
::selection { background: var(--primary-soft); color: var(--primary-2); }

/* tabular numerals for any data context */
.num, .nums, table, .stat, [data-num] {
  font-variant-numeric: tabular-nums;
}

/* ----- App shell ----- */
.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background: var(--bg);
}
.app--collapsed { grid-template-columns: 72px 1fr; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: grid; place-items: center;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -.01em;
  box-shadow: var(--shadow-sm);
  flex: none;
}
.brand-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .04em;
}
.brand-sub {
  font-size: 10.5px;
  color: var(--text-3);
  letter-spacing: .12em;
  text-transform: uppercase;
}

.profile-card {
  margin: 14px 12px 6px;
  padding: 10px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.profile-card:hover { background: var(--surface-3); }
.profile-card.open { border-color: var(--border-2); background: var(--surface-3); }
.profile-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  flex: none;
}
.profile-meta { flex: 1; min-width: 0; }
.profile-name { font-size: 13.5px; font-weight: 600; line-height: 1.2; }
.profile-sub  { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.profile-chev { color: var(--text-3); font-size: 11px; }

.nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.nav-group-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-4);
  padding: 14px 12px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
  position: relative;
  white-space: nowrap;
}
.nav-item > span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary-2);
  font-weight: 600;
}
[data-theme="dark"] .nav-item.active { color: var(--primary-2); }
.nav-item .nav-icon { width: 18px; height: 18px; flex: none; color: var(--text-3); }
.nav-item.active .nav-icon { color: var(--primary); }
.nav-item .nav-count {
  margin-left: auto;
  flex: none;
  font-size: 11px;
  background: var(--st-crit);
  color: #fff;
  padding: 1px 7px;
  border-radius: 999px;
  font-weight: 600;
  min-width: 0;
  line-height: 1.4;
}

.sidebar-footer {
  padding: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 6px;
}
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  width: 32px; height: 32px;
  display: grid; place-items: center;
  cursor: pointer;
  color: var(--text-2);
  transition: background var(--t-fast), border-color var(--t-fast);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-2); }
.icon-btn.is-active { background: var(--primary-soft); color: var(--primary-2); border-color: var(--primary); }

/* ----- Main content ----- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar {
  height: 60px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  flex: none;
}
.topbar h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -.01em;
  white-space: nowrap;
}
.topbar .crumbs {
  font-size: 12px;
  color: var(--text-3);
  margin-left: 2px;
  white-space: nowrap;
}
.topbar .spacer { flex: 1; }
.search {
  position: relative;
  width: 260px;
}
.search input {
  width: 100%;
  height: 34px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--bg);
  padding: 0 12px 0 32px;
  outline: none;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.search input:focus { border-color: var(--primary); background: var(--surface); }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); }

.content {
  flex: 1;
  overflow: auto;
  padding: 24px 32px 60px;
  min-height: 0;
}
.content-inner { width: 100%; margin: 0; }

/* ----- Cards ----- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}
.card.elevated { box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.card-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 12px;
  gap: 10px;
}
.card-h h3 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: .02em;
}
.card-h .h-sub { font-size: 11.5px; color: var(--text-3); }
.card-body { padding: 0 18px 18px; }
.card-fluid .card-body { padding: 0; }

/* ----- Buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  height: 34px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}
.btn:hover { background: var(--surface-2); border-color: var(--border-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-2); border-color: var(--primary-2); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.lg { height: 40px; padding: 0 18px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ----- Pills / badges ----- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .01em;
  line-height: 1.4;
  white-space: nowrap;
}
.pill .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}
.pill--normal   { color: var(--st-normal);  background: var(--st-normal-bg); }
.pill--mild     { color: var(--st-mild);    background: var(--st-mild-bg); }
.pill--mod      { color: var(--st-mod);     background: var(--st-mod-bg); }
.pill--crit     { color: var(--st-crit);    background: var(--st-crit-bg); }
.pill--review   { color: var(--st-review);  background: var(--st-review-bg); }
.pill--soft     { color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); }

/* ----- Tables ----- */
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data th, table.data td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
table.data th {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-3);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }

/* ----- Misc UI ----- */
.h-divider { height: 1px; background: var(--border); margin: 14px 0; }
.kbd {
  font-family: var(--font-data);
  font-size: 11px;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-2);
}
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: skel 1.4s infinite;
  border-radius: 4px;
}
@keyframes skel { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .9s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* scrollbar */
.content::-webkit-scrollbar, .nav::-webkit-scrollbar { width: 10px; }
.content::-webkit-scrollbar-track, .nav::-webkit-scrollbar-track { background: transparent; }
.content::-webkit-scrollbar-thumb, .nav::-webkit-scrollbar-thumb {
  background: var(--border-2);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}
.content::-webkit-scrollbar-thumb:hover, .nav::-webkit-scrollbar-thumb:hover { background-color: var(--border-strong); background-clip: content-box; }

/* page transitions */
.page-enter { opacity: 1; }
@keyframes pageIn {
  0% { opacity: 0; transform: translateY(4px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* Dashboard grid */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 18px;
}
.gc-2 { grid-column: span 2; }
.gc-3 { grid-column: span 3; }
.gc-4 { grid-column: span 4; }
.gc-5 { grid-column: span 5; }
.gc-6 { grid-column: span 6; }
.gc-7 { grid-column: span 7; }
.gc-8 { grid-column: span 8; }
.gc-12 { grid-column: span 12; }

@media (max-width: 1180px) {
  .gc-3, .gc-4 { grid-column: span 6; }
  .gc-5, .gc-7 { grid-column: span 12; }
  .gc-6 { grid-column: span 12; }
  .gc-8 { grid-column: span 12; }
}

/* Greeting / dashboard intro */
.hello {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -.01em;
  margin: 4px 0 4px;
}
.hello-sub { color: var(--text-3); font-size: 13px; margin-bottom: 18px; }

/* metric tile */
.metric {
  padding: 14px 16px 16px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 96px;
  cursor: pointer;
  transition: border-color var(--t-fast), transform var(--t-fast);
  position: relative;
  overflow: hidden;
}
.metric:hover { border-color: var(--border-2); transform: translateY(-1px); }
.metric .m-name { font-size: 11.5px; color: var(--text-3); letter-spacing: .04em; text-transform: uppercase; }
.metric .m-value { font-size: 24px; font-weight: 600; letter-spacing: -.01em; line-height: 1.1; margin-top: 2px; }
.metric .m-value .unit { font-size: 12px; color: var(--text-3); font-weight: 400; margin-left: 4px; }
.metric .m-meta { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-3); margin-top: auto; }
.metric .m-arrow { font-weight: 600; }
.metric .m-arrow.up { color: var(--st-crit); }
.metric .m-arrow.down { color: var(--st-normal); }
.metric .m-arrow.flat { color: var(--text-3); }
.metric .m-sparkline { position: absolute; right: 12px; top: 12px; opacity: .55; }

/* status-tinted metric */
.metric.tone-mild   { background: linear-gradient(180deg, var(--st-mild-bg)   0%, var(--surface) 75%); }
.metric.tone-mod    { background: linear-gradient(180deg, var(--st-mod-bg)    0%, var(--surface) 75%); }
.metric.tone-crit   { background: linear-gradient(180deg, var(--st-crit-bg)   0%, var(--surface) 75%); }
.metric.tone-normal { background: linear-gradient(180deg, var(--st-normal-bg) 0%, var(--surface) 80%); }

/* dropdown menu */
.menu {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  padding: 6px;
  z-index: 50;
  min-width: 200px;
  opacity: 1;
}
.menu-item {
  padding: 8px 10px;
  font-size: 13px;
  border-radius: var(--r-xs);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item.active { background: var(--primary-soft); color: var(--primary-2); }
.menu-divider { height: 1px; background: var(--border); margin: 4px 0; }
.menu-header { padding: 6px 10px; font-size: 10.5px; color: var(--text-4); letter-spacing: .1em; text-transform: uppercase; }

/* modal */
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(8,10,12,.42);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: grid; place-items: center;
  opacity: 1;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  width: min(720px, 92vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 1;
}
.modal-h {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-h h2 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-body { padding: 22px; overflow: auto; flex: 1; }
.modal-f {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* form */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; color: var(--text-2); font-weight: 500; }
.field .hint { font-size: 11px; color: var(--text-3); }
.field .err  { font-size: 11px; color: var(--st-crit); }
.input, select.input, textarea.input {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  padding: 0 12px;
  outline: none;
  transition: border-color var(--t-fast);
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--primary); }
.field.error .input { border-color: var(--st-crit); }
.input[disabled] { background: var(--surface-2); color: var(--text-3); }

/* tooltip */
.tip {
  position: absolute;
  background: var(--text);
  color: var(--surface);
  font-size: 11px;
  padding: 6px 8px;
  border-radius: var(--r-xs);
  pointer-events: none;
  z-index: 90;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
}
[data-theme="dark"] .tip { background: var(--surface-3); color: var(--text); border: 1px solid var(--border); }

/* page header */
.page-h { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-h h2 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -.01em; }
.page-h .sub { color: var(--text-3); font-size: 12.5px; margin-top: 4px; }
.page-h .actions { display: flex; gap: 8px; }

/* Chip / tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--t-fast), border-color var(--t-fast);
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary-2); border-bottom-color: var(--primary); font-weight: 600; }
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 2px;
  background: var(--surface-2);
}
.seg button {
  padding: 4px 10px;
  border: 0;
  background: transparent;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-2);
  white-space: nowrap;
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); font-weight: 600; }

/* chat */
.chat-shell { display: flex; flex-direction: column; height: calc(100vh - 60px - 60px); }
.chat-msgs { flex: 1; overflow: auto; padding: 24px 0; }
.bubble { max-width: 720px; padding: 12px 16px; border-radius: 14px; line-height: 1.6; font-size: 14px; }
.bubble.user { background: var(--primary-soft); color: var(--primary-2); margin-left: auto; border-bottom-right-radius: 4px; }
.bubble.ai   { background: var(--surface); border: 1px solid var(--border); margin-right: auto; border-bottom-left-radius: 4px; }
.bubble.ai .src { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); font-size: 11.5px; color: var(--text-3); }
/* Typing dots animation */
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30%            { transform: translateY(-5px); opacity: 1; }
}
.typing-dots { display: inline-flex; align-items: center; gap: 5px; padding: 2px 0; }
.typing-dots span {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--primary); animation: typingBounce 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
.chat-input {
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding: 14px 0;
}
.chat-input textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 12px 14px;
  resize: none;
  outline: none;
  font: inherit;
  min-height: 56px;
}

/* utility */
.row { display: flex; align-items: center; gap: 10px; }
.row.gap-4 { gap: 4px; } .row.gap-12 { gap: 12px; } .row.gap-16 { gap: 16px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.col.gap-4 { gap: 4px; } .col.gap-16 { gap: 16px; }
.muted { color: var(--text-3); }
.faint { color: var(--text-4); }
.bold  { font-weight: 600; }
.txt-sm { font-size: 12px; }
.txt-xs { font-size: 11px; }
.center { display: grid; place-items: center; }
.right { margin-left: auto; }
.wrap { flex-wrap: wrap; }
.fill { flex: 1; min-width: 0; }
.mono { font-family: var(--font-data); }
.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-3);
  font-size: 13px;
}
.empty .empty-title { font-size: 14px; color: var(--text-2); font-weight: 600; margin-bottom: 4px; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
  display: grid;
  grid-template-columns: 3fr 1fr;
  width: 100vw; height: 100vh;
  overflow: hidden;
  background: var(--bg);
}
@media (max-width: 940px) {
  .login-page { grid-template-columns: 1fr; }
  .login-brand { display: none !important; }
}

.login-brand {
  position: relative;
  background:
    radial-gradient(circle at 18% 20%, rgba(255,255,255,.18), transparent 38%),
    radial-gradient(circle at 90% 90%, rgba(0,0,0,.18), transparent 45%),
    linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: #fff;
  overflow: hidden;
}
.login-brand::before {
  content: '';
  position: absolute; inset: 0;
  background-image:
    radial-gradient(circle at 80% 18%, rgba(255,255,255,.10) 0, transparent 70px),
    radial-gradient(circle at 22% 78%, rgba(255,255,255,.08) 0, transparent 90px);
  pointer-events: none;
}
.login-brand-inner {
  position: relative;
  width: 100%; height: 100%;
  padding: 56px 64px 40px;
  display: flex; flex-direction: column;
}
.login-mark { display: flex; align-items: center; gap: 12px; }

.login-feat {
  display: flex; align-items: flex-start; gap: 12px;
}
.login-feat-ico {
  width: 30px; height: 30px; border-radius: 8px;
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.18);
  display: grid; place-items: center;
  color: #fff; flex: none;
}

.login-form-wrap {
  position: relative;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px;
  overflow: auto;
}
.login-form {
  width: 100%;
  max-width: 380px;
}
.login-footer {
  position: absolute; bottom: 24px;
  display: flex; gap: 8px; align-items: center;
}
.login-footer a { cursor: pointer; }
.login-footer a:hover { color: var(--text-2); }

.login-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 24px 0 16px;
  color: var(--text-4);
  font-size: 11px;
}
.login-divider::before, .login-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

.code-input {
  width: 46px; height: 52px;
  text-align: center;
  font-size: 22px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 0;
}

/* ============================================================
   SETTINGS PAGE
   ============================================================ */
.settings-page { width: 100%; }
.settings-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 24px;
  align-items: flex-start;
}
.settings-nav {
  position: sticky;
  top: 0;
  display: flex; flex-direction: column;
  gap: 2px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.settings-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.settings-nav-item:hover { background: var(--surface-2); color: var(--text); }
.settings-nav-item.active {
  background: var(--primary-soft);
  color: var(--primary-2);
  font-weight: 600;
}
.settings-content { min-width: 0; max-width: none; }

.setting-row {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: 0; padding-bottom: 0; }
.setting-row:first-child { padding-top: 0; }

@keyframes fadeOut { 0% { opacity: 1; } 70% { opacity: 1; } 100% { opacity: 0; } }

/* ── Accessibility ── */
.high-contrast {
  --border: rgba(0,0,0,.4);
  --border-2: rgba(0,0,0,.6);
  --text-2: var(--text);
  --text-3: color-mix(in srgb, var(--text) 75%, transparent);
}
[data-theme="dark"].high-contrast {
  --border: rgba(255,255,255,.45);
  --border-2: rgba(255,255,255,.65);
}
.high-contrast .card,
.high-contrast .input,
.high-contrast .btn:not(.primary) { border-width: 1.5px; }

.reduce-motion *,
.reduce-motion *::before,
.reduce-motion *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}
