/* =========================================================================
   styles.css — design tokens, app shell, reusable components
   Identity: warm paper, editorial serif headings, blush + plum + sage,
   soft physical depth. Calm to sit in, dense enough to actually work in.
   ========================================================================= */

/* ------------------------------- tokens --------------------------------- */
:root {
  /* paper & ink */
  --paper:        #FAF6F2;
  --paper-2:      #F3EDE7;
  --surface:      #FFFFFF;
  --surface-2:    #FBF8F5;
  --surface-3:    #F5EFEA;
  --ink:          #2A2330;
  --ink-2:        #5A4F60;
  --ink-3:        #8B7F91;
  --line:         #E7DED6;
  --line-2:       #D9CCC1;

  /* brand */
  --plum:         #6B4470;
  --plum-soft:    #F0E6F2;
  --plum-deep:    #4A2C50;
  --blush:        #D98A93;
  --blush-soft:   #FBEBEC;
  --sage:         #7E9B7A;
  --sage-soft:    #E9F1E7;
  --gold:         #C29A3E;
  --gold-soft:    #FAF1DC;

  /* semantic */
  --ok:           #4E8C63;
  --ok-soft:      #E4F1E8;
  --warn:         #C98A2E;
  --warn-soft:    #FCF0DB;
  --danger:       #C15C58;
  --danger-soft:  #FBE7E5;
  --info:         #5B7FA8;
  --info-soft:    #E6EDF5;

  /* chart series */
  --c1: #6B4470;  --c2: #D98A93;  --c3: #7E9B7A;  --c4: #C29A3E;
  --c5: #5B7FA8;  --c6: #B0758F;  --c7: #8C9BA8;

  /* geometry */
  --r-xs: 8px;  --r-sm: 12px;  --r-md: 16px;  --r-lg: 22px;  --r-xl: 28px;
  --r-pill: 999px;

  /* elevation — soft, warm-tinted, never grey */
  --sh-1: 0 1px 2px rgba(42,35,48,.05), 0 1px 1px rgba(42,35,48,.03);
  --sh-2: 0 2px 4px rgba(42,35,48,.04), 0 8px 20px -10px rgba(42,35,48,.14);
  --sh-3: 0 4px 8px rgba(42,35,48,.05), 0 20px 44px -16px rgba(42,35,48,.20);
  --sh-4: 0 8px 16px rgba(42,35,48,.06), 0 32px 70px -20px rgba(42,35,48,.28);
  --ring: 0 0 0 3px rgba(107,68,112,.18);

  /* type */
  --font-display: 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --font-body: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', ui-monospace, 'Cascadia Mono', Menlo, Consolas, monospace;

  /* layout */
  --sidebar-w: 254px;
  --topbar-h: 66px;
  --gutter: 26px;

  /* motion */
  --ease: cubic-bezier(.32, .72, 0, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --t-fast: 130ms;
  --t: 220ms;
  --t-slow: 420ms;
}

/* dark: dusk, not black. Keeps the warmth. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #16121A;  --paper-2: #1B1620;  --surface: #211A27;
    --surface-2: #261E2D;  --surface-3: #2E2436;
    --ink: #F4EEF4;  --ink-2: #C3B6C8;  --ink-3: #918498;
    --line: #342A3C;  --line-2: #44384D;
    --plum: #C79FCC;  --plum-soft: #32243A;  --plum-deep: #E3CDE6;
    --blush: #E8A3AC;  --blush-soft: #3A252C;
    --sage: #9DBE98;  --sage-soft: #24301F;
    --gold: #DDB558;  --gold-soft: #372D18;
    --ok: #7FC195;  --ok-soft: #1F3227;
    --warn: #E0AD5E;  --warn-soft: #362A18;
    --danger: #E38B86;  --danger-soft: #3A2320;
    --info: #92B4D8;  --info-soft: #1F2A36;
    --c1: #C79FCC; --c2: #E8A3AC; --c3: #9DBE98; --c4: #DDB558;
    --c5: #92B4D8; --c6: #D79BB4; --c7: #A3B0BC;
    --sh-1: 0 1px 2px rgba(0,0,0,.30);
    --sh-2: 0 2px 6px rgba(0,0,0,.34), 0 10px 26px -12px rgba(0,0,0,.55);
    --sh-3: 0 6px 14px rgba(0,0,0,.38), 0 24px 52px -18px rgba(0,0,0,.62);
    --sh-4: 0 10px 22px rgba(0,0,0,.44), 0 36px 80px -22px rgba(0,0,0,.70);
    --ring: 0 0 0 3px rgba(199,159,204,.26);
  }
}
:root[data-theme="dark"] {
  --paper: #16121A;  --paper-2: #1B1620;  --surface: #211A27;
  --surface-2: #261E2D;  --surface-3: #2E2436;
  --ink: #F4EEF4;  --ink-2: #C3B6C8;  --ink-3: #918498;
  --line: #342A3C;  --line-2: #44384D;
  --plum: #C79FCC;  --plum-soft: #32243A;  --plum-deep: #E3CDE6;
  --blush: #E8A3AC;  --blush-soft: #3A252C;
  --sage: #9DBE98;  --sage-soft: #24301F;
  --gold: #DDB558;  --gold-soft: #372D18;
  --ok: #7FC195;  --ok-soft: #1F3227;
  --warn: #E0AD5E;  --warn-soft: #362A18;
  --danger: #E38B86;  --danger-soft: #3A2320;
  --info: #92B4D8;  --info-soft: #1F2A36;
  --c1: #C79FCC; --c2: #E8A3AC; --c3: #9DBE98; --c4: #DDB558;
  --c5: #92B4D8; --c6: #D79BB4; --c7: #A3B0BC;
  --sh-1: 0 1px 2px rgba(0,0,0,.30);
  --sh-2: 0 2px 6px rgba(0,0,0,.34), 0 10px 26px -12px rgba(0,0,0,.55);
  --sh-3: 0 6px 14px rgba(0,0,0,.38), 0 24px 52px -18px rgba(0,0,0,.62);
  --sh-4: 0 10px 22px rgba(0,0,0,.44), 0 36px 80px -22px rgba(0,0,0,.70);
  --ring: 0 0 0 3px rgba(199,159,204,.26);
}

/* ------------------------------- reset ---------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* a whisper of paper grain — grounds the whole surface */
body::before {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none; z-index: 0;
  opacity: .5;
  background-image:
    radial-gradient(circle at 12% 8%, rgba(217,138,147,.07), transparent 42%),
    radial-gradient(circle at 88% 4%, rgba(107,68,112,.06), transparent 40%),
    radial-gradient(circle at 70% 92%, rgba(126,155,122,.05), transparent 46%);
}

h1, h2, h3, h4 { font-weight: 600; line-height: 1.2; letter-spacing: -.012em; }
h1 { font-family: var(--font-display); font-size: clamp(1.55rem, 3.2vw, 2rem); font-weight: 600; letter-spacing: -.02em; }
h2 { font-family: var(--font-display); font-size: 1.16rem; font-weight: 600; }
h3 { font-size: .95rem; }

a { color: var(--plum); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; max-width: 100%; }
ul, ol { padding: 0; list-style: none; }

:focus-visible { outline: 2px solid var(--plum); outline-offset: 2px; border-radius: 6px; }

::selection { background: var(--plum-soft); color: var(--plum-deep); }

/* scrollbars, quietly */
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--ink-3); background-clip: content-box; }

.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

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

/* =============================== SHELL ================================== */
.shell { display: flex; min-height: 100vh; position: relative; z-index: 1; }

/* ------------------------------ sidebar --------------------------------- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  z-index: 40;
}
.sidebar__head {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand__mark {
  width: 34px; height: 34px; flex: 0 0 34px;
  display: grid; place-items: center;
  font-size: 17px;
  background: linear-gradient(145deg, var(--blush-soft), var(--plum-soft));
  border-radius: 11px;
  box-shadow: var(--sh-1);
}
.brand__text { display: flex; flex-direction: column; min-width: 0; }
.brand__text strong {
  font-family: var(--font-display); font-size: 1.04rem; font-weight: 600;
  letter-spacing: -.02em; line-height: 1.15;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand__text small { font-size: .66rem; color: var(--ink-3); letter-spacing: .09em; text-transform: uppercase; }
.sidebar__close { display: none; }

.nav { flex: 1 1 auto; overflow-y: auto; padding: 14px 10px 18px; }
.nav__group { margin-bottom: 18px; }
.nav__label {
  font-size: .63rem; font-weight: 700; letter-spacing: .13em; text-transform: uppercase;
  color: var(--ink-3); padding: 0 10px 7px;
}
.nav__item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--r-sm);
  color: var(--ink-2); font-weight: 500; font-size: .875rem;
  position: relative; cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
  width: 100%; text-align: left;
}
.nav__item:hover { background: var(--surface-3); color: var(--ink); text-decoration: none; }
.nav__item:active { transform: scale(.985); }
.nav__item.is-active { background: var(--plum-soft); color: var(--plum-deep); font-weight: 600; }
.nav__item.is-active::before {
  content: ''; position: absolute; left: -10px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 17px; background: var(--plum); border-radius: 0 3px 3px 0;
}
.nav__ico { width: 19px; text-align: center; font-size: 15px; flex: 0 0 19px; opacity: .9; }
.nav__txt { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav__count {
  font-size: .68rem; font-weight: 700; min-width: 19px; height: 19px;
  padding: 0 6px; border-radius: var(--r-pill);
  display: grid; place-items: center;
  background: var(--surface-3); color: var(--ink-2);
}
.nav__count--hot { background: var(--danger-soft); color: var(--danger); }
.nav__count--warm { background: var(--warn-soft); color: var(--warn); }

.sidebar__foot { flex: 0 0 auto; padding: 12px; border-top: 1px solid var(--line); }
.calmchip {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--line);
  cursor: pointer; transition: box-shadow var(--t), transform var(--t), border-color var(--t);
}
.calmchip:hover { box-shadow: var(--sh-2); transform: translateY(-1px); border-color: var(--line-2); }
.calmchip__ring { flex: 0 0 34px; width: 34px; height: 34px; }
.calmchip__txt { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.calmchip__txt strong { font-size: .84rem; font-weight: 600; }
.calmchip__txt small { font-size: .66rem; color: var(--ink-3); letter-spacing: .05em; text-transform: uppercase; }

.sidebar__scrim {
  display: none; position: fixed; inset: 0; z-index: 39;
  background: rgba(42,35,48,.42); backdrop-filter: blur(2px);
}

/* -------------------------------- main ---------------------------------- */
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 14px;
  padding: 0 var(--gutter);
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: saturate(150%) blur(14px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .topbar { background: var(--paper); }
}
.topbar__burger { display: none; }
.topbar__actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

/* ------------------------------- search --------------------------------- */
.search { position: relative; flex: 1 1 440px; max-width: 480px; }
.search__icon {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--ink-3); font-size: 17px; pointer-events: none;
}
.search__input {
  width: 100%; height: 40px;
  padding: 0 46px 0 36px;
  border: 1px solid var(--line); border-radius: var(--r-pill);
  background: var(--surface); color: var(--ink);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.search__input::placeholder { color: var(--ink-3); }
.search__input:focus { outline: none; border-color: var(--plum); box-shadow: var(--ring); }
.search__input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search__kbd {
  position: absolute; right: 11px; top: 50%; transform: translateY(-50%);
  font-family: var(--font-mono); font-size: .68rem;
  padding: 2px 7px; border-radius: 6px;
  background: var(--surface-3); color: var(--ink-3);
  border: 1px solid var(--line); pointer-events: none;
}
.search__input:focus ~ .search__kbd { opacity: 0; }
.search__results {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); box-shadow: var(--sh-4);
  max-height: min(64vh, 480px); overflow-y: auto; z-index: 60;
  padding: 6px;
  animation: pop var(--t) var(--ease-out);
}
.sres {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: var(--r-sm); cursor: pointer; width: 100%; text-align: left;
}
.sres:hover, .sres.is-sel { background: var(--surface-3); }
.sres__ico { flex: 0 0 24px; font-size: 15px; text-align: center; }
.sres__body { min-width: 0; flex: 1 1 auto; display: flex; flex-direction: column; }
.sres__title { display: block; font-weight: 600; font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sres__meta { display: block; font-size: .74rem; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sres__type {
  font-size: .62rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-3); flex: 0 0 auto; padding-left: 8px;
}
.sres__group {
  font-size: .63rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-3); padding: 10px 11px 5px;
}
.sres__empty { padding: 22px 14px; text-align: center; color: var(--ink-3); font-size: .85rem; }

/* -------------------------------- view ---------------------------------- */
.view {
  flex: 1 1 auto; min-width: 0;
  padding: 26px var(--gutter) 76px;
  max-width: 1480px; width: 100%;
  animation: rise var(--t-slow) var(--ease-out);
}
@keyframes rise { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: translateY(-5px) scale(.985); } to { opacity: 1; transform: none; } }

/* ------------------------------- tabbar (mobile) ------------------------ */
.tabbar {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 35;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(160%) blur(16px);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
@supports not (background: color-mix(in srgb, red 50%, blue)) { .tabbar { background: var(--surface); } }
.tabbar__inner { display: flex; }
.tabbar__item {
  flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px; border-radius: var(--r-sm);
  color: var(--ink-3); font-size: .63rem; font-weight: 600;
  position: relative; min-width: 0;
}
.tabbar__item span:first-child { font-size: 19px; line-height: 1; }
.tabbar__item.is-active { color: var(--plum); }
.tabbar__item .dot {
  position: absolute; top: 4px; right: calc(50% - 15px);
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--danger); border: 1.5px solid var(--surface);
}

/* ============================ COMPONENTS ================================ */

/* ------------------------------ page head ------------------------------- */
.phead {
  display: flex; align-items: flex-end; gap: 18px; flex-wrap: wrap;
  margin-bottom: 22px;
}
.phead__body { flex: 1 1 320px; min-width: 0; }
.phead__eyebrow {
  font-size: .68rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: var(--blush); margin-bottom: 5px;
}
.phead__sub { color: var(--ink-2); font-size: .9rem; margin-top: 5px; max-width: 68ch; }
.phead__actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* -------------------------------- cards --------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
  transition: box-shadow var(--t), transform var(--t), border-color var(--t);
}
.card--pad { padding: 20px; }
.card--hover:hover { box-shadow: var(--sh-3); transform: translateY(-2px); border-color: var(--line-2); }
.card__head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.card__head h2, .card__head h3 { flex: 1 1 auto; min-width: 0; }
.card__body { padding: 20px; }
.card__body--flush { padding: 0; }
.card__foot { padding: 13px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.card__hint { font-size: .76rem; color: var(--ink-3); margin-top: 10px; line-height: 1.5; }

/* grids */
.grid { display: grid; gap: 16px; }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(198px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(258px, 1fr)); }
.grid--wide { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); }
.grid--side { grid-template-columns: minmax(0, 1fr) minmax(0, 340px); align-items: start; }
@media (max-width: 1080px) { .grid--wide, .grid--side { grid-template-columns: 1fr; } }

.stack { display: flex; flex-direction: column; gap: 16px; }
.stack--sm { gap: 9px; }
.stack--lg { gap: 24px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.row--tight { gap: 6px; }
.spacer { flex: 1 1 auto; }

/* -------------------------------- stat ---------------------------------- */
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 17px 18px;
  box-shadow: var(--sh-1);
  position: relative; overflow: hidden;
  transition: box-shadow var(--t), transform var(--t);
}
.stat--link { cursor: pointer; }
.stat--link:hover { box-shadow: var(--sh-3); transform: translateY(-2px); }
.stat::after {
  content: ''; position: absolute; inset: 0 0 auto auto;
  width: 82px; height: 82px; border-radius: 50%;
  background: var(--accent-soft, var(--plum-soft));
  opacity: .5; transform: translate(30%, -42%);
  pointer-events: none;
}
.stat__label {
  font-size: .71rem; font-weight: 700; letter-spacing: .085em; text-transform: uppercase;
  color: var(--ink-3); display: flex; align-items: center; gap: 6px;
  position: relative; z-index: 1;
}
.stat__value {
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 2.5vw, 1.72rem); font-weight: 600;
  letter-spacing: -.024em; line-height: 1.12; margin-top: 7px;
  position: relative; z-index: 1;
  font-variant-numeric: tabular-nums;
}
.stat__value--sm { font-size: 1.28rem; }
.stat__meta { font-size: .78rem; color: var(--ink-2); margin-top: 5px; position: relative; z-index: 1; }
.stat__spark { margin-top: 10px; position: relative; z-index: 1; }
.stat--plum   { --accent: var(--plum);   --accent-soft: var(--plum-soft); }
.stat--blush  { --accent: var(--blush);  --accent-soft: var(--blush-soft); }
.stat--sage   { --accent: var(--sage);   --accent-soft: var(--sage-soft); }
.stat--gold   { --accent: var(--gold);   --accent-soft: var(--gold-soft); }
.stat--danger { --accent: var(--danger); --accent-soft: var(--danger-soft); }
.stat--info   { --accent: var(--info);   --accent-soft: var(--info-soft); }

/* ------------------------------- buttons -------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 16px;
  border-radius: var(--r-pill);
  font-size: .855rem; font-weight: 600;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-2);
  cursor: pointer; white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast), color var(--t-fast);
}
.btn:hover { background: var(--surface-3); border-color: var(--ink-3); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn--primary {
  background: var(--plum); color: #fff; border-color: transparent;
  box-shadow: 0 1px 2px rgba(42,35,48,.14), 0 6px 16px -6px rgba(107,68,112,.5);
}
.btn--primary:hover { background: var(--plum-deep); border-color: transparent; }
/* on dusk the plum token is light, so flip the label to keep contrast */
:root[data-theme="dark"] .btn--primary { color: #1B1421; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn--primary { color: #1B1421; }
}
.btn--ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn--ghost:hover { background: var(--surface-3); color: var(--ink); border-color: transparent; }
.btn--danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn--danger:hover { background: var(--danger); color: #fff; border-color: transparent; }
.btn--sm { height: 32px; padding: 0 13px; font-size: .8rem; }
.btn--xs { height: 27px; padding: 0 10px; font-size: .74rem; gap: 5px; }
.btn--block { width: 100%; }
.btn--lg { height: 44px; padding: 0 22px; font-size: .92rem; }

.iconbtn {
  width: 38px; height: 38px; flex: 0 0 38px;
  display: grid; place-items: center;
  border-radius: var(--r-pill); font-size: 16px;
  color: var(--ink-2); position: relative;
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.iconbtn:hover { background: var(--surface-3); color: var(--ink); }
.iconbtn:active { transform: scale(.93); }
.iconbtn--sm { width: 30px; height: 30px; flex: 0 0 30px; font-size: 14px; }
.iconbtn .dot {
  position: absolute; top: 7px; right: 8px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger); border: 1.5px solid var(--paper);
  animation: pulse 2.4s var(--ease) infinite;
}
@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.22); opacity: .78; } }

/* ------------------------------- pills ---------------------------------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  height: 23px; padding: 0 9px;
  border-radius: var(--r-pill);
  font-size: .715rem; font-weight: 600; letter-spacing: .01em;
  background: var(--surface-3); color: var(--ink-2);
  white-space: nowrap; max-width: 100%;
}
.pill--ok { background: var(--ok-soft); color: var(--ok); }
.pill--warn { background: var(--warn-soft); color: var(--warn); }
.pill--danger { background: var(--danger-soft); color: var(--danger); }
.pill--info { background: var(--info-soft); color: var(--info); }
.pill--plum { background: var(--plum-soft); color: var(--plum-deep); }
.pill--blush { background: var(--blush-soft); color: #A85761; }
.pill--sage { background: var(--sage-soft); color: #4E7049; }
.pill--gold { background: var(--gold-soft); color: #8A6A19; }
.pill--outline { background: transparent; border: 1px solid var(--line-2); color: var(--ink-2); }
.pill--lg { height: 28px; padding: 0 12px; font-size: .78rem; }
.pill__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: 0 0 6px; }

/* stage colours */
.stage--slate   { background: #EEF0F3; color: #54606E; }
.stage--sky     { background: #E4F0F7; color: #35708F; }
.stage--rose    { background: var(--blush-soft); color: #A85761; }
.stage--violet  { background: var(--plum-soft); color: var(--plum-deep); }
.stage--amber   { background: var(--warn-soft); color: var(--warn); }
.stage--orange  { background: #FBE8D9; color: #A9622C; }
.stage--emerald { background: var(--ok-soft); color: var(--ok); }
.stage--teal    { background: #DFF0EE; color: #2F736C; }
.stage--indigo  { background: #E6E7F7; color: #4E52A0; }
.stage--sage    { background: var(--sage-soft); color: #4E7049; }
:root[data-theme="dark"] .stage--slate { background: #2B313A; color: #A9B5C2; }
:root[data-theme="dark"] .stage--sky { background: #1E2E38; color: #8FC3DE; }
:root[data-theme="dark"] .stage--orange { background: #382518; color: #E2A46F; }
:root[data-theme="dark"] .stage--teal { background: #1B302E; color: #7FC3BB; }
:root[data-theme="dark"] .stage--indigo { background: #232541; color: #A4A8E8; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .stage--slate { background: #2B313A; color: #A9B5C2; }
  :root:not([data-theme="light"]) .stage--sky { background: #1E2E38; color: #8FC3DE; }
  :root:not([data-theme="light"]) .stage--orange { background: #382518; color: #E2A46F; }
  :root:not([data-theme="light"]) .stage--teal { background: #1B302E; color: #7FC3BB; }
  :root:not([data-theme="light"]) .stage--indigo { background: #232541; color: #A4A8E8; }
  :root:not([data-theme="light"]) .pill--blush { color: #E8A3AC; }
  :root:not([data-theme="light"]) .pill--sage { color: #9DBE98; }
  :root:not([data-theme="light"]) .pill--gold { color: #DDB558; }
}
:root[data-theme="dark"] .pill--blush { color: #E8A3AC; }
:root[data-theme="dark"] .pill--sage { color: #9DBE98; }
:root[data-theme="dark"] .pill--gold { color: #DDB558; }

/* ------------------------------- avatar --------------------------------- */
.avatar {
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 13px;
  display: grid; place-items: center;
  font-weight: 700; font-size: .82rem; letter-spacing: .01em;
  background: linear-gradient(145deg, var(--plum-soft), var(--blush-soft));
  color: var(--plum-deep);
  box-shadow: inset 0 0 0 1px rgba(107,68,112,.08);
}
.avatar--lg { width: 54px; height: 54px; flex: 0 0 54px; border-radius: 17px; font-size: 1.1rem; }
.avatar--sm { width: 30px; height: 30px; flex: 0 0 30px; border-radius: 10px; font-size: .7rem; }

/* ------------------------------ progress -------------------------------- */
.bar { height: 7px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.bar__fill {
  height: 100%; border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--plum), var(--blush));
  transition: width var(--t-slow) var(--ease-out);
  min-width: 2px;
}
.bar--sm { height: 5px; }
.bar--lg { height: 10px; }
.bar__fill--ok { background: linear-gradient(90deg, var(--ok), var(--sage)); }
.bar__fill--warn { background: linear-gradient(90deg, var(--warn), var(--gold)); }
.bar__fill--danger { background: linear-gradient(90deg, var(--danger), var(--blush)); }
.bar__fill--info { background: linear-gradient(90deg, var(--info), #8FB3D4); }

.barlabel { display: flex; justify-content: space-between; font-size: .74rem; color: var(--ink-3); margin-bottom: 5px; }
.barlabel strong { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ------------------------------- tables --------------------------------- */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .86rem; }
.tbl th {
  text-align: left; font-size: .68rem; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase; color: var(--ink-3);
  padding: 11px 14px; border-bottom: 1px solid var(--line);
  white-space: nowrap; background: var(--surface-2);
  position: sticky; top: 0; z-index: 1;
}
.tbl th.num, .tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl th.ctr, .tbl td.ctr { text-align: center; }
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr { transition: background var(--t-fast); }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr.is-clickable { cursor: pointer; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl__sub { font-size: .75rem; color: var(--ink-3); }
.tbl__main { font-weight: 600; }
.tbl__actions { display: flex; gap: 3px; justify-content: flex-end; opacity: .45; transition: opacity var(--t-fast); }
tr:hover .tbl__actions, .tbl__actions:focus-within { opacity: 1; }
.tbl--sortable th[data-sort] { cursor: pointer; user-select: none; }
.tbl--sortable th[data-sort]:hover { color: var(--ink); }
.tbl th .sortmark { opacity: .55; font-size: .6rem; margin-left: 3px; }

/* ------------------------------ empty state ----------------------------- */
.empty { text-align: center; padding: 46px 22px; }
.empty__ico { font-size: 38px; margin-bottom: 12px; opacity: .65; }
.empty__title { font-family: var(--font-display); font-size: 1.06rem; font-weight: 600; margin-bottom: 5px; }
.empty__sub { color: var(--ink-3); font-size: .86rem; max-width: 44ch; margin: 0 auto 16px; line-height: 1.55; }

/* -------------------------------- forms --------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field__label { font-size: .78rem; font-weight: 600; color: var(--ink-2); display: flex; gap: 5px; align-items: baseline; }
.field__req { color: var(--blush); font-weight: 700; }
.field__hint { font-size: .73rem; color: var(--ink-3); line-height: 1.45; }
.field__err { font-size: .73rem; color: var(--danger); font-weight: 600; }
.field.has-error .input, .field.has-error .select, .field.has-error textarea.input { border-color: var(--danger); }

.input, .select {
  height: 40px; width: 100%;
  padding: 0 13px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
textarea.input { height: auto; min-height: 84px; padding: 10px 13px; resize: vertical; line-height: 1.55; }
.input:focus, .select:focus { outline: none; border-color: var(--plum); box-shadow: var(--ring); }
.input::placeholder { color: var(--ink-3); }
.input:disabled, .select:disabled { background: var(--surface-3); color: var(--ink-3); cursor: not-allowed; }
.select {
  appearance: none; -webkit-appearance: none;
  padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='7' viewBox='0 0 11 7'%3E%3Cpath d='M1 1l4.5 4.5L10 1' stroke='%238B7F91' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center;
}
.input--lock { text-align: center; letter-spacing: .5em; font-size: 1.2rem; height: 50px; margin-bottom: 12px; }

.formgrid { display: grid; gap: 15px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.formgrid .col-2 { grid-column: span 2; }
@media (max-width: 620px) {
  .formgrid { grid-template-columns: 1fr; }
  .formgrid .col-2 { grid-column: span 1; }
}
.fieldset { border: 0; padding: 0; }
.fieldset__legend {
  font-size: .68rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--blush); padding: 0; margin-bottom: 11px;
  display: flex; align-items: center; gap: 9px;
}
.fieldset__legend::after { content: ''; flex: 1 1 auto; height: 1px; background: var(--line); }
.fieldset + .fieldset { margin-top: 24px; }

.check { display: flex; align-items: flex-start; gap: 9px; cursor: pointer; font-size: .86rem; line-height: 1.45; }
.check input { width: 17px; height: 17px; margin-top: 2px; accent-color: var(--plum); flex: 0 0 17px; cursor: pointer; }

.segmented { display: inline-flex; padding: 3px; background: var(--surface-3); border-radius: var(--r-pill); gap: 2px; flex-wrap: wrap; }
.segmented__btn {
  height: 29px; padding: 0 13px; border-radius: var(--r-pill);
  font-size: .78rem; font-weight: 600; color: var(--ink-3);
  transition: background var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
  white-space: nowrap;
}
.segmented__btn:hover { color: var(--ink); }
.segmented__btn.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--sh-1); }

.filters {
  display: flex; gap: 9px; flex-wrap: wrap; align-items: center;
  margin-bottom: 16px;
}
.filters .input, .filters .select { height: 36px; width: auto; min-width: 140px; }
.filters .input[type="search"] { min-width: 210px; }

/* -------------------------------- modal --------------------------------- */
.modal { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 18px; }
.modal[hidden] { display: none; }
.modal__scrim {
  position: absolute; inset: 0;
  background: rgba(30,24,34,.5); backdrop-filter: blur(3px);
  animation: fade var(--t) var(--ease-out);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal__panel {
  position: relative; z-index: 1;
  width: min(660px, 100%); max-height: calc(100vh - 36px);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-xl); box-shadow: var(--sh-4);
  display: flex; flex-direction: column; overflow: hidden;
  animation: modalIn var(--t) var(--ease-out);
}
.modal__panel--wide { width: min(940px, 100%); }
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
.modal__head {
  display: flex; align-items: center; gap: 12px;
  padding: 17px 20px; border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.modal__title { flex: 1 1 auto; font-family: var(--font-display); font-size: 1.12rem; font-weight: 600; min-width: 0; }
.modal__body { padding: 20px; overflow-y: auto; flex: 1 1 auto; }
.modal__foot {
  display: flex; gap: 9px; justify-content: flex-end; flex-wrap: wrap;
  padding: 15px 20px; border-top: 1px solid var(--line);
  background: var(--surface-2); flex: 0 0 auto;
}
.modal__foot:empty { display: none; }
.modal__foot .spacer { flex: 1 1 auto; }

/* -------------------------------- toasts -------------------------------- */
.toasts {
  position: fixed; z-index: 120;
  bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 9px;
  max-width: min(370px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 13px 15px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); box-shadow: var(--sh-4);
  pointer-events: auto;
  animation: toastIn var(--t) var(--ease-out);
  border-left: 3px solid var(--plum);
}
.toast.is-out { animation: toastOut var(--t) var(--ease-out) forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(22px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(22px) scale(.97); } }
.toast--ok { border-left-color: var(--ok); }
.toast--warn { border-left-color: var(--warn); }
.toast--danger { border-left-color: var(--danger); }
.toast__ico { font-size: 16px; flex: 0 0 auto; line-height: 1.4; }
.toast__body { flex: 1 1 auto; min-width: 0; }
.toast__title { font-weight: 600; font-size: .86rem; }
.toast__msg { font-size: .79rem; color: var(--ink-2); margin-top: 2px; line-height: 1.5; }
.toast__act { font-size: .78rem; font-weight: 700; color: var(--plum); margin-top: 7px; }
.toast__x { flex: 0 0 auto; color: var(--ink-3); font-size: 13px; padding: 2px 4px; border-radius: 6px; }
.toast__x:hover { background: var(--surface-3); color: var(--ink); }

/* -------------------------------- lock ---------------------------------- */
.lock {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center; padding: 22px;
  background:
    radial-gradient(circle at 22% 18%, var(--blush-soft), transparent 52%),
    radial-gradient(circle at 78% 82%, var(--plum-soft), transparent 52%),
    var(--paper);
}
.lock.hidden { display: none; }
.lock__card {
  width: min(380px, 100%); text-align: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-xl); box-shadow: var(--sh-4);
  padding: 34px 28px 26px;
  animation: modalIn var(--t-slow) var(--ease-out);
}
.lock__mark { font-size: 40px; margin-bottom: 12px; }
.lock__title { font-family: var(--font-display); font-size: 1.6rem; margin-bottom: 5px; }
.lock__sub { color: var(--ink-2); font-size: .88rem; margin-bottom: 20px; }
.lock__err { color: var(--danger); font-size: .8rem; font-weight: 600; margin-top: 11px; min-height: 19px; }
.lock__note { font-size: .7rem; color: var(--ink-3); margin-top: 16px; line-height: 1.55; }

/* ------------------------------ boot error ------------------------------ */
.booterr {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 150;
  background: var(--danger-soft); color: var(--danger);
  padding: 11px 18px; font-size: .82rem; font-weight: 600;
  border-top: 1px solid var(--danger);
}
.booterr.hidden { display: none; }

/* -------------------------------- misc ---------------------------------- */
.divider { height: 1px; background: var(--line); border: 0; margin: 0; }
.muted { color: var(--ink-3); }
.small { font-size: .79rem; }
.tiny { font-size: .72rem; }
.bold { font-weight: 600; }
.nums { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); font-size: .82em; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

.notebox {
  background: var(--gold-soft); border: 1px solid transparent;
  border-left: 3px solid var(--gold);
  border-radius: var(--r-sm); padding: 12px 14px;
  font-size: .83rem; line-height: 1.6; color: var(--ink-2);
  white-space: pre-wrap; word-break: break-word;
}
.notebox--info { background: var(--info-soft); border-left-color: var(--info); }
.notebox--danger { background: var(--danger-soft); border-left-color: var(--danger); }
.notebox--sage { background: var(--sage-soft); border-left-color: var(--sage); }

.kv { display: grid; grid-template-columns: minmax(110px, auto) 1fr; gap: 9px 16px; font-size: .86rem; }
.kv dt { color: var(--ink-3); font-size: .79rem; }
.kv dd { margin: 0; word-break: break-word; }

/* ======================== RESPONSIVE BREAKPOINTS ======================== */
@media (max-width: 1020px) {
  :root { --gutter: 18px; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform var(--t) var(--ease);
    box-shadow: var(--sh-4);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .sidebar__scrim { display: block; animation: fade var(--t); }
  .sidebar__close { display: grid; }
  .topbar__burger { display: grid; }
  .search { max-width: none; }
  .search__kbd { display: none; }
}
/* On a phone the topbar has to give the search box room to breathe:
   the New button drops to its icon and the chrome tightens up. */
@media (max-width: 560px) {
  .topbar { gap: 6px; padding: 0 10px; }
  .topbar__newtxt { display: none; }
  .topbar__new { padding: 0 12px; }
  .iconbtn { width: 34px; height: 34px; flex: 0 0 34px; }
  .search__input { padding-right: 14px; }
}

@media (max-width: 720px) {
  :root { --gutter: 14px; --topbar-h: 60px; }
  body { font-size: 14px; }
  .view { padding: 18px var(--gutter) 96px; }
  .tabbar { display: block; }
  .grid { gap: 12px; }
  .grid--stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .stat { padding: 14px 15px; border-radius: var(--r-md); }
  .stat__value { font-size: 1.25rem; }
  .card { border-radius: var(--r-md); }
  .card--pad, .card__body { padding: 15px; }
  .card__head { padding: 13px 15px; }
  .card__foot { padding: 11px 15px; }
  .toasts { bottom: calc(72px + env(safe-area-inset-bottom)); right: 12px; left: 12px; max-width: none; }
  .modal { padding: 0; place-items: end stretch; }
  .modal__panel {
    width: 100%; max-height: 94vh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    animation: sheetIn var(--t) var(--ease-out);
  }
  @keyframes sheetIn { from { transform: translateY(100%); } to { transform: none; } }
  .modal__foot { padding-bottom: calc(15px + env(safe-area-inset-bottom)); }
  .modal__foot .btn { flex: 1 1 auto; }
  .phead { margin-bottom: 16px; }
  .phead__actions { width: 100%; }
  .filters .input[type="search"] { min-width: 100%; }
  .filters .input, .filters .select { flex: 1 1 42%; min-width: 0; }
}

/* ------------------------------- print ---------------------------------- */
/* The print sheet is built on demand and is invisible on screen. */
.printsheet { display: none; }

@media print {
  .sidebar, .topbar, .tabbar, .toasts, .modal, .tbl__actions, .no-print { display: none !important; }
  body, .view { background: #fff; padding: 0; }
  body::before { display: none; }
  .card { break-inside: avoid; box-shadow: none; border-color: #ccc; }

  /* When a clean sheet has been built, print only that */
  body.printing .shell { display: none !important; }
  body.printing .printsheet { display: block; }

  .printsheet { color: #000; font-size: 11pt; }
  .printsheet__head { margin-bottom: 18pt; border-bottom: 1pt solid #999; padding-bottom: 10pt; }
  .printsheet__head h1 { font-family: var(--font-display); font-size: 20pt; margin-bottom: 4pt; }
  .printsheet__head p { font-size: 9.5pt; color: #444; margin: 1pt 0; }
  .printsheet__table { width: 100%; border-collapse: collapse; }
  .printsheet__table th {
    text-align: left; font-size: 8.5pt; text-transform: uppercase; letter-spacing: .06em;
    border-bottom: 1pt solid #666; padding: 6pt 8pt 5pt 0; color: #333;
  }
  .printsheet__table td {
    padding: 7pt 8pt 7pt 0; border-bottom: .5pt solid #ddd;
    vertical-align: top; break-inside: avoid;
  }
  .printsheet__table .sub { font-size: 8.5pt; color: #555; }
  .printsheet__foot { margin-top: 14pt; font-size: 8.5pt; color: #666; }

  /* app components reused inside a print sheet (e.g. the invoice) */
  .printsheet .tbl th { background: transparent; color: #333; position: static; }
  .printsheet .tbl td, .printsheet .tbl th { border-color: #ddd; }
  .printsheet .notebox { background: transparent; border: .5pt solid #bbb; border-left-width: 2pt; }
  .printsheet a { color: #000; text-decoration: none; }

  @page { margin: 14mm; }
}
