/* ==========================================================================
   LoanDisk x Zoho -- application skin.

   The sign-in screen sets the visual language: deep navy, a brand-to-indigo
   gradient, soft aurora light, generous radii. This file carries that into
   the signed-in app and makes it themeable, because dense financial tables
   are not equally readable on both backgrounds -- so the operator chooses.

   Everything is driven by tokens declared once per theme below. Tailwind is
   bound to the same tokens in views/layout.php (bg-surface, text-ink,
   border-line, text-ok ...), so a view never names a raw colour and every
   screen switches theme together.

   Colours are stored as space-separated RGB triplets so both this file
   (rgb(var(--ink))) and Tailwind's alpha modifiers (text-ink/60) can use them.
   ========================================================================== */

/* --- Tokens: light -------------------------------------------------------- */

:root,
:root[data-theme="light"] {
  --ink:        15 23 42;    /* headings, figures            */
  --ink-2:      71 85 105;   /* body, secondary              */
  --ink-3:     148 163 184;  /* captions, disabled           */

  --surface:   255 255 255;  /* panels                       */
  --raised:    248 250 252;  /* table heads, inline fills    */
  --line:      226 232 240;  /* borders, rules               */

  --page:      247 249 252;
  --page-2:    255 255 255;

  --accent:    210  25  58;  /* links, focus -- brand-500    */
  --brand-a:   210  25  58;  /* gradient start (brand-500)   */
  --brand-b:   158  15  39;  /* gradient end   (brand-700)   */

  --ok-ink:      4 120 87;   --ok-bg:  236 253 245;  --ok-line:  167 243 208;
  --warn-ink:  180  83  9;   --warn-bg: 255 251 235; --warn-line: 253 230 138;
  --bad-ink:   190  18 60;   --bad-bg:  255 241 242; --bad-line:  254 205 211;
  --info-ink:   51  65  85;  --info-bg: 248 250 252; --info-line: 203 213 225;

  --field-bg:  255 255 255;
  --code-bg:   241 245 249;

  --card-shadow: 0 1px 2px rgb(15 23 42 / .04), 0 12px 28px -18px rgb(15 23 42 / .18);
  --card-sheen:  linear-gradient(180deg, rgb(255 255 255 / .9), rgb(255 255 255 / 0) 120px);

  --grid-line:  rgb(15 23 42 / .045);
  --aurora-1:   rgb(210 25 58 / .10);
  --aurora-2:   rgb(158 15 39 / .09);
  --aurora-3:   rgb(150 20 90 / .07);

  --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");

  color-scheme: light;
}

/* --- Tokens: dark --------------------------------------------------------- */

:root[data-theme="dark"] {
  --ink:       247 247 248;  /* sign-in --ink   #F7F7F8      */
  --ink-2:     179 178 181;  /* sign-in --ink-2 (.70)        */
  --ink-3:     138 137 141;  /* sign-in --ink-3 (.52)        */

  --surface:    20  18  23;  /* the card        #141217      */
  --raised:     27  25  31;  /* table heads     #1B191F      */
  --line:       40  37  44;  /* sign-in --line  (.075)       */

  --page:        7   6   9;  /* sign-in body    #070609      */
  --page-2:     12  11  15;

  --accent:    242 102 126;  /* brand-400 -- links need lift on near-black */
  --brand-a:   210  25  58;
  --brand-b:   158  15  39;

  --ok-ink:     52 211 153;  --ok-bg:    16  61  50;  --ok-line:   16  90  70;
  --warn-ink:  252 211  77;  --warn-bg:  66  48  12;  --warn-line: 104  74  18;
  --bad-ink:   253 164 175;  --bad-bg:   73  25  38;  --bad-line: 110  36  54;
  --info-ink:  168 166 172;  --info-bg:  30  28  34;  --info-line: 52  49  58;

  --field-bg:   16  15  19;
  --code-bg:    18  17  21;

  --card-shadow: 0 1px 0 rgb(255 255 255 / .04) inset, 0 24px 48px -28px rgb(0 0 0 / .9);
  --card-sheen:  linear-gradient(180deg, rgb(255 255 255 / .035), rgb(255 255 255 / 0) 120px);

  --grid-line:  rgb(247 247 248 / .055);
  --aurora-1:   rgb(210 25 58 / .28);
  --aurora-2:   rgb(158 15 39 / .22);
  --aurora-3:   rgb(150 20 90 / .12);

  --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a898d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");

  color-scheme: dark;
}

/* --- Base ----------------------------------------------------------------- */

body {
  background-color: rgb(var(--page));
  color: rgb(var(--ink-2));
  font-feature-settings: "cv11", "ss01";
}

.tabular { font-variant-numeric: tabular-nums; }

::selection { background: rgb(var(--brand-a) / .28); }

:focus-visible {
  outline: 2px solid rgb(var(--accent) / .7);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Scrollbars follow the theme; a bright track on navy is the one thing that
   gives away a retro-fitted dark mode. */
* { scrollbar-color: rgb(var(--ink-3) / .45) transparent; scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgb(var(--ink-3) / .35);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover { background: rgb(var(--ink-3) / .6); background-clip: content-box; }

/* A wide table's own horizontal scrollbar sits at the foot of the card, off
   screen on long pages. This proxy bar is pinned to the window bottom and is
   scroll-synced by the layout script to whichever table it currently serves. */
#xbar {
  position: fixed;
  bottom: 0;
  z-index: 40;
  height: 14px;
  overflow-x: auto;
  overflow-y: hidden;
  display: none;
  background: rgb(var(--surface) / .92);
  border-top: 1px solid rgb(var(--line) / .8);
}
#xbar.is-on { display: block; }
#xbar > div { height: 1px; }

/* --- Page backdrop -------------------------------------------------------- */
/* Same three-layer construction as the sign-in screen: gradient, grid, glow. */

.app-bg {
  position: fixed;
  inset: 0;
  z-index: -10;
  background: linear-gradient(160deg, rgb(var(--page)) 0%, rgb(var(--page)) 45%, rgb(var(--page-2)) 100%);
}

.app-grid {
  position: fixed;
  inset: 0;
  z-index: -10;
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(ellipse 90% 55% at 60% 0%, #000 20%, transparent 75%);
          mask-image: radial-gradient(ellipse 90% 55% at 60% 0%, #000 20%, transparent 75%);
}

.app-glow { position: fixed; inset: 0; z-index: -10; overflow: hidden; pointer-events: none; }
.app-glow span {
  position: absolute;
  display: block;
  border-radius: 9999px;
  filter: blur(120px);
  animation: drift 26s ease-in-out infinite;
  will-change: transform;
}
.app-glow span:nth-child(1) { top: -14rem; right: -8rem;  width: 34rem; height: 34rem; background: var(--aurora-1); }
.app-glow span:nth-child(2) { bottom: -18rem; left: 8rem; width: 38rem; height: 38rem; background: var(--aurora-2); animation-duration: 32s; animation-delay: -8s; }
.app-glow span:nth-child(3) { top: 30%; right: 25%;       width: 26rem; height: 26rem; background: var(--aurora-3); animation-duration: 38s; animation-delay: -16s; }

@keyframes drift {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  33%      { transform: translate3d(5%, -7%, 0) scale(1.12); }
  66%      { transform: translate3d(-6%, 4%, 0) scale(.94); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.rise   { animation: rise .5s cubic-bezier(.16, 1, .3, 1) both; }
.rise-1 { animation-delay: .04s; }
.rise-2 { animation-delay: .10s; }

@media (prefers-reduced-motion: reduce) {
  .app-glow span, .rise { animation: none !important; opacity: 1; transform: none; }
}

/* --- Sidebar -------------------------------------------------------------- */
/* Modelled on the Zoho Books navigation, because operators here spend their
   day in Books and switch into this bridge: same flat navy bar, same module
   icons in module colours, same expanding parents, same green active band.
   Deliberately dark in both themes -- it is chrome, not content. */

.side {
  --side-w:      15rem;
  --side-rail:   3.5rem;

  --zb-bar:      #121016;   /* the bar itself                */
  --zb-head:     #0C0B0F;   /* product header + footer       */
  --zb-hover:    rgb(255 255 255 / .06);
  --zb-open:     rgb(255 255 255 / .04);
  --zb-sel:      #9E0F27;   /* selection band (brand-700)    */
  --zb-sel-2:    #D2193A;   /* selection band (brand-500)    */
  --zb-label:    #F0EFF2;
  --zb-sub:      #9B99A1;

  width: var(--side-w);
  background: var(--zb-bar);
  color: var(--zb-label);
  font-size: .8125rem;
  position: relative;
  isolation: isolate;
  transition: width .18s ease;
}

/* Product header -- Books puts a mark and the app name above the modules. */
.side-brand {
  display: flex;
  align-items: center;
  gap: .625rem;
  flex: none;
  height: 3.375rem;
  padding: 0 .875rem;
  background: var(--zb-head);
  color: #fff;
  font-size: .9375rem;
}
.side-brand:hover { background: #212940; }
.side-mark {
  display: grid;
  place-items: center;
  width: 1.625rem;
  height: 1.625rem;
  flex: none;
  border-radius: .4375rem;
  background: linear-gradient(135deg, rgb(var(--brand-a)), rgb(var(--brand-b)));
}
.side-brand-text { min-width: 0; }

/* --- Portal switcher ------------------------------------------------------- */
/* Zoho's app grid, reduced to the two portals this bridge mirrors. A segmented
   pair rather than a drawer: with exactly two destinations, showing both costs
   one row and saves a click. The active side wears the same green the module
   selection band does, so "where am I" reads the same way everywhere. */

.side-switch {
  display: flex;
  flex: none;
  gap: .25rem;
  margin: .5rem .625rem .125rem;
  padding: .1875rem;
  border-radius: .5rem;
  background: rgb(255 255 255 / .07);
}
.side-switch a {
  flex: 1;
  min-width: 0;
  text-align: center;
  padding: .3125rem .25rem;
  border-radius: .375rem;
  font-size: .75rem;
  font-weight: 500;
  color: var(--zb-label);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background-color .12s ease, color .12s ease;
}
.side-switch a:hover { color: #fff; background: var(--zb-hover); }
.side-switch a.is-on,
.side-switch a.is-on:hover {
  color: #fff;
  background: linear-gradient(180deg, var(--zb-sel-2), var(--zb-sel));
}

/* Full names normally; initials once the rail leaves no room for words. */
.side-switch-min { display: none; }

/* --- Module list ---------------------------------------------------------- */

.side-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: .25rem 0 .75rem;
  scrollbar-width: thin;
  scrollbar-color: rgb(255 255 255 / .16) transparent;
}
.side-nav::-webkit-scrollbar { width: 6px; }
.side-nav::-webkit-scrollbar-thumb { background: rgb(255 255 255 / .16); border-radius: 9999px; }

.side-link {
  position: relative;
  z-index: 0;
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: 2.25rem;
  padding: .375rem .75rem .375rem .5rem;
  color: var(--zb-label);
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .12s ease, color .12s ease;
}
.side-link:hover { background: var(--zb-hover); color: #fff; }

/* The selection band is inset from both edges and drawn behind the row, so
   turning it on never shifts the label the way a margin would. */
.side-link::before {
  content: "";
  position: absolute;
  inset: 0 .5rem;
  z-index: -1;
  border-radius: .375rem;
  background: transparent;
}
.side-link.is-active,
.side-link.is-active:hover {
  color: #fff;
  font-weight: 500;
  background: transparent;
}
.side-link.is-active::before {
  background: linear-gradient(180deg, var(--zb-sel-2), var(--zb-sel));
}

/* Caret column. Modules with no children get an empty one so the icons of the
   whole bar line up, exactly as they do in Books. */
.side-caret {
  width: .875rem;
  height: .875rem;
  flex: none;
  color: rgb(255 255 255 / .5);
  transition: transform .15s ease;
}
.side-gap { width: .875rem; flex: none; }
.side-tree[open] > .side-link > .side-caret { transform: rotate(90deg); }
.side-tree > summary { list-style: none; }
.side-tree > summary::-webkit-details-marker { display: none; }
.side-tree[open] > .side-link { background: var(--zb-open); color: #fff; }

/* Books keeps every module icon the same off-white -- it inherits the row's
   colour, so hover and selection lift the icon and the label together. */
.side-ico { width: 1.0625rem; height: 1.0625rem; flex: none; color: inherit; }

.side-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* Blank space, not a caption, is how Books separates blocks of modules. */
.side-space { height: .625rem; }

/* Children carry no icon in Books -- indentation does the work. */
.side-sub {
  min-height: 2.125rem;
  padding-left: 2.625rem;
  color: var(--zb-sub);
}

/* --- Footer -------------------------------------------------------------- */

.side-foot {
  flex: none;
  background: var(--zb-head);
  padding: .5rem 0 .375rem;
}
.side-user {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .25rem .75rem .5rem;
}
.side-avatar {
  display: grid;
  place-items: center;
  width: 1.625rem;
  height: 1.625rem;
  flex: none;
  border-radius: 9999px;
  background: rgb(255 255 255 / .12);
  color: #fff;
  font-size: .6875rem;
  font-weight: 600;
}
.side-email {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: .6875rem;
  color: var(--zb-sub);
}
.side-foot-row { display: flex; align-items: center; }
.side-foot-row .side-link { flex: 1; }

/* Separates the Settings section from the More drawer below it. */
.side-foot-rule {
  height: 1px;
  margin: .5rem .75rem;
  background: rgb(255 255 255 / .08);
}
:root[data-nav="rail"] .side-foot-rule { margin-inline: .375rem; }

/* The gear drawer. Its list is scrollable because the report pages alone would
   otherwise push the user row off a short screen. */
.side-more > summary { list-style: none; }
.side-more > summary::-webkit-details-marker { display: none; }
.side-more-caret {
  width: .875rem;
  height: .875rem;
  flex: none;
  margin-left: auto;
  color: rgb(255 255 255 / .45);
  transition: transform .15s ease;
}
.side-more[open] > .side-link > .side-more-caret { transform: rotate(180deg); }
.side-more[open] > .side-link { color: #fff; }
.side-more-list {
  max-height: 40vh;
  overflow-y: auto;
  padding-bottom: .375rem;
  scrollbar-width: thin;
  scrollbar-color: rgb(255 255 255 / .16) transparent;
}
.side-more-list::-webkit-scrollbar { width: 6px; }
.side-more-list::-webkit-scrollbar-thumb { background: rgb(255 255 255 / .16); border-radius: 9999px; }
.side-more-head {
  padding: .5rem .75rem .1875rem 2.625rem;
  font-size: .6875rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: rgb(255 255 255 / .38);
}

.side-collapse {
  display: none;          /* below lg the sidebar is a drawer, not a rail */
  place-items: center;
  width: 2rem;
  height: 2rem;
  flex: none;
  margin-right: .5rem;
  border-radius: .25rem;
  color: rgb(255 255 255 / .55);
  transition: background-color .12s ease, color .12s ease;
}
.side-collapse:hover { background: var(--zb-hover); color: #fff; }
.side-collapse svg { transition: transform .18s ease; }

/* --- Collapsed rail ------------------------------------------------------ */
/* Books collapses to an icon rail. Below lg the sidebar is a drawer instead,
   so the rail only exists on wide screens. */

@media (min-width: 1024px) {
  .side-collapse { display: grid; }

  :root[data-nav="rail"] .side { --side-w: var(--side-rail); }

  :root[data-nav="rail"] .side-brand-text,
  :root[data-nav="rail"] .side-label,
  :root[data-nav="rail"] .side-caret,
  :root[data-nav="rail"] .side-email,
  :root[data-nav="rail"] .side-gap,
  :root[data-nav="rail"] .side-more-caret,
  :root[data-nav="rail"] .side-more-list,
  :root[data-nav="rail"] .side-tree > div { display: none; }

  :root[data-nav="rail"] .side-brand,
  :root[data-nav="rail"] .side-user,
  :root[data-nav="rail"] .side-link { justify-content: center; padding-inline: 0; gap: 0; }

  :root[data-nav="rail"] .side-link::before { inset: 0 .375rem; }
  :root[data-nav="rail"] .side-space { height: .5rem; }

  /* A collapsed parent still has to show that the page you are on lives inside
     it, since its children are hidden. */
  :root[data-nav="rail"] .side-link.has-active::before {
    background: linear-gradient(180deg, var(--zb-sel-2), var(--zb-sel));
  }
  :root[data-nav="rail"] .side-link.has-active { color: #fff; }

  :root[data-nav="rail"] .side-switch { flex-direction: column; margin-inline: .375rem; }
  :root[data-nav="rail"] .side-switch-full { display: none; }
  :root[data-nav="rail"] .side-switch-min { display: inline; }

  :root[data-nav="rail"] .side-user     { flex-direction: column; gap: .375rem; }
  :root[data-nav="rail"] .side-foot-row { flex-direction: column; gap: .25rem; }
  :root[data-nav="rail"] .side-collapse { margin-right: 0; }
  :root[data-nav="rail"] .side-collapse svg { transform: rotate(180deg); }
  :root[data-nav="rail"] .theme-switch { flex-direction: column; }
}

/* --- Surfaces ------------------------------------------------------------- */

.card {
  position: relative;
  background-color: rgb(var(--surface));
  background-image: var(--card-sheen);
  border: 1px solid rgb(var(--line));
  border-radius: 1rem;
  box-shadow: var(--card-shadow);
}

.card-head {
  padding: .875rem 1.25rem;
  border-bottom: 1px solid rgb(var(--line));
}

/* A stat tile is a card that leads with a number. */
.tile {
  position: relative;
  overflow: hidden;
  background-color: rgb(var(--surface));
  background-image: var(--card-sheen);
  border: 1px solid rgb(var(--line));
  border-radius: 1rem;
  padding: 1rem 1.125rem;
  box-shadow: var(--card-shadow);
}
.tile-label {
  font-size: .6875rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgb(var(--ink-3));
}
.tile-value {
  margin-top: .375rem;
  font-size: 1.5rem;
  line-height: 1.15;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: rgb(var(--ink));
}
.tile-note { margin-top: .375rem; font-size: .6875rem; color: rgb(var(--ink-3)); }

/* Accent hairline along the top edge, tinted per tone. */
.tile::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, rgb(var(--brand-a)), rgb(var(--brand-b)));
  opacity: .0;
}
.tile-accent::after { opacity: .8; }
.tile-ok::after   { background: rgb(var(--ok-ink));   opacity: .7; }
.tile-bad::after  { background: rgb(var(--bad-ink));  opacity: .7; }
.tile-warn::after { background: rgb(var(--warn-ink)); opacity: .7; }

/* A card that is also a link. */
.card-link { transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease; }
.card-link:hover {
  transform: translateY(-2px);
  border-color: rgb(var(--accent) / .55);
  box-shadow: 0 1px 2px rgb(15 23 42 / .05), 0 18px 34px -22px rgb(var(--brand-a) / .65);
}

/* --- Buttons -------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  white-space: nowrap;
  border: 1px solid transparent;
  border-radius: .625rem;
  padding: .5rem 1rem;
  font-size: .875rem;
  font-weight: 500;
  line-height: 1.25rem;
  cursor: pointer;
  transition: background-color .15s ease, box-shadow .15s ease, transform .15s ease, color .15s ease;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }

.btn-primary {
  background-image: linear-gradient(90deg, rgb(var(--brand-a)), rgb(var(--brand-b)));
  color: #fff;
  box-shadow: 0 10px 22px -12px rgb(var(--brand-a) / .95);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 14px 26px -12px rgb(var(--brand-a)); }
.btn-primary:active { transform: none; }

.btn-ghost {
  background: rgb(var(--surface));
  border-color: rgb(var(--line));
  color: rgb(var(--ink-2));
}
.btn-ghost:hover { background: rgb(var(--raised)); color: rgb(var(--ink)); }

.btn-dark {
  background: rgb(var(--ink));
  color: rgb(var(--surface));
}
.btn-dark:hover { background: rgb(var(--ink) / .85); }

.btn-sm { padding: .3125rem .75rem; font-size: .75rem; border-radius: .5rem; }

/* --- Form controls -------------------------------------------------------- */
/* Element selectors, so an input a view never restyled still themes correctly.
   Any Tailwind utility in the markup still wins on specificity. */

input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]),
select,
textarea {
  background-color: rgb(var(--field-bg));
  border: 1px solid rgb(var(--line));
  border-radius: .625rem;
  color: rgb(var(--ink));
  transition: border-color .15s ease, box-shadow .15s ease;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgb(var(--accent));
  box-shadow: 0 0 0 3px rgb(var(--accent) / .22);
}

::placeholder { color: rgb(var(--ink-3)); }

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: var(--select-chevron);
  background-repeat: no-repeat;
  background-position: right .625rem center;
  padding-right: 2rem;
}

/* The native date picker button is black-on-black in dark mode. */
:root[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(1) opacity(.55);
}

input[type="checkbox"] { accent-color: rgb(var(--brand-a)); }

.field-label {
  display: block;
  margin-bottom: .375rem;
  font-size: .6875rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: rgb(var(--ink-3));
}

/* Books-style labelled fields, for forms that mirror a Books form. Sentence
   case and full width, because that is what the operator is comparing against. */
.lbl {
  display: block;
  margin-bottom: .375rem;
  font-size: .8125rem;
  font-weight: 500;
  color: rgb(var(--ink-2));
}
.fld {
  display: block;
  width: 100%;
  padding: .5rem .75rem;
  font-size: .875rem;
}
.fld-sm { padding: .375rem .5rem; font-size: .8125rem; border-radius: .5rem; }
select.fld { padding-right: 2rem; }
.hint { display: block; margin-top: .25rem; font-size: .6875rem; color: rgb(var(--ink-3)); }

/* --- Charts --------------------------------------------------------------- */
/* Series colours are the validated categorical slots 1-3 (blue, orange, aqua),
   stepped per mode -- dark is selected for the dark surface, not an automatic
   flip of light. Slot order is the colour-blind-safety mechanism, so series are
   assigned in order and never cycled; a fourth category folds into "Other" in
   recessive gray rather than inventing a hue. Text never wears a series colour:
   the mark beside it carries identity. */

.viz {
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-other: rgb(var(--ink-3));
  --viz-grid: rgb(var(--ink) / .08);
  --viz-zero: rgb(var(--ink) / .28);
  --viz-ink:  rgb(var(--ink-3));
}
:root[data-theme="dark"] .viz {
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --viz-grid: rgb(226 232 240 / .10);
  --viz-zero: rgb(226 232 240 / .32);
}

.viz svg { display: block; height: auto; overflow: visible; }
.viz text { fill: var(--viz-ink); font-size: 11px; }

/* Time-series charts fill the width and scroll rather than squash: below the
   min-width the marks and their labels compress into an unreadable strip. The
   rule is scoped, because the donut is a fixed-size mark that must keep the
   width its own class gives it. */
.viz-wide { overflow-x: auto; overflow-y: hidden; }
.viz-wide svg { width: 100%; min-width: 34rem; }
.viz .grid { stroke: var(--viz-grid); stroke-width: 1; }
.viz .zero { stroke: var(--viz-zero); stroke-width: 1; }
.viz .hit  { fill: transparent; cursor: crosshair; }
.viz .crosshair { stroke: var(--viz-zero); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0; }
.viz .hit:hover ~ .crosshair { opacity: 1; }

/* Swatch used by every legend, so identity is never colour-alone -- it always
   sits beside its label. */
.swatch {
  display: inline-block;
  width: .625rem;
  height: .625rem;
  border-radius: .1875rem;
  flex: none;
}

#vizTip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -115%);
  transition: opacity .1s ease;
  padding: .375rem .5rem;
  border-radius: .5rem;
  border: 1px solid rgb(var(--line));
  background: rgb(var(--surface));
  box-shadow: 0 10px 24px -12px rgb(0 0 0 / .5);
  font-size: .75rem;
  line-height: 1.35;
  color: rgb(var(--ink));
  white-space: nowrap;
}
#vizTip.on { opacity: 1; }

/* --- Tables --------------------------------------------------------------- */
/* Opt-in wrapper: views keep their own padding utilities, this only supplies
   the head/row/foot colouring that has to follow the theme. */

.tbl thead th {
  background: rgb(var(--raised));
  color: rgb(var(--ink-3));
  font-size: .6875rem;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  border-bottom: 1px solid rgb(var(--line));
}
.tbl tbody tr:hover { background: rgb(var(--ink) / .035); }
.tbl tbody td { color: rgb(var(--ink-2)); }
.tbl tfoot { background: rgb(var(--raised)); }
.tbl tfoot td { border-top: 1px solid rgb(var(--line)); color: rgb(var(--ink)); }

/* --- Badges and notes ----------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  border: 1px solid transparent;
  border-radius: 9999px;
  padding: .125rem .5rem;
  font-size: .6875rem;
  font-weight: 600;
  line-height: 1.1rem;
}
.badge-ok      { background: rgb(var(--ok-bg));   color: rgb(var(--ok-ink));   border-color: rgb(var(--ok-line)); }
.badge-warn    { background: rgb(var(--warn-bg)); color: rgb(var(--warn-ink)); border-color: rgb(var(--warn-line)); }
.badge-bad     { background: rgb(var(--bad-bg));  color: rgb(var(--bad-ink));  border-color: rgb(var(--bad-line)); }
.badge-info    { background: rgb(var(--info-bg)); color: rgb(var(--info-ink)); border-color: rgb(var(--info-line)); }
.badge-neutral { background: rgb(var(--raised));  color: rgb(var(--ink-2));    border-color: rgb(var(--line)); }

.note {
  border: 1px solid rgb(var(--line));
  background: rgb(var(--raised));
  color: rgb(var(--ink-2));
  border-radius: .875rem;
  padding: .75rem 1rem;
  font-size: .875rem;
}
.note-ok   { background: rgb(var(--ok-bg));   border-color: rgb(var(--ok-line));   color: rgb(var(--ok-ink)); }
.note-warn { background: rgb(var(--warn-bg)); border-color: rgb(var(--warn-line)); color: rgb(var(--warn-ink)); }
.note-bad  { background: rgb(var(--bad-bg));  border-color: rgb(var(--bad-line));  color: rgb(var(--bad-ink)); }
.note-info { background: rgb(var(--info-bg)); border-color: rgb(var(--info-line)); color: rgb(var(--info-ink)); }

/* --- Typography helpers --------------------------------------------------- */

.page-title { font-size: 1.5rem; line-height: 1.2; font-weight: 600; color: rgb(var(--ink)); letter-spacing: -.01em; }
.page-sub   { margin-top: .375rem; font-size: .875rem; color: rgb(var(--ink-2)); }

code, pre, .font-mono { font-variant-ligatures: none; }

code:not(.raw) {
  background: rgb(var(--code-bg));
  border-radius: .25rem;
  padding: .0625rem .3125rem;
  color: rgb(var(--ink-2));
}

pre {
  background: #0b1122;
  color: rgb(226 232 240);
  border: 1px solid rgb(var(--line));
  border-radius: .75rem;
}
pre code:not(.raw) { background: none; padding: 0; color: inherit; }

/* --- Theme switch --------------------------------------------------------- */

.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: .125rem;
  padding: .1875rem;
  border-radius: 9999px;
  background: rgb(255 255 255 / .06);
  border: 1px solid rgb(255 255 255 / .10);
}
.theme-switch button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 9999px;
  color: rgb(148 163 184);
  transition: background-color .15s ease, color .15s ease;
}
.theme-switch button:hover { color: #fff; }
.theme-switch button[aria-pressed="true"] {
  background: rgb(255 255 255 / .12);
  color: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / .4);
}

/* --- Mobile drawer -------------------------------------------------------- */

@media (max-width: 1023px) {
  .drawer {
    position: fixed;
    inset: 0 auto 0 0;
    width: 17rem;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.16, 1, .3, 1);
  }
  .drawer.is-open { transform: translateX(0); }
  .drawer-scrim {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgb(7 6 9 / .66);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
  }
  .drawer-scrim.is-open { opacity: 1; pointer-events: auto; }
}

/* --- Print ---------------------------------------------------------------- */
/* Statements get printed and emailed. Chrome, glow and controls are noise. */

@media print {
  .side, .app-glow, .app-grid, .no-print { display: none !important; }
  .card, .tile { box-shadow: none; border-color: #cbd5e1; break-inside: avoid; }
  body { background: #fff; }
}
