/* NEODRIFT Interns Audit - structure and components.
   Colours, glass and the backdrop come from the per-theme tokens that
   core/theme.py writes into the page head; nothing here hard-codes a theme.
   Glass is applied selectively - sidebar, cards, alerts, tabs - while tables
   and forms stay denser so data reads cleanly. */

:root {
  --r: 20px; --r-lg: 28px; --r-sm: 14px;
  --ease: cubic-bezier(.32, .72, 0, 1);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  /* Safe-area insets as variables (Rule 10a): overridable for testing, env() is not. */
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  --lvh: calc(100dvh - var(--sat, 0px) - var(--sab, 0px));
  --side-w: 264px;
}

html { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100dvh; font-family: var(--font); color: var(--ink-2);
  font-size: 15px; line-height: 1.5;
}
a { color: var(--blue); }
h1, h2, h3, h4 { color: var(--ink); letter-spacing: -.028em; font-weight: 600; }
h1 { font-size: 2.3rem; line-height: 1.07; margin: .2rem 0 .7rem; }
h2 { font-size: 1.4rem; margin: 1.6rem 0 .6rem; }
h3 { font-size: 1.1rem; margin: 1.9rem 0 .55rem; letter-spacing: -.02em; }
code { font-size: .86em; background: var(--grey-tint); padding: .08rem .35rem; border-radius: 6px; color: var(--ink); }
hr.divider { border: 0; border-top: 1px solid var(--edge-soft); margin: 1.2rem 0; }
[hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.md p { margin: .35rem 0 .7rem; }
.md ul, .md ol { margin: .3rem 0 .8rem 1.2rem; padding: 0; }
.md li { margin: .2rem 0; }
.caption { color: var(--ink-3); font-size: .8rem; margin: .25rem 0 .6rem; line-height: 1.45; }
.tc-red { color: var(--red); } .tc-green { color: var(--green); } .tc-orange { color: var(--amber); }
.tc-blue { color: var(--blue); } .tc-violet { color: var(--violet); } .tc-gray, .tc-grey { color: var(--ink-3); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100dvh; }
.side {
  position: sticky; top: 0; height: 100dvh; overflow-y: auto; overscroll-behavior: contain;
  padding: calc(1rem + var(--sat)) 1rem calc(1.2rem + var(--sab)) calc(1rem + var(--sal));
  background: var(--panel-strong); border-right: 1px solid var(--edge);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  display: flex; flex-direction: column; gap: 1rem; z-index: 40;
}
.brand { display: flex; align-items: center; gap: .65rem; padding: .2rem .3rem .4rem; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 13px; flex: 0 0 40px;
  background: linear-gradient(140deg, var(--blue), var(--violet) 55%, var(--magenta));
  display: flex; align-items: center; justify-content: center;
  color: var(--on-accent); font-weight: 700; letter-spacing: -.035em;
}
.brand-name { color: var(--ink); font-weight: 600; font-size: 1.02rem; letter-spacing: -.02em; }
.brand-sub { color: var(--ink-3); font-size: .78rem; }
.side-close { display: none; margin-left: auto; background: none; border: 0; color: var(--ink-2); font-size: 1.6rem; line-height: 1; min-width: 44px; min-height: 44px; cursor: pointer; }
.nav { display: flex; flex-direction: column; gap: .18rem; }
.nav a {
  display: flex; align-items: center; gap: .65rem; text-decoration: none;
  color: var(--ink-2); font-weight: 500; font-size: .93rem;
  padding: .62rem .9rem; border-radius: 999px; border: 1px solid transparent;
  transition: background .3s var(--ease); min-height: 44px;
}
.nav a:hover { background: var(--hover); }
.nav a.on { background: var(--panel-dense); border-color: var(--edge); box-shadow: var(--rim); color: var(--ink); font-weight: 600; }
.nav-g { width: 1.2rem; text-align: center; opacity: .9; }
.side-sec { border-top: 1px solid var(--edge-soft); padding-top: .9rem; display: flex; flex-direction: column; gap: .5rem; }
.side-cap { color: var(--ink-3); font-size: .78rem; line-height: 1.4; }
.side-cap b { color: var(--ink-2); }
.side-metric { background: var(--panel); border: 1px solid var(--edge); border-radius: var(--r-sm); padding: .6rem .8rem; }
.side-metric-label { font-size: .78rem; color: var(--ink-3); }
.side-metric-value { font-size: 1.5rem; font-weight: 600; color: var(--ink); letter-spacing: -.03em; }
.scrim { display: none; }

.content { min-width: 0; padding: 0 calc(1.6rem + var(--sar)) calc(3rem + var(--sab)) 1.6rem; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: .6rem;
  padding: calc(.7rem + var(--sat)) 0 .6rem; margin: 0 -1.6rem 0; padding-left: 1.6rem; padding-right: 1.6rem;
  background: linear-gradient(var(--panel-strong), var(--panel-strong));
  -webkit-backdrop-filter: var(--blur-light); backdrop-filter: var(--blur-light);
  border-bottom: 1px solid var(--edge-soft);
}
.hamburger { display: none; flex-direction: column; justify-content: center; gap: 4px; width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--edge); background: var(--panel-strong); cursor: pointer; padding: 0 11px; }
.hamburger span { display: block; height: 2px; background: var(--ink); border-radius: 2px; }
.flux-spacer { flex: 1 1 auto; }
.main { max-width: 1520px; position: relative; }
.main.htmx-request .progress { opacity: 1; animation: progress 1.1s var(--ease) infinite; }
.progress {
  position: fixed; top: var(--sat); left: 0; right: 0; height: 3px; z-index: 60; opacity: 0;
  background: linear-gradient(90deg, transparent, var(--blue), var(--violet), transparent);
  background-size: 50% 100%; background-repeat: no-repeat; transition: opacity .2s;
  pointer-events: none;
}
@keyframes progress { 0% { background-position: -50% 0; } 100% { background-position: 150% 0; } }
.main.htmx-request .pageform { opacity: .62; transition: opacity .2s .15s; }

/* ---------- theme dock + version picker ---------- */
.theme-dock {
  display: flex; gap: .15rem; padding: .25rem; border-radius: 999px;
  background: var(--panel-strong); border: 1px solid var(--edge); box-shadow: var(--shadow);
}
.theme-dock form { margin: 0; }
.theme-dock button {
  border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: .76rem;
  padding: .38rem .72rem; border-radius: 999px; cursor: pointer; min-height: 32px; white-space: nowrap;
}
.theme-dock button.on { background: linear-gradient(135deg, var(--blue), var(--violet)); color: var(--on-accent); font-weight: 600; }
.verpick > summary { white-space: nowrap; font-size: 1.12rem; font-weight: 600; color: var(--ink); letter-spacing: -.026em; padding: .3rem .5rem; border-radius: 10px; }
.verpick > summary:hover { background: var(--hover); }
.verpick .chev { color: var(--ink-3); font-size: .9rem; }
.ver-opt {
  display: flex; align-items: center; width: 100%; border: 0; background: transparent; color: var(--ink);
  font: inherit; font-size: .93rem; font-weight: 500; padding: .5rem .65rem; border-radius: 9px; cursor: pointer; text-align: left; min-height: 40px;
}
.ver-opt:hover, .ver-opt.on { background: var(--hover); }
.verpick form { margin: 0; }
.vernote { margin: .7rem 0 0; }
.flux-ver-note { display: inline-block; font-size: .78rem; color: var(--ink-3); margin: .1rem 0 .3rem; }
.flux-ver-pill { display: inline-block; font-size: .68rem; font-weight: 600; padding: .14rem .48rem; border-radius: 999px; margin-left: .45rem; background: var(--green-tint); color: var(--green); }

/* ---------- top bar (who + when) ---------- */
.flux-top { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin: 1rem 0 .6rem; }
.flux-user { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.flux-avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: 0 0 44px;
  background: linear-gradient(140deg, var(--blue), var(--violet) 55%, var(--magenta));
  display: flex; align-items: center; justify-content: center;
  color: var(--on-accent); font-weight: 700; font-size: .92rem;
  letter-spacing: -.02em; border: 2px solid var(--edge); box-shadow: var(--shadow);
}
.flux-user-name { font-size: .93rem; font-weight: 600; color: var(--ink); line-height: 1.25; }
.flux-user-mail { font-size: .78rem; color: var(--ink-3); line-height: 1.25; overflow-wrap: anywhere; }
.flux-datepill {
  display: inline-flex; align-items: center; gap: .5rem;
  -webkit-backdrop-filter: var(--blur-light); backdrop-filter: var(--blur-light);
  background: var(--panel-strong); border: 1px solid var(--edge);
  border-radius: 999px; padding: .5rem 1rem; box-shadow: var(--shadow), var(--rim);
  font-size: .84rem; color: var(--ink-2); font-weight: 500;
}
.flux-datepill b { color: var(--ink); font-weight: 600; }

/* ---------- motion (never a filter on anything that holds glass) ---------- */
@keyframes liftIn { 0% { opacity: 0; transform: translateY(12px); } 100% { opacity: 1; transform: none; } }
@keyframes riseIn { 0% { opacity: 0; transform: translateY(14px); filter: blur(10px); } 60% { opacity: 1; } 100% { opacity: 1; transform: none; filter: blur(0); } }
.main h1, .main h3, .section-note, .src-note { animation: riseIn .55s var(--ease) both; }

/* ---------- crystal surfaces ---------- */
.kpi-card, .callout, .g-hero, .g-alert, .alert-mini, .toast, .signin-card, .tab-list, .popover-body, .metric {
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  background: var(--panel); border: 1px solid var(--edge);
  box-shadow: var(--shadow), var(--rim); transform: translateZ(0);
}
.tbl-wrap, details.expander, .chart, .bordered {
  -webkit-backdrop-filter: var(--blur-dense); backdrop-filter: var(--blur-dense);
  background: var(--panel-dense); border: 1px solid var(--edge);
  box-shadow: var(--shadow), var(--rim);
}

/* ---------- hero ---------- */
.g-hero { border-radius: var(--r-lg); padding: 1.2rem 1.4rem; margin-bottom: 1.1rem; animation: liftIn .5s var(--ease) both; }
.g-hero-title { font-size: 1.05rem; font-weight: 600; color: var(--ink); margin-bottom: .22rem; }
.g-hero-sub { font-size: .875rem; color: var(--ink-2); line-height: 1.55; }

/* ---------- stat cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(196px, 1fr)); gap: .8rem; margin: .55rem 0 1.25rem 0; }
.kpi-card {
  position: relative; border-radius: var(--r); padding: 1.05rem 1.15rem 1rem; min-width: 0;
  transition: transform .4s var(--ease), box-shadow .4s var(--ease);
  animation: liftIn .46s var(--ease) both;
}
.kpi-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-hi), var(--rim); }
.kpi-grid .kpi-card:nth-child(2) { animation-delay: .045s } .kpi-grid .kpi-card:nth-child(3) { animation-delay: .09s }
.kpi-grid .kpi-card:nth-child(4) { animation-delay: .135s } .kpi-grid .kpi-card:nth-child(5) { animation-delay: .18s }
.kpi-grid .kpi-card:nth-child(n+6) { animation-delay: .22s }
.kpi-head { display: flex; align-items: center; gap: .55rem; margin-bottom: .95rem; }
.kpi-dot {
  width: 30px; height: 30px; border-radius: 50%; flex: 0 0 30px; background: var(--grey-tint);
  display: flex; align-items: center; justify-content: center; font-size: .82rem; line-height: 1; border: 1px solid var(--edge);
}
.kpi-label { font-size: .845rem; font-weight: 500; color: var(--ink-2); line-height: 1.3; overflow-wrap: break-word; }
.kpi-value { font-size: 2.05rem; font-weight: 600; line-height: 1.05; color: var(--ink); letter-spacing: -.042em; overflow-wrap: break-word; display: flex; align-items: baseline; gap: .42rem; flex-wrap: wrap; }
.kpi-unit { font-size: .82rem; font-weight: 500; color: var(--ink-3); letter-spacing: 0; }
.kpi-badge { display: inline-block; font-size: .715rem; font-weight: 600; padding: .18rem .52rem; border-radius: 999px; background: var(--green-tint); color: var(--green); border: 1px solid var(--edge); letter-spacing: -.01em; }
.kpi-badge.down { background: var(--red-tint); color: var(--red); }
.kpi-badge.flat { background: var(--grey-tint); color: var(--ink-2); }
.kpi-sub { font-size: .775rem; color: var(--ink-3); margin-top: .4rem; line-height: 1.4; }
.kpi-card.is-red { background: linear-gradient(180deg, var(--red-tint), var(--panel)); }
.kpi-card.is-amber { background: linear-gradient(180deg, var(--amber-tint), var(--panel)); }
.kpi-card.is-green { background: linear-gradient(180deg, var(--green-tint), var(--panel)); }

/* ---------- chips, callouts, notes ---------- */
.chip { display: inline-block; padding: .3rem .8rem; border-radius: 999px; font-size: .765rem; font-weight: 600; margin: .16rem .34rem .16rem 0; border: 1px solid var(--edge); white-space: nowrap; box-shadow: var(--rim); }
.chip-red { background: var(--red-tint); color: var(--red); } .chip-amber { background: var(--amber-tint); color: var(--amber); }
.chip-green { background: var(--green-tint); color: var(--green); } .chip-grey { background: var(--grey-tint); color: var(--ink-2); }
.callout { border-radius: var(--r); padding: 1.05rem 1.2rem; margin: .5rem 0 1.2rem 0; font-size: .895rem; color: var(--ink-2); animation: liftIn .46s var(--ease) both; }
.callout strong { color: var(--ink); font-weight: 600; }
.callout.red { background: linear-gradient(180deg, var(--red-tint), var(--panel)); }
.callout.amber { background: linear-gradient(180deg, var(--amber-tint), var(--panel)); }
.callout.green { background: linear-gradient(180deg, var(--green-tint), var(--panel)); }
.callout ul { margin: .4rem 0 0 1.15rem; padding: 0; } .callout li { margin: .24rem 0; line-height: 1.55; }
.section-note { color: var(--ink-3); font-size: .865rem; margin: -.3rem 0 .8rem 0; }
.src-note { color: var(--ink-3); font-size: .775rem; margin-top: .5rem; opacity: .85; }

/* ---------- alerts ---------- */
.g-alert { display: flex; gap: .9rem; align-items: flex-start; border-radius: var(--r); padding: 1rem 1.15rem; margin: .45rem 0 .7rem 0; border-left: 4px solid var(--amber); background: linear-gradient(180deg, var(--amber-tint), var(--panel)); animation: liftIn .46s var(--ease) both; }
.g-alert.red { border-left-color: var(--red); background: linear-gradient(180deg, var(--red-tint), var(--panel)); }
.g-alert-body { flex: 1; min-width: 0; }
.g-alert-title { font-weight: 600; color: var(--ink); font-size: .93rem; margin-bottom: .2rem; }
.g-alert-text { font-size: .855rem; color: var(--ink-2); line-height: 1.55; }
.g-alert-meta { font-size: .775rem; color: var(--ink-3); margin-top: .32rem; }
.alert-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .7rem; margin: .4rem 0 1rem 0; }
.alert-mini { border-radius: var(--r-sm); border-left: 4px solid var(--amber); padding: .85rem .95rem; min-width: 0; animation: liftIn .44s var(--ease) both; background: linear-gradient(180deg, var(--amber-tint), var(--panel)); transition: transform .32s var(--ease), box-shadow .32s var(--ease); }
.alert-mini:hover { transform: translateY(-2px); box-shadow: var(--shadow-hi), var(--rim); }
.alert-mini.red { border-left-color: var(--red); background: linear-gradient(180deg, var(--red-tint), var(--panel)); }
.alert-mini-name { font-size: .875rem; font-weight: 600; color: var(--ink); margin-bottom: .2rem; }
.alert-mini-msg { font-size: .795rem; color: var(--ink-2); line-height: 1.45; }
.alert-mini-meta { font-size: .715rem; color: var(--ink-3); margin-top: .32rem; line-height: 1.4; }
@media (max-width: 1100px) { .alert-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .alert-grid { grid-template-columns: 1fr; } }

/* ---------- toasts (pinned bottom-right; dismiss is a pure CSS toggle) ---------- */
.toast-stack { position: fixed; right: calc(18px + var(--sar)); bottom: calc(18px + var(--sab)); z-index: 50; display: flex; flex-direction: column; gap: .45rem; width: 300px; max-width: calc(100vw - 36px); pointer-events: none; }
.toast-stack > * { pointer-events: auto; }
.toast-head { align-self: flex-end; font-size: .68rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-2); background: var(--panel-strong); border: 1px solid var(--edge); border-radius: 999px; padding: .22rem .62rem; box-shadow: var(--shadow); }
.toast-x { display: none; }
.toast { display: flex; gap: .55rem; align-items: flex-start; border-left: 3px solid var(--red); border-radius: var(--r-sm); padding: .65rem .75rem; box-shadow: var(--shadow-hi), var(--rim); background: linear-gradient(180deg, var(--red-tint), var(--panel-strong)); animation: toastIn .46s var(--ease) both; }
.toast.amber { border-left-color: var(--amber); background: linear-gradient(180deg, var(--amber-tint), var(--panel-strong)); }
.toast-x:checked + .toast { display: none; }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-size: .775rem; font-weight: 600; color: var(--ink); line-height: 1.3; margin-bottom: .1rem; }
.toast-text { font-size: .715rem; color: var(--ink-2); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.toast-close { cursor: pointer; color: var(--ink-3); font-size: 1.1rem; line-height: 1; padding: .1rem .3rem; flex: 0 0 auto; user-select: none; min-width: 28px; min-height: 28px; text-align: center; }
.toast-close:hover { color: var(--ink); }
@keyframes toastIn { 0% { opacity: 0; transform: translateX(22px); } 100% { opacity: 1; transform: none; } }

/* ---------- messages ---------- */
.msg { display: flex; gap: .65rem; align-items: flex-start; border-radius: var(--r-sm); padding: .8rem 1rem; margin: .5rem 0 .9rem; border: 1px solid var(--edge); font-size: .9rem; }
.msg-icon { flex: 0 0 auto; font-size: 1rem; line-height: 1.4; }
.msg-body { flex: 1; min-width: 0; } .msg-body p { margin: 0 0 .4rem; } .msg-body p:last-child { margin: 0; }
.msg-info { background: var(--grey-tint); color: var(--ink); }
.msg-success { background: var(--green-tint); color: var(--ink); } .msg-success .msg-icon { color: var(--green); }
.msg-warning { background: var(--amber-tint); color: var(--ink); } .msg-warning .msg-icon { color: var(--amber); }
.msg-error { background: var(--red-tint); color: var(--ink); } .msg-error .msg-icon { color: var(--red); }

/* ---------- layout blocks ---------- */
.block { min-width: 0; }
.bordered { border-radius: var(--r); padding: 1rem 1.1rem; margin: .5rem 0 1rem; }
.cols { display: grid; grid-template-columns: var(--cols); gap: 1rem; align-items: start; margin: .2rem 0; }
.cols.gap-small { gap: .6rem; } .cols.gap-large { gap: 1.6rem; }
.cols.va-center { align-items: center; } .cols.va-bottom { align-items: end; }
.col { min-width: 0; }
@media (max-width: 760px) { .cols { grid-template-columns: 1fr !important; gap: .4rem; } }

.tabs { margin: .4rem 0 1rem; }
.tab-list { display: flex; gap: .2rem; padding: .28rem; margin-bottom: .75rem; overflow-x: auto; border-radius: 999px; width: fit-content; max-width: 100%; scrollbar-width: none; }
.tab-list::-webkit-scrollbar { display: none; }
.tab { border: 0; background: transparent; border-radius: 999px; padding: .5rem 1.05rem; font: inherit; font-size: .865rem; font-weight: 500; color: var(--ink-3); white-space: nowrap; cursor: pointer; min-height: 40px; transition: background .32s var(--ease), color .32s var(--ease); }
.tab:hover { color: var(--ink); }
.tab.on { color: var(--on-accent); font-weight: 600; background: linear-gradient(135deg, var(--blue), var(--violet)); }
.tab-pane { display: none; } .tab-pane.on { display: block; animation: liftIn .4s var(--ease) both; }

details.expander { border-radius: var(--r-sm); margin: .55rem 0 .9rem; }
details.expander > summary { cursor: pointer; padding: .8rem 1rem; color: var(--ink); font-weight: 500; font-size: .92rem; list-style: none; display: flex; gap: .5rem; align-items: center; min-height: 44px; }
details.expander > summary::-webkit-details-marker { display: none; }
details.expander > summary::before { content: "▸"; color: var(--ink-3); transition: transform .2s; }
details.expander[open] > summary::before { transform: rotate(90deg); }
.expander-body { padding: 0 1rem 1rem; }
details.popover { position: relative; display: inline-block; }
details.popover > summary { cursor: pointer; list-style: none; user-select: none; }
details.popover > summary::-webkit-details-marker { display: none; }
.popover-body { position: absolute; left: 0; top: calc(100% + .35rem); z-index: 70; min-width: 210px; padding: .35rem; border-radius: var(--r-sm); background: var(--menu); }

.metric { border-radius: var(--r-sm); padding: .8rem 1rem; margin: .3rem 0 .8rem; }
.metric-label { font-size: .82rem; color: var(--ink-3); } .metric-value { font-size: 1.7rem; font-weight: 600; color: var(--ink); letter-spacing: -.03em; }
.metric-delta { font-size: .8rem; font-weight: 600; } .metric-delta.up { color: var(--green); } .metric-delta.down { color: var(--red); } .metric-delta.flat { color: var(--ink-3); }
pre.code { background: var(--panel-dense); border: 1px solid var(--edge); border-radius: var(--r-sm); padding: .8rem 1rem; overflow-x: auto; color: var(--ink); font-size: .82rem; margin: .4rem 0 .9rem; }
pre.code code { background: none; padding: 0; }

/* ---------- controls ---------- */
.widget { margin: 0 0 .75rem; min-width: 0; }
.w-label { display: block; font-size: .85rem; color: var(--ink-2); margin: 0 0 .32rem; font-weight: 500; }
.help { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; margin-left: .25rem; border-radius: 50%; font-size: .66rem; background: var(--grey-tint); color: var(--ink-3); cursor: help; vertical-align: 1px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink);
  background: var(--panel-strong); border: 1px solid var(--edge); border-radius: var(--r-sm);
  padding: .55rem .8rem; min-height: 44px; outline: none; color-scheme: var(--scheme);
}
textarea { min-height: 96px; resize: vertical; }
select { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 2.2rem; }
select option { background: var(--flat-panel); color: var(--ink); }
input:focus, select:focus, textarea:focus, summary:focus-visible, .btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
input::placeholder, textarea::placeholder { color: var(--ink-3); opacity: 1; }
.range1 { display: flex; align-items: center; gap: .7rem; }
.range1 input[type=range] { flex: 1; accent-color: var(--blue); min-height: 32px; }
.range1 output { min-width: 3ch; font-weight: 600; color: var(--ink); }
.range2 { display: flex; gap: .5rem; align-items: center; } .range2 span { color: var(--ink-3); font-size: .85rem; }
.checkbox, .switch { display: flex; align-items: center; gap: .55rem; cursor: pointer; min-height: 40px; color: var(--ink-2); font-size: .92rem; }
.checkbox input, .switch input { width: 20px; height: 20px; accent-color: var(--blue); flex: 0 0 auto; }
.switch input { appearance: none; -webkit-appearance: none; width: 40px; height: 24px; border-radius: 999px; background: var(--grey-tint); border: 1px solid var(--edge); position: relative; transition: background .25s var(--ease); }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--ink-2); transition: transform .25s var(--ease); }
.switch input:checked { background: linear-gradient(135deg, var(--blue), var(--violet)); }
.switch input:checked::after { transform: translateX(16px); background: var(--on-accent); }
.seg { display: inline-flex; flex-wrap: wrap; gap: .25rem; padding: .25rem; border-radius: 999px; border: 1px solid var(--edge); background: var(--panel-strong); max-width: 100%; }
.seg-opt { position: relative; cursor: pointer; }
.seg-opt input { position: absolute; opacity: 0; pointer-events: none; }
.seg-opt span { display: inline-flex; align-items: center; min-height: 36px; padding: .35rem .85rem; border-radius: 999px; font-size: .85rem; font-weight: 500; color: var(--ink-2); }
.seg-opt.on span, .seg-opt input:checked + span { background: linear-gradient(135deg, var(--blue), var(--violet)); color: var(--on-accent); font-weight: 600; }
.seg-opt input:focus-visible + span { outline: 2px solid var(--blue); }

details.ms { position: relative; }
details.ms > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: .5rem; min-height: 44px; padding: .5rem .8rem; border-radius: var(--r-sm); border: 1px solid var(--edge); background: var(--panel-strong); color: var(--ink); font-size: .92rem; }
details.ms > summary::-webkit-details-marker { display: none; }
details.ms > summary::after { content: "⌄"; color: var(--ink-3); margin-left: auto; }
.ms-sum { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-sum.ph { color: var(--ink-3); }
.ms-count:not(:empty) { font-size: .72rem; font-weight: 700; background: var(--blue); color: var(--on-accent); border-radius: 999px; padding: .05rem .45rem; }
.ms-list { position: absolute; z-index: 65; left: 0; right: 0; top: calc(100% + .3rem); max-height: min(340px, 60dvh); overflow-y: auto; padding: .4rem; border-radius: var(--r-sm); background: var(--menu); border: 1px solid var(--edge); box-shadow: var(--shadow-hi); }
.ms-find { margin-bottom: .3rem; min-height: 40px !important; }
.ms-opt { display: flex; align-items: center; gap: .55rem; padding: .45rem .5rem; border-radius: 9px; cursor: pointer; color: var(--ink); font-size: .9rem; min-height: 40px; }
.ms-opt:hover { background: var(--hover); }
.ms-opt input { width: 18px; height: 18px; accent-color: var(--blue); flex: 0 0 auto; }
.ms-clear { margin-top: .3rem; width: 100%; border: 1px solid var(--edge); background: transparent; color: var(--ink-2); border-radius: 9px; padding: .45rem; font: inherit; font-size: .85rem; cursor: pointer; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  border-radius: 999px; font: inherit; font-size: .9rem; font-weight: 500; text-decoration: none;
  border: 1px solid var(--edge); background: var(--panel-strong); color: var(--ink);
  padding: .55rem 1.1rem; min-height: 44px; cursor: pointer; margin: .15rem 0 .6rem;
  -webkit-backdrop-filter: var(--blur-light); backdrop-filter: var(--blur-light);
  transition: transform .28s var(--ease), background .28s var(--ease);
}
.btn:hover { transform: translateY(-1px); background: var(--hover); }
.btn:active { transform: scale(.978); }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: linear-gradient(135deg, var(--blue), var(--violet)); border: none; color: var(--on-accent); font-weight: 600; }
.btn-primary:hover { background: linear-gradient(135deg, var(--blue), var(--violet)); filter: brightness(1.06); }
.btn-tertiary { background: transparent; border-color: transparent; min-height: 36px; padding: .3rem .7rem; }
.btn.full { width: 100%; }
.side .btn { margin: 0; }
.side form { margin: 0; }
.b-icon { font-size: 1em; }
.up-file { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-top: .4rem; font-size: .85rem; color: var(--ink-2); }
input[type=file] { font: inherit; font-size: .85rem; color: var(--ink-2); max-width: 100%; }

/* ---------- tables ---------- */
.tbl-wrap { border-radius: var(--r-sm); overflow: auto; margin: .4rem 0 1rem; max-width: 100%; -webkit-overflow-scrolling: touch; }
.tbl { width: 100%; border-collapse: collapse; font-size: .84rem; }
.tbl th { position: sticky; top: 0; z-index: 2; background: var(--panel-strong); -webkit-backdrop-filter: var(--blur-light); backdrop-filter: var(--blur-light); color: var(--ink); font-weight: 600; text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--edge); white-space: nowrap; }
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th[data-dir=asc]::after { content: " ▲"; font-size: .7em; color: var(--ink-3); }
.tbl th[data-dir=desc]::after { content: " ▼"; font-size: .7em; color: var(--ink-3); }
.tbl td { padding: .5rem .75rem; border-bottom: 1px solid var(--edge-soft); color: var(--ink-2); vertical-align: top; max-width: 420px; overflow-wrap: anywhere; }
.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tbody tr:hover td { background: var(--hover); }
.tbl-empty { padding: .9rem; color: var(--ink-3); font-size: .85rem; }
.editor .tbl td { padding: .3rem .4rem; }
.editor input[type=text], .editor input[type=number], .editor input[type=date], .editor select { min-height: 36px; padding: .3rem .5rem; font-size: 14px; border-radius: 9px; min-width: 110px; }
.editor input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--blue); }
.pbar { height: 6px; border-radius: 999px; background: var(--grey-tint); overflow: hidden; } .pbar span { display: block; height: 100%; background: var(--blue); }

/* ---------- charts ---------- */
.chart { border-radius: var(--r); padding: .55rem .5rem .3rem .5rem; overflow: hidden; margin: .4rem 0 1rem; }
.plot { width: 100%; min-height: 200px; }
.plot .main-svg { background: transparent !important; }

/* ---------- sign-in (Rule 10b: the card fits the usable height) ---------- */
body.auth { display: flex; min-height: 100dvh; }
.signin-wrap { margin: auto; width: 100%; display: flex; align-items: center; justify-content: center; padding: calc(clamp(.5rem, 3vh, 2rem) + var(--sat)) 16px calc(clamp(.5rem, 3vh, 2rem) + var(--sab)); min-height: 100dvh; overflow-y: auto; }
.signin-card { width: 100%; max-width: 430px; text-align: center; border-radius: var(--r-lg); padding: clamp(1.3rem, 4vh, 2.4rem) clamp(1.1rem, 4vw, 2rem) clamp(1.1rem, 3vh, 1.9rem); box-shadow: var(--shadow-hi), var(--rim); animation: liftIn .55s var(--ease) both; margin: auto; }
.signin-card.wide { max-width: 640px; text-align: left; }
.signin-mark { width: 62px; height: 62px; margin: 0 auto clamp(.6rem, 2vh, 1.15rem); border-radius: 19px; background: linear-gradient(140deg, var(--blue), var(--violet) 55%, var(--magenta)); display: flex; align-items: center; justify-content: center; color: var(--on-accent); font-size: 1.45rem; font-weight: 700; letter-spacing: -.035em; }
.signin-card.wide .signin-mark { margin-left: 0; }
.signin-title { font-size: 1.45rem; font-weight: 600; color: var(--ink); letter-spacing: -.03em; margin-bottom: .45rem; }
.signin-sub { font-size: .9rem; color: var(--ink-2); line-height: 1.6; margin: 0 auto clamp(.8rem, 2.4vh, 1.4rem); max-width: 330px; }
.signin-foot { font-size: .775rem; color: var(--ink-3); margin-top: clamp(.7rem, 2vh, 1.15rem); padding-top: clamp(.6rem, 1.6vh, 1rem); border-top: 1px solid var(--edge-soft); }
.gsi-btn { display: flex; justify-content: center; min-height: 44px; margin: .2rem 0 .4rem; }
.or { display: flex; align-items: center; gap: .6rem; color: var(--ink-3); font-size: .8rem; margin: .8rem 0; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--edge-soft); }
.pass-form { text-align: left; } .pass-form .btn { margin-top: .6rem; }
.setup-help { font-size: .9rem; } .setup-help p { margin: .6rem 0; }

/* ---------- phones and tablets ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: min(86vw, 320px); transform: translateX(-105%); transition: transform .35s var(--ease); box-shadow: var(--shadow-hi); background: var(--panel-dense); }
  body.nav-open .side { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, .45); }
  .side-close { display: block; }
  .hamburger { display: flex; }
  .content { padding: 0 calc(.9rem + var(--sar)) calc(3rem + var(--sab)) calc(.9rem + var(--sal)); }
  .topbar { margin: 0 calc(-.9rem - var(--sar)) 0 calc(-.9rem - var(--sal)); padding-left: calc(.9rem + var(--sal)); padding-right: calc(.9rem + var(--sar)); }
  h1 { font-size: 1.9rem; }
}
@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(146px, 1fr)); gap: .55rem; }
  .kpi-card { padding: .8rem .85rem; border-radius: 16px; }
  .kpi-value { font-size: 1.5rem; } .kpi-head { margin-bottom: .65rem; }
  .kpi-dot { width: 26px; height: 26px; flex: 0 0 26px; font-size: .72rem; } .kpi-label { font-size: .765rem; }
  .g-hero { padding: .95rem 1.05rem; border-radius: 20px; }
  .flux-avatar { width: 38px; height: 38px; flex: 0 0 38px; font-size: .82rem; }
  .theme-dock button { font-size: .68rem; padding: .3rem .5rem; }
  .toast-stack { width: calc(100vw - 24px - var(--sal) - var(--sar)); right: calc(12px + var(--sar)); bottom: calc(12px + var(--sab)); gap: .35rem; }
  .toast-text { -webkit-line-clamp: 1; }
  .chart { padding: .4rem .3rem .2rem .3rem; border-radius: var(--r-sm); }
  h1 { font-size: 1.6rem; }
  .flux-datepill { font-size: .78rem; padding: .4rem .8rem; }
}
@media (max-width: 420px) {
  .theme-dock { overflow-x: auto; max-width: 62vw; scrollbar-width: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.colorw { display: flex; align-items: center; gap: .6rem; }
.colorw input[type=color] { width: 52px; height: 40px; border: 1px solid var(--edge); border-radius: 10px; background: var(--panel-strong); padding: 3px; cursor: pointer; }
