/*
  GoodCloud AIOS Client Portal: shared stylesheet.
  Implements DESIGN_CONSTITUTION_2026-09-03.md (TG-AIOS/portal-design/).
  One stylesheet for the workspace (TG-branded) and the AIOS login/denied
  screens (GoodCloud-branded, near-black + teal, per the Constitution's
  ASSUMPTION section, pending Architect confirmation of GoodCloud tokens).

  Contrast note: the Constitution names --accent (#586FF6), a hover shade
  (#4D62D9) and an active shade (#4152B6) as one default/hover/active
  progression for buttons and links. Checked against WCAG AA (4.5:1 for
  normal text), white text on the raw #586FF6 fill measures 4.18:1, a
  fail. This stylesheet keeps all three hexes but reassigns their roles:
  --accent stays the decorative brand hue (chart lines, the active nav
  marker, focus rings, thin borders, non-text uses, which only need
  3:1) and the two darker shades become the actual link/button text and
  fill colours, which do clear 4.5:1. Same fix applied to --success,
  --warning and the login teal, whose literal Constitution hex values
  also measured under 4.5:1 for text. See portal-design/evidence for the
  full before/after contrast table.
*/

/* ---------- Fonts ---------- */
/* Each page links Google Fonts in <head> (Outfit, Inter, JetBrains Mono,
   display=swap). This file only declares the stacks with system fallbacks
   below, so layout never depends on the web fonts loading. */

:root {
  /* Type stacks (fallback-safe) */
  --font-heading: 'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;

  /* ---- TG workspace colour tokens (Constitution section 3) ---- */
  --paper: #FFFFFF;
  --soft: #F7F9FB;
  --line: #E6EBF4;
  --navy: #0D1D46;
  --ink: #0E1C3D;
  --ink-2: #4A5570;
  --blue-soft: #EAF0FF;

  /* Accent: #586FF6 is the brand hue, kept for decorative / non-text use
     (chart lines, active-nav marker, focus rings, thin borders: 3:1 is
     enough there). Text and button fills use the two darker steps so
     normal text clears 4.5:1. See file header note. */
  --accent: #586FF6;
  --accent-text: #4D62D9;
  --accent-text-strong: #4152B6;

  /* Semantic (darkened from the Constitution's literal hex where the raw
     value failed 4.5:1 as text on paper, see file header note) */
  --success: #146C44;
  --warning: #8A5A16;
  --error: #B42318;
  --info: #2F5BEA;

  /* Confidence badges: letter + label always, never colour alone */
  --badge-a-text: #146C44;  --badge-a-fill: #E6F4EC; --badge-a-border: #BFE3CE;
  --badge-b-text: #1F3FAE;  --badge-b-fill: #EAF0FF; --badge-b-border: #C6D6FA;
  --badge-c-text: #8A5A16;  --badge-c-fill: #FBF0DD; --badge-c-border: #EFD9A6;
  --badge-d-text: #4A5570;  --badge-d-fill: #EEF1F6; --badge-d-border: #D7DEEA;
  --badge-unavailable-text: #B42318; --badge-unavailable-border: #E3A79D;
  --badge-notmeasured-text: #4A5570; --badge-notmeasured-border: #B9C1D1;

  /* Radii / shadow */
  --radius-card: 16px;
  --radius-control: 10px;
  --shadow-card: 0 1px 2px rgba(13, 29, 70, 0.06), 0 8px 24px rgba(13, 29, 70, 0.06);

  /* Spacing scale (8px base) */
  --space-1: 8px;
  --space-2: 12px;
  --space-3: 16px;
  --space-4: 20px;
  --space-5: 24px;
  --space-6: 28px;
  --space-7: 40px;

  /* Type scale */
  --text-xs: 13px;
  --text-sm: 15px;
  --text-base: 17px;
  --text-lg: 20px;
  --text-xl: 24px;
  --text-2xl: 32px;
  --text-3xl: 40px;
  --text-3xl-mobile: 28px;

  /* Layout */
  --shell-max: 1120px;
  --reading-max: 720px;
  --tabbar-height: 56px;

  color-scheme: light;
}

/* ---- AIOS (GoodCloud) login / denied palette, ASSUMPTION, see Constitution ---- */
:root {
  --login-ink: #0B0F19;
  --login-paper: #FFFFFF;
  --login-accent: #0FA37F;        /* decorative: icon, ring, border */
  --login-accent-text: #0B7A5F;   /* AA-safe text / button fill */
  --login-accent-text-strong: #0A6F57;
}

/* ---------- Reset ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
a { color: var(--accent-text); }
a:hover { color: var(--accent-text-strong); }
h1, h2, h3 {
  font-family: var(--font-heading);
  color: var(--ink);
  line-height: 1.15;
  margin: 0 0 var(--space-3) 0;
}
h1 { font-size: var(--text-3xl); font-weight: 700; }
h2 { font-size: var(--text-xl); font-weight: 600; }
h3 { font-size: var(--text-lg); font-weight: 600; }
p { margin: 0 0 var(--space-3) 0; max-width: 72ch; }
.eyebrow {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-2);
}

@media (max-width: 767px) {
  h1 { font-size: var(--text-3xl-mobile); }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

/* ---------- Focus visibility ---------- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
summary:focus-visible,
.tab-link:focus-visible,
.nav-link:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Skip link ---------- */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--navy);
  color: #FFFFFF;
  padding: var(--space-2) var(--space-4);
  z-index: 1000;
  border-radius: 0 0 var(--radius-control) 0;
  font-weight: 600;
}
.skip-link:focus {
  left: 0;
}

/* ---------- Shell / layout ---------- */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.header-band {
  background: var(--navy);
  color: #FFFFFF;
  padding: var(--space-3) var(--space-5);
}
.header-band-inner {
  max-width: var(--shell-max);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.header-tenant {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: var(--text-lg);
  color: #FFFFFF;
}
.header-period {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: #C7D2E8;
  letter-spacing: 0.02em;
}
.body-frame {
  display: flex;
  flex: 1;
  max-width: var(--shell-max);
  width: 100%;
  margin: 0 auto;
  align-items: flex-start;
}
.sidebar {
  width: 220px;
  flex-shrink: 0;
  padding: var(--space-5) var(--space-3);
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  align-self: stretch;
}
.sidebar-logo {
  display: block;
  width: 140px;
  height: auto;
  margin: 0 var(--space-2) var(--space-5) var(--space-2);
}
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius-control);
  color: var(--ink-2);
  text-decoration: none;
  font-weight: 500;
  font-size: var(--text-sm);
  min-height: 44px;
}
.nav-link:hover { background: var(--soft); color: var(--ink); }
.nav-link[aria-current="page"] {
  background: var(--blue-soft);
  color: var(--accent-text-strong);
  border-left: 3px solid var(--accent);
  padding-left: calc(var(--space-2) - 3px);
}
.main-content {
  flex: 1;
  min-width: 0;
  padding: var(--space-5);
}
.page-margins { padding-left: var(--space-5); padding-right: var(--space-5); }

.tab-bar {
  display: none;
}

@media (max-width: 767px) {
  .sidebar { display: none; }
  .main-content { padding: var(--space-3) var(--space-3) calc(var(--tabbar-height) + var(--space-4)); }
  .page-margins { padding-left: var(--space-3); padding-right: var(--space-3); }
  .header-band { padding: var(--space-2) var(--space-3); }
  .tab-bar {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: var(--tabbar-height);
    background: var(--paper);
    border-top: 1px solid var(--line);
    z-index: 100;
  }
  .tab-link {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    text-decoration: none;
    color: var(--ink-2);
    font-size: 10px;
    font-weight: 500;
    min-height: 44px;
    padding: 0 2px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .tab-link[aria-current="page"] {
    color: var(--accent-text-strong);
  }
  .tab-link[aria-current="page"] .tab-dot {
    display: block;
  }
  .tab-dot {
    display: none;
    width: 4px; height: 4px; border-radius: 50%;
    background: var(--accent);
    margin-bottom: 1px;
  }
}

.section { margin-bottom: var(--space-7); }
@media (max-width: 767px) {
  .section { margin-bottom: var(--space-6); }
}

.reading-column {
  max-width: var(--reading-max);
}

footer.proto-footer {
  border-top: 1px solid var(--line);
  padding: var(--space-4) var(--space-5);
  color: var(--ink-2);
  font-size: var(--text-xs);
  text-align: center;
}

/* ---------- Freshness / period strip ---------- */
.freshness-line {
  color: var(--ink-2);
  font-size: var(--text-xs);
  margin: var(--space-1) 0 var(--space-5) 0;
}

/* ---------- KPI cards ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
}
@media (max-width: 767px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 419px) {
  .kpi-grid { grid-template-columns: minmax(0, 1fr); gap: var(--space-2); }
}
.kpi-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
@media (max-width: 767px) {
  .kpi-card { padding: var(--space-3); }
}
.kpi-label {
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-2);
  overflow-wrap: anywhere;
}
.kpi-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--ink);
  line-height: 1.2;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.kpi-unit {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--ink-2);
}
.kpi-period {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--ink-2);
  overflow-wrap: anywhere;
}
.kpi-footer {
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-1);
}

/* ---------- Confidence badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 3px 10px 3px 6px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  background: rgba(255,255,255,0.55);
}
.badge-a { color: var(--badge-a-text); background: var(--badge-a-fill); border-color: var(--badge-a-border); }
.badge-b { color: var(--badge-b-text); background: var(--badge-b-fill); border-color: var(--badge-b-border); }
.badge-c { color: var(--badge-c-text); background: var(--badge-c-fill); border-color: var(--badge-c-border); }
.badge-d { color: var(--badge-d-text); background: var(--badge-d-fill); border-color: var(--badge-d-border); }
.badge-unavailable {
  color: var(--badge-unavailable-text);
  background: var(--paper);
  border: 1.5px solid var(--badge-unavailable-border);
}
.badge-notmeasured {
  color: var(--badge-notmeasured-text);
  background: var(--paper);
  border: 1.5px dashed var(--badge-notmeasured-border);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: 12px 18px;
  border-radius: var(--radius-control);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: 1.5px solid transparent;
  min-height: 44px;
  line-height: 1.2;
}
.btn-primary {
  background: var(--accent-text);
  color: #FFFFFF;
}
.btn-primary:hover { background: var(--accent-text-strong); color: #FFFFFF; }
.btn-secondary {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--line);
}
.btn-secondary:hover { background: var(--soft); }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: var(--space-2); flex-wrap: wrap; }
@media (max-width: 767px) {
  .btn-row { flex-direction: column; }
}

/* ---------- Callout ---------- */
.callout {
  background: var(--soft);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-control);
  padding: var(--space-3) var(--space-4);
}
.callout-navy {
  background: var(--navy);
  color: #FFFFFF;
  border: none;
}
.callout-navy .kpi-label,
.callout-navy p { color: #D7DEEE; }
.callout-navy h3 { color: #FFFFFF; }

/* ---------- Expandable sections ---------- */
details.expand {
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  padding: 0;
  margin-bottom: var(--space-2);
  background: var(--paper);
}
details.expand summary {
  cursor: pointer;
  list-style: none;
  padding: var(--space-3) var(--space-4);
  font-weight: 600;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
}
details.expand summary::-webkit-details-marker { display: none; }
details.expand summary::after {
  content: "+";
  font-family: var(--font-mono);
  color: var(--accent-text);
  font-size: var(--text-lg);
  margin-left: var(--space-2);
}
details.expand[open] summary::after { content: "\2212"; }
details.expand .expand-body {
  padding: 0 var(--space-4) var(--space-4) var(--space-4);
  color: var(--ink-2);
}

/* ---------- Stacked key-value cards (table replacement under 768px) ---------- */
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
table.data-table th, table.data-table td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--line);
}
table.data-table th {
  color: var(--ink-2);
  font-weight: 500;
  text-transform: uppercase;
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
}
@media (max-width: 767px) {
  table.data-table, table.data-table thead, table.data-table tbody, table.data-table th, table.data-table td, table.data-table tr {
    display: block;
  }
  table.data-table thead { display: none; }
  table.data-table tr {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius-card);
    padding: var(--space-3);
    margin-bottom: var(--space-2);
  }
  table.data-table td {
    border: none;
    padding: 4px 0;
    display: flex;
    justify-content: space-between;
    gap: var(--space-2);
  }
  table.data-table td::before {
    content: attr(data-label);
    color: var(--ink-2);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 500;
    padding-right: var(--space-2);
  }
}

/* ---------- Report list item ---------- */
.report-list { display: flex; flex-direction: column; gap: var(--space-2); }
.report-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.report-item-main { min-width: 0; }
.report-title { font-weight: 600; font-size: var(--text-base); color: var(--ink); margin-bottom: 2px; }
.report-meta { font-size: var(--text-xs); color: var(--ink-2); font-family: var(--font-mono); }
.report-actions { display: flex; gap: var(--space-1); flex-wrap: wrap; }
.pill-historical {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-2);
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  margin-left: var(--space-1);
}

/* ---------- Video card ---------- */
.video-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  overflow: hidden;
  max-width: 480px;
  box-shadow: var(--shadow-card);
}
.video-poster {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--navy);
}
.video-poster img { width: 100%; height: 100%; object-fit: cover; }
.video-play-badge {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-play-circle {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: rgba(255,255,255,0.92);
  display: flex; align-items: center; justify-content: center;
  color: var(--navy);
  font-size: 20px;
}
.video-duration {
  position: absolute;
  right: 8px; bottom: 8px;
  background: rgba(13,29,70,0.85);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
}
.video-body { padding: var(--space-4); }

/* ---------- Denied notice ---------- */
.denied-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  background: var(--soft);
}
.denied-card {
  max-width: 480px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-7) var(--space-5);
  text-align: center;
}
.denied-mark {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--soft);
  border: 1px solid var(--line);
  color: var(--ink-2);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto var(--space-4) auto;
  font-size: 22px;
}
.denied-text { color: var(--ink); font-size: var(--text-base); margin: 0; }

/* ---------- Login card ---------- */
.login-shell {
  min-height: 100vh;
  background: var(--login-paper);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  font-family: var(--font-body);
}
.login-card {
  width: 100%;
  max-width: 400px;
}
.login-wordmark {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: var(--text-xl);
  color: var(--login-ink);
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: var(--space-5);
}
.login-wordmark .dot { color: var(--login-accent-text); }
.login-card h1 {
  color: var(--login-ink);
  font-size: var(--text-2xl);
  margin-bottom: var(--space-1);
}
.login-card .sub {
  color: var(--login-ink);
  opacity: 0.72;
  margin-bottom: var(--space-5);
}
.login-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  padding: 12px 18px;
  border-radius: var(--radius-control);
  border: 1.5px solid #D8DCE3;
  background: var(--login-paper);
  color: var(--login-ink);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--text-sm);
  min-height: 48px;
  cursor: pointer;
  margin-bottom: var(--space-2);
}
.login-btn:hover { border-color: var(--login-accent-text); }
.login-btn.primary {
  background: var(--login-accent-text);
  border-color: var(--login-accent-text);
  color: #FFFFFF;
}
.login-btn.primary:hover { background: var(--login-accent-text-strong); border-color: var(--login-accent-text-strong); }
.login-fineprint {
  margin-top: var(--space-4);
  font-size: var(--text-xs);
  color: var(--login-ink);
  opacity: 0.62;
  line-height: 1.6;
}
.login-fineprint a { color: var(--login-accent-text); }

/* ---------- Hero photo (report page) ---------- */
.hero-photo {
  width: 100%;
  aspect-ratio: 16 / 6;
  object-fit: cover;
  border-radius: var(--radius-card);
  margin-bottom: var(--space-5);
}
@media (max-width: 767px) {
  .hero-photo { aspect-ratio: 4 / 3; }
}

/* ---------- Facts / interpretation / recommendation labels ---------- */
.fir-block { margin-top: var(--space-3); }
.fir-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-2);
  margin-bottom: 4px;
}
.fir-label.facts { color: var(--ink-2); }
.fir-label.interpretation { color: var(--accent-text-strong); }
.fir-label.recommendation { color: var(--success); }

/* ---------- How-to-read panel ---------- */
.howto-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3);
}

/* ---------- Utility ---------- */
.stack { display: flex; flex-direction: column; gap: var(--space-2); }
.text-muted { color: var(--ink-2); }
.mono { font-family: var(--font-mono); }
.section-divider { height: 1px; background: var(--line); border: none; margin: var(--space-6) 0; }
