/*
 * Layout, type and spacing. NO COLOUR VALUES LIVE HERE.
 *
 * Every colour in this file is a var() pointing at a token defined in
 * palette.css, which is the mirror of public/palette.js. That separation is
 * enforced: the gate refuses a hex literal anywhere under public/ except
 * palette.js, and tests/palette.test.mjs measures the declared contrast pairs
 * and fails with the actual ratio when one of them does not clear its
 * threshold. Colour is the thing that drifts silently, so it gets one home and
 * a test that can tell when somebody moves it.
 *
 * palette.css is linked separately in index.html, BEFORE this file. It is not
 * imported from here: an @import is only discovered once the importing sheet
 * has been fetched and parsed, which costs a serial round trip before the first
 * paint, where two link elements are fetched at the same time.
 */

*, *::before, *::after { box-sizing: border-box; }

/*
 * The `hidden` attribute has to win, and it does not win on its own here.
 *
 * A browser's default sheet says `[hidden] { display: none }`, but that is an
 * attribute selector at the lowest possible priority, so any class rule below
 * that sets a display beats it. This page has several - `.signin` is a grid,
 * `.app` is a flex column, `.view` and `.panel` are blocks - and every one of
 * them is toggled by `hidden`. Without this line a signed-in visitor gets the
 * dashboard rendered UNDERNEATH a sign-in card that was told to hide and did
 * not, which is exactly what happened the first time this page was opened.
 */
[hidden] { display: none !important; }

/*
 * color-scheme follows the attribute theme.js writes, rather than being
 * assigned from JavaScript. Assigning it there worked but produced a style
 * attribute on <html>, and this page's policy reports a violation for every
 * one of those. It tells the browser which way to paint scrollbars, form
 * controls and the flash before the first paint.
 */
html { color-scheme: light dark; }
html[data-theme="light"] { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  background: var(--mint-bg);
  color: var(--mint-text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.86rem; color: var(--mint-text-muted); font-weight: 600; }
a { color: var(--mint-link); }
a:hover { color: var(--mint-link-hover); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  padding: 10px 16px; background: var(--mint-surface); color: var(--mint-text);
}
.skip:focus { left: 8px; top: 8px; }

:focus-visible { outline: 2px solid var(--mint-focus); outline-offset: 2px; }

/* ------------------------------------------------------------------ sign in */

.signin {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.signin-card {
  width: min(380px, 100%); text-align: center;
  background: var(--mint-surface); border: 1px solid var(--mint-border);
  border-radius: 14px; padding: 40px 32px;
}
.mark { margin-bottom: 14px; }
.signin-lede { color: var(--mint-text-muted); margin: 6px 0 24px; }
.signin-note { color: var(--mint-danger); font-size: 0.86rem; margin-top: 16px; }

/* ------------------------------------------------------------------- chrome */

.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 10px 20px; border-bottom: 1px solid var(--mint-border);
  background: var(--mint-surface); position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; }

.tabs { display: flex; gap: 2px; }
.tab {
  border: 0; background: none; color: var(--mint-text-muted); cursor: pointer;
  padding: 7px 12px; border-radius: 7px; font: inherit; font-size: 0.9rem;
}
.tab:hover { background: var(--mint-surface-sunken); color: var(--mint-text); }
.tab[aria-current="page"] { background: var(--mint-surface-sunken); color: var(--mint-text); font-weight: 600; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.who { display: flex; align-items: center; gap: 8px; }
.who img { border-radius: 50%; }
.who-text { display: flex; flex-direction: column; line-height: 1.25; font-size: 0.8rem; }
.who-text a { font-size: 0.74rem; color: var(--mint-text-subtle); text-decoration: none; }
.who-text a:hover { text-decoration: underline; }

select, input[type="text"], input[type="number"], input[type="password"] {
  font: inherit; font-size: 0.9rem; padding: 6px 9px;
  border: 1px solid var(--mint-border); border-radius: 7px;
  background: var(--mint-surface); color: var(--mint-text);
}

.button {
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; font-size: 0.88rem; padding: 7px 14px; cursor: pointer;
  border: 1px solid var(--mint-border); border-radius: 8px;
  background: var(--mint-surface); color: var(--mint-text); text-decoration: none;
}
.button:hover { background: var(--mint-surface-sunken); }
.button.primary { background: var(--mint-accent); border-color: var(--mint-accent); color: var(--mint-on-accent); }
.button.primary:hover { background: var(--mint-accent-hover); }
.button.danger { color: var(--mint-danger); border-color: var(--mint-danger-line); }
.button.small { padding: 4px 9px; font-size: 0.8rem; }
.button:disabled { opacity: 0.55; cursor: default; }
.icon-button {
  font: inherit; font-size: 0.8rem; padding: 5px 10px; cursor: pointer;
  border: 1px solid var(--mint-border); border-radius: 7px;
  background: var(--mint-surface); color: var(--mint-text-muted);
}

main { flex: 1; padding: 20px; max-width: 1500px; width: 100%; margin: 0 auto; }

.banner {
  padding: 10px 14px; border-radius: 9px; margin-bottom: 16px; font-size: 0.9rem;
  border: 1px solid var(--mint-border);
}
.banner-warn { background: var(--mint-warn-soft); border-color: var(--mint-warn-line); color: var(--mint-warn-ink); }
.banner-danger { background: var(--mint-danger-soft); border-color: var(--mint-danger-line); color: var(--mint-danger-ink); }

.empty { color: var(--mint-text-subtle); text-align: center; padding: 48px 0; }
.fatal { color: var(--mint-danger); padding: 24px; }

/* -------------------------------------------------------------------- cards */

.grid {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr));
}

.card {
  background: var(--mint-surface); border: 1px solid var(--mint-border);
  border-radius: 13px; padding: 18px; display: flex; flex-direction: column; gap: 14px;
}
.card-disabled { opacity: 0.7; }
.card-head { display: flex; align-items: flex-start; gap: 12px; }
.card-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-health { margin-left: auto; }
.card-note { margin: 0; font-size: 0.8rem; color: var(--mint-text-subtle); }
.card-note-quiet { font-size: 0.76rem; }
.card-actions { display: flex; gap: 8px; }

.chip {
  font-size: 0.72rem; padding: 2px 8px; border-radius: 999px;
  background: var(--mint-surface-sunken); color: var(--mint-text-muted); border: 1px solid var(--mint-border);
}
.chip-ok { background: var(--mint-ok-soft); color: var(--mint-ok-ink); border-color: var(--mint-ok-line); }
.chip-muted { color: var(--mint-text-subtle); }

.badge { font-size: 0.74rem; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--mint-border); }
.badge-ok { background: var(--mint-ok-soft); color: var(--mint-ok-ink); border-color: var(--mint-ok-line); }
.badge-warn { background: var(--mint-warn-soft); color: var(--mint-warn-ink); border-color: var(--mint-warn-line); }
.badge-danger { background: var(--mint-danger-soft); color: var(--mint-danger-ink); border-color: var(--mint-danger-line); }
/*
 * text-muted, not text-subtle. Measured, subtle on unknown-soft is 3.40 in
 * dark, under the 4.5 this app holds text to; muted is 5.07 there and 6.42 in
 * light. The third text level cannot be lifted to pass without collapsing into
 * the second, so this badge uses the second.
 */
.badge-unknown { background: var(--mint-unknown-soft); color: var(--mint-text-muted); border-color: var(--mint-unknown); }

.gauges {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}
.gauge-slot { min-width: 0; }

/* ----------------------------------------------------------- model meters */

.model-rows { display: flex; flex-direction: column; gap: 5px; }
.model-row {
  display: grid; gap: 8px; align-items: center;
  grid-template-columns: minmax(90px, 1.4fr) repeat(3, minmax(0, 1fr));
  font-size: 0.76rem;
}
.model-name {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem; color: var(--mint-text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.meter { display: flex; align-items: center; gap: 5px; min-width: 0; }
.meter-label { color: var(--mint-text-subtle); font-size: 0.68rem; width: 20px; }
/*
 * The meter is an SVG so that a bar's length is a width attribute rather than a
 * style, which keeps `style-src 'self'` free of violations. Everything below
 * paints it; nothing below sets its geometry.
 */
.meter-rail { flex: 1; height: 6px; min-width: 20px; display: block; }
.meter-track { fill: var(--mint-track); }
.meter-fill { fill: var(--mint-ok); }
.meter-warn .meter-fill { fill: var(--mint-warn); }
.meter-danger .meter-fill { fill: var(--mint-danger); }
/*
 * The unknown rail is dashed and empty, never a zero-width fill. A zero-width
 * fill says "nothing is happening"; a dashed outline says "we were not told the
 * limit", and those are different facts that must not look the same.
 */
.meter-unknown {
  fill: none; stroke: var(--mint-unknown); stroke-width: 1; stroke-dasharray: 3 3;
}
.meter-value { color: var(--mint-text-muted); font-variant-numeric: tabular-nums; font-size: 0.7rem; }

/* ------------------------------------------------------------------- charts */

.charts { display: flex; flex-direction: column; gap: 14px; }
.chart { display: flex; flex-direction: column; gap: 6px; }
/*
 * Wide content scrolls inside its own container. The page body must never
 * scroll sideways, which is what happens the moment a chart with sixty-two days
 * of bars is allowed to set the page width.
 */
.chart-canvas { overflow-x: auto; overflow-y: hidden; }

.breakdown { font-size: 0.82rem; }
.breakdown summary { cursor: pointer; color: var(--mint-text-muted); }
.breakdown-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.breakdown-list li { display: flex; justify-content: space-between; gap: 12px; }
.breakdown-label { color: var(--mint-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.breakdown-value { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------- panels */

.panel {
  background: var(--mint-surface); border: 1px solid var(--mint-border);
  border-radius: 13px; padding: 18px; margin-bottom: 18px;
}
.panel-lede { color: var(--mint-text-muted); font-size: 0.86rem; margin: 6px 0 14px; max-width: 72ch; }

.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--mint-border); }
.table th { color: var(--mint-text-subtle); font-weight: 600; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em; }
.table td.mono, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.8rem; }
.table td.yes { color: var(--mint-ok-ink); }
.table td.no { color: var(--mint-text-subtle); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.form { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: start; }
.form-inline { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--mint-border); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 0.78rem; color: var(--mint-text-muted); font-weight: 600; }
.hint { margin: 0; font-size: 0.74rem; color: var(--mint-text-subtle); }
.form-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; }
.form-message { font-size: 0.82rem; color: var(--mint-text-muted); }

.explain { margin: 0; }
.explain dt { font-weight: 600; margin-top: 14px; font-size: 0.9rem; }
.explain dd { margin: 4px 0 0; color: var(--mint-text-muted); font-size: 0.86rem; max-width: 76ch; }
.capability-note { font-size: 0.84rem; color: var(--mint-text-muted); max-width: 76ch; }

.footer {
  padding: 14px 20px; border-top: 1px solid var(--mint-border);
  color: var(--mint-text-subtle); font-size: 0.78rem; display: flex; gap: 8px;
}
.footer-sep { opacity: 0.5; }

@media (max-width: 720px) {
  .topbar { gap: 10px; }
  .topbar-right { width: 100%; margin-left: 0; }
  .who-text { display: none; }
  main { padding: 14px; }
}

/* ------------------------------------------------------- gauge and charts */
/*
 * These rules used to live in style attributes inside gauge.js and bars.js,
 * and the content security policy blocked every one of them: `style-src 'self'`
 * with no unsafe-inline refuses a style attribute outright, so the gauges
 * rendered with no layout at all and reported it only to the browser console.
 * Markup carries classes; anything genuinely computed is assigned through the
 * CSSOM, which CSP does not gate.
 */

.mint-gauge {
  margin: 0; display: flex; flex-direction: column; gap: 3px; align-items: center;
}
.mint-gauge__dial { width: 100%; height: auto; display: block; }
.mint-gauge__source {
  font-size: 0.68rem; color: var(--mint-text-subtle); text-align: center;
  line-height: 1.3;
  /*
   * Two lines and then an ellipsis. This caption says where a limit came from
   * and how old it is, which matters, but it is a footnote to the number above
   * it. Unbounded it wrapped into a six-line tower that was three times the
   * height of the gauge it belonged to, and the reading stopped being the thing
   * the eye landed on. The full sentence stays in the title and in the SVG's
   * aria-label, so nothing is lost to a screen reader or a hover.
   */
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  overflow: hidden;
}

.mint-bars { display: flex; flex-direction: column; }
.mint-bars--empty {
  display: flex; align-items: center; justify-content: center;
  min-height: 8rem; color: var(--mint-text-subtle);
  border: 1px dashed var(--mint-border); border-radius: 8px; font-size: 0.85rem;
}
.mint-bars__scroll { overflow-x: auto; max-width: 100%; }
.mint-bars__plot { display: block; max-width: 100%; height: auto; }
.mint-bars__legend {
  display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px;
  font-size: 0.72rem; color: var(--mint-text-muted);
}
.mint-bars__key { display: inline-flex; align-items: center; gap: 5px; }
.mint-bars__swatch { width: 11px; height: 11px; flex: none; display: block; }
.mint-bars__swatch--unknown rect { fill: var(--mint-unknown-soft); stroke: var(--mint-unknown); }


/* -------------------------------------------------------- estate rollup */
/*
 * The rollup reads as one block above the cards, not as another card. It gets
 * more horizontal room than a card does because its table is wide and its
 * question is a whole-estate one.
 */
.estate { display: flex; flex-direction: column; gap: 16px; }
.estate-head h2 { margin-bottom: 2px; }
.estate-head .panel-lede { margin: 0; }

.estate-figures {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
}
.figure {
  background: var(--mint-surface-sunken); border: 1px solid var(--mint-border);
  border-radius: 10px; padding: 12px 14px;
}
/* The number is the hero and the qualification underneath it is not optional
 * decoration: "not reported" and "covering 2 of 3 accounts" are the difference
 * between a figure somebody can plan against and one that misleads them. */
.figure-value { font-size: 1.35rem; font-weight: 650; letter-spacing: -0.02em; }
.figure-label { font-size: 0.78rem; color: var(--mint-text-muted); margin-top: 2px; }
.figure-note { font-size: 0.72rem; color: var(--mint-text-subtle); margin-top: 5px; line-height: 1.35; }

.estate-charts {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr));
}
.estate-where { display: flex; gap: 5px; flex-wrap: wrap; }
.estate-note {
  margin: 0; font-size: 0.76rem; color: var(--mint-text-subtle);
  max-width: 90ch; line-height: 1.45;
}
