/* =====================================================================
   Metalogalva OCR — Design System
   Port directo do protótipo (data/_design_ref_v2/styles.css)
   adaptado para SSR Jinja + HTMX + Alpine (sem Tailwind, sem React).
   ===================================================================== */

:root {
  --paper: #F4F1EB;
  --paper-2: #ECE7DD;
  --paper-3: #E2DCCE;
  --ink: #16140F;
  --ink-2: #2A271F;
  --ink-3: #4A453A;
  --ink-4: #756F61;
  --ink-5: #9B9587;
  --rule: #D6CFBE;
  --rule-2: #C2BAA5;
  --surface: #FBFAF6;
  --surface-2: #FFFFFF;

  --accent: #D4A574;
  --accent-ink: #8A5F2D;
  --accent-soft: #F0E2C9;

  --ok: #2F7D43;
  --ok-soft: #DDEBD8;
  --warn: #B8841C;
  --warn-soft: #F5E7C2;
  --crit: #B53024;
  --crit-soft: #F4D7D2;
  --info: #2D5B8A;
  --info-soft: #D5E2EE;

  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --font-hand: 'Caveat', cursive;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

/* Alpine.js x-cloak — Alpine 3 doesn't inject this rule itself.
   Without it, x-show/x-if elements briefly flash before Alpine boots. */
[x-cloak] { display: none !important; }

body {
  font-family: var(--font-sans);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: inherit; text-decoration: none; }
input, button, select, textarea { font-family: inherit; }

.mono { font-family: var(--font-mono); font-feature-settings: 'tnum'; }
.tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-4); }
.tiny { font-size: 11px; }
.lbl {
  font-family: var(--font-mono); font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-4);
}
.scroll-x { overflow-x: auto; }
hr.rule { border: none; border-top: 1px solid var(--rule); margin: 0; }

/* =====================================================================
   App shell — sidebar 240px + main flex
   ===================================================================== */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--ink);
  color: var(--paper);
  padding: 24px 0;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.sb-brand {
  padding: 0 20px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 12px;
}
.sb-brand-title { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.sb-brand-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  color: rgba(255,255,255,0.5);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  margin-top: 4px;
}
.sb-section {
  padding: 14px 20px 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  color: rgba(255,255,255,0.4);
  text-transform: uppercase;
}
.sb-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px;
  font-size: 14px;
  color: rgba(255,255,255,0.75);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background .12s;
}
.sb-item:hover { background: rgba(255,255,255,0.04); color: white; }
.sb-item.active {
  color: white; background: rgba(212,165,116,0.12);
  border-left-color: var(--accent);
}
.sb-num {
  font-family: var(--font-mono); font-size: 10px;
  color: rgba(255,255,255,0.4); margin-right: 4px;
}
.sb-foot {
  margin-top: auto; padding: 20px;
  font-size: 11px; color: rgba(255,255,255,0.4);
  font-family: var(--font-mono); letter-spacing: 0.08em;
}

.main {
  background: var(--paper);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Mobile: collapse sidebar to top bar (when SSR detection fails to omit it) */
@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: relative; height: auto;
    padding: 12px 16px; flex-direction: row;
    align-items: center; gap: 12px; overflow-x: auto;
  }
  .sb-brand { padding: 0; border: none; margin: 0; flex-shrink: 0; }
  .sb-brand-sub { display: none; }
  .sb-section { display: none; }
  .sb-item {
    padding: 6px 10px; border-left: none;
    border-bottom: 2px solid transparent;
    flex-shrink: 0; font-size: 13px;
  }
  .sb-item.active { border-bottom-color: var(--accent); border-left: none; }
  .sb-num { display: none; }
  .sb-foot { display: none; }
}

/* Phase A (Round 29): on mobile devices, the SSR detection (User-Agent
   sniffing) drops the sidebar entirely — the body gets ".mobile" class.
   The capture page is the ONLY meaningful surface on a phone; everything
   else is desktop-only. These rules ensure the layout collapses cleanly
   when the sidebar is omitted server-side. */
body.mobile .app { grid-template-columns: 1fr; }
body.mobile .main { padding: 0; }
/* Hide elements not relevant to the capture-only mobile flow. Pages that
   don't make sense on a phone (queue, dashboards) still render but without
   chrome — a future iteration can redirect them to /capture. */
body.mobile .live-pulse { display: none; }

/* Round 34 — mobile camera: cap viewport so shutter + concluir button
   stay visible on small screens. */
body.mobile .cam-wrap {
  max-height: 50vh;
  min-height: 200px;
}
body.mobile .cam-bar {
  padding: 10px 14px 14px;
}
body.mobile .shutter {
  width: 56px; height: 56px; border-width: 3px;
}

/* Round 36 — global rule: native date inputs need ≥160px to show
   full DD/MM/YYYY including the year. Inline `min-width:auto` overrides
   in templates were truncating to ~80px and hiding the year. Applied
   globally so any future date input is correct by default. */
input[type="date"] {
  min-width: 160px;
}

/* Round 36 — compact header inline in /sheet/{id} banner.
   Each field rendered as label + _cell.html micro-table for editing. */
.sheet-header-inline {
  display: flex; gap: 18px; flex-wrap: wrap;
  align-items: flex-end;
  padding: 10px 0 4px;
  border-top: 1px dashed var(--rule);
  margin-top: 8px;
}
.sheet-header-inline .hb-field {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
}
.sheet-header-inline .hb-field .lbl {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  color: var(--ink-4);
  text-transform: uppercase;
  margin: 0;
}
.sheet-header-inline table { border-collapse: collapse; }
.sheet-header-inline table td { background: var(--paper-2); border-radius: 4px; }

/* Round 34c — image rotation moved server-side (see /image/{sheet_id}
   in main.py). PIL handles EXIF + portrait→landscape, results cached
   next to the original. CSS rotate-cw hack removed (was causing
   layout overflow when transformed image's bounding box stayed
   vertical). */
.img-rotate-wrap {
  /* Wrapper that keeps the rotated image bounded — apply to <div> around <img>. */
  display: inline-block;
  position: relative;
  overflow: hidden;
}

/* =====================================================================
   Page header
   ===================================================================== */
.page-h {
  padding: 24px 40px 12px;
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}
.page-eyebrow {
  font-family: var(--font-mono); font-size: 11px;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-4); margin-bottom: 4px;
}
.page-title { font-size: 28px; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
.page-content { padding: 28px 40px 60px; }

@media (max-width: 768px) {
  .page-h { padding: 16px 18px 10px; }
  .page-title { font-size: 22px; }
  .page-content { padding: 18px; }
}

/* =====================================================================
   Buttons
   ===================================================================== */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--rule-2);
  background: var(--surface-2);
  border-radius: 6px;
  font-size: 13px; font-weight: 500;
  color: var(--ink); cursor: pointer;
  transition: all .12s;
  text-decoration: none;
}
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.primary:hover { background: var(--ink-2); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--paper-2); }
.btn.lg { padding: 14px 20px; font-size: 16px; }
.btn.danger { background: var(--crit); color: white; border-color: var(--crit); }

/* =====================================================================
   Pills & dots
   ===================================================================== */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-family: var(--font-mono); font-size: 10px;
  letter-spacing: 0.08em; text-transform: uppercase;
  font-weight: 500;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.crit { background: var(--crit-soft); color: var(--crit); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.neutral { background: var(--paper-2); color: var(--ink-3); }

.dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 999px;
  flex-shrink: 0;
}
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.crit { background: var(--crit); }
.dot.info { background: var(--info); }
.dot.idle { background: var(--ink-5); }

/* =====================================================================
   Cards
   ===================================================================== */
.card {
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: 8px;
}
.card-h {
  padding: 14px 18px; border-bottom: 1px solid var(--rule);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.card-h-title { font-weight: 600; font-size: 14px; }
.card-h-sub {
  font-family: var(--font-mono); font-size: 10px;
  color: var(--ink-4); letter-spacing: 0.12em; text-transform: uppercase;
}
.card-b { padding: 18px; }

/* =====================================================================
   Tables
   ===================================================================== */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left; padding: 10px 12px;
  font-family: var(--font-mono); font-size: 10px;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-4); font-weight: 500;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}
.tbl td {
  padding: 12px;
  border-bottom: 1px solid var(--rule);
  font-size: 13px; vertical-align: middle;
}
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: var(--paper); }

/* =====================================================================
   KPI cards
   ===================================================================== */
.kpi-grid { display: grid; gap: 16px; }
.kpi {
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 18px;
}
.kpi-l {
  font-family: var(--font-mono); font-size: 10px;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-4);
}
.kpi-v {
  font-size: 36px; font-weight: 600; letter-spacing: -0.02em;
  margin-top: 4px; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.kpi-u { font-size: 14px; color: var(--ink-4); font-weight: 400; margin-left: 4px; }
.kpi-d { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 12px; }

/* =====================================================================
   Bars
   ===================================================================== */
.bar-track {
  background: var(--paper-2);
  border-radius: 99px;
  height: 6px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--ink);
  border-radius: 99px;
  transition: width .3s;
}
.bar-fill.ok { background: var(--ok); }
.bar-fill.warn { background: var(--warn); }
.bar-fill.crit { background: var(--crit); }

/* MiniBars (sparkline-ish) */
.minibars {
  display: flex; gap: 2px; align-items: flex-end;
  height: 40px;
}
.minibars > span {
  flex: 1;
  background: var(--ink);
  border-radius: 1px 1px 0 0;
  min-height: 2px;
  display: block;
}
.minibars.ok > span { background: var(--ok); }
.minibars.warn > span { background: var(--warn); }
.minibars.crit > span { background: var(--crit); }

/* =====================================================================
   Tabs
   ===================================================================== */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--rule); }
.tab {
  padding: 10px 16px; cursor: pointer;
  border-bottom: 2px solid transparent;
  font-size: 13px; font-weight: 500; color: var(--ink-4);
  margin-bottom: -1px;
  background: transparent; border-top: none; border-left: none; border-right: none;
}
.tab.active { color: var(--ink); border-bottom-color: var(--ink); }
.tab:hover { color: var(--ink-2); }

/* =====================================================================
   Confidence cells (DQ)
   ===================================================================== */
.cell-conf-hi { background: transparent; }
.cell-conf-md {
  background: var(--warn-soft);
  box-shadow: inset 0 0 0 1px var(--warn);
  position: relative;
}
.cell-conf-lo {
  background: var(--crit-soft);
  box-shadow: inset 0 0 0 1.5px var(--crit);
  position: relative;
}
.cell-conf-md::after {
  content: '?'; position: absolute; top: 1px; right: 4px;
  font-size: 9px; font-weight: 700; color: var(--warn);
}
.cell-conf-lo::after {
  content: '!'; position: absolute; top: 1px; right: 4px;
  font-size: 9px; font-weight: 700; color: var(--crit);
}

/* Round 50 — folha validada: cells read-only (lock visual). */
.cell-locked {
  cursor: default !important;
  user-select: text;
  opacity: 0.92;
}
.cell-locked:hover {
  background-color: inherit !important;
}

/* =====================================================================
   Cross-check verification colors (Round 33)
   - cc-match: cell value matches reference (plan/SAP) → green
   - cc-no-match: cell diverges from reference → red
   - cc-na: empty/currently no value to validate → neutral
   These OVERRIDE the conf-* backgrounds when applied (specificity via
   ordering — they appear after, so cascade wins).
   ===================================================================== */
.cc-match {
  background: var(--ok-soft) !important;
  box-shadow: inset 0 0 0 1px var(--ok);
  position: relative;
}
.cc-no-match {
  background: var(--crit-soft) !important;
  box-shadow: inset 0 0 0 1.5px var(--crit);
  position: relative;
}
/* Round 41c: cc-warn (strong yellow) for dimensional fields (esp,
   larg_mm, comp_mm, lbase, ltopo) when they diverge from plan/SAP.
   Yellow = "verify, may be operator decision OR OCR error", distinct
   from cc-no-match (red) used for hard mismatches in identity fields
   (OF, cliente, OV, modelo, lote). */
.cc-warn {
  background: #fde68a !important;            /* strong amber/yellow */
  box-shadow: inset 0 0 0 1.5px #d97706;     /* darker amber border */
  position: relative;
}
.cc-warn::before {
  content: '!'; position: absolute; top: 1px; left: 4px;
  font-size: 10px; font-weight: 700; color: #b45309;
}
.cc-na {
  /* R56/R216: visible neutral colour for empty cells with no value to
     validate. User explicit: "tem de ter tudo cor".
     Light slate-grey background + faint `—` marker distinguishes from
     MATCH (green) and stub-accept (yellow soft). */
  background: rgba(148, 163, 184, 0.10) !important;
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.25);
  position: relative;
}
.cc-na::before {
  content: '—'; position: absolute; top: 1px; left: 4px;
  font-size: 9px; font-weight: 600; color: rgba(100, 116, 139, 0.6);
}

/* R56: 14×14px swatches for the color legend strip. Reuses existing
   cc-* classes which already define backgrounds + ::before icons. */
.legend-swatch {
  display: inline-block; width: 14px; height: 14px;
  border-radius: 2px; position: relative; flex-shrink: 0;
}
/* R52 F4: cc-na-suspended — stale/legacy suspended NA from stub-accept
   (row otherwise validates but this field disagrees with plan/SAP). Soft
   yellow with `?` marker distinguishes from cc-na (empty/no value). Operator sees "review me"
   without the urgency of NO_MATCH red. */
.cc-na-suspended {
  background: rgba(254, 240, 138, 0.35);
  box-shadow: inset 0 0 0 1px rgba(217, 119, 6, 0.3);
  position: relative;
}
.cc-na-suspended::before {
  content: '?'; position: absolute; top: 1px; left: 4px;
  font-size: 10px; font-weight: 700; color: rgba(180, 83, 9, 0.85);
}
.cc-match::before {
  content: '✓'; position: absolute; top: 1px; left: 4px;
  font-size: 10px; font-weight: 700; color: var(--ok);
}
.cc-no-match::before {
  content: '✗'; position: absolute; top: 1px; left: 4px;
  font-size: 10px; font-weight: 700; color: var(--crit);
}

/* =====================================================================
   Forms
   ===================================================================== */
input[type="text"], input[type="number"], input[type="search"],
input:not([type]), select, textarea {
  padding: 8px 12px;
  border: 1px solid var(--rule-2);
  border-radius: 6px;
  font-size: 14px;
  background: var(--surface-2);
  color: var(--ink);
  outline: none;
  transition: border-color .12s;
}
input:focus, select:focus, textarea:focus { border-color: var(--ink-3); }

label.inline {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--ink-3);
}

/* =====================================================================
   Camera viewport (Fase 2)
   ===================================================================== */
.cam-wrap {
  flex: 1 1 auto;
  max-height: 60vh;       /* desktop cap */
  min-height: 240px;
  background: #111;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 360px;
  border-radius: 12px;
}
.cam-wrap video, .cam-wrap canvas {
  width: 100%; height: 100%;
  object-fit: cover; display: block;
}
.cam-guides {
  position: absolute; inset: 18px;
  pointer-events: none;
}
.cam-corner {
  position: absolute;
  width: 28px; height: 28px;
  border: 2px solid var(--accent);
}
.cam-corner.tl { top: 0; left: 0; border-right: none; border-bottom: none; }
.cam-corner.tr { top: 0; right: 0; border-left: none; border-bottom: none; }
.cam-corner.bl { bottom: 0; left: 0; border-right: none; border-top: none; }
.cam-corner.br { bottom: 0; right: 0; border-left: none; border-top: none; }
.cam-hint {
  position: absolute; top: 16px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.65);
  color: #fff; padding: 6px 14px; border-radius: 99px;
  font-family: var(--font-mono); font-size: 11px;
  letter-spacing: 0.1em; pointer-events: none;
}
.cam-bar {
  flex-shrink: 0; background: var(--ink); color: var(--paper);
  padding: 18px 22px 22px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px;
}
.shutter {
  width: 68px; height: 68px; border-radius: 50%;
  background: #fff;
  border: 4px solid rgba(255,255,255,0.4);
  cursor: pointer; flex-shrink: 0; padding: 0;
  transition: transform .1s;
}
.shutter:active { transform: scale(0.95); }
.shutter:disabled { opacity: 0.5; pointer-events: none; }
.cam-meta {
  font-size: 11px; color: rgba(255,255,255,0.65);
  font-family: var(--font-mono);
}
.cam-meta b { color: #fff; font-weight: 500; font-family: var(--font-sans); }

/* =====================================================================
   Bottom-sheet modal (mobile cell editor)
   ===================================================================== */
.sheet-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: flex-end;
  z-index: 50;
  animation: fadein .15s;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.sheet-modal {
  background: var(--surface-2);
  width: 100%;
  border-radius: 18px 18px 0 0;
  padding: 20px 22px 28px;
  display: flex; flex-direction: column; gap: 10px;
  animation: slideup .2s;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-modal input {
  width: 100%; padding: 14px;
  font-size: 22px; font-family: var(--font-mono);
  border: 2px solid var(--ink); border-radius: 8px;
}

/* =====================================================================
   Spinner / progress (Fase 2/3)
   ===================================================================== */
.spinner {
  width: 64px; height: 64px; border-radius: 50%;
  border: 3px solid var(--rule);
  border-top-color: var(--ink);
  animation: spin 1s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.proc {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 18px; padding: 32px; text-align: center;
}

/* =====================================================================
   Toast
   ===================================================================== */
.toast {
  position: fixed; bottom: 20px; left: 50%;
  transform: translateX(-50%);
  background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: 8px;
  font-size: 13px; z-index: 60;
}

/* =====================================================================
   Alerts banner (Fase 3 + 6)
   ===================================================================== */
.alert {
  padding: 10px 14px; border-radius: 6px;
  font-size: 13px; border: 1px solid;
  display: flex; gap: 8px; align-items: flex-start;
}
.alert.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.alert.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.alert.crit { background: var(--crit-soft); border-color: var(--crit); color: var(--crit); }
.alert.info { background: var(--info-soft); border-color: var(--info); color: var(--info); }

/* =====================================================================
   Avatar circle (Fase 5 — workers)
   ===================================================================== */
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--paper-2);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 12px;
  font-family: var(--font-mono);
  flex-shrink: 0;
}

/* =====================================================================
   Live-update indicator (Phase B — HTMX polling)
   ===================================================================== */
.live-pulse {
  position: fixed;
  bottom: 16px; right: 20px;
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: 99px;
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-4);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  z-index: 40;
  display: flex; align-items: center; gap: 6px;
  pointer-events: none;
}
.live-pulse-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ok);
}
.live-pulse.refreshing .live-pulse-dot {
  background: var(--accent);
  animation: live-pulse-blink 0.8s ease-in-out infinite;
}
@keyframes live-pulse-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* =====================================================================
   Severity rail (Fase 6 — alerts)
   ===================================================================== */
.sev-rail {
  width: 8px; align-self: stretch; border-radius: 4px;
  flex-shrink: 0;
}
.sev-rail.crit { background: var(--crit); }
.sev-rail.warn { background: var(--warn); }
.sev-rail.info { background: var(--info); }

/* =====================================================================
   R80 — Cross-check snap indicator (cells auto-corrigidas)
   Marca passiva: pointer-events:none deixa clicks passarem para a célula.
   ===================================================================== */
.cc-snapped-mark {
  display: inline-block;
  margin-left: 3px;
  font-weight: 700;
  font-size: 10px;
  color: var(--ink);
  opacity: 0.65;
  vertical-align: super;
  line-height: 1;
  pointer-events: none;
}
.sev-rail.idle { background: var(--ink-5); }

/* ===================================================================
   Aprendizagens & Regras  (/learnings)  — Round 98
   =================================================================== */
.lr-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--rule-2);
  margin-bottom: 18px;
}
.lr-tab {
  padding: 9px 18px;
  font: 600 13px/1 var(--font-sans);
  color: var(--ink-4);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.lr-tab:hover { color: var(--ink-2); }
.lr-tab.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.lr-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.lr-toolbar select {
  padding: 7px 10px;
  border: 1px solid var(--rule-2);
  border-radius: 6px;
  background: var(--surface-2);
  font: 500 12px var(--font-sans);
}
.lr-metric {
  margin-left: auto;
  font: 500 12px var(--font-sans);
  color: var(--ink-3);
}
.lr-metric b { font-size: 18px; color: var(--ink); }

.lr-rule {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--rule);
  border-left: 4px solid var(--rule-2);
  border-radius: 8px;
  background: var(--surface-2);
  margin-bottom: 8px;
}
.lr-rule.quarantine { border-left-color: var(--accent); background: var(--surface); }
.lr-rule.approved   { border-left-color: var(--ok); }
.lr-rule.rejected   { border-left-color: var(--ink-5); opacity: 0.6; }
.lr-rule-main { flex: 1; min-width: 0; }
.lr-rule-desc { font: 500 13px var(--font-sans); color: var(--ink); }
.lr-rule-desc .mono { font-family: var(--font-mono); }
.lr-rule-meta { margin-top: 4px; font: 400 11px var(--font-sans); color: var(--ink-4); }
.lr-rule-actions { display: flex; gap: 6px; flex-shrink: 0; }

.lr-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 99px;
  font: 600 10px/1.5 var(--font-mono);
  text-transform: uppercase;
  background: var(--paper-3);
  color: var(--ink-3);
}
.lr-badge.quarantine { background: var(--accent-soft); color: var(--accent-ink); }
.lr-badge.approved   { background: var(--ok-soft); color: var(--ok); }
.lr-badge.rejected   { background: var(--paper-3); color: var(--ink-4); }
.lr-evidence { color: var(--ink-4); font-size: 11px; }

.lr-edit { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.lr-edit input {
  padding: 6px 8px;
  border: 1px solid var(--rule-2);
  border-radius: 6px;
  font: 500 12px var(--font-mono);
}

/* --- LLM tab --- */
.lr-attractor {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--rule);
  border-radius: 7px;
  background: var(--surface-2);
  margin-bottom: 6px;
}
.lr-attractor-bar {
  width: 4px;
  align-self: stretch;
  border-radius: 2px;
  background: var(--ink-5);
}
.lr-attractor-bar.alta  { background: var(--crit); }
.lr-attractor-bar.media { background: var(--warn); }
.lr-attractor-bar.baixa { background: var(--ok); }
.lr-attractor-main { flex: 1; min-width: 0; }

.lr-chat {
  display: flex;
  flex-direction: column;
  height: 62vh;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--surface-2);
  overflow: hidden;
}
.lr-chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
@keyframes lr-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.lr-msg {
  max-width: 80%;
  padding: 11px 14px;
  border-radius: 14px;
  font: 400 13px/1.6 var(--font-sans);
  overflow-wrap: anywhere;
  animation: lr-fade-in 0.22s ease-out;
}
.lr-msg.user {
  align-self: flex-end;
  background: var(--ink);
  color: var(--paper);
  border-bottom-right-radius: 4px;
}
.lr-msg.assistant {
  align-self: flex-start;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(22, 20, 15, 0.05);
}

/* Markdown body inside an assistant bubble */
.lr-md > :first-child { margin-top: 0; }
.lr-md > :last-child  { margin-bottom: 0; }
.lr-md p { margin: 0 0 8px; }
.lr-md ul, .lr-md ol { margin: 0 0 8px; padding-left: 20px; }
.lr-md li { margin: 2px 0; }
.lr-md h4 {
  margin: 10px 0 6px;
  font: 600 13px var(--font-sans);
  color: var(--ink);
}
.lr-md strong { font-weight: 600; color: var(--ink); }
.lr-md code {
  font: 500 12px var(--font-mono);
  background: var(--paper-2);
  padding: 1px 5px;
  border-radius: 4px;
}

/* "a pensar" — three bouncing dots */
.lr-typing { display: flex; gap: 4px; align-items: center; }
.lr-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-4);
  animation: lr-bounce 1.2s infinite ease-in-out;
}
.lr-typing span:nth-child(2) { animation-delay: 0.15s; }
.lr-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes lr-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-4px); }
}

.lr-msg-chart {
  margin-top: 10px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 10px;
}
.lr-proposed {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  background: var(--surface);
}
.lr-chat-input {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--rule);
  background: var(--surface);
}
.lr-chat-input textarea {
  flex: 1;
  resize: none;
  padding: 9px 11px;
  border: 1px solid var(--rule-2);
  border-radius: 10px;
  font: 400 13px var(--font-sans);
}

/* Round 99 — sized chart containers. Chart.js with maintainAspectRatio
   false fills its parent, so the parent must have an explicit height. */
.lr-chart-box {
  position: relative;
  width: 100%;
  height: 200px;
}
.lr-chart-box.tall { height: 300px; }
.lr-msg-chart .lr-chart-box { height: 190px; }

/* ============ R104 — página Refs SAP/Plan ============ */
.refs-flash {
  padding: 10px 14px; border-radius: 8px; margin-bottom: 14px;
  font-size: 13px; font-weight: 600;
}
.refs-flash.ok  { background: var(--ok-soft);   color: var(--ok);
                  box-shadow: inset 0 0 0 1px var(--ok); }
.refs-flash.err { background: var(--warn-soft); color: var(--crit);
                  box-shadow: inset 0 0 0 1px var(--crit); }

.refs-status { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.refs-stat {
  background: var(--paper-2); border-radius: 8px; padding: 14px 16px;
}
.refs-stat-name {
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
  color: var(--ink-4); text-transform: uppercase;
}
.refs-stat-big {
  font-size: 34px; font-weight: 800; color: var(--ink); line-height: 1.1;
  margin-top: 4px;
}
.refs-stat-lbl { font-size: 12px; color: var(--ink-3); }
.refs-stat-sub { font-size: 12px; color: var(--ink-3); margin-top: 6px; }
.refs-stat-sub.muted { color: var(--ink-5); margin-top: 2px; }

.refs-reval {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--paper-2); border-radius: 8px;
  padding: 12px 16px; margin-bottom: 14px; font-size: 13px;
}
.refs-reval.done { box-shadow: inset 0 0 0 1px var(--ok); }
.refs-reval-top { display: flex; align-items: center; gap: 8px; }
.refs-dot {
  width: 9px; height: 9px; border-radius: 50%; display: inline-block;
  flex: 0 0 auto;
}
.refs-dot.busy { background: var(--warn); animation: refs-pulse 1s infinite; }
.refs-dot.ok   { background: var(--ok); }
@keyframes refs-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }
.refs-bar {
  height: 8px; border-radius: 4px; background: var(--paper-3);
  overflow: hidden;
}
.refs-bar-fill {
  height: 100%; background: var(--accent); border-radius: 4px;
  transition: width 0.4s ease;
}

.refs-uploads { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.refs-form { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.refs-form input[type=file] { font-size: 13px; color: var(--ink-3); }

/* R123 — chip de confirmação do ficheiro escolhido no upload de refs */
.refs-file-chosen {
  font-size: 12px; color: var(--ok);
  display: flex; gap: 6px; align-items: center;
}
.refs-file-chosen strong { font-family: var(--font-mono); color: var(--ink); }

.refs-log { width: 100%; border-collapse: collapse; font-size: 13px; }
.refs-log th {
  text-align: left; font-size: 11px; font-weight: 700; color: var(--ink-4);
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 6px 10px; border-bottom: 1px solid var(--paper-3);
}
.refs-log td { padding: 7px 10px; border-bottom: 1px solid var(--paper-2); }
.refs-log th.num, .refs-log td.num { text-align: right; }
