/* ============================================================
   PBS Ops Center — design system (dark + light themes)
   Loaded AFTER base.html inline styles; wins ties via cascade.
   ============================================================ */

:root, [data-theme="dark"] {
  --bg: #0b1120;
  --surface: #0f172a;
  --card: #182338;
  --card2: #131d30;
  --border: #263449;
  --text: #eef2f8;
  --muted: #8fa1b8;
  --accent: #38bdf8;
  --blue: #38bdf8;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --purple: #a78bfa;
  --shadow: 0 4px 18px rgba(2, 6, 18, .45);
  --shadow-lift: 0 10px 30px rgba(2, 6, 18, .55);
  --brand-grad: linear-gradient(135deg, #0ea5e9, #6366f1 60%, #a855f7);
  --header-bg: rgba(9, 14, 27, .92);
  --input-bg: #0b1220;
  --log-bg: #070d18;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #eef2f8;
  --surface: #ffffff;
  --card: #ffffff;
  --card2: #f1f5fb;
  --border: #dbe4ef;
  --text: #17233b;
  --muted: #5c6f8a;
  --accent: #0284c7;
  --blue: #0284c7;
  --green: #059669;
  --amber: #b45309;
  --red: #dc2626;
  --purple: #7c3aed;
  --shadow: 0 3px 14px rgba(30, 50, 90, .10);
  --shadow-lift: 0 12px 30px rgba(30, 50, 90, .16);
  --brand-grad: linear-gradient(135deg, #0ea5e9, #6366f1 60%, #a855f7);
  --header-bg: rgba(255, 255, 255, .92);
  --input-bg: #f4f7fc;
  --log-bg: #0d1526;
  color-scheme: light;
}

/* ---------- typography scale ---------- */
body { font-size: 16.5px; }
h2.section { font-size: 17px; font-weight: 700; color: var(--text); text-transform: none; letter-spacing: 0; margin: 26px 0 12px; }
h2.section .muted { font-size: 12.5px; font-weight: 400; }
.page-title { font-size: 24px; font-weight: 800; margin: 4px 0 2px; }
.page-sub { color: var(--muted); font-size: 13.5px; margin-bottom: 14px; }

/* ---------- surfaces ---------- */
body { background: var(--bg); color: var(--text); }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow); padding: 16px 18px;
}
.card .label { font-size: 13px; font-weight: 600; letter-spacing: .06em; }
.card .value { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 6px; }
.card .sub { font-size: 13px; margin-top: 4px; }
.clickable { cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; }
.clickable:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }

/* severity accents */
.acc-crit { border-left: 4px solid var(--red); }
.acc-warn { border-left: 4px solid var(--amber); }
.acc-ok { border-left: 4px solid var(--green); }
.acc-info { border-left: 4px solid var(--accent); }

/* ---------- KPI cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  position: relative; border-radius: 16px; padding: 18px; overflow: hidden;
  background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease;
}
.kpi.clickable:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.kpi .k-label { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.kpi .k-icon { font-size: 18px; }
.kpi .k-value { font-size: 38px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.15; margin-top: 6px; }
.kpi .k-sub { font-size: 13.5px; color: var(--muted); margin-top: 4px; }
.kpi .k-delta { font-weight: 700; }
.kpi .k-delta.up { color: var(--green); }
.kpi .k-delta.down { color: var(--red); }
.kpi.danger .k-value { color: var(--red); }
.kpi.warn .k-value { color: var(--amber); }
.kpi.good .k-value { color: var(--green); }
.kpi.accent .k-value { color: var(--accent); }
.kpi::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px;
  background: var(--brand-grad); opacity: .0; transition: opacity .15s;
}
.kpi:hover::before { opacity: 1; }

/* ---------- header ---------- */
header.top {
  background: var(--header-bg); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
header.top::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: var(--brand-grad); opacity: .8;
}
header.top { position: sticky; }
.brand-tile {
  width: 30px; height: 30px; border-radius: 9px; background: var(--brand-grad);
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 13px; box-shadow: 0 2px 8px rgba(80, 100, 255, .4);
}
.theme-toggle {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  color: var(--muted); font-size: 16px; padding: 4px 9px; cursor: pointer;
}
.theme-toggle:hover { color: var(--text); background: var(--card); }

/* ---------- tables ---------- */
table { border-radius: 14px; font-size: 13.5px; }
th { font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--card2); }

/* ---------- log viewer ---------- */
.logview {
  background: var(--log-bg); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; overflow: auto; max-height: 420px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-word;
  color: #c9d4e6;
}
.logview .lt { color: #5b6b85; }                 /* timestamp */
.logview .lv-ERROR, .logview .lv-ERR { color: #f87171; font-weight: 600; }
.logview .lv-CRITICAL, .logview .lv-CRIT { color: #e879f9; font-weight: 700; }
.logview .lv-WARNING, .logview .lv-WARN { color: #fbbf24; }
.logview .lv-INFO { color: #60a5fa; }
.logview .lv-DEBUG { color: #7c8aa0; }
.logview .ln { color: #3d4a61; user-select: none; display: inline-block; min-width: 3.2em; }

/* markdown-lite rendering inside answers */
.md-body { font-size: 14.5px; line-height: 1.6; }
.md-body h1 { font-size: 20px; margin: 16px 0 8px; font-weight: 800; }
.md-body h2 { font-size: 17px; margin: 16px 0 8px; font-weight: 700; }
.md-body h3, .md-body h4 { font-size: 15px; margin: 12px 0 6px; font-weight: 700; }
.md-body p { margin: 0 0 8px; }
.md-body table { width: 100%; border-collapse: collapse; margin: 10px 0 14px; font-size: 13px; }
.md-body th, .md-body td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; vertical-align: top; }
.md-body th { background: var(--card); font-weight: 700; }
.md-body tr:nth-child(even) td { background: rgba(127,127,127,.06); }
.md-body code, .md-body pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--log-bg); color: #c9d4e6; border-radius: 6px; font-size: 12.5px;
}
.md-body code { padding: 1px 5px; }
.md-body pre { padding: 10px 12px; overflow-x: auto; white-space: pre-wrap; border: 1px solid var(--border); }
.md-body pre code { padding: 0; background: none; }
.md-body ul, .md-body ol { margin: 6px 0 6px 20px; }
.md-body strong { color: var(--text); }
.md-body hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* ---------- charts ---------- */
.chart-card { background: var(--card); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 14px; }
.chart-card .c-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 10px; }
.chart-box { position: relative; height: 280px; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }

/* ---------- skeleton ---------- */
.skel { position: relative; overflow: hidden; background: var(--card2); border-radius: 8px; min-height: 14px; }
.skel::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(140, 160, 190, .18), transparent);
  animation: skel 1.2s infinite;
}
@keyframes skel { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ---------- pending/task card ---------- */
.task-pending {
  border: 1px solid var(--accent); border-radius: 12px; padding: 12px 14px;
  background: var(--card); margin: 8px 0; font-size: 14px;
}
.task-pending .pulse { display: inline-block; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- product thumbnails + image modal ---------- */
.pthumb {
  width: 34px; height: 34px; border-radius: 8px; object-fit: contain;
  background: var(--card2); border: 1px solid var(--border); cursor: zoom-in;
  vertical-align: middle; transition: transform .12s;
}
.pthumb:hover { transform: scale(1.15); }
.pthumb-ph {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px; background: var(--card2);
  border: 1px solid var(--border); color: var(--muted); font-size: 14px;
  vertical-align: middle;
}
.pthumb.big { width: 84px; height: 84px; border-radius: 12px; }
.pthumb-ph.big { width: 84px; height: 84px; border-radius: 12px; font-size: 30px; }
#pimg-backdrop {
  display: none; position: fixed; inset: 0; z-index: 120; background: rgba(0,0,0,.82);
  align-items: center; justify-content: center; flex-direction: column; padding: 16px;
}
#pimg-backdrop img {
  max-width: 90vw; max-height: 85vh; border-radius: 14px; background: #fff;
  box-shadow: 0 20px 60px rgba(0,0,0,.6); object-fit: contain;
}
#pimg-cap {
  color: #e2e8f0; font-size: 14px; margin-top: 10px; text-align: center;
  max-width: 90vw;
}
#pimg-close {
  position: absolute; top: 14px; right: 18px; background: none; border: none;
  color: #fff; font-size: 26px; cursor: pointer;
}

/* light-theme tweaks for badges/pills (keep contrast) */
[data-theme="light"] .b-CRITICAL { background: #fee2e2; color: #991b1b; }
[data-theme="light"] .b-WARNING { background: #fef3c7; color: #92400e; }
[data-theme="light"] .b-INFO { background: #e0f2fe; color: #075985; }
[data-theme="light"] .b-DEBUG { background: #e2e8f0; color: #334155; }
[data-theme="light"] .pill-ACTIVE { background: #fee2e2; color: #991b1b; }
[data-theme="light"] .pill-RESOLVED, [data-theme="light"] .pill-SENT { background: #dcfce7; color: #166534; }
[data-theme="light"] .pill-SUPPRESSED { background: #e2e8f0; color: #475569; }

/* drawer + header in light */
[data-theme="light"] .drawer, [data-theme="light"] header.top { background: var(--header-bg); }
[data-theme="light"] input, [data-theme="light"] select, [data-theme="light"] textarea { color-scheme: light; }

/* forms */
input, select, textarea { background: var(--input-bg) !important; color: var(--text) !important; }

@media (max-width: 640px) {
  body { font-size: 16px; }
  .kpi .k-value { font-size: 32px; }
  .chart-box { height: 240px; }
}
