/* ==========================================================================
   CrownRole Design System — cc.css
   Tokens, layout shell, and reusable component styles.
   ========================================================================== */

:root {
  /* Brand */
  --deep-emerald: #064E3B;
  --emerald: #047857;
  --emerald-600: #065F46;
  --emerald-50: #ECF5F1;
  --emerald-100: #D3E9E0;
  --gold: #C6A667;
  --gold-dark: #8A6D2F;
  --soft-gold: #E8D5A7;
  --gold-50: #F7F0DF;
  --ivory: #FAF8F3;
  --white: #FFFFFF;
  --charcoal: #1F2937;

  /* Semantic */
  --bg: var(--ivory);
  --surface: var(--white);
  --surface-2: #F4F1E9;
  --text: var(--charcoal);
  --text-muted: #5B6472;
  --text-subtle: #8A919C;
  --border: #E6E0D2;
  --border-strong: #D4CCB9;
  --primary: var(--emerald);
  --primary-hover: var(--emerald-600);
  --primary-text: #FFFFFF;
  --focus: #C6A667;

  --success: #047857;  --success-bg: #E3F2EC;
  --warning: #9A5B05;  --warning-bg: #FBF0DC;
  --danger:  #B42318;  --danger-bg:  #FCE9E7;
  --info:    #1F4E8C;  --info-bg:    #E6EEF8;
  --neutral: #4B5563;  --neutral-bg: #EEECE6;

  /* Chart palette (validated for contrast on ivory/white) */
  --c1: #047857; --c2: #C6A667; --c3: #1F4E8C; --c4: #9C4A6B; --c5: #5B7F6E; --c6: #B07A2A;

  /* Typography */
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs-xs: 12px; --fs-sm: 13px; --fs-base: 15px; --fs-md: 17px; --fs-lg: 20px; --fs-xl: 26px; --fs-2xl: 34px; --fs-3xl: 44px;

  /* Spacing (4pt) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px; --s12: 48px;

  /* Shape & depth */
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-xl: 20px; --r-full: 999px;
  --shadow-sm: 0 1px 2px rgba(31,41,55,.05);
  --shadow-md: 0 4px 16px rgba(31,41,55,.07), 0 1px 3px rgba(31,41,55,.05);
  --shadow-lg: 0 18px 50px rgba(6,78,59,.16), 0 4px 12px rgba(31,41,55,.08);

  --sidebar-w: 256px;
  --rail-w: 76px;
  --topbar-h: 64px;
  --bottomnav-h: 64px;
  --ease: cubic-bezier(.2,.8,.2,1);
}

[data-theme="dark"] {
  --bg: #0C1714;
  --surface: #13211C;
  --surface-2: #182922;
  --text: #EDE9DF;
  --text-muted: #AEB4AE;
  --text-subtle: #858D87;
  --border: #24372F;
  --border-strong: #31493F;
  --primary: #1F9D74;
  --primary-hover: #25B184;
  --emerald-50: #15302A;
  --emerald-100: #1C3D34;
  --gold-50: #2A2617;
  --success-bg: #16362B; --success: #5FD1A5;
  --warning-bg: #3A2C12; --warning: #E9B65A;
  --danger-bg:  #3D1C1A; --danger:  #F28B82;
  --info-bg:    #182B44; --info:    #8AB4F0;
  --neutral-bg: #222D29; --neutral: #C3C8C2;
  --shadow-md: 0 4px 16px rgba(0,0,0,.35);
  --shadow-lg: 0 18px 50px rgba(0,0,0,.5);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 var(--fs-base)/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.2; color: var(--text); }
h1, .display { font-family: var(--font-display); font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); font-weight: 650; }
h3 { font-size: var(--fs-md); font-weight: 650; }
h4 { font-size: var(--fs-base); font-weight: 650; }
p { margin: 0 0 var(--s3); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 999; border-radius: 8px; }
.skip-link:focus { left: 8px; }
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.eyebrow { font-size: var(--fs-xs); letter-spacing: .12em; text-transform: uppercase; color: var(--gold-dark); font-weight: 650; }
[data-theme="dark"] .eyebrow { color: var(--gold); }
.num { font-variant-numeric: tabular-nums; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--s5) 0; }

/* ---------- Layout helpers ---------- */
.stack > * + * { margin-top: var(--s4); }
.stack-sm > * + * { margin-top: var(--s2); }
.stack-lg > * + * { margin-top: var(--s6); }
.row { display: flex; align-items: center; gap: var(--s3); }
.row-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.between { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.spacer { flex: 1; }
.grid { display: grid; gap: var(--s4); }
.grid-2 { display: grid; gap: var(--s4); grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { display: grid; gap: var(--s4); grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-4 { display: grid; gap: var(--s4); grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid-auto { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.layout-main-side { display: grid; gap: var(--s5); grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .layout-main-side { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
}
@media (max-width: 420px) { .grid-4 { grid-template-columns: 1fr 1fr; gap: var(--s3); } }

/* ---------- App shell ---------- */
.app { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  background: var(--deep-emerald); color: #E9F0EC; display: flex; flex-direction: column;
  transition: transform .25s var(--ease);
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px 14px; color: #fff; text-decoration: none; }
.brand-mark { width: 34px; height: 34px; flex: none; }
.brand-name { font-family: var(--font-display); font-size: 19px; letter-spacing: .02em; color: #fff; }
.brand-name b { color: var(--soft-gold); font-weight: 600; }
.role-chip {
  margin: 4px 16px 10px; padding: 10px 12px; border-radius: var(--r-md);
  background: rgba(255,255,255,.07); border: 1px solid rgba(232,213,167,.22);
}
.role-chip .eyebrow { color: var(--soft-gold); font-size: 10.5px; }
.role-chip strong { display: block; color: #fff; font-size: 14px; font-weight: 600; }
.role-chip span { font-size: 12px; color: #B9CEC5; }
.nav { flex: 1; overflow-y: auto; padding: 6px 10px 12px; }
.nav-label { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: #8FB0A3; padding: 14px 12px 6px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; margin: 2px 0;
  color: #D7E4DE; border-radius: var(--r-md); text-decoration: none; font-size: 14.5px; position: relative;
}
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a[aria-current="page"] { background: rgba(232,213,167,.14); color: #fff; font-weight: 600; }
.nav a[aria-current="page"]::before { content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--gold); }
.nav a .count { margin-left: auto; background: var(--gold); color: var(--deep-emerald); font-size: 11px; font-weight: 700; border-radius: var(--r-full); padding: 1px 7px; }
.nav svg { flex: none; opacity: .92; }
.sidebar-foot { border-top: 1px solid rgba(255,255,255,.08); padding: 12px 16px; display: flex; align-items: center; gap: 10px; }
.sidebar-foot a { color: #D7E4DE; font-size: 13px; }
.sidebar-foot .who { line-height: 1.25; min-width: 0; }
.sidebar-foot .who strong { display: block; color: #fff; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s6);
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar .title { min-width: 0; }
.topbar .title h1 { font-size: 21px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .crumbs { font-size: 12px; color: var(--text-subtle); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .crumbs a { color: var(--text-muted); }
.icon-btn.menu-btn { display: none; }
.page { padding: var(--s6); max-width: 1320px; width: 100%; margin: 0 auto; flex: 1; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s5); flex-wrap: wrap; }
.page-head h2 { font-family: var(--font-display); font-size: var(--fs-xl); font-weight: 600; }
.page-head p { margin: 4px 0 0; color: var(--text-muted); }
.demo-ribbon {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase;
  color: var(--gold-dark); background: var(--gold-50); border: 1px solid var(--soft-gold); border-radius: var(--r-full); padding: 3px 10px; cursor: pointer;
}
[data-theme="dark"] .demo-ribbon { color: var(--soft-gold); border-color: #5A4C2A; }
.bottomnav { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(12,23,20,.45); z-index: 35; opacity: 0; pointer-events: none; transition: opacity .2s; }
body.nav-open .scrim { opacity: 1; pointer-events: auto; }

/* Tablet: navigation rail */
@media (max-width: 1100px) and (min-width: 761px) {
  .sidebar { width: var(--rail-w); }
  .sidebar .brand-name, .role-chip, .nav-label, .nav a span, .nav a .count, .sidebar-foot .who, .sidebar-foot .foot-links { display: none; }
  .sidebar .brand { justify-content: center; padding: 16px 0; }
  .nav a { justify-content: center; padding: 11px 0; }
  .nav a .dot { position: absolute; top: 6px; right: 14px; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
  .sidebar-foot { justify-content: center; }
  .main { margin-left: var(--rail-w); }
  body.nav-open .sidebar { width: var(--sidebar-w); box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar .brand-name, body.nav-open .role-chip, body.nav-open .nav-label, body.nav-open .nav a span, body.nav-open .nav a .count, body.nav-open .sidebar-foot .who { display: revert; }
  body.nav-open .nav a { justify-content: flex-start; padding: 9px 12px; }
  .icon-btn.menu-btn { display: inline-grid; }
}
.nav a .dot { display: none; }
@media (max-width: 1100px) and (min-width: 761px) { .nav a .dot { display: block; } body.nav-open .nav a .dot { display: none; } }

/* Mobile: bottom navigation + drawer */
@media (max-width: 760px) {
  .sidebar { transform: translateX(-100%); width: min(86vw, 300px); }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .main { margin-left: 0; padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom)); }
  .topbar { padding: 0 var(--s4); gap: var(--s2); height: 58px; }
  .topbar .title h1 { font-size: 18px; }
  .topbar .hide-sm { display: none !important; }
  .icon-btn.menu-btn { display: inline-grid; }
  .switcher-btn.role { padding: 0 10px; height: 36px; font-size: 12.5px; }
  .page { padding: var(--s4); }
  .page-head h2 { font-size: 23px; }
  .bottomnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -4px 18px rgba(31,41,55,.05);
  }
  .bottomnav a, .bottomnav button {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    font: 600 11px/1 var(--font-body); color: var(--text-subtle); text-decoration: none; background: none; border: 0; cursor: pointer; position: relative;
  }
  .bottomnav [aria-current="page"] { color: var(--primary); }
  .bottomnav [aria-current="page"]::after { content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--gold); }
}

/* ---------- Surfaces ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); padding: var(--s5); min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s4); }
.card-head h3 { font-size: 16px; }
.card-head .sub { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 2px; }
.card.flush { padding: 0; }
.card.flush > .card-head { padding: var(--s5) var(--s5) 0; }
.card.tint { background: var(--emerald-50); border-color: var(--emerald-100); }
.card.gold { background: var(--gold-50); border-color: var(--soft-gold); }
.card.hero {
  background: linear-gradient(135deg, var(--deep-emerald) 0%, #0A5C47 60%, #0E6B52 100%);
  color: #EEF4F0; border: 0; position: relative; overflow: hidden;
}
.card.hero h2, .card.hero h3, .card.hero h1 { color: #fff; }
.card.hero .muted { color: #BFD5CB; }
.card.hero::after { content: ""; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px; border-radius: 50%; border: 1px solid rgba(232,213,167,.25); }
.card.hero::before { content: ""; position: absolute; right: -20px; top: -20px; width: 140px; height: 140px; border-radius: 50%; border: 1px solid rgba(232,213,167,.18); }
.card.interactive { transition: box-shadow .2s, transform .2s, border-color .2s; cursor: pointer; }
.card.interactive:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); border-color: var(--border-strong); }
.divider-list > * { padding: var(--s3) 0; border-top: 1px solid var(--border); }
.divider-list > *:first-child { border-top: 0; padding-top: 0; }
.divider-list > *:last-child { padding-bottom: 0; }
.kv { display: grid; grid-template-columns: minmax(120px, 38%) 1fr; gap: 8px 16px; font-size: 14px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-weight: 500; }

/* Metric card */
.metric { display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: inherit; }
.metric:hover { text-decoration: none; }
.metric .m-top { display: flex; align-items: center; justify-content: space-between; color: var(--text-muted); font-size: 13px; font-weight: 550; }
.metric .m-ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--emerald-50); color: var(--primary); }
.metric .m-val { font-family: var(--font-display); font-size: 30px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.metric .m-foot { font-size: 12.5px; color: var(--text-subtle); }
.delta-up { color: var(--success); font-weight: 600; }
.delta-down { color: var(--danger); font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px;
  border-radius: var(--r-md); border: 1px solid transparent; font: 600 14px/1 var(--font-body); cursor: pointer;
  text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, color .15s, box-shadow .15s; user-select: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-gold { background: var(--gold); color: var(--deep-emerald); }
.btn-gold:hover { background: #B8975A; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.94); }
.btn-danger-outline { background: var(--surface); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-lg { min-height: 48px; padding: 0 22px; font-size: 15.5px; }
.btn-block { width: 100%; }
.btn[disabled], .btn.is-disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after { content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-color: rgba(255,255,255,.9) rgba(255,255,255,.9) transparent transparent; animation: spin .7s linear infinite; }
.btn-secondary.is-loading::after { border-color: var(--primary) var(--primary) transparent transparent; }
.icon-btn {
  width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: var(--r-md);
  border: 1px solid transparent; background: transparent; color: var(--text-muted); cursor: pointer; position: relative; flex: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.bordered { border-color: var(--border); background: var(--surface); }
.icon-btn .pip { position: absolute; top: 7px; right: 7px; min-width: 16px; height: 16px; border-radius: 8px; padding: 0 4px; background: var(--gold); color: var(--deep-emerald); font-size: 10px; font-weight: 800; display: grid; place-items: center; border: 2px solid var(--bg); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: var(--r-full);
  font-size: 12px; font-weight: 650; white-space: nowrap; background: var(--neutral-bg); color: var(--neutral);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.plain::before { display: none; }
.badge.success { background: var(--success-bg); color: var(--success); }
.badge.warning { background: var(--warning-bg); color: var(--warning); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.gold { background: var(--gold-50); color: var(--gold-dark); border: 1px solid var(--soft-gold); }
[data-theme="dark"] .badge.gold { color: var(--soft-gold); border-color: #5A4C2A; }
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: var(--r-full); background: var(--surface-2); border: 1px solid var(--border); font-size: 12.5px; color: var(--text-muted); }

/* ---------- Avatar ---------- */
.avatar {
  --size: 40px; width: var(--size); height: var(--size); border-radius: 50%; flex: none; display: inline-grid; place-items: center;
  font-weight: 650; font-size: calc(var(--size) * .38); color: #fff; letter-spacing: .02em; position: relative; overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.avatar.ring { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--gold); }
.avatar-stack { display: flex; }
.avatar-stack .avatar { margin-left: -8px; box-shadow: 0 0 0 2px var(--surface); }
.avatar-stack .avatar:first-child { margin-left: 0; }

/* ---------- Progress ---------- */
.progress { height: 8px; background: var(--surface-2); border-radius: var(--r-full); overflow: hidden; border: 1px solid var(--border); }
.progress > i { display: block; height: 100%; background: var(--primary); border-radius: inherit; transition: width .6s var(--ease); }
.progress.gold > i { background: var(--gold); }
.progress.thin { height: 5px; }
.progress-label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; color: var(--text-muted); }
.progress-label b { color: var(--text); font-variant-numeric: tabular-nums; }
.ring { position: relative; display: inline-grid; place-items: center; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring .ring-val { position: absolute; text-align: center; line-height: 1.1; }
.ring .ring-val b { display: block; font-family: var(--font-display); font-size: 1.35em; font-variant-numeric: tabular-nums; }
.ring .ring-val small { font-size: 11px; color: var(--text-muted); }
.card.hero .ring .ring-val small { color: #BFD5CB; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label, .label { font-size: 13.5px; font-weight: 600; color: var(--text); }
.req { color: var(--danger); margin-left: 2px; }
.hint { font-size: 12.5px; color: var(--text-subtle); }
.input, .select, .textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border-radius: var(--r-md); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: 400 15px/1.4 var(--font-body); transition: border-color .15s, box-shadow .15s;
}
.textarea { min-height: 110px; resize: vertical; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%235B6472' stroke-width='1.8'%3E%3Cpath d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-subtle); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
.input[disabled], .select[disabled], .textarea[disabled], .input[readonly] { background: var(--surface-2); color: var(--text-muted); cursor: not-allowed; }
.field.has-error .input, .field.has-error .select, .field.has-error .textarea { border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 12%, transparent); }
.field-error { display: none; font-size: 12.5px; color: var(--danger); font-weight: 550; }
.field.has-error .field-error { display: flex; gap: 4px; align-items: center; }
.input-wrap { position: relative; }
.input-wrap > svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-subtle); pointer-events: none; }
.input-wrap > .input { padding-left: 38px; }
.input-wrap > .input-action { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.form-grid { display: grid; gap: var(--s4); grid-template-columns: repeat(2, minmax(0,1fr)); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: var(--s3); justify-content: flex-end; flex-wrap: wrap; padding-top: var(--s4); border-top: 1px solid var(--border); margin-top: var(--s5); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--primary); flex: none; }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 13px; background: var(--border-strong); transition: background .2s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .2s var(--ease); }
.switch input:checked + i { background: var(--primary); }
.switch input:checked + i::after { transform: translateX(18px); }
.switch input:focus-visible + i { outline: 3px solid var(--focus); outline-offset: 2px; }
.radio-cards { display: grid; gap: var(--s3); }
.radio-card { display: flex; gap: 14px; align-items: flex-start; padding: 16px; border: 1.5px solid var(--border); border-radius: var(--r-lg); background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s; }
.radio-card:hover { border-color: var(--border-strong); }
.radio-card input { margin-top: 3px; accent-color: var(--primary); width: 18px; height: 18px; flex: none; }
.radio-card:has(input:checked) { border-color: var(--primary); background: var(--emerald-50); }
.char-count { font-size: 12px; color: var(--text-subtle); text-align: right; }
.char-count.over { color: var(--danger); font-weight: 600; }
.range { width: 100%; accent-color: var(--primary); height: 28px; }
.otp { display: flex; gap: 10px; }
.otp input { width: 48px; height: 56px; text-align: center; font-size: 22px; font-weight: 650; border-radius: var(--r-md); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); }
.otp input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
.pw-meter { display: flex; gap: 4px; margin-top: 4px; }
.pw-meter i { flex: 1; height: 4px; border-radius: 2px; background: var(--border); }
.pw-meter[data-score="1"] i:nth-child(-n+1) { background: var(--danger); }
.pw-meter[data-score="2"] i:nth-child(-n+2) { background: var(--warning); }
.pw-meter[data-score="3"] i:nth-child(-n+3) { background: var(--gold); }
.pw-meter[data-score="4"] i { background: var(--success); }

/* Search / filter bar */
.toolbar { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; margin-bottom: var(--s4); }
.toolbar .search { flex: 1 1 240px; max-width: 420px; }
.toolbar .select { width: auto; min-width: 140px; min-height: 40px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { height: 34px; padding: 0 14px; border-radius: var(--r-full); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-muted); font: 600 13px/1 var(--font-body); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip:hover { border-color: var(--text-subtle); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--deep-emerald); border-color: var(--deep-emerald); color: #fff; }
.chip .n { font-size: 11px; opacity: .75; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted); background: var(--surface-2); padding: 11px 14px; white-space: nowrap; border-bottom: 1px solid var(--border); }
.table th[data-sort] { cursor: pointer; user-select: none; }
.table th[data-sort]:hover { color: var(--text); }
.table th .arrow { opacity: .35; margin-left: 4px; }
.table th[aria-sort] .arrow { opacity: 1; color: var(--primary); }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr:hover { background: color-mix(in srgb, var(--emerald-50) 60%, transparent); }
.table tbody tr.selected { background: var(--emerald-50); }
.table .cell-person { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.table .cell-person strong { display: block; font-weight: 600; }
.table .cell-person small { color: var(--text-muted); font-size: 12.5px; }
.table input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--primary); }
.table-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: 10px 14px; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-muted); flex-wrap: wrap; }
.pager { display: flex; gap: 4px; }
.bulkbar { display: none; align-items: center; gap: var(--s3); padding: 10px 14px; background: var(--deep-emerald); color: #fff; border-radius: var(--r-md); margin-bottom: var(--s3); flex-wrap: wrap; }
.bulkbar.show { display: flex; }
.bulkbar .btn-secondary { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
@media (max-width: 760px) {
  table.table.responsive thead { display: none; }
  table.table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive tr { padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .table.responsive td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; gap: 12px; }
  .table.responsive td::before { content: attr(data-label); font-size: 12px; color: var(--text-subtle); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
  .table.responsive td.td-main { display: block; padding-bottom: 6px; }
  .table.responsive td.td-main::before { display: none; }
}

/* ---------- Lists, timeline, cards ---------- */
.list-item { display: flex; align-items: center; gap: var(--s3); min-width: 0; }
.list-item .li-body { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .li-sub { font-size: 13px; color: var(--text-muted); }
.ico-tile { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--emerald-50); color: var(--primary); }
.ico-tile.gold { background: var(--gold-50); color: var(--gold-dark); }
.ico-tile.danger { background: var(--danger-bg); color: var(--danger); }
.ico-tile.info { background: var(--info-bg); color: var(--info); }
.ico-tile.warning { background: var(--warning-bg); color: var(--warning); }
[data-theme="dark"] .ico-tile.gold { color: var(--soft-gold); }
.date-tile { width: 48px; flex: none; text-align: center; border-radius: 10px; border: 1px solid var(--border); overflow: hidden; background: var(--surface); }
.date-tile small { display: block; background: var(--deep-emerald); color: var(--soft-gold); font-size: 10px; font-weight: 700; letter-spacing: .08em; padding: 2px 0; text-transform: uppercase; }
.date-tile b { display: block; font-family: var(--font-display); font-size: 19px; padding: 3px 0 4px; }

.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 var(--s5) 34px; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; left: 10px; top: 22px; bottom: -2px; width: 2px; background: var(--border); }
.timeline li:last-child::before { display: none; }
.timeline .t-dot { position: absolute; left: 0; top: 2px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 2px solid var(--border-strong); color: var(--text-subtle); }
.timeline li.done .t-dot { background: var(--primary); border-color: var(--primary); color: #fff; }
.timeline li.done::before { background: var(--primary); }
.timeline li.current .t-dot { border-color: var(--gold); background: var(--gold-50); color: var(--gold-dark); box-shadow: 0 0 0 4px color-mix(in srgb, var(--gold) 25%, transparent); }
.timeline .t-title { font-weight: 600; font-size: 14.5px; }
.timeline .t-meta { font-size: 12.5px; color: var(--text-muted); }
.timeline .t-body { font-size: 13.5px; color: var(--text-muted); margin-top: 4px; }

.person-card { text-align: center; padding: var(--s5) var(--s4); }
.person-card .avatar { margin: 0 auto var(--s3); }
.person-card .pc-name { font-weight: 650; }
.person-card .pc-sub { font-size: 13px; color: var(--text-muted); }
.person-card .pc-number { position: absolute; top: 12px; left: 12px; font-family: var(--font-display); font-size: 13px; color: var(--gold-dark); background: var(--gold-50); border-radius: 6px; padding: 1px 8px; }
.person-card { position: relative; }

.notif { display: flex; gap: var(--s3); padding: var(--s4); border-radius: var(--r-md); position: relative; }
.notif.unread { background: color-mix(in srgb, var(--emerald-50) 70%, transparent); }
.notif.unread::after { content: ""; position: absolute; right: 16px; top: 20px; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
.notif .n-title { font-weight: 600; font-size: 14.5px; padding-right: 18px; }
.notif .n-body { font-size: 13.5px; color: var(--text-muted); margin: 2px 0 4px; }
.notif .n-time { font-size: 12px; color: var(--text-subtle); }

/* Steps */
.steps { display: flex; gap: 0; list-style: none; padding: 0; margin: 0 0 var(--s6); counter-reset: step; }
.steps li { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; position: relative; font-size: 12.5px; color: var(--text-subtle); font-weight: 600; text-align: center; }
.steps li::before { counter-increment: step; content: counter(step); width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 2px solid var(--border-strong); z-index: 1; font-size: 13px; color: var(--text-muted); }
.steps li::after { content: ""; position: absolute; top: 15px; left: 50%; width: 100%; height: 2px; background: var(--border); }
.steps li:last-child::after { display: none; }
.steps li.done::before { content: "✓"; background: var(--primary); border-color: var(--primary); color: #fff; }
.steps li.done::after { background: var(--primary); }
.steps li.current { color: var(--text); }
.steps li.current::before { border-color: var(--primary); color: var(--primary); box-shadow: 0 0 0 4px var(--emerald-50); }
@media (max-width: 560px) { .steps li span { display: none; } .steps li.current span { display: block; position: absolute; top: 38px; white-space: nowrap; } .steps { margin-bottom: var(--s8); } }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: var(--s5); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 12px 14px; border: 0; background: none; font: 600 14px/1 var(--font-body); color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--gold); }
.tab .n { font-size: 11px; background: var(--surface-2); border-radius: 10px; padding: 2px 7px; margin-left: 6px; color: var(--text-muted); }
.segmented { display: inline-flex; padding: 3px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--border); gap: 2px; }
.segmented button { border: 0; background: none; padding: 7px 14px; border-radius: 8px; font: 600 13px/1 var(--font-body); color: var(--text-muted); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
[role="tabpanel"][hidden] { display: none; }

/* ---------- States ---------- */
.empty { text-align: center; padding: var(--s10) var(--s5); color: var(--text-muted); }
.empty .e-ico { width: 64px; height: 64px; margin: 0 auto var(--s4); border-radius: 50%; display: grid; place-items: center; background: var(--gold-50); color: var(--gold-dark); border: 1px solid var(--soft-gold); }
.empty.error .e-ico { background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.empty h3 { margin-bottom: 6px; color: var(--text); font-family: var(--font-display); font-size: 20px; font-weight: 600; }
.empty p { max-width: 420px; margin: 0 auto var(--s4); }
.skel { background: linear-gradient(90deg, var(--surface-2) 0%, color-mix(in srgb, var(--surface-2) 40%, var(--surface)) 50%, var(--surface-2) 100%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 8px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.alert { display: flex; gap: var(--s3); align-items: flex-start; padding: 12px 14px; border-radius: var(--r-md); font-size: 14px; border: 1px solid; }
.alert svg { flex: none; margin-top: 1px; }
.alert.info { background: var(--info-bg); color: var(--info); border-color: color-mix(in srgb, var(--info) 22%, transparent); }
.alert.success { background: var(--success-bg); color: var(--success); border-color: color-mix(in srgb, var(--success) 22%, transparent); }
.alert.warning { background: var(--warning-bg); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 25%, transparent); }
.alert.danger { background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert.demo { background: var(--gold-50); color: var(--gold-dark); border-color: var(--soft-gold); }
[data-theme="dark"] .alert.demo { color: var(--soft-gold); border-color: #5A4C2A; }
.alert strong { color: inherit; }
.alert .a-body { flex: 1; }
.offline-bar { position: fixed; top: 0; left: 0; right: 0; z-index: 90; background: var(--charcoal); color: #fff; text-align: center; font-size: 13px; padding: 8px; transform: translateY(-100%); transition: transform .25s; }
body.is-offline .offline-bar { transform: none; }

/* ---------- Overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 80; background: rgba(12,23,20,.5); display: flex; align-items: center; justify-content: center; padding: var(--s4); animation: fade .18s ease; }
.modal { background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; animation: pop .22s var(--ease); }
.modal.lg { max-width: 760px; }
.modal-head { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s5) var(--s5) 0; }
.modal-head h2 { font-size: 19px; flex: 1; font-family: var(--font-display); font-weight: 600; }
.modal-body { padding: var(--s4) var(--s5); overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s3); padding: var(--s4) var(--s5) var(--s5); flex-wrap: wrap; }
.modal .m-ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex: none; background: var(--emerald-50); color: var(--primary); }
.modal .m-ico.danger { background: var(--danger-bg); color: var(--danger); }
.modal .m-ico.warning { background: var(--warning-bg); color: var(--warning); }
.drawer-overlay { justify-content: flex-end; padding: 0; align-items: stretch; }
.drawer { background: var(--surface); width: min(560px, 100%); height: 100%; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: slide .26s var(--ease); }
.drawer .modal-head { padding: var(--s5); border-bottom: 1px solid var(--border); align-items: center; }
.drawer .modal-body { flex: 1; padding: var(--s5); }
.drawer .modal-foot { border-top: 1px solid var(--border); padding: var(--s4) var(--s5); }
@media (max-width: 760px) {
  .overlay:not(.drawer-overlay) { align-items: flex-end; padding: 0; }
  .modal { border-radius: var(--r-xl) var(--r-xl) 0 0; max-height: 92vh; animation: sheet .28s var(--ease); }
  .modal::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--border-strong); margin: 10px auto -6px; }
  .drawer-overlay { align-items: flex-end; }
  .drawer { height: 92vh; border-radius: var(--r-xl) var(--r-xl) 0 0; animation: sheet .28s var(--ease); width: 100%; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
@keyframes sheet { from { transform: translateY(60px); opacity: 0; } }
.menu { position: absolute; z-index: 60; min-width: 240px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); padding: 6px; animation: pop .16s var(--ease); }
.menu .menu-label { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--text-subtle); padding: 8px 10px 4px; font-weight: 650; }
.menu a, .menu button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; border: 0; background: none; font: 500 14px/1.3 var(--font-body); color: var(--text); text-align: left; cursor: pointer; text-decoration: none; }
.menu a:hover, .menu button:hover { background: var(--surface-2); text-decoration: none; }
.menu [aria-checked="true"] { background: var(--emerald-50); }
.menu .check-mark { margin-left: auto; color: var(--primary); }
.menu small { display: block; color: var(--text-muted); font-size: 12px; }
.menu hr { margin: 6px 0; }
.toasts { position: fixed; z-index: 100; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: 10px; align-items: center; min-width: 260px; max-width: 380px; padding: 12px 14px; border-radius: var(--r-md); background: var(--charcoal); color: #fff; box-shadow: var(--shadow-lg); font-size: 14px; animation: pop .2s var(--ease); }
.toast.success svg { color: #6EE7B7; }
.toast.danger svg { color: #FCA5A5; }
.toast.info svg { color: var(--soft-gold); }
@media (max-width: 760px) { .toasts { left: 16px; right: 16px; bottom: calc(var(--bottomnav-h) + 16px); } .toast { max-width: none; } }

.switcher-btn { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border-radius: var(--r-md); border: 1px solid var(--border); background: var(--surface); font: 600 13.5px/1 var(--font-body); color: var(--text); cursor: pointer; max-width: 240px; }
.switcher-btn:hover { border-color: var(--border-strong); }
.switcher-btn .sw-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switcher-btn .sw-kicker { font-size: 10.5px; color: var(--text-subtle); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; display: block; margin-bottom: 2px; }
.switcher-btn.role { background: var(--deep-emerald); color: #fff; border-color: var(--deep-emerald); }
.switcher-btn.role .sw-kicker { color: var(--soft-gold); }
.org-dot { width: 22px; height: 22px; border-radius: 6px; flex: none; display: grid; place-items: center; font-size: 10px; font-weight: 800; color: #fff; }

/* ---------- Charts ---------- */
.chart { width: 100%; }
.chart text { fill: var(--text-muted); font-size: 11.5px; font-family: var(--font-body); }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .bar { transition: opacity .15s; }
.chart .bar:hover { opacity: .82; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--text-muted); margin-top: var(--s3); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.hbar { display: grid; grid-template-columns: minmax(90px, 32%) 1fr 48px; gap: 10px; align-items: center; font-size: 13px; padding: 5px 0; }
.hbar .track { height: 10px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; border-radius: 6px; background: var(--primary); }
.hbar b { text-align: right; font-variant-numeric: tabular-nums; }
.chart-tip { position: fixed; z-index: 120; pointer-events: none; background: var(--charcoal); color: #fff; font-size: 12.5px; padding: 6px 10px; border-radius: 8px; box-shadow: var(--shadow-md); white-space: nowrap; }

/* Calendar */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { font-size: 11px; font-weight: 700; color: var(--text-subtle); text-align: center; padding: 4px 0; text-transform: uppercase; letter-spacing: .06em; }
.cal .day { min-height: 74px; border: 1px solid var(--border); border-radius: 8px; padding: 5px 6px; font-size: 12px; background: var(--surface); display: flex; flex-direction: column; gap: 3px; overflow: hidden; }
.cal .day.out { opacity: .4; }
.cal .day.today { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.cal .day b { font-weight: 650; font-size: 12px; color: var(--text-muted); }
.cal .ev { font-size: 11px; line-height: 1.25; padding: 2px 5px; border-radius: 4px; background: var(--emerald-50); color: var(--primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.cal .ev.gold { background: var(--gold-50); color: var(--gold-dark); }
.cal .ev.danger { background: var(--danger-bg); color: var(--danger); }
@media (max-width: 600px) { .cal .day { min-height: 46px; } .cal .ev { font-size: 0; height: 6px; padding: 0; } }

/* Upload & gallery */
.dropzone { display: block; border: 2px dashed var(--border-strong); border-radius: var(--r-lg); padding: var(--s6); text-align: center; background: var(--surface-2); cursor: pointer; transition: border-color .15s, background .15s; color: var(--text-muted); }
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--emerald-50); }
.dropzone strong { color: var(--text); }
.file-row { display: flex; align-items: center; gap: var(--s3); padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); }
.file-row .progress { flex: 1; }
.gallery { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.gallery .g-item { aspect-ratio: 4/5; border-radius: var(--r-md); overflow: hidden; position: relative; cursor: pointer; border: 1px solid var(--border); background: var(--surface-2); }
.gallery .g-item img, .gallery .g-item svg { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery .g-item .g-cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 22px 10px 8px; font-size: 12px; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.6)); font-weight: 600; }
.gallery .g-item .g-badge { position: absolute; top: 8px; left: 8px; }
.gallery.video .g-item { aspect-ratio: 16/10; }
.play { position: absolute; inset: 0; display: grid; place-items: center; }
.play span { width: 46px; height: 46px; border-radius: 50%; background: rgba(255,255,255,.92); display: grid; place-items: center; color: var(--deep-emerald); }

/* Chat */
.chat { display: flex; flex-direction: column; height: calc(100vh - var(--topbar-h) - 48px); min-height: 480px; }
.chat-scroll { flex: 1; overflow-y: auto; padding: var(--s5); display: flex; flex-direction: column; gap: var(--s4); }
.bubble { max-width: min(640px, 86%); padding: 12px 16px; border-radius: 18px; font-size: 14.5px; line-height: 1.55; }
.bubble p:last-child { margin: 0; }
.bubble.me { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 6px; }
.bubble.coach { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.bubble-meta { font-size: 11.5px; color: var(--text-subtle); margin-top: -8px; }
.bubble-meta.me { align-self: flex-end; }
.typing { display: inline-flex; gap: 4px; padding: 14px 16px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-subtle); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.composer { border-top: 1px solid var(--border); padding: var(--s3) var(--s4); display: flex; gap: var(--s2); align-items: flex-end; background: var(--surface); }
.composer textarea { flex: 1; min-height: 44px; max-height: 160px; resize: none; }
.prompt-chip { border: 1px solid var(--border-strong); background: var(--surface); border-radius: var(--r-full); padding: 8px 14px; font: 500 13px/1.2 var(--font-body); color: var(--text); cursor: pointer; text-align: left; }
.prompt-chip:hover { border-color: var(--primary); background: var(--emerald-50); }
@media (max-width: 760px) { .chat { height: calc(100vh - 58px - var(--bottomnav-h) - 32px); } }

/* Kanban */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: var(--s3); overflow-x: auto; padding-bottom: var(--s2); }
.col { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s3); min-height: 200px; }
.col.drop { outline: 2px dashed var(--primary); outline-offset: -4px; }
.col-head { display: flex; justify-content: space-between; align-items: center; font-weight: 650; font-size: 13.5px; padding: 4px 6px 10px; }
.kcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 12px; margin-bottom: 8px; cursor: grab; box-shadow: var(--shadow-sm); }
.kcard:active { cursor: grabbing; }
.kcard.dragging { opacity: .5; }

/* Scoring */
.criterion { border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s4); background: var(--surface); }
.criterion.scored { border-color: var(--emerald-100); }
.criterion .c-head { display: flex; justify-content: space-between; gap: var(--s3); align-items: flex-start; }
.criterion .weight { font-family: var(--font-display); font-size: 15px; color: var(--gold-dark); background: var(--gold-50); border: 1px solid var(--soft-gold); padding: 2px 10px; border-radius: var(--r-full); white-space: nowrap; }
[data-theme="dark"] .criterion .weight { color: var(--soft-gold); }
.score-ctrl { display: flex; align-items: center; gap: var(--s3); margin-top: var(--s3); }
.score-ctrl .range { flex: 1; }
.score-ctrl .input { width: 84px; text-align: center; font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
.score-total { font-family: var(--font-display); font-size: 48px; line-height: 1; font-variant-numeric: tabular-nums; }
.sticky-side { position: sticky; top: calc(var(--topbar-h) + 16px); }

/* Auth / standalone */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.auth-art { background: var(--deep-emerald); color: #E3EEE9; padding: var(--s10); display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-art .brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.auth-art h1 { color: #fff; font-size: 42px; max-width: 460px; line-height: 1.12; }
.auth-art h1 em { color: var(--soft-gold); font-style: italic; font-weight: 500; }
.auth-art p { color: #B9CEC5; max-width: 420px; font-size: 16px; }
.auth-art .compass-bg { position: absolute; right: -140px; bottom: -140px; width: 520px; height: 520px; opacity: .14; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: var(--s8) var(--s6); }
.auth-form .inner { width: 100%; max-width: 420px; }
.auth-form h2 { font-family: var(--font-display); font-size: 30px; font-weight: 600; margin-bottom: 6px; }
.auth-form .lead { color: var(--text-muted); margin-bottom: var(--s6); }
.oauth { display: grid; gap: 10px; }
.or { display: flex; align-items: center; gap: 12px; color: var(--text-subtle); font-size: 12.5px; margin: var(--s5) 0; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth-art { padding: var(--s6); min-height: 0; }
  .auth-art h1 { font-size: 28px; }
  .auth-art .art-copy p, .auth-art .art-foot { display: none; }
  .auth-art .compass-bg { width: 280px; height: 280px; right: -80px; bottom: -110px; }
}
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: var(--s6); text-align: center; }
.center-screen .inner { max-width: 460px; }
.state-art { width: 120px; height: 120px; margin: 0 auto var(--s5); border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-md); color: var(--primary); }
.state-art.danger { color: var(--danger); }
.state-art.gold { color: var(--gold-dark); }
.code-pill { font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; }

/* Countdown */
.countdown { display: flex; gap: 10px; }
.countdown div { text-align: center; background: rgba(255,255,255,.08); border: 1px solid rgba(232,213,167,.25); border-radius: 12px; padding: 8px 10px; min-width: 62px; }
.countdown b { display: block; font-family: var(--font-display); font-size: 26px; color: #fff; font-variant-numeric: tabular-nums; line-height: 1.1; }
.countdown small { font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--soft-gold); }

/* Public profile preview */
.profile-cover { height: 150px; border-radius: var(--r-lg) var(--r-lg) 0 0; background: linear-gradient(120deg, var(--deep-emerald), #0E6B52 55%, #2F7F63); position: relative; overflow: hidden; }
.profile-cover::after { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 85% 30%, rgba(232,213,167,.35), transparent 40%); }
.profile-id { display: flex; align-items: flex-end; gap: var(--s4); margin-top: -48px; padding: 0 var(--s5); position: relative; flex-wrap: wrap; }
.profile-id .avatar { box-shadow: 0 0 0 4px var(--surface), 0 0 0 6px var(--gold); }

/* Hub */
.hub-hero { background: var(--deep-emerald); color: #E3EEE9; padding: 56px var(--s6) 64px; position: relative; overflow: hidden; }
.hub-hero .wrap, .hub-body { max-width: 1180px; margin: 0 auto; }
.hub-hero h1 { color: #fff; font-size: 44px; max-width: 640px; }
.hub-hero h1 em { color: var(--soft-gold); font-style: italic; font-weight: 500; }
.hub-hero p { color: #B9CEC5; max-width: 600px; font-size: 16.5px; }
.hub-body { padding: var(--s8) var(--s6) var(--s12); margin-top: -36px; position: relative; }
.role-tile { display: flex; flex-direction: column; gap: 10px; text-decoration: none; color: inherit; }
.role-tile:hover { text-decoration: none; }
.screen-list { columns: 2; column-gap: var(--s6); font-size: 14px; margin: 0; padding: 0; list-style: none; }
.screen-list li { break-inside: avoid; padding: 4px 0; display: flex; gap: 8px; align-items: baseline; }
.screen-list li::before { content: "—"; color: var(--gold); }
@media (max-width: 640px) { .screen-list { columns: 1; } .hub-hero h1 { font-size: 32px; } }

/* Utility */
.hide { display: none !important; }
.mt-0 { margin-top: 0 !important; } .mt-2 { margin-top: var(--s2); } .mt-4 { margin-top: var(--s4); } .mt-6 { margin-top: var(--s6); }
.mb-0 { margin-bottom: 0 !important; } .mb-2 { margin-bottom: var(--s2); } .mb-4 { margin-bottom: var(--s4); }
.w-full { width: 100%; }
.text-right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fade-in { animation: fade .3s ease; }
.prose { max-width: 720px; }
.prose h3 { margin: var(--s6) 0 var(--s2); }
.prose p, .prose li { color: var(--text-muted); }
details.faq { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); padding: 0 var(--s4); }
details.faq + details.faq { margin-top: var(--s2); }
details.faq summary { cursor: pointer; padding: var(--s4) 0; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: var(--s3); }
details.faq summary::-webkit-details-marker { display: none; }
details.faq summary::after { content: "+"; font-size: 20px; line-height: 1; color: var(--gold-dark); }
details.faq[open] summary::after { content: "–"; }
details.faq p { color: var(--text-muted); padding-bottom: var(--s4); margin: 0; }
mark { background: var(--soft-gold); color: var(--charcoal); border-radius: 3px; padding: 0 2px; }

/* Fixes */
[hidden] { display: none !important; }
.divider-list > a { display: block; }
.divider-list > a.list-item { display: flex; }
.profile-id { margin-top: 0; align-items: flex-start; padding-top: 0; }
.profile-id > .avatar { margin-top: -56px; }
.profile-id > div { padding-top: 14px; }
.range[data-unset] { opacity: .35; }
.page-head .select { width: auto; }
@media (max-width: 1100px) { .layout-main-side { grid-template-columns: minmax(0, 1fr) !important; } .sticky-side { position: static; } }
@media (max-width: 760px) { .hide-sm { display: none !important; } .chat { min-height: 420px; } }
.grid-2 > *, .grid-3 > *, .grid-4 > *, .stack > * { min-width: 0; }
