/* ========================================================= theme.css
   The "operations console" design identity. Loaded LAST so it wins.

   Direction: a churn-management command centre for a CS team working ~1,000
   accounts a day. A fixed dark rail gives the product an identity a plain top
   nav never could; the content sits on a cool slate canvas so white cards and
   severity colour carry the eye. One flat accent (iris) for active/primary/
   focus only — no gradients. Semantic green/amber/red are reserved for health
   and priority and never used as the accent. Fully theme-aware + reduced-motion.
   ======================================================================= */

/* ------------------------------------------------------------ design tokens */
:root {
  /* Cool slate-indigo neutrals — biased toward the accent, not flat grey. */
  --canvas:       #eef0f5;   /* app background behind the cards */
  --surface-1:    #ffffff;   /* cards / raised surfaces */
  --surface-2:    #f4f5f9;   /* insets, hovers, quiet fills */
  --plane:        #f4f5f9;
  --text-primary: #14161f;
  --text-secondary:#4b4e5c;
  --text-muted:   #878a99;
  --grid:         #e7e9f0;
  --axis:         #cfd2dd;
  --border:       rgba(20, 22, 43, 0.10);
  --border-strong:rgba(20, 22, 43, 0.16);

  /* One flat accent. Iris — distinct from the generic dashboard blue. */
  --accent:       #5b5bd6;
  --accent-ink:   #ffffff;
  --accent-tint:  color-mix(in srgb, var(--accent) 10%, var(--surface-1));
  --series-1:     #5b5bd6;
  --series-1-soft:#dcdcf7;

  /* Semantic severity — kept clearly apart from the accent hue. */
  --good:         #17915a;
  --success-text: #0f7a49;
  --warning:      #c9820a;
  --serious:      #e0703a;
  --critical:     #d64545;

  /* Usage tiers, retuned to the cooler ground. */
  --tier-power:   #17915a;
  --tier-active:  #5b5bd6;
  --tier-light:   #c9820a;
  --tier-dormant: #e0703a;
  --tier-none:    #878a99;

  /* Fixed dark rail — the sidebar keeps this palette in BOTH themes so the
     product's identity stays constant. */
  --rail:         #14151d;
  --rail-2:       #1c1d27;
  --rail-line:    rgba(255,255,255,0.08);
  --rail-text:    #c7c9d6;
  --rail-muted:   #767995;
  --rail-active-bg: color-mix(in srgb, var(--accent) 20%, transparent);

  --radius:      12px;
  --radius-sm:   8px;
  --radius-pill: 999px;

  --shadow-sm:   0 1px 2px rgba(20, 22, 43, 0.06);
  --shadow:      0 1px 2px rgba(20, 22, 43, 0.05), 0 3px 10px rgba(20, 22, 43, 0.06);
  --shadow-md:   0 2px 6px rgba(20, 22, 43, 0.07), 0 10px 26px rgba(20, 22, 43, 0.09);
  --shadow-lg:   0 12px 34px rgba(20, 22, 43, 0.14);

  --sidebar-w:   236px;
  --ease:        cubic-bezier(0.22, 0.61, 0.36, 1);

  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    --canvas:       #0a0b10;
    --surface-1:    #16171f;
    --surface-2:    #1e1f29;
    --plane:        #1e1f29;
    --text-primary: #f3f4f8;
    --text-secondary:#b6b9c8;
    --text-muted:   #7e8195;
    --grid:         #262834;
    --axis:         #363948;
    --border:       rgba(255, 255, 255, 0.09);
    --border-strong:rgba(255, 255, 255, 0.17);
    --accent:       #8987f2;
    --accent-ink:   #0a0b10;
    --accent-tint:  color-mix(in srgb, var(--accent) 16%, var(--surface-1));
    --series-1:     #8987f2;
    --series-1-soft:#2b2c53;
    --good:         #2ea36a;
    --success-text: #43c07f;
    --warning:      #d99521;
    --serious:      #e0703a;
    --critical:     #e5645f;
    --tier-power:   #2ea36a;
    --tier-active:  #8987f2;
    --tier-light:   #d99521;
    --tier-dormant: #e0703a;
    --rail:         #0e0f16;
    --rail-2:       #171823;
    --rail-line:    rgba(255,255,255,0.07);
    --rail-text:    #c2c4d4;
    --rail-muted:   #6f7290;
    --shadow-sm:   0 1px 2px rgba(0,0,0,0.5);
    --shadow:      0 1px 2px rgba(0,0,0,0.5), 0 6px 18px rgba(0,0,0,0.4);
    --shadow-md:   0 4px 16px rgba(0,0,0,0.5);
    --shadow-lg:   0 18px 44px rgba(0,0,0,0.6);
  }
}
:root[data-theme="dark"] {
  --canvas:       #0a0b10;
  --surface-1:    #16171f;
  --surface-2:    #1e1f29;
  --plane:        #1e1f29;
  --text-primary: #f3f4f8;
  --text-secondary:#b6b9c8;
  --text-muted:   #7e8195;
  --grid:         #262834;
  --axis:         #363948;
  --border:       rgba(255, 255, 255, 0.09);
  --border-strong:rgba(255, 255, 255, 0.17);
  --accent:       #8987f2;
  --accent-ink:   #0a0b10;
  --accent-tint:  color-mix(in srgb, var(--accent) 16%, var(--surface-1));
  --series-1:     #8987f2;
  --series-1-soft:#2b2c53;
  --good:         #2ea36a;
  --success-text: #43c07f;
  --warning:      #d99521;
  --serious:      #e0703a;
  --critical:     #e5645f;
  --tier-power:   #2ea36a;
  --tier-active:  #8987f2;
  --tier-light:   #d99521;
  --tier-dormant: #e0703a;
  --rail:         #0e0f16;
  --rail-2:       #171823;
  --rail-line:    rgba(255,255,255,0.07);
  --rail-text:    #c2c4d4;
  --rail-muted:   #6f7290;
  --shadow-sm:   0 1px 2px rgba(0,0,0,0.5);
  --shadow:      0 1px 2px rgba(0,0,0,0.5), 0 6px 18px rgba(0,0,0,0.4);
  --shadow-md:   0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg:   0 18px 44px rgba(0,0,0,0.6);
}

/* --------------------------------------------------------------- typography */
body {
  background: var(--canvas);
  color: var(--text-primary);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.006em;
}
h1 { font-size: 24px; font-weight: 760; letter-spacing: -0.025em; }
h2 { font-size: 16px; font-weight: 680; letter-spacing: -0.015em; }
h3 { font-size: 13px; font-weight: 640; }
.subtle { color: var(--text-muted); }
code, .mono, .copytext { font-family: var(--mono); }

/* --------------------------------------------------------- staging banner */
.staging-banner {
  background: #b45309; color: #fff; text-align: center;
  font-size: 12px; font-weight: 700; padding: 3px 8px; letter-spacing: 0.03em;
}

/* ================================================================ app shell */
.app-shell { display: block; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 60;
  display: flex; flex-direction: column;
  background: var(--rail); color: var(--rail-text);
  border-right: 1px solid var(--rail-line);
  padding: 14px 12px 12px;
}
.app-main { margin-left: var(--sidebar-w); min-height: 100vh; min-width: 0; }
/* Fill the whole viewport beside the rail — this is a dense data console, so it
   uses the full width with fixed gutters rather than a centred column. */
.app-main .wrap { max-width: none; margin: 0; padding: 26px 34px 72px; }
@media (min-width: 1800px) { .app-main .wrap { padding: 30px 48px 80px; } }

/* brand */
.sidebar .brand {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px 4px;
  margin-bottom: 14px; text-decoration: none; color: #fff;
}
.sidebar .brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 30px; height: 30px; flex: none;
  border-radius: 9px; background: var(--accent); color: #fff;
  font-weight: 800; font-size: 13px; letter-spacing: -0.02em;
  box-shadow: 0 2px 10px -2px color-mix(in srgb, var(--accent) 70%, transparent);
}
.brand-word { font-weight: 720; font-size: 15px; letter-spacing: -0.02em; color: #fff; }

/* nav */
.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.side-group {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em;
  font-weight: 700; color: var(--rail-muted); padding: 14px 10px 5px;
}
.side-link {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px;
  border-radius: var(--radius-sm); color: var(--rail-text);
  font-size: 13.5px; font-weight: 550; position: relative;
  transition: background .14s var(--ease), color .14s var(--ease);
}
.side-link:hover { background: var(--rail-2); color: #fff; text-decoration: none; }
.side-link.active { background: var(--rail-active-bg); color: #fff; font-weight: 650; }
.side-link.active::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--accent);
}
.nav-ic { width: 18px; height: 18px; flex: none; opacity: 0.85; }
.side-link.active .nav-ic { opacity: 1; color: color-mix(in srgb, var(--accent) 55%, #fff); }

/* footer: user + actions */
.side-foot { border-top: 1px solid var(--rail-line); padding-top: 10px; margin-top: 8px;
  display: flex; align-items: center; gap: 8px; }
.side-user { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0;
  color: var(--rail-text); text-decoration: none; padding: 4px; border-radius: var(--radius-sm); }
.side-user:hover { background: var(--rail-2); text-decoration: none; color: #fff; }
.side-avatar { display: grid; place-items: center; width: 28px; height: 28px; flex: none;
  border-radius: 50%; background: var(--rail-2); border: 1px solid var(--rail-line);
  font-weight: 700; font-size: 12px; color: #fff; }
.side-user-name { font-size: 12.5px; font-weight: 600; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.ghost-btn { display: grid; place-items: center; width: 30px; height: 30px; flex: none;
  border-radius: var(--radius-sm); border: 1px solid var(--rail-line);
  background: transparent; color: var(--rail-text); cursor: pointer; font-size: 15px;
  text-decoration: none; }
.ghost-btn:hover { background: var(--rail-2); color: #fff; text-decoration: none; }

/* Mobile top bar + hamburger (hidden on desktop). */
.mobile-bar { display: none; }
.nav-backdrop { display: none; }
.nav-toggle {
  display: grid; place-items: center; width: 40px; height: 40px; flex: none;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-1); color: var(--text-primary); cursor: pointer;
}
.mobile-brand { display: flex; align-items: center; gap: 9px; font-weight: 720;
  font-size: 15px; letter-spacing: -0.02em; color: var(--text-primary); text-decoration: none; }
.mobile-brand:hover { text-decoration: none; }

/* Below 900px the rail becomes an off-canvas drawer opened by the hamburger. */
@media (max-width: 900px) {
  .mobile-bar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 50;
    padding: 9px 14px; background: var(--surface-1);
    border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm);
  }
  .app-main { margin-left: 0; }
  .sidebar {
    width: 274px; z-index: 70;
    transform: translateX(-100%);
    transition: transform 0.22s var(--ease);
    box-shadow: var(--shadow-lg); padding-top: 16px;
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 65;
    background: rgba(0, 0, 0, 0.5);
  }
  body.nav-open { overflow: hidden; }
  .app-main .wrap { padding: 16px 15px 56px; }
  /* Sticky filter/day headers clear the mobile bar, not a desktop top bar. */
  .filters, .cal-dayhead { top: 52px; }
}
@media (max-width: 900px) and (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

/* The filter-bar toggle is desktop-hidden; the bar shows all fields inline. */
.filters-toggle { display: none; }

@media (max-width: 720px) {
  /* Filters collapse behind a toggle so the list is visible on a phone. The
     bar is no longer sticky here — a tall open form must scroll away. */
  .filters { position: static; flex-direction: column; align-items: stretch; gap: 10px; }
  .filters-toggle {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; padding: 10px 14px; font: inherit; font-weight: 650;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface-1); color: var(--text-primary); cursor: pointer;
  }
  .filters-toggle .ft-caret { transition: transform .16s var(--ease); }
  .filters.filters-open .filters-toggle .ft-caret { transform: rotate(180deg); }
  /* Hide every field until opened; the toggle itself always stays. */
  .filters:not(.filters-open) > *:not(.filters-toggle) { display: none; }
  .filters label.field, .filters label.field.grow { min-width: 0; width: 100%; }
}

/* Very small screens: single-column KPI tiles. */
@media (max-width: 480px) {
  .tiles, .tiles.k5 { grid-template-columns: 1fr; }
  h1 { font-size: 21px; }
}

/* -------------------------------------------------- responsive card tables
   Under 720px a table tagged .table-cards becomes a stack of cards: the header
   row is dropped and each cell shows its column name (from data-label) beside
   its value. One account reads top-to-bottom instead of scrolling sideways. */
@media (max-width: 720px) {
  table.table-cards thead { position: absolute; width: 1px; height: 1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  table.table-cards, table.table-cards tbody { display: block; width: 100%; }
  table.table-cards tbody tr {
    display: block; background: var(--surface-1);
    border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); padding: 4px 13px; margin-bottom: 10px;
  }
  /* tbody in the selector so it out-specifies `table.dense tbody td` padding. */
  table.table-cards tbody td {
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
    padding: 8px 0; border: none; border-bottom: 1px solid var(--grid);
    text-align: right; white-space: normal;
  }
  table.table-cards tbody tr td:last-child { border-bottom: none; }
  table.table-cards tbody td::before {
    content: attr(data-label); flex: none; text-align: left;
    font-size: 10.5px; font-weight: 700; letter-spacing: 0.04em;
    text-transform: uppercase; color: var(--text-muted);
  }
  table.table-cards tbody td[data-label=""]::before,
  table.table-cards tbody td:not([data-label])::before { content: none; }
  /* Full-bleed leading cell (name / priority) reads as the card title. */
  table.table-cards tbody td.cardtitle { justify-content: flex-start; text-align: left;
    font-size: 15px; font-weight: 680; padding-top: 10px; }
  table.table-cards tbody td.cardtitle::before { content: none; }
  table.table-cards tbody td .subtle { text-align: right; }
}

/* ---------------------------------------------------------------- surfaces */
.card, .tile, .kpi, .focus-tile, .witem, .lead-action, .brief-side, .triage-cell {
  transition: box-shadow .16s var(--ease), transform .16s var(--ease), border-color .16s var(--ease);
}
.card { border-radius: var(--radius); box-shadow: var(--shadow); border-color: var(--border); }
.card-head { border-bottom-color: var(--border); }

.tiles { gap: 14px; }
.tile { border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 15px 17px; }
a.tile:hover, .tile.clickable:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.tile.is-on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow-md); }
.tile .label { color: var(--text-muted); letter-spacing: 0.06em; }
.tile .value { letter-spacing: -0.03em; font-weight: 700; }
.tile.danger { border-left: 3px solid var(--critical); }

.kpi { border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.kpi:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kpi-v { letter-spacing: -0.03em; }

/* ----------------------------------------------------------------- buttons */
.btn {
  border-radius: var(--radius-sm); border-color: var(--border-strong);
  font-weight: 620;
  transition: background .14s var(--ease), box-shadow .14s var(--ease),
              transform .1s var(--ease), border-color .14s var(--ease);
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
  box-shadow: 0 2px 8px -3px color-mix(in srgb, var(--accent) 75%, transparent);
}
.btn.primary:hover { filter: brightness(1.06);
  box-shadow: 0 4px 12px -3px color-mix(in srgb, var(--accent) 80%, transparent); }

/* segmented controls */
.seg { border-radius: var(--radius-sm); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.seg a.on, .seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.seg a, .seg button { transition: background .12s var(--ease), color .12s var(--ease); }

a { color: var(--accent); }

/* ------------------------------------------------------------- pills/badges */
.pill { border-radius: var(--radius-pill); box-shadow: var(--shadow-sm);
  background: var(--surface-1); font-weight: 620; }
.pri-badge { border-radius: var(--radius-pill); box-shadow: var(--shadow-sm); font-weight: 720; }
.tag { border-radius: 6px; }

/* --------------------------------------------------------------- work items */
.witem { border-radius: var(--radius); box-shadow: var(--shadow-sm); border-left-width: 4px; }
.witem:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.witem-play .witem-play-do { color: var(--accent); }

/* Lead action / briefing — flat accent-tinted surface, no gradient. */
.lead-action, .lead-action.hero {
  border-radius: var(--radius); box-shadow: var(--shadow);
  background: var(--surface-1);
}

/* triage cells keep their severity rails; just round + lift. */
.triage-cell { border-radius: var(--radius); }
.triage-cell.lvl-medium { border-left-color: var(--accent); }

/* ------------------------------------------------------------ sticky offsets
   The global top bar is gone (nav lives in the rail), so anything that used to
   clear a 52/64px header now sticks to the top of the scroll area. */
.filters { top: 0; box-shadow: var(--shadow-sm); border-radius: var(--radius); }
.cal-dayhead { top: 0; }
.ov-rail { top: 18px; }

/* ------------------------------------------------------------- tables/misc */
tbody tr { transition: background .1s var(--ease); }
tbody tr:hover { background: var(--surface-2); }
thead th { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }

/* ------------------------------------------------------------ scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--axis) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--axis); border-radius: 999px;
  border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-muted); background-clip: content-box; }
.side-nav { scrollbar-width: none; }
.side-nav::-webkit-scrollbar { display: none; }

/* --------------------------------------------------------- reduced motion */
@media (prefers-reduced-motion: reduce) {
  .card, .tile, .kpi, .witem, .btn, .side-link, .seg a, .seg button, tbody tr {
    transition: none !important;
  }
  a.tile:hover, .tile.clickable:hover, .kpi:hover, .witem:hover, .btn:hover {
    transform: none !important;
  }
}
