/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg:        #f5f7fa;
  --surface:   #ffffff;
  --border:    #e2e8f0;
  --text:      #1a202c;
  --text-muted:#718096;
  --primary:   #4f8ef7;
  --radius:    8px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);

  /* sidebar */
  --sb-width:           240px;
  --sb-width-collapsed: 60px;
  --sb-bg:              #1a202c;
  --sb-bg-hover:        #2d3748;
  --sb-bg-active:       #4f8ef7;
  --sb-text:            #cbd5e0;
  --sb-text-muted:      #718096;
  --sb-text-active:     #ffffff;
  --sb-border:          #2d3748;
  --topbar-h:           48px;

  /* env colours */
  --dev:     #4f8ef7;
  --staging: #f7934f;
  --uat:     #a44ff7;
  --prod:    #f74f6a;

  /* status colours */
  --pass:    #38a169;
  --fail:    #e53e3e;
  --bug:     #dd6b20;
  --blocked: #718096;
  --skip:    #a0aec0;

  /* priority */
  --high:    #e53e3e;
  --medium:  #d69e2e;
  --low:     #38a169;
  /* ── SPEC_002 semantic colour tokens ── */
  --color-good-bg:     #d1fae5;  --color-good-text:   #065f46;  --color-good-border:   #86efac;
  --color-warn-bg:     #fef3c7;  --color-warn-text:   #92400e;  --color-warn-border:   #fcd34d;
  --color-fail-bg:     #fee2e2;  --color-fail-text:   #991b1b;  --color-fail-border:   #fca5a5;
  --color-neutral-bg:  #e5e7eb;  --color-neutral-text: #374151;
  --color-info-bg:     #dbeafe;  --color-info-text:   #1e40af;
  --color-purple-bg:   #ede9fe;  --color-purple-text: #5b21b6;
  --color-cyan-bg:     #cffafe;  --color-cyan-text:   #0e7490;
  --color-amber-bg:    #fed7aa;  --color-amber-text:  #9a3412;
}
body { background: var(--bg); color: var(--text); font-family: system-ui, sans-serif; font-size: 14px; line-height: 1.6; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── App shell — sidebar + main ───────────────────────────────────────────── */
.app { display: grid; grid-template-columns: var(--sb-width) 1fr; min-height: 100vh; }
html.sidebar-collapsed .app { grid-template-columns: var(--sb-width-collapsed) 1fr; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--sb-bg); color: var(--sb-text);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow: hidden;
  border-right: 1px solid var(--sb-border);
}
.sidebar:hover { overflow-y: auto; }
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--sb-border); border-radius: 3px; }

/* Header */
.sb-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .85rem .85rem .65rem; border-bottom: 1px solid var(--sb-border);
  flex-shrink: 0; position: relative;
}
.sb-brand {
  display: flex; align-items: center; gap: .55rem; color: var(--sb-text-active);
  font-weight: 700; text-decoration: none; min-width: 0;
}
.sb-brand:hover { text-decoration: none; color: var(--sb-text-active); }
.sb-brand-logo {
  width: 28px; height: 28px; flex-shrink: 0; border-radius: 6px;
  background: linear-gradient(135deg, var(--primary), #9d7af0);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 800; letter-spacing: -.05em;
}
.sb-brand-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.sb-brand-name { font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-version { font-size: .65rem; color: var(--sb-text-muted); font-weight: 500; text-decoration: none; }
.sb-version:hover { color: var(--sb-text-active); text-decoration: none; }
.sb-collapse-btn {
  background: transparent; border: 1px solid var(--sb-border); color: var(--sb-text-muted);
  width: 24px; height: 24px; border-radius: 5px; cursor: pointer; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
  transition: background .12s, color .12s;
}
.sb-collapse-btn:hover { background: var(--sb-bg-hover); color: var(--sb-text-active); }
.sb-collapse-icon { font-size: .9rem; line-height: 1; transition: transform .15s; display: inline-block; }
html.sidebar-collapsed .sb-collapse-icon { transform: rotate(180deg); }

/* Workspace switcher */
.sb-workspace { padding: .65rem .75rem .8rem; border-bottom: 1px solid var(--sb-border); flex-shrink: 0; }
.sb-workspace-label { display: flex; align-items: baseline; gap: .25rem; margin-bottom: .35rem; line-height: 1; min-width: 0; }
.sb-ws-client { font-size: .6rem; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: .08em; }
.sb-ws-sep { font-size: .6rem; color: var(--sb-text-muted); }
.sb-ws-project { font-size: .65rem; font-weight: 600; color: var(--sb-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-ws-select {
  width: 100%; background: var(--sb-bg-hover); border: 1px solid var(--sb-border);
  color: var(--sb-text-active); padding: .35rem .5rem; border-radius: 5px;
  font-size: .78rem; cursor: pointer; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--sb-text-muted) 50%),
                    linear-gradient(135deg, var(--sb-text-muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) center, calc(100% - 9px) center;
  background-size: 5px 5px; background-repeat: no-repeat;
  padding-right: 24px;
}
.sb-ws-select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.sb-ws-select option { background: var(--sb-bg); color: var(--sb-text); }
.sb-ws-select optgroup { color: var(--sb-text-muted); font-style: normal; }
.sb-mig-badge {
  margin-top: .55rem; padding: .25rem .5rem; border-radius: 5px;
  background: rgba(254, 243, 199, .12); border: 1px solid rgba(245, 158, 11, .3);
  color: #fcd34d; font-size: .68rem; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; display: flex; align-items: center; gap: .35rem;
  cursor: help;
}

/* Nav sections */
.sb-nav { flex: 1; padding: .5rem 0 .85rem; overflow-y: auto; }
.sb-section { margin-bottom: 1rem; }
.sb-section-title {
  font-size: .65rem; font-weight: 700; color: var(--sb-text-muted);
  text-transform: uppercase; letter-spacing: .08em;
  padding: 0 .85rem; margin: .85rem 0 .25rem;
}
.sb-items { list-style: none; padding: 0; margin: 0; }
.sb-item {
  display: flex; align-items: center; gap: .65rem;
  padding: .42rem .85rem; color: var(--sb-text); text-decoration: none;
  font-size: .85rem; font-weight: 500;
  border-left: 2px solid transparent;
  transition: background .12s, color .12s, border-left-color .12s;
}
.sb-item:hover { background: var(--sb-bg-hover); color: var(--sb-text-active); text-decoration: none; }
.sb-item.active {
  background: rgba(79, 142, 247, .14);
  color: var(--sb-text-active);
  border-left-color: var(--primary);
}
.sb-icon { font-size: 1rem; flex-shrink: 0; width: 20px; text-align: center; }
.sb-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-count {
  background: var(--sb-bg-hover); color: var(--sb-text-muted);
  padding: .05rem .42rem; border-radius: 999px;
  font-size: .68rem; font-weight: 700; letter-spacing: 0;
  flex-shrink: 0;
}
.sb-item.active .sb-count { background: rgba(255,255,255,.18); color: var(--sb-text-active); }

/* Footer / user dropdown */
.sb-footer { padding: .55rem .65rem .75rem; border-top: 1px solid var(--sb-border); flex-shrink: 0; }
.sb-user { width: 100%; }
.sb-user > summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: .55rem; padding: .4rem .55rem;
  border-radius: 6px; transition: background .12s;
}
.sb-user > summary::-webkit-details-marker { display: none; }
.sb-user > summary:hover { background: var(--sb-bg-hover); }
.sb-user-avatar {
  width: 28px; height: 28px; flex-shrink: 0; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #9d7af0); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .82rem; font-weight: 700;
}
.sb-user-info { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.sb-user-name { font-size: .82rem; color: var(--sb-text-active); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user-email { font-size: .68rem; color: var(--sb-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user-chev { font-size: .7rem; color: var(--sb-text-muted); flex-shrink: 0; transition: transform .15s; }
.sb-user[open] .sb-user-chev { transform: rotate(180deg); }
.sb-user-menu {
  list-style: none; padding: .4rem 0; margin-top: .3rem;
  background: var(--sb-bg-hover); border: 1px solid var(--sb-border); border-radius: 6px;
}
.sb-user-menu li { margin: 0; }
.sb-user-menu li > a,
.sb-user-menu li > button,
.sb-user-menu li > form > button {
  display: block; width: 100%; padding: .42rem .8rem;
  color: var(--sb-text); text-decoration: none; font-size: .8rem;
  background: transparent; border: none; text-align: left; cursor: pointer; font-family: inherit;
}
.sb-user-menu li > a:hover,
.sb-user-menu li > button:hover,
.sb-user-menu li > form > button:hover { background: rgba(79, 142, 247, .14); color: var(--sb-text-active); }
.sb-user-menu .sb-user-divider { height: 1px; background: var(--sb-border); margin: .3rem 0; }
.sb-user-signout { color: #fca5a5 !important; }
.sb-user-signout:hover { background: rgba(252, 165, 165, .12) !important; color: #fca5a5 !important; }
.sb-signin {
  display: block; text-align: center; padding: .55rem; border-radius: 6px;
  background: var(--primary); color: #fff !important; font-weight: 600; text-decoration: none;
  font-size: .82rem;
}
.sb-signin:hover { opacity: .9; text-decoration: none; }

/* ── Collapsed sidebar (icon-only rail) ─────────────────────────────────── */
html.sidebar-collapsed .sb-brand-text,
html.sidebar-collapsed .sb-ws-select,
html.sidebar-collapsed .sb-ws-client,
html.sidebar-collapsed .sb-ws-sep,
html.sidebar-collapsed .sb-ws-project,
html.sidebar-collapsed .sb-mig-text,
html.sidebar-collapsed .sb-section-title,
html.sidebar-collapsed .sb-label,
html.sidebar-collapsed .sb-count,
html.sidebar-collapsed .sb-user-info,
html.sidebar-collapsed .sb-user-chev,
html.sidebar-collapsed .sb-user-menu,
html.sidebar-collapsed .sb-signin { display: none; }

html.sidebar-collapsed .sb-header { justify-content: center; padding: .8rem .35rem .6rem; }
html.sidebar-collapsed .sb-collapse-btn { position: absolute; right: -12px; top: 14px; background: var(--sb-bg); z-index: 5; }
html.sidebar-collapsed .sb-workspace { padding: .55rem .35rem; text-align: center; }
html.sidebar-collapsed .sb-workspace-label { display: none; }
html.sidebar-collapsed .sb-mig-badge { padding: .25rem; justify-content: center; font-size: .9rem; }
html.sidebar-collapsed .sb-section { margin-bottom: .25rem; }
html.sidebar-collapsed .sb-section + .sb-section { padding-top: .35rem; border-top: 1px solid var(--sb-border); }
html.sidebar-collapsed .sb-item { justify-content: center; padding: .55rem .35rem; gap: 0; }
html.sidebar-collapsed .sb-icon { font-size: 1.15rem; width: auto; }
html.sidebar-collapsed .sb-footer { padding: .4rem .3rem .6rem; }
html.sidebar-collapsed .sb-user > summary { justify-content: center; padding: .4rem; }
/* When collapsed, icon-only items get a tooltip via title="" attribute (set in template) */

/* ── Main / topbar / breadcrumb ─────────────────────────────────────────── */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 1.25rem; display: flex; align-items: center; gap: 1rem;
  position: sticky; top: 0; z-index: 50;
}
.breadcrumb {
  display: flex; align-items: center; gap: .35rem;
  font-size: .85rem; flex: 1; min-width: 0;
  /* overflow-x: auto removed — it forces overflow-y: auto which clips
     absolutely-positioned .info-tip-card tooltips (CSS spec §overflow). */
}
.breadcrumb a {
  color: var(--text-muted); text-decoration: none; font-weight: 500;
  white-space: nowrap; padding: .2rem .35rem; border-radius: 4px;
  transition: background .12s, color .12s;
}
.breadcrumb a:hover { color: var(--primary); background: var(--bg); text-decoration: none; }
.breadcrumb .bc-sep {
  color: var(--text-muted); font-weight: 300; font-size: .72rem;
  margin: 0 .05rem; user-select: none; opacity: .55;
}
.breadcrumb .bc-current {
  color: var(--text); font-weight: 700; white-space: nowrap;
  padding: .2rem .4rem;
}

/* Sync All — visually quieter than primary actions on the page itself.
   Uses a "ghost" look until hover so it doesn't compete with breadcrumb. */
.topbar-divider {
  width: 1px; height: 22px; background: var(--border); margin: 0 .5rem;
  flex-shrink: 0;
}
.topbar-sync { margin: 0; flex-shrink: 0; }
.topbar-sync button {
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px; padding: .28rem .7rem;
  font-size: .74rem; font-weight: 600; letter-spacing: .01em;
  cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: .3rem;
  transition: background .12s, color .12s, border-color .12s;
}
.topbar-sync button:hover {
  background: var(--primary); color: #fff; border-color: var(--primary);
}
.topbar-sync button:disabled {
  opacity: .65; cursor: progress;
  background: var(--bg); color: var(--text-muted); border-color: var(--border);
}

/* ── Reusable info-tooltip — `<span class="tip" data-tip="...">ⓘ</span>` ── */
.tip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; margin-left: .25rem;
  border-radius: 50%; background: var(--bg); border: 1px solid var(--border);
  color: var(--text-muted); font-size: .65rem; font-weight: 700; font-style: normal;
  cursor: help; position: relative; vertical-align: middle;
  transition: background .12s, color .12s, border-color .12s;
}
.tip::before { content: "i"; font-family: Georgia, serif; line-height: 1; }
.tip:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.tip[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute; left: 50%; top: calc(100% + 8px); transform: translateX(-50%);
  background: #1a202c; color: #fff;
  padding: .55rem .75rem; border-radius: 6px;
  font-size: .74rem; font-weight: 400; line-height: 1.45;
  white-space: pre-line; min-width: 220px; max-width: 320px; text-align: left;
  z-index: 1000; box-shadow: 0 6px 20px rgba(0,0,0,.18);
  pointer-events: none;
}
/* Variant: small tip rendered inline next to a label, with no left margin */
.tip.tip-tight { margin-left: .15rem; width: 12px; height: 12px; font-size: .58rem; }

/* ── Unified status badge — `{% raw %}{{ badge(value) }}{% endraw %}` macro ──────────────────── */
.qf-badge {
  display: inline-flex; align-items: center; padding: .12rem .55rem;
  border-radius: 999px; font-size: .68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
  border: 1px solid transparent; line-height: 1.4;
  white-space: nowrap;
}
.qf-badge-good    { background: #d1fae5; color: #065f46; border-color: #86efac; }
.qf-badge-warn    { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.qf-badge-bad     { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.qf-badge-neutral { background: #e5e7eb; color: #374151; border-color: #d1d5db; }
.qf-badge-info    { background: #dbeafe; color: #1e40af; border-color: #93c5fd; }
.qf-badge-purple  { background: #ede9fe; color: #5b21b6; border-color: #c4b5fd; }
.qf-badge-cyan    { background: #cffafe; color: #0e7490; border-color: #67e8f9; }
.qf-badge-amber   { background: #fed7aa; color: #9a3412; border-color: #fdba74; }
/* Teal — used for the SPECKIT layout chip (distinct from purple SDS). */
.qf-badge-speckit { background: #ccfbf1; color: #115e59; border: 1px solid #5eead4;
                    display: inline-flex; align-items: center;
                    padding: .12rem .55rem; border-radius: 999px;
                    font-size: .68rem; font-weight: 700; }

/* ── Empty state card — `{% raw %}{{ empty_state(...) }}{% endraw %}` macro ──────────────────── */
.qf-empty {
  background: var(--surface); border: 1px dashed var(--border);
  border-radius: var(--radius); padding: 2.5rem 1.5rem;
  text-align: center; color: var(--text-muted);
  display: flex; flex-direction: column; align-items: center; gap: .55rem;
}
.qf-empty-icon { font-size: 2.6rem; opacity: .5; line-height: 1; margin-bottom: .15rem; }
.qf-empty-title { font-size: 1rem; font-weight: 700; color: var(--text); }
.qf-empty-message { font-size: .85rem; max-width: 460px; line-height: 1.55; }
.qf-empty-hint { font-size: .76rem; max-width: 540px; line-height: 1.6; color: var(--text-muted); }
.qf-empty-hint code { background: var(--bg); padding: .1rem .35rem; border-radius: 3px; font-size: .9em; }
.qf-empty-cta {
  margin-top: .5rem; display: inline-block;
  padding: .55rem 1.2rem; border-radius: 6px;
  background: var(--primary); color: #fff !important; font-weight: 600;
  font-size: .85rem; text-decoration: none;
}
.qf-empty-cta:hover { opacity: .9; text-decoration: none; }

/* ── KPI grid — wrap multiple `qf-kpi` cards ────────────────────── */
.kpi-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .75rem; margin-bottom: 1rem;
}

/* ── KPI card — `{% raw %}{{ kpi(...) }}{% endraw %}` macro ──────────────────── */
.qf-kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .75rem .9rem;
  display: flex; flex-direction: column; gap: .15rem; min-width: 0;
}
.qf-kpi-label {
  font-size: .68rem; color: var(--text-muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
  display: flex; align-items: center;
}
.qf-kpi-value {
  font-size: 1.5rem; font-weight: 700; line-height: 1.15;
  color: var(--text);
}
.qf-kpi-suffix { font-size: .7rem; font-weight: 500; color: var(--text-muted); margin-left: .25rem; }
.qf-kpi-good .qf-kpi-value { color: #15803d; }
.qf-kpi-warn .qf-kpi-value { color: #d97706; }
.qf-kpi-bad  .qf-kpi-value { color: #dc2626; }
.qf-kpi-neutral .qf-kpi-value { color: var(--text-muted); }

/* clickable-kpis (BUG_070+) — kpi cards wrapped in `<a class="qf-kpi-link">`
   gain hover affordance + cursor. The drill-down navigation itself is
   handled by the anchor's href. */
.qf-kpi-link {
  display: block; text-decoration: none; color: inherit; border-radius: 8px;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.qf-kpi-link:hover { text-decoration: none; }
.qf-kpi-link:hover .qf-kpi {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0,0,0,.08);
  border-color: var(--primary);
  cursor: pointer;
}
.qf-kpi-link:focus-visible .qf-kpi {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ── Layout ── */
.container { max-width: 1400px; margin: 0 auto; padding: 1.5rem; width: 100%; }
.page-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 1.25rem; display: flex; align-items: center; gap: .5rem; }
.count-badge { background: var(--primary); color: #fff; border-radius: 999px; font-size: .75rem; padding: .1rem .55rem; font-weight: 600; }
.section { margin-top: 2rem; }
.section h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: .75rem; }
.empty-state { color: var(--text-muted); font-style: italic; }

/* ── KPI Grid ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem 1rem; text-align: center; box-shadow: var(--shadow); }
.kpi-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.kpi-label { color: var(--text-muted); font-size: .8rem; margin-top: .35rem; }
.kpi-green .kpi-value { color: var(--pass); }
.kpi-yellow .kpi-value { color: var(--bug); }
.kpi-red .kpi-value { color: var(--fail); }

/* ── Charts ── */
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.chart-card h3 { font-size: .9rem; font-weight: 600; margin-bottom: .75rem; color: var(--text-muted); }

/* (Removed in v0.3.2: legacy .layout-sidebar / .sidebar filter-panel rules.
    The bare `.sidebar` selector clashed with the new app-shell sidebar at the
    top of this file and was overriding it via source order. Both classes are
    no longer referenced in any template. If a future page needs an inline
    filter sidebar, give it a unique class like `.filter-sidebar`.) */
.btn-primary { width: 100%; padding: .45rem; background: var(--primary); color: #fff; border: none; border-radius: 5px; font-size: .85rem; font-weight: 600; cursor: pointer; margin-top: .5rem; }
.btn-primary:hover { opacity: .88; }
.btn-ghost { display: block; text-align: center; margin-top: .4rem; font-size: .8rem; color: var(--text-muted); }

/* ── Table ── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: .85rem; }
.data-table th { background: var(--bg); font-weight: 600; text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--border); white-space: nowrap; color: var(--text-muted); }
.data-table td { padding: .55rem .8rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f0f4ff; }
.notes-cell { max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-muted); }

/* ── Badges ── */
.badge { display: inline-block; border-radius: 999px; padding: .1rem .5rem; font-size: .72rem; font-weight: 600; white-space: nowrap; }

/* status */
.badge-status-draft       { background: #e2e8f0; color: #4a5568; }
.badge-status-ready       { background: #c6f6d5; color: #276749; }
.badge-status-stable      { background: #bee3f8; color: #2a69ac; }
.badge-status-deprecated  { background: #fef9ef; color: #92612a; }  /* warm amber-gray — "retired" */
.badge-status-blocked     { background: #fef3c7; color: #92400e; }  /* amber/orange — "attention needed" */
.badge-status-update-ready { background: #ede9fe; color: #5b21b6; } /* violet — hints need update before re-run */
.badge-status-needre-run  { background: #ffedd5; color: #9a3412; }  /* orange — must be re-run after fix */

/* run result */
.badge-run-pass    { background: #c6f6d5; color: #276749; }
.badge-run-fail    { background: #fed7d7; color: #9b2c2c; }
.badge-run-bug     { background: #feebc8; color: #7b341e; }
.badge-run-blocked { background: #e2e8f0; color: #4a5568; }
.badge-run-skip    { background: #e9d8fd; color: #553c9a; }

/* priority */
.badge-pri-high   { background: #fed7d7; color: #9b2c2c; }
.badge-pri-medium { background: #fefcbf; color: #744210; }
.badge-pri-low    { background: #c6f6d5; color: #276749; }
.prio-badge   { display:inline-block; border-radius:4px; padding:.12rem .45rem; font-size:.7rem; font-weight:700; }
.badge-high   { background:#fed7d7; color:#c53030; }
.badge-medium { background:#fef3c7; color:#92400e; }
.badge-low    { background:#e2e8f0; color:#4a5568; }

/* type — Bundle 4 (FR-4) — slug-based classes are emitted at page render
   time by web.type_taxonomy.render_css() into a <style> block in the
   page <head>; see web/templates/base.html. Hardcoded .badge-type-*
   rules used to live here for Functional/Performance/Middleware/
   Compression and were removed; the lint test
   tests/test_type_taxonomy.py::TestNoLegacyBadgeClasses guards against
   reintroduction. */

/* env */
.badge-env-dev      { background: #bee3f8; color: #2a69ac; }
.badge-env-staging  { background: #feebc8; color: #7b341e; }
.badge-env-uat      { background: #e9d8fd; color: #553c9a; }
.badge-env-prod     { background: #fed7d7; color: #9b2c2c; }

/* sprint (FR-8 — sprint linkage) */
.badge-sprint {
  background: #ede9fe; color: #5b21b6; border: 1px solid #c4b5fd;
  text-decoration: none; font-family: monospace;
}
.badge-sprint:hover { background: #ddd6fe; color: #4c1d95; text-decoration: none; }

.badge-bug { background: #feebc8; color: #7b341e; font-family: monospace; }

/* ── TC Detail ── */
.breadcrumb { margin-bottom: 1rem; color: var(--text-muted); font-size: .85rem; }
.tc-header { margin-bottom: 1.25rem; }
.tc-header h1 { font-size: 1.4rem; font-weight: 700; display: flex; align-items: center; gap: .6rem; }
.tc-title { color: var(--text-muted); margin-top: .25rem; font-size: .95rem; }

.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .65rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1.5rem; }
.meta-item { display: flex; flex-direction: column; gap: .15rem; }
.meta-label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }

/* Markdown body */
.tc-body { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem 1.5rem; }
.tc-body h2 { font-size: 1.05rem; font-weight: 700; margin: 1.25rem 0 .5rem; padding-bottom: .25rem; border-bottom: 1px solid var(--border); }
.tc-body h3 { font-size: .95rem; font-weight: 600; margin: 1rem 0 .4rem; color: var(--text-muted); }
.tc-body p  { margin: .5rem 0; }
.tc-body ul, .tc-body ol { padding-left: 1.4rem; margin: .5rem 0; }
.tc-body li { margin: .2rem 0; }
.tc-body table { width: 100%; border-collapse: collapse; margin: .75rem 0; font-size: .85rem; }
.tc-body th { background: var(--bg); font-weight: 600; text-align: left; padding: .4rem .6rem; border: 1px solid var(--border); }
.tc-body td { padding: .4rem .6rem; border: 1px solid var(--border); vertical-align: top; }
.tc-body pre { background: #1a202c; color: #e2e8f0; border-radius: 6px; padding: 1rem; overflow-x: auto; margin: .75rem 0; font-size: .82rem; }
.tc-body code { font-family: 'Fira Code', 'Cascadia Code', monospace; }
.tc-body p > code { background: #edf2f7; padding: .1rem .3rem; border-radius: 3px; font-size: .82rem; }
.tc-body strong { font-weight: 700; }
.tc-body blockquote { border-left: 3px solid var(--primary); padding-left: .75rem; color: var(--text-muted); margin: .5rem 0; }

/* ── Reports ── */
.report-nav { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.pill { padding: .35rem .9rem; border: 1px solid var(--border); border-radius: 999px; font-size: .82rem; font-weight: 500; color: var(--text-muted); background: var(--surface); }
.pill:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.pill-active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Responsive ── */
@media (max-width: 768px) {
  .layout-sidebar { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-grid { grid-template-columns: 1fr; }
}

/* ── Rally Sync ── */
.rally-bar { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.btn-rally { background: #6b21a8; color: #fff; border: none; border-radius: var(--radius); padding: .45rem 1rem; font-size: .88rem; font-weight: 600; cursor: pointer; transition: background .15s; }
.btn-rally:hover { background: #7e22ce; }
.rally-folder { font-size: .82rem; color: var(--text-muted); }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-box { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1.5rem; width: min(600px, 92vw); max-height: 80vh; overflow-y: auto; box-shadow: 0 8px 32px rgba(0,0,0,.2); }
.modal-box h3 { margin: 0 0 .25rem; font-size: 1.1rem; }
.modal-sub { color: var(--text-muted); font-size: .85rem; margin: 0 0 1rem; }
.modal-actions { display: flex; gap: .75rem; margin-top: 1.25rem; justify-content: flex-end; }

/* ── SPEC_002: Dark mode ─────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:        #0d1117;
  --surface:   #161b22;
  --border:    #30363d;
  --text:      #e6edf3;
  --text-muted:#8b949e;
  --shadow:    0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  /* SPEC_002 semantic tokens — dark */
  --color-good-bg:     #1a3a2a;  --color-good-text:   #86efac;  --color-good-border:   #22c55e;
  --color-warn-bg:     #3a2e15;  --color-warn-text:   #fbbf24;  --color-warn-border:   #f59e0b;
  --color-fail-bg:     #3a1515;  --color-fail-text:   #f87171;  --color-fail-border:   #ef4444;
  --color-neutral-bg:  #2d3139;  --color-neutral-text: #d1d5db;
  --color-info-bg:     #1e3a5f;  --color-info-text:   #60a5fa;
  --color-purple-bg:   #2d1b4e;  --color-purple-text: #d8b4fe;
  --color-cyan-bg:     #164e63;  --color-cyan-text:   #22d3ee;
  --color-amber-bg:    #4a2a0a;  --color-amber-text:  #fcd34d;
  /* SPEC_002 qf-badge dark overrides — WCAG AA compliant */
}
[data-theme="dark"] .qf-badge-good    { background: #1a3a2a; color: #86efac; border-color: #22c55e; }
[data-theme="dark"] .qf-badge-warn    { background: #3a2e15; color: #fbbf24; border-color: #f59e0b; }
[data-theme="dark"] .qf-badge-bad     { background: #3a1515; color: #f87171; border-color: #ef4444; }
[data-theme="dark"] .qf-badge-neutral { background: #2d3139; color: #d1d5db; border-color: #9ca3af; }
[data-theme="dark"] .qf-badge-info    { background: #1e3a5f; color: #60a5fa; border-color: #3b82f6; }
[data-theme="dark"] .qf-badge-purple  { background: #2d1b4e; color: #d8b4fe; border-color: #a78bfa; }
[data-theme="dark"] .qf-badge-cyan    { background: #164e63; color: #22d3ee; border-color: #06b6d4; }
[data-theme="dark"] .qf-badge-amber   { background: #4a2a0a; color: #fcd34d; border-color: #f59e0b; }
[data-theme="dark"] .qf-badge-speckit { background: #134e4a; color: #5eead4; border-color: #14b8a6; }
/* tc-body code block — stays dark in both themes (already dark in light mode) */
[data-theme="dark"] .tc-body p > code { background: #30363d; color: #e6edf3; }
/* Ensure table headers use surface in dark mode */
[data-theme="dark"] .tc-body th { background: var(--surface); }

/* ── SPEC_002: Cmd+K search palette ─────────────────────────────────────── */
#cmdk-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 9000;
  background: rgba(0, 0, 0, .55);
  align-items: flex-start; justify-content: center;
  padding-top: clamp(48px, 12vh, 120px);
  backdrop-filter: blur(2px);
}
#cmdk-overlay.cmdk-open { display: flex; }
#cmdk-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 56px rgba(0,0,0,.35);
  width: min(600px, 94vw);
  max-height: min(480px, 80vh);
  display: flex; flex-direction: column;
  overflow: hidden;
}
#cmdk-input-row {
  display: flex; align-items: center; gap: .6rem;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#cmdk-search-icon { font-size: 1rem; color: var(--text-muted); flex-shrink: 0; }
#cmdk-input {
  flex: 1; border: none; outline: none;
  background: transparent; color: var(--text);
  font-size: 1rem; font-family: inherit;
  min-width: 0;
}
#cmdk-input::placeholder { color: var(--text-muted); }
#cmdk-esc-hint {
  flex-shrink: 0; font-size: .72rem; font-family: inherit;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text-muted); border-radius: 4px;
  padding: .1rem .35rem; line-height: 1.4;
}
#cmdk-results {
  flex: 1; overflow-y: auto;
  padding: .35rem 0;
  scrollbar-width: thin;
}
#cmdk-results::-webkit-scrollbar { width: 5px; }
#cmdk-results::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.cmdk-empty {
  padding: 2rem 1rem; text-align: center;
  color: var(--text-muted); font-size: .88rem;
}
.cmdk-row {
  display: flex; align-items: center; gap: .65rem;
  padding: .55rem 1rem; cursor: pointer;
  transition: background .1s;
  min-height: 44px; /* touch-friendly */
}
.cmdk-row:hover, .cmdk-row-active { background: rgba(79,142,247,.1); }
.cmdk-row-icon { font-size: .95rem; flex-shrink: 0; width: 22px; text-align: center; }
.cmdk-row-body { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: .45rem; }
.cmdk-row-id {
  font-size: .75rem; font-weight: 700; color: var(--primary);
  white-space: nowrap; flex-shrink: 0;
}
.cmdk-row-title {
  font-size: .88rem; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cmdk-row-sub {
  font-size: .74rem; color: var(--text-muted);
  white-space: nowrap; flex-shrink: 0; max-width: 30%;
  overflow: hidden; text-overflow: ellipsis;
}
#cmdk-footer {
  display: flex; gap: 1rem; justify-content: center;
  padding: .4rem .8rem; font-size: .72rem; color: var(--text-muted);
  border-top: 1px solid var(--border); flex-shrink: 0;
  background: var(--bg);
}

/* ── Cmd+K search button in topbar (visible on all sizes) ───────────────── */
.cmdk-open-btn {
  display: inline-flex; align-items: center; gap: .4rem;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text-muted); border-radius: 6px;
  padding: .26rem .65rem; font-size: .78rem; font-weight: 500;
  cursor: pointer; font-family: inherit;
  transition: background .12s, border-color .12s, color .12s;
  flex-shrink: 0; white-space: nowrap;
}
.cmdk-open-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--surface); }
.cmdk-open-btn .cmdk-hint {
  font-size: .68rem; color: var(--text-muted);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 4px; padding: .05rem .3rem; line-height: 1.4;
  display: none; /* hidden on mobile, shown on md+ */
}
@media (min-width: 600px) {
  .cmdk-open-btn .cmdk-hint { display: inline; }
}

/* Mobile (≤480px) — full-width overlay box */
@media (max-width: 480px) {
  #cmdk-overlay { padding-top: 0; align-items: flex-end; }
  #cmdk-box {
    width: 100%; border-radius: 16px 16px 0 0;
    max-height: 75vh;
  }
}
