/* =============================================================================
   IT Ops Dashboard — styles
   No framework, no build step. Colours are CSS variables ("tokens") defined
   once below; dark mode just redefines them. Sections:
     1. Tokens  2. Base  3. Layout  4. KPI ribbon  5. Panels & grids
     6. Forms & buttons  7. Tables  8. Badges  9. Components  10. Responsive
   ============================================================================= */

/* 1. Tokens ----------------------------------------------------------------- */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #dbeafe;
  --success: #047857;
  --success-soft: #d1fae5;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --purple: #6d28d9;
  --purple-soft: #ede9fe;
  --sidebar: #0f172a;
  --sidebar-ink: #cbd5e1;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
  --radius: 10px;
  --font: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #0f172a;
    --ink: #e5e7eb;
    --ink-2: #cbd5e1;
    --muted: #94a3b8;
    --line: #1f2937;
    --line-strong: #334155;
    --accent: #3b82f6;
    --accent-soft: #1e3a8a;
    --success: #34d399;
    --success-soft: #064e3b;
    --warn: #fbbf24;
    --warn-soft: #451a03;
    --danger: #f87171;
    --danger-soft: #450a0a;
    --purple: #a78bfa;
    --purple-soft: #2e1065;
    --sidebar: #020617;
    --shadow: none;
    color-scheme: dark;
  }
}

/* 2. Base ------------------------------------------------------------------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); color: var(--ink); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a.plain { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; margin: 16px 0 8px; }
code, kbd, .mono { font-family: var(--mono); font-size: 12.5px; }
code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
kbd { border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--surface); }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.text-danger { color: var(--danger); }
.text-warn { color: var(--warn); }
.pre { white-space: pre-wrap; font-family: var(--mono); font-size: 12px; margin: 6px 0; color: var(--ink-2); }
.pre-line { white-space: pre-line; }
.truncate-1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* 3. Layout ----------------------------------------------------------------- */
.layout { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--sidebar); color: var(--sidebar-ink);
  display: flex; flex-direction: column; padding: 18px 12px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; padding: 4px 8px 18px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 800; font-size: 13px; flex: none;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { color: var(--sidebar-ink); padding: 8px 10px; border-radius: 7px; font-weight: 500; }
.nav a:hover { background: rgba(255, 255, 255, .06); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(59, 130, 246, .18); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255, 255, 255, .08); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sidebar-foot a { color: var(--sidebar-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-btn { background: none; border: 0; color: var(--sidebar-ink); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

.main { padding: 20px 28px 48px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* 4. KPI ribbon ------------------------------------------------------------- */
.kpi-ribbon { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); color: var(--ink); display: block;
  border-top: 3px solid var(--accent);
}
.kpi-card:hover { text-decoration: none; border-color: var(--line-strong); border-top-color: var(--accent); }
.kpi-label { font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kpi-value { font-size: 30px; font-weight: 750; line-height: 1.15; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12.5px; color: var(--ink-2); }
.kpi-sub.muted { color: var(--muted); }
.kpi-flag.is-alert { color: var(--warn); font-weight: 650; }
.kpi-flag.is-alert::before { content: "● "; }

/* 5. Panels & grids --------------------------------------------------------- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 16px; box-shadow: var(--shadow); min-width: 0;
}
.panel.flush { padding: 0; overflow: hidden; }
.panel-accent { border-top: 3px solid var(--success); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.panel > h2 { margin-bottom: 12px; }
details.panel > summary { cursor: pointer; list-style: none; }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary h2 { display: inline; color: var(--accent); }
details.panel[open] > summary { margin-bottom: 14px; }
.danger-zone { background: transparent; border-style: dashed; box-shadow: none; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.grid-2 > .panel { margin-bottom: 0; }
.grid-2.wide-left { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.grid-2 + .panel, .panel + .grid-2 { margin-top: 16px; }
.grid-dash { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-dash > .panel { margin-bottom: 0; }
.span-2 { grid-column: span 2; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack > .panel { margin-bottom: 0; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin-bottom: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); color: var(--ink); display: flex; flex-direction: column; gap: 8px;
}
a.card:hover { text-decoration: none; border-color: var(--accent); }
.card h3 { margin: 0; font-size: 15px; }
.group-title { margin: 8px 0 10px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }

/* 6. Forms & buttons ------------------------------------------------------- */
label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
label.check { flex-direction: row; align-items: center; gap: 6px; font-weight: 500; align-self: end; padding-bottom: 8px; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 7px; padding: 7px 9px; width: 100%; min-width: 0;
}
input[type="checkbox"] { width: auto; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea[readonly] { background: var(--surface-2); font-family: var(--mono); font-size: 12.5px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid .span-all { grid-column: 1 / -1; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid h3 { margin: 8px 0 0; }

.quick-form { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.quick-form label { flex: 1 1 140px; }
.quick-form label.grow { flex: 3 1 280px; }
.quick-form label.check { flex: 0 0 auto; }
.quick-entry { border-top: 3px solid var(--accent); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  font: inherit; font-weight: 600; font-size: 13px; line-height: 1.2;
  padding: 8px 13px; border-radius: 7px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-success { color: #022c22; } }
.btn-danger { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--line); }
.btn-block { width: 100%; }
.inline-form { display: inline; margin: 0; }
.hint { font-size: 12px; font-weight: 400; color: var(--muted); }

/* 7. Tables ----------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table thead th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); font-weight: 650; }
.table tbody tr:hover { background: var(--surface-2); }
.table tfoot td { background: var(--surface-2); }
.table.compact th, .table.compact td { padding: 7px 8px; }
.table td.right, .table th.right { text-align: right; }
.table .btn + .inline-form, .table .inline-form + .btn, .table .inline-form + .inline-form { margin-left: 4px; }
.row-p1 { box-shadow: inset 3px 0 0 var(--danger); }
.row-done td { color: var(--muted); }
.row-done td:first-child { text-decoration: line-through; }
.group-row th { background: var(--surface-2); font-size: 12px; color: var(--accent); text-transform: uppercase; letter-spacing: .05em; }
.inline-assign { display: flex; gap: 6px; align-items: center; min-width: 440px; }
.inline-assign input { padding: 5px 7px; }
.inline-assign input.short { max-width: 110px; }
.inline-assign select { width: auto; flex: none; min-width: 124px; padding: 5px 7px; }
.inline-assign .btn { flex: none; }

/* 8. Badges ----------------------------------------------------------------- */
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 650;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; vertical-align: middle;
}
.badge-p1, .badge-rma { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge-p2, .badge-pending-hq, .badge-pending, .badge-on-hold, .badge-lab-practiced { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-open, .badge-in-progress, .badge-approved, .badge-in-use, .badge-src-email, .badge-rule { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge-resolved, .badge-paid, .badge-completed, .badge-done, .badge-buffer-stock, .badge-production-verified { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-learning, .badge-planning { background: var(--purple-soft); color: var(--purple); border-color: transparent; }
.badge-retired, .badge-to-do, .badge-p3, .badge-src-manual { background: var(--surface-2); color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .badge-open, .badge-in-progress, .badge-approved, .badge-in-use, .badge-src-email, .badge-rule { color: #bfdbfe; }
}

/* 9. Components ------------------------------------------------------------- */
/* Flash messages */
.flashes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.flash { padding: 10px 40px 10px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); position: relative; }
.flash-success { background: var(--success-soft); border-color: transparent; color: var(--success); }
.flash-error { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.flash-info { background: var(--accent-soft); border-color: transparent; color: var(--ink); }
.flash-close { position: absolute; right: 8px; top: 6px; background: none; border: 0; font-size: 18px; cursor: pointer; color: inherit; opacity: .6; }

/* Tabs + filter toolbar */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 4px; }
.tab { padding: 6px 12px; border-radius: 6px; color: var(--ink-2); font-weight: 600; font-size: 13px; }
.tab:hover { background: var(--surface-2); text-decoration: none; }
.tab.active { background: var(--accent); color: var(--accent-ink); }
.tab .count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 999px; background: rgba(100, 116, 139, .15); font-size: 11.5px; text-align: center; }
.tab.active .count { background: rgba(255, 255, 255, .25); }
.tab-alert:not(.active) .count { background: var(--warn-soft); color: var(--warn); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input[type="search"] { width: 240px; }
.filters select { width: auto; }

/* Pipeline / stage strip */
.stage-strip { display: flex; align-items: stretch; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.stage { flex: 1 1 160px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; display: flex; flex-direction: column; color: var(--ink); box-shadow: var(--shadow); }
a.stage:hover { text-decoration: none; border-color: var(--accent); }
.stage.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.stage strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.stage-name { font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stage-arrow { align-self: center; color: var(--muted); font-size: 18px; }
.stage-pending, .stage-lab-practiced { border-left: 4px solid var(--warn); }
.stage-approved { border-left: 4px solid var(--accent); }
.stage-paid, .stage-production-verified { border-left: 4px solid var(--success); }
.stage-learning { border-left: 4px solid var(--purple); }
.pipeline { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; font-size: 11px; font-weight: 650; }
.pipeline .step { padding: 2px 7px; color: var(--muted); background: var(--surface-2); }
.pipeline .step + .step { border-left: 1px solid var(--line); }
.pipeline .step.done { background: var(--success-soft); color: var(--success); }
.pipeline .step.current { background: var(--accent); color: var(--accent-ink); }
.pipeline-actions { margin-top: 4px; }

/* Lists, meters, charts */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.meter { height: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; margin-top: 5px; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.meter.big { height: 12px; margin: 12px 0; }
.legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-left: 8px; }
.sw-opened, .bar-opened { background: var(--accent); }
.sw-resolved, .bar-resolved { background: var(--success); }
.trend { display: grid; grid-template-columns: repeat(14, 1fr); gap: 6px; height: 140px; align-items: end; }
.trend-day { display: flex; flex-direction: column; height: 100%; }
.trend-bars { flex: 1; display: flex; align-items: flex-end; gap: 2px; justify-content: center; }
.trend-bars .bar { width: 40%; max-width: 14px; min-height: 2px; border-radius: 3px 3px 0 0; }
.trend-label { text-align: center; font-size: 11px; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }
.empty { padding: 22px; text-align: center; color: var(--muted); }
.dl { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; margin: 0; }
.dl dt { color: var(--muted); font-size: 12.5px; }
.dl dd { margin: 0; }
.checklist { padding-left: 18px; margin: 0 0 16px; }
.checklist li { margin: 3px 0; }
.project-summary { display: flex; gap: 28px; flex-wrap: wrap; }
.project-summary > div { display: flex; flex-direction: column; gap: 2px; }
.mini-tasks { list-style: none; padding: 0; margin: 4px 0 0; font-size: 12.5px; display: flex; flex-direction: column; gap: 4px; }
.handoff textarea { min-height: 140px; }
.level-select { width: auto; font-weight: 600; }
.level-production-verified { color: var(--success); }
.level-lab-practiced { color: var(--warn); }
.level-learning { color: var(--purple); }
.embed summary { cursor: pointer; font-size: 12.5px; color: var(--accent); }
.embed-frame iframe { width: 100%; height: 420px; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; background: #fff; }
.link-group { margin-bottom: 8px; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: 0 10px 30px rgba(15, 23, 42, .08); display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 20px; }
.login-card p { margin: 0; }
.login-brand .brand-mark { width: 44px; height: 44px; font-size: 16px; border-radius: 11px; }

/* 10. Responsive ------------------------------------------------------------ */
@media (max-width: 1200px) {
  .grid-dash { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-dash .span-2 { grid-column: span 2; }
  .form-grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1000px) {
  .kpi-ribbon { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .grid-2.wide-left { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; gap: 8px; }
  .brand { padding: 0; }
  .brand-name { display: none; }
  .nav { flex-direction: row; overflow-x: auto; flex: 1 1 100%; order: 3; gap: 4px; padding-bottom: 2px; }
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .nav a.active { box-shadow: inset 0 -2px 0 var(--accent); }
  .sidebar-foot { margin: 0 0 0 auto; border: 0; padding: 0; gap: 12px; }
  .sidebar-foot form { flex: none; }
  .main { padding: 16px; }
  .grid-dash { grid-template-columns: 1fr; }
  .grid-dash .span-2, .span-2 { grid-column: auto; }
  .form-grid, .form-grid.cols-4 { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .filters input[type="search"] { width: 100%; }
  .kpi-value { font-size: 24px; }
}
@media (max-width: 480px) {
  .kpi-ribbon { grid-template-columns: 1fr; }
}
