/* =========================================================================
   MSA GTM Control Tower — application styles
   Brand system (context §1.5):
     Fonts   Playfair Display (display) / DM Sans (body)
     Palette Navy #0f2a44 · Steel #5b7fa6 · Slate #2e4a62 · Cool Gray #c8d4de
             Off-White #f4f5f3 · Muted Gold #b89a3e
   ========================================================================= */

:root {
  --navy: #0f2a44;
  --steel: #5b7fa6;
  --slate: #2e4a62;
  --cool-gray: #c8d4de;
  --off-white: #f4f5f3;
  --gold: #b89a3e;

  --rag-green: #3f7d5a;
  --rag-amber: #c99a2e;
  --rag-red: #b1483c;
  --rag-neutral: #9aa9b6;

  --ink: #1c2b38;
  --muted: #63788a;
  --line: #dfe6ec;
  --card: #ffffff;
  --shadow: 0 1px 2px rgba(15, 42, 68, .06), 0 6px 18px rgba(15, 42, 68, .06);
  --radius: 12px;

  --font-body: 'DM Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --font-display: 'Playfair Display', Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--off-white);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--steel); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- App shell --------------------------------------------------------- */
.app-shell {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

.app-main { display: flex; flex-direction: column; min-width: 0; }

/* ---- Sidebar ----------------------------------------------------------- */
.sidebar {
  background: var(--navy);
  color: #eaf0f5;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

/* Brand lockup: company wordmark stacked above the product name, separated by
   a gold hairline. Vertical stack (not the old inline badge + text) because the
   wordmark is a wide horizontal logotype — sitting it beside text would force
   it down to an illegible height in a 248px rail. */
.sidebar__brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 2px 8px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, .12);
  margin-bottom: 14px;
}

/* The official MSA wordmark. currentColor makes it cream against the navy. */
.sidebar__logo {
  display: block;
  width: 152px;
  max-width: 100%;
  height: auto;
  color: var(--off-white);
}

.sidebar__brand-text {
  font-weight: 600;
  font-size: 11px;
  line-height: 1.2;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--cool-gray);
  padding-top: 9px;
  border-top: 2px solid var(--gold);
}

/* The square logomark only appears once the rail collapses. */
.sidebar__logomark { display: none; width: 40px; height: 40px; border-radius: 9px; }

.sidebar__nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.sidebar__link,
.sidebar__logout {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  color: #cdd8e2;
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 500;
  transition: background .12s ease, color .12s ease;
}
.sidebar__link:hover,
.sidebar__logout:hover { background: rgba(255, 255, 255, .07); text-decoration: none; color: #fff; }
.sidebar__link.is-active { background: var(--slate); color: #fff; }

/* Keyboard focus must stay obvious on a dark ground. */
.sidebar__link:focus-visible,
.sidebar__logout:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  color: #fff;
}

.sidebar__link-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  color: var(--steel);
}
.sidebar__link-icon .icon { width: 20px; height: 20px; display: block; }
.sidebar__link:hover .sidebar__link-icon,
.sidebar__logout:hover .sidebar__link-icon { color: #dce6ef; }
.sidebar__link.is-active .sidebar__link-icon { color: var(--gold); }

.sidebar__link-text { min-width: 0; }

.sidebar__footer { padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, .12); }
.sidebar__logout { font-size: 13px; }

/* ---- Topbar ------------------------------------------------------------ */
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 30px 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.topbar__title {
  font-family: var(--font-display);
  font-size: 24px;
  margin: 0;
  color: var(--navy);
}
.topbar__summary { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; max-width: 70ch; }

.topbar__meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--muted);
  flex: 0 0 auto;
}
/* Each meta item stays intact; only the row between them may wrap. Without
   this, "Refreshed Jul 22, 4:18pm" broke mid-phrase and the user chip jumped
   to its own line on some pages but not others. */
.topbar__source, .topbar__refresh, .topbar__user { white-space: nowrap; }

.topbar__source { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--slate); }
.topbar__source-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
.topbar__user {
  background: var(--off-white);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  font-weight: 600;
  color: var(--slate);
}

/* ---- Content ----------------------------------------------------------- */
.content { padding: 22px 30px 40px; }

/* ---- Alerts ------------------------------------------------------------ */
.alert {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  background: #fff;
}
.alert__title { font-weight: 700; text-transform: uppercase; letter-spacing: .6px; font-size: 11.5px; }
.alert--sample { background: #fbf4e0; border-color: #e7d29a; color: #7a5f16; }
.alert--sample .alert__title { color: var(--gold); }
.alert--info { background: #eef4fa; border-color: #cadcec; color: var(--slate); }
.alert--warning { background: #fbf1e5; border-color: #eccfa8; color: #855a1c; }
.alert--error { background: #fbeceb; border-color: #eabfba; color: #8f3229; }
.alert--success { background: #ecf5ef; border-color: #b9d9c5; color: #2f6045; }

/* ---- KPI grid ---------------------------------------------------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.kpi-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.kpi-card__value { font-family: var(--font-display); font-size: 26px; font-weight: 700; color: var(--navy); line-height: 1.1; }
.kpi-card__label { margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.kpi-card__rag { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--rag-neutral); }
.kpi-card.rag-green  .kpi-card__rag { background: var(--rag-green); }
.kpi-card.rag-amber  .kpi-card__rag { background: var(--rag-amber); }
.kpi-card.rag-red    .kpi-card__rag { background: var(--rag-red); }
.kpi-card--flag .kpi-card__value { color: var(--rag-red); font-size: 15px; font-family: var(--font-body); }

/* ---- Chart grid + cards ------------------------------------------------ */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.chart-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px 20px;
  min-width: 0;
}
.chart-card--full { grid-column: 1 / -1; }

/* Cards holding a multi-column data table ALWAYS span the full grid width.
   A 5-6 column table in a half-width cell needs ~506px but gets ~470px at
   1366px wide — the most common laptop resolution — which clipped the last
   column. Tables get the full row; charts are what pair side by side. */
.chart-card--table { grid-column: 1 / -1; }

.chart-card__head { margin-bottom: 12px; }
.chart-card__title { font-size: 15px; margin: 0; color: var(--navy); font-weight: 600; }
.chart-card__subtitle { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }
.chart-card__note { margin: 12px 0 0; font-size: 12px; color: var(--muted); font-style: italic; }
.chart-card__body { position: relative; height: 280px; }

/* ---- Tables ------------------------------------------------------------ */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 2px solid var(--line);
  white-space: nowrap;
}
.data-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table tr:last-child td { border-bottom: none; }
.table-empty { color: var(--muted); font-style: italic; text-align: center; padding: 18px; }
.cell-flag { color: var(--rag-red); font-weight: 600; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--off-white);
  border: 1px solid var(--line);
  color: var(--slate);
}
.pill.rag-green  { background: #ecf5ef; border-color: #b9d9c5; color: var(--rag-green); }
.pill.rag-amber  { background: #fbf4e0; border-color: #e7d29a; color: #8a6a15; }
.pill.rag-red    { background: #fbeceb; border-color: #eabfba; color: var(--rag-red); }

/* ---- Buttons ----------------------------------------------------------- */
.btn {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 11px 18px;
  cursor: pointer;
}
.btn--primary { background: var(--navy); color: #fff; }
.btn--primary:hover { background: var(--slate); }
.btn--block { width: 100%; }

/* ---- App footer -------------------------------------------------------- */
.app-footer {
  margin-top: auto;
  padding: 16px 30px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  background: #fff;
}

/* ---- Login ------------------------------------------------------------- */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1100px 600px at 15% -10%, rgba(91, 127, 166, .25), transparent),
    var(--navy);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 16px;
  padding: 30px 30px 34px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .32);
}
.login-card__brand { text-align: center; margin-bottom: 22px; }

/* The real MSA wordmark, inherited navy from currentColor on the white card. */
.login-card__logo {
  display: block;
  width: 210px;
  max-width: 78%;
  height: auto;
  margin: 0 auto;
  color: var(--navy);
}

/* Gold hairline separating the company mark from the product name, so the
   lockup reads as "Main Street Advisory / GTM Control Tower" rather than as
   one run-on title. Keeps the brand gold present now the badge is gone. */
.login-card__title {
  font-family: var(--font-display);
  color: var(--navy);
  font-size: 20px;
  margin: 18px 0 2px;
  padding-top: 16px;
  position: relative;
}
.login-card__title::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 46px;
  height: 2px;
  background: var(--gold);
}
.login-card__subtitle { color: var(--muted); font-size: 13px; margin: 0; }

.login-form { display: flex; flex-direction: column; gap: 14px; margin-top: 6px; }
.login-form__label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--slate); }
.login-form__label input {
  font: inherit;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--off-white);
}
.login-form__label input:focus { outline: 2px solid var(--steel); outline-offset: 1px; background: #fff; }

/* ---- Responsive --------------------------------------------------------
   The stylesheet previously had a single breakpoint at 900px and nothing
   above it, which left a dead zone from 901px to ~1400px where the two-column
   chart grid squeezed data tables until they clipped. Laptops live in that
   zone. The scale below covers it. */

/* Narrow laptops (1366x768 and similar): stack the chart grid so charts and
   tables each get the full content width instead of half of it. */
@media (max-width: 1400px) {
  .chart-grid { grid-template-columns: 1fr; }
  /* Doughnuts would stretch to the full row and read as a thin band, so cap
     the plot area and centre it. Bar charts stay full-bleed via --wide. */
  .chart-card__body { max-width: 760px; margin-left: auto; margin-right: auto; }
  .chart-card--wide .chart-card__body { max-width: none; }
}

/* Tablet / small laptop: tighten the page gutters, and drop the topbar meta
   onto its own left-aligned row instead of letting it wrap unpredictably
   against the title. */
@media (max-width: 1100px) {
  .content { padding: 18px 20px 32px; }
  .topbar { padding: 18px 20px 14px; flex-direction: column; align-items: stretch; gap: 12px; }
  .topbar__meta { justify-content: flex-start; }
}

/* Phone / very narrow: sidebar becomes a horizontal bar above the content. */
/* ---- Collapsed icon rail ----------------------------------------------
   Below this width the sidebar narrows to icons instead of becoming a
   horizontal bar. The previous top-bar treatment consumed ~200px of vertical
   height -- the scarcest dimension on a laptop -- and wrapped into ragged
   rows. The rail costs 64px of horizontal space and never reflows, so the
   two-column shell survives all the way down to phone width. */
@media (max-width: 1000px) {
  .app-shell { grid-template-columns: 64px 1fr; }

  .sidebar { padding: 16px 8px; align-items: center; }

  /* Swap the horizontal wordmark for the square mark: at 64px the wordmark's
     stacked text lines fall to ~5px tall and stop being readable. */
  .sidebar__logo,
  .sidebar__brand-text { display: none; }
  .sidebar__logomark { display: block; }
  .sidebar__brand {
    align-items: center;
    padding: 0 0 14px;
    width: 100%;
  }

  .sidebar__nav { width: 100%; align-items: center; }

  /* Icon centred, label removed from the visual flow but kept for assistive
     tech -- clip rather than display:none so the link keeps its accessible name. */
  .sidebar__link,
  .sidebar__logout {
    justify-content: center;
    gap: 0;
    padding: 11px 0;
    width: 48px;
  }
  .sidebar__link-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  /* Hover/focus label, drawn to the right of the rail. CSS-only, no JS. */
  .sidebar__link::after,
  .sidebar__logout::after {
    content: attr(data-label);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--ink);
    color: #fff;
    font-size: 12.5px;
    font-weight: 600;
    letter-spacing: .01em;
    padding: 6px 10px;
    border-radius: 7px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity .12s ease;
    pointer-events: none;
    z-index: 20;
    box-shadow: 0 4px 14px rgba(15, 42, 68, .28);
  }
  .sidebar__link:hover::after,
  .sidebar__link:focus-visible::after,
  .sidebar__logout:hover::after,
  .sidebar__logout:focus-visible::after { opacity: 1; visibility: visible; }

  .sidebar__footer { width: 100%; display: flex; justify-content: center; }
}

/* Users who prefer reduced motion get the label instantly, no fade. */
@media (prefers-reduced-motion: reduce) {
  .sidebar__link, .sidebar__logout,
  .sidebar__link::after, .sidebar__logout::after { transition: none; }
}

/* ---- Filter bar (context §4) ------------------------------------------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 14px;
  padding: 14px 16px;
  margin-bottom: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filter-bar__field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }

.filter-bar__label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

.filter-bar__select {
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--off-white);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 168px;
  max-width: 260px;
}
.filter-bar__select:hover { border-color: var(--cool-gray); }
.filter-bar__select:focus-visible {
  outline: 2px solid var(--steel);
  outline-offset: 1px;
  background: #fff;
}

.filter-bar__clear {
  margin-left: auto;
  align-self: center;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--rag-red);
}

.filter-bar__apply { padding: 7px 14px; font-size: 13px; }

/* Tells the reader the numbers above are narrowed, not the whole picture. */
.filter-note {
  margin: -8px 0 16px;
  font-size: 12.5px;
  color: var(--muted);
  font-style: italic;
}

@media (max-width: 1000px) {
  .filter-bar__select { min-width: 0; width: 100%; }
  .filter-bar__field { flex: 1 1 180px; }
  .filter-bar__clear { margin-left: 0; }
}

/* ---- Error pages (403 / 404 / 500) ------------------------------------- */
.error-card { text-align: center; }
.error-card__code {
  font-family: var(--font-display);
  font-size: 56px;
  font-weight: 700;
  line-height: 1;
  color: var(--gold);
  margin: 0 0 4px;
}
.error-card__heading {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--navy);
  margin: 0 0 8px;
}
.error-card__message {
  color: var(--muted);
  font-size: 13.5px;
  margin: 0 0 22px;
  line-height: 1.5;
}

/* ---- KPI status: never colour alone (handoff §5) ----------------------- */
.kpi-card__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-top: 10px;
  font-size: 11.5px;
  color: var(--muted);
}

.kpi-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--off-white);
  color: var(--slate);
}
/* Glyph differs by state as well as colour, so the status survives greyscale,
   colour-blindness and low-contrast displays. */
.kpi-status__glyph { font-size: 9px; line-height: 1; }
.kpi-status--green   { background: #ecf5ef; border-color: #b9d9c5; color: var(--rag-green); }
.kpi-status--amber   { background: #fbf4e0; border-color: #e7d29a; color: #8a6a15; }
.kpi-status--red     { background: #fbeceb; border-color: #eabfba; color: var(--rag-red); }
.kpi-status--neutral { background: var(--off-white); border-color: var(--line); color: var(--muted); }

.kpi-card__target, .kpi-card__period { white-space: nowrap; }
.kpi-card__note {
  margin: 8px 0 0;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--muted);
  font-style: italic;
}

/* ---- Kanban widget ----------------------------------------------------- */
.kanban {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
}
.kanban__col {
  flex: 0 0 210px;
  background: var(--off-white);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}
.kanban__col-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--slate);
}
.kanban__count {
  background: var(--navy);
  color: #fff;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 10.5px;
}
.kanban__card {
  background: #fff;
  border: 1px solid var(--line);
  border-left: 3px solid var(--steel);
  border-radius: 7px;
  padding: 8px 10px;
  margin-bottom: 7px;
}
.kanban__card:last-child { margin-bottom: 0; }
.kanban__card-title { margin: 0; font-size: 12.5px; line-height: 1.35; color: var(--ink); }
.kanban__card-meta  { margin: 4px 0 0; font-size: 11px; color: var(--muted); }

/* --- Section headings & exception strips (Phase C) ------------------------
   The config-driven page body renders whatever the base's Dashboard Widgets
   table defines. Sections computed by the app itself — exception strips, the
   leakage/ageing charts, the learning ledger — sit outside it and need a
   heading of their own so the page does not read as one undifferentiated wall
   of cards. */
.section-head { margin: 26px 0 10px; }
.section-head:first-child { margin-top: 2px; }
.section-head__title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .7px;
  text-transform: uppercase;
  color: var(--slate);
}
.section-head__subtitle {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  max-width: 80ch;
}

/* A chart card with no series yet: say so, rather than drawing an empty grid
   that reads as a measured zero. */
.chart-card__body--empty { display: flex; align-items: center; justify-content: center; }
.chart-card__body--empty .table-empty { margin: 0; }
