:root {
  --pine: #1F4E3D;
  --pine-deep: #163A2D;
  --canvas: #EEF1EF;
  --surface: #FFFFFF;
  --ink: #17242B;
  --muted: #5A6B66;
  --line: #D5DCD8;
  --amber: #D99A00;
  --risk: #B83A2E;
  --risk-bg: #FBEDEB;
  --ok: #2E7D4F;
  --ai: #5B3FD6;
  --ai-bg: #F0EDFD;
  --font: 'Barlow', system-ui, sans-serif;
  --font-cond: 'Barlow Semi Condensed', 'Barlow', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--canvas);
  display: grid;
  grid-template-columns: 220px 1fr;
  font-variant-numeric: tabular-nums;
}
a { color: var(--pine); }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }

/* Navigation rail */
.rail {
  background: var(--pine);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  position: sticky;
  top: 0;
  height: 100vh;
}
.rail a, .rail .linklike {
  color: #DCE7E2;
  text-decoration: none;
  padding: 10px 24px;
  font-weight: 500;
  border-left: 4px solid transparent;
}
.rail a:hover { color: #fff; background: var(--pine-deep); }
.rail a[aria-current="page"] { color: #fff; border-left-color: var(--amber); background: var(--pine-deep); }
.brand { display: flex; gap: 10px; align-items: center; margin-bottom: 24px; font-weight: 700; font-size: 18px; line-height: 1.1; color: #fff !important; }
.brand small { font-weight: 500; font-size: 13px; color: #BFD3CA; }
.brand svg { width: 34px; height: 34px; stroke: var(--amber); stroke-width: 3.2; fill: none; stroke-linecap: round; }
.rail-foot { margin-top: auto; display: flex; flex-direction: column; font-size: 14px; }
.linklike { background: none; border: 0; text-align: left; font: inherit; cursor: pointer; }

/* Main */
.main { min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 2;
}
.topbar h1 { margin: 0; font-size: 26px; font-weight: 600; }
.live { display: flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 500; }
.live .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--amber); }
.live.pulse .dot { animation: pulse 0.9s ease-out; }
.live.offline .dot { background: var(--risk); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(217,154,0,.7); } 100% { box-shadow: 0 0 0 12px rgba(217,154,0,0); } }

#view { padding: 24px 32px 48px; outline: none; }

/* KPI band */
.kpis {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 24px;
}
.kpi { padding: 16px 20px; border-right: 1px solid var(--line); }
.kpi:last-child { border-right: 0; }
.kpi b { display: block; font-size: 30px; font-weight: 600; line-height: 1.1; }
.kpi span { color: var(--muted); font-size: 14px; }
.kpi.alert b { color: var(--risk); }

.cols { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.panel > h2 { margin: 0; font-size: 18px; font-weight: 600; padding: 14px 20px; border-bottom: 1px solid var(--line); }
#view > .panel + .panel { margin-top: 24px; }
.attention { list-style: none; margin: 0; padding: 0; }
.attention li { padding: 14px 20px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; }
.attention li:last-child { border-bottom: 0; }
.attention .what { font-weight: 600; }
.attention .why { color: var(--muted); font-size: 14px; grid-column: 1 / -1; }
.attention .tag { align-self: start; }
.empty { padding: 16px 20px; color: var(--muted); }

/* Live feed: the moving heart of the overview */
.feed { list-style: none; margin: 0; padding: 0; max-height: 640px; overflow: hidden; }
.feed li { display: grid; grid-template-columns: 64px 1fr; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--line); font-size: 15px; }
.feed time { color: var(--muted); font-family: var(--font-cond); }
.feed li.new { animation: arrive 1.6s ease-out; }
.feed li.ai { background: var(--ai-bg); box-shadow: inset 4px 0 var(--ai); }
@keyframes arrive { from { background: #FFF4D6; } to { background: transparent; } }

/* Tags */
.tag { display: inline-block; font-family: var(--font-cond); font-weight: 600; font-size: 13px; padding: 2px 8px; border-radius: 3px; background: #E4EAE7; color: var(--ink); white-space: nowrap; }
.tag.risk { background: var(--risk-bg); color: var(--risk); }
.tag.ok { background: #E3F2E8; color: var(--ok); }
.tag.ai { background: var(--ai); color: #fff; }
.tag.pending { background: #FFF1CC; color: #7A5600; }

/* Tables */
.toolbar { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.toolbar select, .toolbar input { font: inherit; padding: 6px 10px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-family: var(--font-cond); font-weight: 600; color: var(--muted); font-size: 14px; background: #F6F8F7; }
td.num, th.num { text-align: right; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #F6F8F7; }
tr.ai td:first-child { box-shadow: inset 4px 0 var(--ai); }
tr.risk td:first-child { box-shadow: inset 4px 0 var(--risk); }

/* Detail */
.detail-head { display: flex; justify-content: space-between; align-items: start; gap: 16px; margin-bottom: 16px; }
.detail-head h2 { margin: 0 0 4px; font-size: 24px; }
.facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; margin-bottom: 20px; }
.facts div { padding: 12px 16px; border-right: 1px solid var(--line); }
.facts div:last-child { border-right: 0; }
.facts dt { color: var(--muted); font-size: 14px; }
.facts dd { margin: 0; font-weight: 600; font-size: 18px; }
.callout { padding: 12px 16px; border-radius: 6px; margin-bottom: 20px; }
.callout.risk { background: var(--risk-bg); color: var(--risk); border: 1px solid #EBC3BD; }
.callout.ok { background: #E3F2E8; color: var(--ok); border: 1px solid #BFE0CA; }
.callout.ai { background: var(--ai-bg); color: #3A2799; border: 1px solid #D3CBF7; }
.back { display: inline-block; margin-bottom: 12px; }
.muted { color: var(--muted); }
.changes { margin: 4px 0 0; padding-left: 18px; color: var(--muted); font-size: 14px; }
.mono { font-family: var(--font-cond); }

button { font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 4px; border: 1px solid var(--pine); background: var(--pine); color: #fff; cursor: pointer; }
button.ghost { background: transparent; color: var(--pine); }
button.danger { background: var(--risk); border-color: var(--risk); }

dialog { border: 1px solid var(--line); border-radius: 8px; padding: 24px; width: min(480px, 92vw); }
dialog h2 { margin-top: 0; }
dialog label { display: grid; gap: 6px; margin-bottom: 16px; }
dialog input { font: inherit; padding: 8px; border: 1px solid var(--line); border-radius: 4px; }
dialog .row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 8px; }
  .rail a, .rail .linklike { padding: 8px 12px; border-left: 0; }
  .brand { margin: 0 12px 0 0; }
  .rail-foot { margin: 0; flex-direction: row; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi { border-bottom: 1px solid var(--line); }
  .cols, .facts { grid-template-columns: 1fr; }
  #view, .topbar { padding-left: 16px; padding-right: 16px; }
  table { display: block; overflow-x: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .feed li.new, .live.pulse .dot { animation: none; }
}
