:root {
  --canvas: #ebe8df;
  --paper: #fffdf8;
  --paper-deep: #f4f0e7;
  --ink: #18211f;
  --muted: #69716c;
  --line: #cfc9bc;
  --line-strong: #a9a496;
  --night: #1b2424;
  --night-soft: #283233;
  --teal: #176e68;
  --teal-soft: #dcece7;
  --rust: #bd4e2c;
  --rust-soft: #f8dfd5;
  --ochre: #bd8618;
  --ochre-soft: #f8eac8;
  --blue: #365dba;
  --shadow: 0 16px 40px rgba(28, 34, 29, 0.08);
  font-family: Inter, Arial, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(90deg, rgba(24, 33, 31, 0.035) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(rgba(24, 33, 31, 0.025) 1px, transparent 1px) 0 0 / 28px 28px,
    var(--canvas);
}

button { font: inherit; }
button:not(:disabled) { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.48; }

.hidden { display: none !important; }

.skip-link {
  position: fixed;
  z-index: 20;
  top: 10px;
  left: 10px;
  padding: 10px 14px;
  color: var(--paper);
  background: var(--night);
  transform: translateY(-160%);
}

.skip-link:focus { transform: translateY(0); }

.app-shell { max-width: 1540px; margin: 0 auto; padding: 28px 30px 42px; }

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 0 22px;
  border-bottom: 1px solid var(--line-strong);
}

.brand-lockup { display: flex; align-items: center; gap: 13px; }

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: var(--paper);
  font: 650 23px/1 Fraunces, Georgia, serif;
  background: var(--rust);
  border-radius: 50% 50% 5px 50%;
  transform: rotate(-8deg);
}

.eyebrow,
.metric-label,
.header-note,
.panel-index,
.count-mark,
.timeline-meta,
.detail-card h3,
.mini-label,
.empty-glyph {
  margin: 0;
  font: 500 10px/1.3 "DM Mono", monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.eyebrow { color: var(--teal); }
.brand-title { margin: 4px 0 0; font: 500 15px/1.2 Fraunces, Georgia, serif; }

.poll-state {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font: 400 12px/1.4 "DM Mono", monospace;
}

.pulse-dot { width: 8px; height: 8px; background: var(--teal); border-radius: 50%; box-shadow: 0 0 0 4px var(--teal-soft); }

.app-layout { display: grid; grid-template-columns: 268px minmax(0, 1fr); gap: 34px; padding-top: 28px; }

.side-rail {
  align-self: start;
  padding: 20px 16px 18px;
  color: #eef2ed;
  background: var(--night);
  box-shadow: var(--shadow);
}

.rail-intro { padding: 4px 7px 18px; border-bottom: 1px solid rgba(255, 253, 248, 0.2); }
.rail-intro .eyebrow { color: #b8d6ce; }
.rail-intro p:last-child { margin: 10px 0 0; color: #d4dad3; font-size: 13px; line-height: 1.55; }

.view-switcher { display: grid; gap: 5px; padding: 18px 0; border-bottom: 1px solid rgba(255, 253, 248, 0.2); }

.view-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 9px;
  color: #bdc6bf;
  text-align: left;
  background: transparent;
  border: 0;
  border-left: 2px solid transparent;
}

.view-tab span { color: #8d9891; font: 400 10px/1 "DM Mono", monospace; }
.view-tab:hover { color: var(--paper); background: rgba(255, 253, 248, 0.07); }
.view-tab.is-active { color: var(--paper); border-left-color: #e7b542; background: rgba(255, 253, 248, 0.09); }

.automation-register { padding-top: 19px; }
.section-label-row { display: flex; align-items: center; justify-content: space-between; padding: 0 7px 10px; }
.section-label-row .eyebrow { color: #b8d6ce; }
.count-mark { color: #e7b542; }
.automation-list { display: grid; gap: 3px; }

.automation-row {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 10px 8px;
  color: #c4ccc5;
  text-align: left;
  background: transparent;
  border: 0;
}

.automation-row:hover { color: var(--paper); background: rgba(255, 253, 248, 0.07); }
.automation-row.is-selected { color: var(--paper); background: #35403e; }
.automation-name { overflow: hidden; font-size: 13px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.automation-state { color: #93a29a; font: 400 9px/1 "DM Mono", monospace; text-transform: uppercase; }

.state-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); }
.state-dot.attention { background: #e7b542; }
.state-dot.approved { background: var(--blue); }

.rail-footnote { margin: 24px 7px 2px; color: #9ea9a1; font-size: 11px; line-height: 1.55; }

.main-stage { min-width: 0; }
.dashboard-view { min-width: 0; }

.view-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 28px; padding: 8px 0 28px; }
.view-header h1 { max-width: 760px; margin: 6px 0 8px; font: 650 clamp(34px, 4vw, 54px)/0.98 Fraunces, Georgia, serif; letter-spacing: -0.04em; }
.lede { max-width: 650px; margin: 0; color: var(--muted); font-size: 15px; line-height: 1.65; }
.header-note { flex: 0 0 auto; padding-top: 11px; color: var(--ink); text-align: right; }
.header-note span { color: var(--muted); letter-spacing: 0; text-transform: none; }

.metric-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line-strong); }
.metric-card { min-height: 170px; padding: 19px 18px 17px; background: rgba(255, 253, 248, 0.63); border-right: 1px solid var(--line); }
.metric-card:last-child { border-right: 0; }
.metric-card-primary { color: var(--paper); background: var(--night); }
.metric-card-alert { background: var(--ochre-soft); }
.metric-card-primary .metric-label, .metric-card-primary .metric-note { color: #c2cec7; }
.metric-label { display: block; color: var(--muted); }
.metric-value { display: block; margin-top: 25px; font: 500 52px/0.8 Fraunces, Georgia, serif; letter-spacing: -0.05em; }
.metric-note { display: block; margin-top: 20px; color: var(--muted); font-size: 11px; line-height: 1.35; }

.overview-grid { display: grid; grid-template-columns: minmax(0, 1.08fr) minmax(310px, 0.92fr); gap: 18px; margin-top: 18px; }
.ledger-panel { min-width: 0; background: rgba(255, 253, 248, 0.8); border: 1px solid var(--line-strong); box-shadow: 0 8px 26px rgba(24, 33, 31, 0.04); }
.fleet-panel, .activity-panel { min-height: 380px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px; border-bottom: 1px solid var(--line); }
.panel-heading h2, .detail-heading h2 { margin: 5px 0 0; font: 650 24px/1 Fraunces, Georgia, serif; letter-spacing: -0.03em; }
.panel-index { color: var(--rust); }

.overview-automations { display: grid; }
.overview-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  width: 100%;
  padding: 18px 20px;
  color: var(--ink);
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
}

.overview-row:last-child { border-bottom: 0; }
.overview-row:hover { background: var(--paper-deep); }
.overview-row-main { display: flex; gap: 12px; align-items: flex-start; }
.overview-row strong { display: block; font-size: 14px; }
.overview-row p { margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.overview-row-meta { min-width: 92px; text-align: right; }
.overview-row-meta time { display: block; margin-top: 7px; color: var(--muted); font: 400 10px/1.4 "DM Mono", monospace; }

.activity-list { display: grid; margin: 0; padding: 0; list-style: none; }
.activity-item { display: grid; grid-template-columns: 11px minmax(0, 1fr); gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.activity-item:last-child { border-bottom: 0; }
.activity-item strong { display: block; font-size: 12px; }
.activity-item p { margin: 4px 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.activity-item time { color: var(--muted); font: 400 10px/1 "DM Mono", monospace; }
.activity-empty { padding: 30px 20px; color: var(--muted); font-size: 13px; line-height: 1.5; }

.workbench-header { padding-bottom: 18px; }
.workbench-actions { display: flex; align-items: center; gap: 10px; padding-top: 11px; }
.status-stamp { padding: 8px 10px; color: var(--teal); font: 500 10px/1 "DM Mono", monospace; letter-spacing: 0.08em; text-transform: uppercase; background: var(--teal-soft); border: 1px solid var(--teal); }
.status-stamp.attention { color: #85550a; background: var(--ochre-soft); border-color: var(--ochre); }
.status-stamp.approved { color: var(--blue); background: #e1e7fb; border-color: var(--blue); }

.break-button, .action-button {
  padding: 12px 14px;
  color: var(--paper);
  font-size: 12px;
  font-weight: 700;
  background: var(--rust);
  border: 1px solid var(--rust);
  box-shadow: 3px 3px 0 var(--night);
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.break-button:hover:not(:disabled), .action-button:hover:not(:disabled) { box-shadow: 1px 1px 0 var(--night); transform: translate(2px, 2px); }

.workbench-grid { display: grid; grid-template-columns: minmax(0, 0.92fr) minmax(360px, 1.08fr); gap: 18px; align-items: start; }
.timeline-panel { min-height: 550px; }
.timeline-empty { padding: 88px 30px; color: var(--muted); text-align: center; }
.empty-glyph { display: block; color: var(--rust); font-size: 32px; letter-spacing: 0; }
.timeline-empty p { margin: 13px 0 5px; color: var(--ink); font: 500 21px/1 Fraunces, Georgia, serif; }
.timeline-empty small { font-size: 12px; line-height: 1.5; }

.timeline { position: relative; display: grid; gap: 0; margin: 0; padding: 0; list-style: none; }
.timeline::before { position: absolute; top: 0; bottom: 0; left: 30px; width: 1px; content: ""; background: var(--line); }
.timeline-node { position: relative; display: grid; grid-template-columns: 61px minmax(0, 1fr); gap: 0; padding: 18px 20px 0 0; }
.timeline-node:last-child { padding-bottom: 20px; }
.timeline-marker { position: relative; z-index: 1; width: 13px; height: 13px; margin: 14px 0 0 24px; background: var(--teal); border: 3px solid var(--paper); border-radius: 50%; box-shadow: 0 0 0 1px var(--teal); }
.timeline-marker.attention { background: var(--ochre); box-shadow: 0 0 0 1px var(--ochre); }
.timeline-marker.approved { background: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.timeline-card { padding: 15px; text-align: left; background: var(--paper); border: 1px solid var(--line); transition: background 150ms ease, border-color 150ms ease; }
.timeline-card:hover { background: var(--paper-deep); border-color: var(--line-strong); }
.timeline-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.timeline-card h3 { margin: 0; font-size: 14px; }
.timeline-card time { color: var(--muted); font: 400 9px/1.35 "DM Mono", monospace; text-align: right; }
.timeline-card p { margin: 10px 0 12px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.timeline-meta { display: flex; flex-wrap: wrap; gap: 5px; }
.mini-label { display: inline-block; padding: 5px 6px; color: var(--teal); background: var(--teal-soft); letter-spacing: 0.07em; }
.mini-label.attention { color: #85550a; background: var(--ochre-soft); }
.mini-label.approved { color: var(--blue); background: #e1e7fb; }
.mini-label.muted { color: var(--muted); background: var(--paper-deep); }

.detail-panel { position: sticky; top: 18px; min-height: 550px; padding: 20px; }
.detail-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding-bottom: 17px; border-bottom: 1px solid var(--line); }
.clear-detail { padding: 4px 0; color: var(--muted); font: 500 10px/1 "DM Mono", monospace; letter-spacing: 0.08em; text-transform: uppercase; background: transparent; border: 0; }
.clear-detail:hover { color: var(--rust); }
.detail-message { margin: 18px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.detail-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 16px; }
.detail-card { padding: 12px; background: var(--paper-deep); border: 1px solid var(--line); }
.detail-card h3 { margin: 0; color: var(--teal); }
.detail-card p { margin: 7px 0 0; font-size: 12px; line-height: 1.45; }
.detail-card .evidence-preview { max-height: 170px; overflow: auto; padding: 8px; color: var(--ink); font: 11px/1.5 "DM Mono", monospace; white-space: pre-wrap; background: var(--paper); border: 1px solid var(--line); }
.detail-review { margin-top: 14px; padding: 14px; color: #77410d; background: var(--ochre-soft); border-left: 3px solid var(--ochre); }
.detail-review h3 { margin: 0; font: 600 12px/1.3 Inter, sans-serif; }
.detail-review ul { margin: 8px 0 0; padding-left: 18px; font-size: 12px; line-height: 1.5; }
.detail-diff-section { margin-top: 18px; }
.detail-diff-section > .eyebrow { margin-bottom: 8px; }
.detail-diff { display: grid; gap: 8px; }
.code-pane { overflow: hidden; border: 1px solid var(--line); }
.code-pane h3 { margin: 0; padding: 9px 11px; color: var(--muted); font: 500 10px/1 "DM Mono", monospace; letter-spacing: 0.1em; text-transform: uppercase; background: var(--paper-deep); border-bottom: 1px solid var(--line); }
.code-pane pre { max-height: 210px; margin: 0; padding: 11px; overflow: auto; color: #33413e; font: 400 10px/1.65 "DM Mono", monospace; background: #f9f7f1; }
.code-line.changed { color: #92341d; background: var(--rust-soft); }
.detail-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 17px; }
.action-button { box-shadow: none; }
.action-button-primary { color: var(--paper); background: var(--night); border-color: var(--night); }
.action-button-alert { color: var(--ink); background: #e7b542; border-color: #e7b542; }

.detail-panel.is-empty .detail-meta,
.detail-panel.is-empty .detail-review,
.detail-panel.is-empty .detail-diff-section,
.detail-panel.is-empty .detail-actions,
.detail-panel.is-empty .clear-detail { display: none; }

@keyframes understudy-arrive {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.timeline-node-new { animation: understudy-arrive 300ms ease-out both; }

button:focus-visible, .timeline-card:focus-visible {
  outline: 3px solid rgba(54, 93, 186, 0.4);
  outline-offset: 2px;
}

@media (max-width: 1100px) {
  .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-card:nth-child(2) { border-right: 0; }
  .metric-card:nth-child(-n + 2) { border-bottom: 1px solid var(--line); }
  .workbench-grid { grid-template-columns: 1fr; }
  .detail-panel { position: static; }
}

@media (max-width: 820px) {
  .app-shell { padding: 18px 16px 28px; }
  .masthead, .view-header { align-items: flex-start; flex-direction: column; }
  .header-note { padding-top: 0; text-align: left; }
  .app-layout { grid-template-columns: 1fr; gap: 18px; padding-top: 18px; }
  .side-rail { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
  .rail-intro { grid-column: 1 / -1; }
  .view-switcher { border-bottom: 0; }
  .automation-register { border-top: 1px solid rgba(255, 253, 248, 0.2); }
  .rail-footnote { display: none; }
  .overview-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .brand-title { font-size: 13px; }
  .poll-state { font-size: 10px; }
  .view-header h1 { font-size: 36px; }
  .metric-strip { grid-template-columns: 1fr; }
  .metric-card, .metric-card:nth-child(2) { min-height: 125px; border-right: 0; border-bottom: 1px solid var(--line); }
  .metric-card:last-child { border-bottom: 0; }
  .workbench-actions { align-items: flex-start; flex-direction: column; }
  .side-rail { display: block; }
  .automation-register { margin-top: 16px; }
  .detail-meta { grid-template-columns: 1fr; }
  .timeline-node { grid-template-columns: 49px minmax(0, 1fr); }
  .timeline::before { left: 24px; }
  .timeline-marker { margin-left: 18px; }
}
