/* BEC AI Scrum Coach
 *
 * Colour roles come from the project's reference palette. Two jobs only:
 *
 *   status   findings by severity. Fixed, never themed. Because `warning` and
 *            `serious` sit below 3:1 on the light surface by design, every
 *            severity also carries an icon AND a text label - colour never
 *            carries meaning alone.
 *   sequential  one hue (blue), light to dark, for the coverage meters. A
 *            meter is magnitude, so it is a single-hue ramp - not a
 *            categorical series, and not a rainbow.
 *
 * Dark mode is selected rather than flipped: its own steps from the same
 * ramps, declared under both the media query and the data-theme scope so the
 * explicit toggle wins either way.
 */

:root {
  color-scheme: light;

  --surface-0: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #eeeeec;
  --border: #dedcd6;
  --border-strong: #c7c5bd;

  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #76746e;

  /* sequential blue - meter fill and primary action */
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-quiet: #cde2fb;

  /* status - fixed, never themed */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgb(11 11 11 / 6%), 0 4px 12px rgb(11 11 11 / 4%);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --border: #35342f;
    --border-strong: #4a4943;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #96948a;
    --accent: #3987e5;
    --accent-ink: #0b0b0b;
    --accent-quiet: #184f95;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 14px rgb(0 0 0 / 30%);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --border: #35342f;
  --border-strong: #4a4943;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #96948a;
  --accent: #3987e5;
  --accent-ink: #0b0b0b;
  --accent-quiet: #184f95;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 14px rgb(0 0 0 / 30%);
}

* { box-sizing: border-box; }

/* The `hidden` attribute must win over every layout rule below.
 *
 * This is not belt-and-braces, it is load-bearing. The UA stylesheet says
 * [hidden]{display:none}, which is specificity (0,1,0) - exactly the same as
 * a class selector, and author styles beat UA styles on a tie. So the moment
 * something declares `.signin{display:grid}` or `.app{display:flex}`, those
 * elements ignore `hidden` completely and render regardless.
 *
 * The symptom is baffling rather than obviously visual: sign-in succeeds, the
 * API returns 200, the dashboard populates - and the user still sees the
 * sign-in card, because it is sitting on top of a perfectly healthy app. The
 * server logs look completely clean, so it reads as an auth bug for a while.
 *
 * !important is warranted here: `hidden` is a statement about whether an
 * element exists for the user at all, and no layout rule should be able to
 * overrule it. Every toggle in app.js depends on this. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--surface-0);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.4rem; }
h2 { font-size: 0.95rem; }

.muted { color: var(--text-secondary); }
.fine { font-size: 0.8rem; }
.spacer { flex: 1; }

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

/* --- controls ----------------------------------------------------------- */

.btn {
  font: inherit;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-1);
  color: var(--text-primary);
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: background 120ms ease, border-color 120ms ease;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 550;
}
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-primary:disabled { opacity: 0.55; cursor: default; filter: none; }

.btn-quiet { border-color: transparent; background: transparent; color: var(--text-secondary); }
.btn-quiet:hover { background: var(--surface-2); }

.select {
  font: inherit;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-1);
  color: var(--text-primary);
}

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

.signin { min-height: 100dvh; display: grid; place-items: center; padding: 2rem; }
.signin-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.25rem;
  max-width: 24rem;
  text-align: center;
}
.signin-card h1 { margin-bottom: 0.5rem; }
.signin-card .btn { margin-top: 1.25rem; }
.signin-card p + p { margin-top: 1rem; }

/* --- shell -------------------------------------------------------------- */

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

.topbar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 0.5rem; }
.brand-mark {
  width: 0.9rem; height: 0.9rem; border-radius: 3px;
  background: var(--accent); display: inline-block;
}
.brand-name { font-weight: 600; letter-spacing: -0.01em; }
.who { font-size: 0.8rem; }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(20rem, 2fr) minmax(22rem, 3fr);
  gap: 1rem;
  padding: 1rem;
  align-items: start;
}
@media (max-width: 60rem) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem 1.2rem;
}
.panel-head {
  display: flex; align-items: baseline; gap: 0.6rem;
  margin: 1.25rem 0 0.5rem;
}
.panel-head:first-child { margin-top: 0; }
.panel-head h2 { flex: 1; }

/* --- stat tiles --------------------------------------------------------- */
/* A coverage percentage is a single headline, so it is a stat tile rather
 * than a chart. The meter beneath it is a one-hue magnitude bar: 4px rounded
 * end, anchored to the track's start, 2px gap from the track edge. */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); gap: 0.6rem; }

.tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.8rem 0.8rem;
}
.tile-label {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); font-weight: 600;
}
.tile-value {
  font-size: 1.65rem; font-weight: 650; letter-spacing: -0.02em;
  line-height: 1.1; margin-top: 0.2rem;
  font-variant-numeric: tabular-nums;
}
.tile-value small { font-size: 0.9rem; font-weight: 500; color: var(--text-secondary); }
.tile-sub { font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.15rem; }

.meter {
  margin-top: 0.55rem; height: 6px; border-radius: 3px;
  background: var(--surface-0);
  border: 1px solid var(--border);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 0 4px 4px 0;   /* rounded data-end only */
  min-width: 2px;
}

/* --- findings ----------------------------------------------------------- */
/* Severity is carried by an icon, a text label AND a colour - never colour
 * alone, which matters because two of the four status steps are sub-3:1 on
 * the light surface by design. */

.findings { display: flex; flex-direction: column; gap: 0.4rem; }

.finding {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 0.6rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  width: 100%;
}
.finding:hover { background: var(--surface-2); }
.finding:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sev-icon { width: 1.05rem; height: 1.05rem; flex: none; margin-top: 0.1rem; }
.sev-critical { color: var(--critical); }
.sev-serious  { color: var(--serious); }
.sev-warning  { color: var(--warning); }
.sev-info     { color: var(--text-muted); }

.finding-title { font-weight: 550; }
.finding-meta { font-size: 0.78rem; color: var(--text-secondary); margin-top: 0.1rem; }
.finding-count {
  font-variant-numeric: tabular-nums; font-weight: 600;
  color: var(--text-secondary); font-size: 0.85rem;
}
.sev-label {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em;
  font-weight: 650;
}

.key { font-family: var(--mono); font-size: 0.78rem; }

.table-wrap { overflow-x: auto; margin-top: 0.5rem; }
table { border-collapse: collapse; width: 100%; font-size: 0.82rem; }
th, td { text-align: left; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; text-transform: uppercase; font-size: 0.7rem; letter-spacing: 0.05em; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- chat --------------------------------------------------------------- */

.chat-panel { display: flex; flex-direction: column; min-height: 32rem; }

.log {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.75rem;
  padding: 0.5rem 0.1rem; min-height: 12rem;
}

.msg { max-width: 44rem; }
.msg-user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius) var(--radius) 2px var(--radius);
}
.msg-coach {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius) var(--radius) var(--radius) 2px;
  white-space: pre-wrap;
}
.msg-error {
  align-self: flex-start;
  border: 1px solid var(--critical);
  color: var(--critical);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
}

.typing { display: inline-flex; gap: 3px; align-items: center; }
.typing i {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--text-muted); display: block;
  animation: blink 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; opacity: 0.6; } }

.prompts { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0; }
.chip {
  font: inherit; font-size: 0.8rem;
  border: 1px solid var(--border-strong); background: var(--surface-1);
  color: var(--text-secondary);
  border-radius: 999px; padding: 0.3rem 0.7rem; cursor: pointer;
}
.chip:hover { background: var(--surface-2); color: var(--text-primary); }

.composer { display: flex; gap: 0.5rem; align-items: flex-end; margin-top: 0.5rem; }
.composer textarea {
  flex: 1; font: inherit; resize: none; max-height: 9rem;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-1);
  color: var(--text-primary);
}
.composer textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }

.empty { color: var(--text-muted); font-size: 0.88rem; padding: 0.5rem 0; }
