/* Agent Flight Recorder · autumn theme
   Light: warm cream and espresso. Dark: chestnut night.
   Color is used only where it means something:
   cranberry = rule failed / no authorization, ochre = held or escalated,
   olive = executed cleanly, plum = human review. */

:root {
  --bg: #f7f2ea;
  --surface: #fffcf7;
  --surface-2: #f1e9dd;
  --ink: #2e2520;
  --muted: #85756a;
  --line: #e9dfd2;
  --accent: #b9542a;        /* burnt orange */
  --accent-ink: #fffaf3;
  --accent-soft: #f6e3d6;
  --bad: #a3312b;           /* cranberry */
  --bad-soft: #f8e4df;
  --warn: #9a6a12;          /* ochre */
  --warn-soft: #f6ead0;
  --ok: #5a7233;            /* olive */
  --ok-soft: #e8eed9;
  --plum: #7d4a6b;
  --plum-soft: #f1e3ec;
  --shadow: 0 1px 2px rgba(60, 40, 25, .05), 0 4px 16px rgba(60, 40, 25, .05);
  --radius: 18px;
  --radius-sm: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1613;
    --surface: #251e1a;
    --surface-2: #2f2621;
    --ink: #f2e8dc;
    --muted: #b09f8f;
    --line: #3a2f28;
    --accent: #e27a45;
    --accent-ink: #1b1613;
    --accent-soft: #3d2a20;
    --bad: #ec8478;
    --bad-soft: #3f2422;
    --warn: #e2b25c;
    --warn-soft: #3a2e1b;
    --ok: #a9c27a;
    --ok-soft: #2a3220;
    --plum: #d29cc0;
    --plum-soft: #382634;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1613;
  --surface: #251e1a;
  --surface-2: #2f2621;
  --ink: #f2e8dc;
  --muted: #b09f8f;
  --line: #3a2f28;
  --accent: #e27a45;
  --accent-ink: #1b1613;
  --accent-soft: #3d2a20;
  --bad: #ec8478;
  --bad-soft: #3f2422;
  --warn: #e2b25c;
  --warn-soft: #3a2e1b;
  --ok: #a9c27a;
  --ok-soft: #2a3220;
  --plum: #d29cc0;
  --plum-soft: #382634;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  transition: background-color .2s, color .2s;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
code { background: var(--surface-2); padding: 2px 7px; border-radius: 6px; font-size: .9em; }
.muted { color: var(--muted); }

/* ------------------------------------------------------------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px max(16px, calc((100vw - 1080px) / 2));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; color: var(--ink); letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: 2px; margin-left: 12px; }
.topbar nav a {
  color: var(--muted); padding: 7px 14px; border-radius: 999px; font-size: 14px;
  display: inline-flex; align-items: center; gap: 6px;
}
.topbar nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.topbar nav a.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; font-size: 12px; font-weight: 650;
  display: inline-grid; place-items: center; background: var(--bad); color: var(--surface);
}
.spacer { flex: 1; }
.fake { font-size: 12px; color: var(--muted); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); display: grid; place-items: center; cursor: pointer;
  padding: 0;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn .sun { display: none; }
:root[data-theme="dark"] .icon-btn .sun { display: block; }
:root[data-theme="dark"] .icon-btn .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-btn .sun { display: block; }
  :root:not([data-theme="light"]) .icon-btn .moon { display: none; }
}

main { max-width: 1080px; margin: 0 auto; padding: 28px 16px 72px; }

/* ------------------------------------------------------------- headings */
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
h1 { margin: 0; font-size: 28px; letter-spacing: -.02em; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sub { margin: 4px 0 0; color: var(--muted); }
.crumb { margin: 0 0 12px; font-size: 14px; }

/* ------------------------------------------------------------- buttons & inputs */
.btn {
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; border-radius: 999px; padding: 9px 18px;
  background: var(--accent); color: var(--accent-ink);
  display: inline-flex; align-items: center; gap: 8px;
}
.btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--accent); }
input, select, textarea {
  font: inherit; font-size: 14px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 9px 12px; min-width: 0;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .icon-btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ------------------------------------------------------------- KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.kpi {
  background: var(--surface); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
  color: var(--ink); display: block; border: 1px solid transparent;
}
a.kpi:hover { border-color: var(--line); text-decoration: none; }
.kpi b { display: block; font-size: 28px; letter-spacing: -.02em; line-height: 1.1; }
.kpi span { font-size: 13px; color: var(--muted); }
.kpi.bad b { color: var(--bad); }
.kpi.plum b { color: var(--plum); }

.banner { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; }
.banner.ok { background: var(--ok-soft); }
.banner.plum { background: var(--plum-soft); }

/* ------------------------------------------------------------- filters */
.toolbar { margin-bottom: 14px; }
.searchrow { display: flex; gap: 8px; }
.search {
  flex: 1; font-size: 15px; padding: 12px 18px; border-radius: 999px;
  background: var(--surface); box-shadow: var(--shadow); border-color: transparent;
}
.views { display: flex; gap: 6px; margin: 14px 0 0; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.views::-webkit-scrollbar { display: none; }
.view {
  white-space: nowrap; font-size: 13.5px; padding: 6px 14px; border-radius: 999px;
  color: var(--muted); border: 1px solid var(--line); background: transparent;
  display: inline-flex; align-items: center; gap: 6px;
}
.view:hover { color: var(--ink); border-color: var(--muted); text-decoration: none; }
.view.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.view .n { font-size: 12px; opacity: .75; }

details.advanced { margin-top: 12px; }
details.advanced > summary {
  list-style: none; cursor: pointer; font-size: 13.5px; color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px; user-select: none;
}
details.advanced > summary::-webkit-details-marker { display: none; }
details.advanced > summary::before { content: "▸"; transition: transform .15s; display: inline-block; }
details.advanced[open] > summary::before { transform: rotate(90deg); }
details.advanced > summary:hover { color: var(--ink); }
.adv-grid {
  margin-top: 10px; padding: 16px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; align-items: end;
}
.adv-grid label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.adv-actions { display: flex; gap: 8px; align-items: center; }

.chips-active { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip-x {
  font-size: 13px; padding: 4px 6px 4px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--ink);
  display: inline-flex; align-items: center; gap: 6px;
}
.chip-x:hover { text-decoration: none; }
.chip-x b { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-weight: 500; color: var(--muted); }
.chip-x:hover b { background: var(--surface); color: var(--bad); }

/* ------------------------------------------------------------- event list */
.count { color: var(--muted); font-size: 13px; margin: 18px 4px 8px; }
.events {
  list-style: none; margin: 0; padding: 4px; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.ev + .ev { border-top: 1px solid var(--line); }
.ev a {
  display: grid; grid-template-columns: 14px 1fr auto; gap: 14px; align-items: start;
  padding: 14px 14px; color: var(--ink); border-radius: var(--radius-sm);
}
.ev a:hover { background: var(--surface-2); text-decoration: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; background: var(--line); }
.ev.flag .dot { background: var(--bad); box-shadow: 0 0 0 4px var(--bad-soft); }
.ev.override .dot { background: var(--plum); box-shadow: 0 0 0 4px var(--plum-soft); }
.ev.ok .dot { background: var(--ok); }
.ev.held .dot { background: var(--warn); }
.title { font-weight: 600; line-height: 1.35; }
.tid { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; color: var(--muted); margin-right: 6px; font-weight: 500; }
.reason { color: var(--muted); font-size: 14px; margin: 3px 0 8px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta { text-align: right; font-size: 12.5px; color: var(--muted); white-space: nowrap; line-height: 1.6; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  font-size: 12px; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink);
  white-space: nowrap;
}
.pill.bad { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
.pill.plum { background: var(--plum-soft); color: var(--plum); }
.pill.executed, .pill.upheld { background: var(--ok-soft); color: var(--ok); }
.pill.blocked, .pill.escalated { background: var(--warn-soft); color: var(--warn); }
.pill.reversed { background: var(--bad-soft); color: var(--bad); }
.pill.quiet { background: transparent; color: var(--muted); padding-left: 0; }
.tag { font-size: 13px; font-weight: 600; padding: 3px 12px; border-radius: 999px; }
.tag.flag { background: var(--bad-soft); color: var(--bad); }
.tag.open { background: var(--warn-soft); color: var(--warn); }
.tag.done { background: var(--plum-soft); color: var(--plum); }

.empty {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 48px 24px; text-align: center; color: var(--muted); margin-top: 18px;
}
.empty .btn { margin-top: 14px; }

/* ------------------------------------------------------------- event detail */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); }
.card h2 {
  font-size: 12.5px; margin: 0 0 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.card h2 .num {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); color: var(--ink); font-size: 12px; letter-spacing: 0;
}
.card h3 { font-size: 14px; margin: 18px 0 8px; }
dl { display: grid; grid-template-columns: 96px 1fr; gap: 6px 14px; margin: 0; }
dt { color: var(--muted); font-size: 13.5px; }
dd { margin: 0; overflow-wrap: anywhere; }
blockquote {
  margin: 14px 0 0; padding: 12px 16px; background: var(--surface-2); border-radius: var(--radius-sm);
  white-space: pre-wrap;
}
blockquote.reasoning { font-style: italic; }
.ctx { margin: 0; padding-left: 18px; font-size: 14px; }
.ctx li + li { margin-top: 4px; }
.rules { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.rules li { display: flex; gap: 12px; padding: 10px 14px; border-radius: var(--radius-sm); }
.rules li.pass { background: var(--ok-soft); }
.rules li.fail { background: var(--bad-soft); color: var(--bad); }
.mark { font-weight: 700; }
.detail { font-size: 13px; opacity: .85; margin-top: 2px; }
.auth { padding: 14px 16px; border-radius: var(--radius-sm); }
.auth.none { background: var(--bad-soft); color: var(--bad); }
.auth.automatic, .auth.human { background: var(--ok-soft); }
.auth.human.weak { background: var(--warn-soft); }
.warn { color: var(--bad); font-weight: 600; }

.review { margin-top: 14px; }
.review form { display: grid; gap: 12px; }
.review .row2 { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; }
.review label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.review textarea { min-height: 72px; resize: vertical; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.segmented label { position: relative; display: block; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { padding: 6px 14px; border-radius: 999px; font-size: 13.5px; cursor: pointer; color: var(--muted); display: block; }
.segmented input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }
.review-list { display: grid; gap: 8px; }
.review-item { background: var(--plum-soft); border-radius: var(--radius-sm); padding: 12px 16px; font-size: 14px; }

details.raw { margin-top: 18px; }
details.raw summary { cursor: pointer; color: var(--muted); font-size: 13.5px; }
details.raw pre {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; overflow: auto; font-size: 12px; margin-top: 10px;
}

/* ------------------------------------------------------------- report */
.reportform { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; align-items: end; max-width: 860px; }
.reportform label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }

/* ------------------------------------------------------------- small screens */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .topbar nav { order: 3; width: 100%; margin-left: 0; overflow-x: auto; }
  .fake { display: none; }
  h1 { font-size: 24px; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi b { font-size: 22px; }
  .grid { grid-template-columns: 1fr; }
  .ev a { grid-template-columns: 12px 1fr; gap: 12px; }
  .meta { grid-column: 2; text-align: left; order: -1; display: flex; gap: 8px; }
  .review .row2 { grid-template-columns: 1fr; }
  .head .btn { width: 100%; justify-content: center; }
}

/* ------------------------------------------------------------- brand mark & user menu */
.mark { color: var(--ink); flex: none; }
.usermenu { position: relative; }
.usermenu > summary { list-style: none; cursor: pointer; }
.usermenu > summary::-webkit-details-marker { display: none; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 15px;
}
.usermenu > summary .avatar { border: 1px solid var(--line); }
.usermenu > summary:hover .avatar { border-color: var(--accent); }
.usermenu .menu {
  position: absolute; right: 0; top: calc(100% + 8px); width: 240px; z-index: 20;
  background: var(--surface); border-radius: var(--radius-sm); box-shadow: var(--shadow); border: 1px solid var(--line);
  padding: 6px; display: grid;
}
.usermenu .who { padding: 10px 10px 8px; display: grid; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.usermenu .who span { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.usermenu .who .role { text-transform: capitalize; }
.usermenu .menu a, .usermenu .menu button {
  font: inherit; font-size: 14px; text-align: left; padding: 8px 10px; border-radius: 8px;
  color: var(--ink); background: none; border: 0; cursor: pointer; width: 100%;
}
.usermenu .menu a:hover, .usermenu .menu button:hover { background: var(--surface-2); text-decoration: none; }

/* ------------------------------------------------------------- sign-in page */
body.auth { min-height: 100vh; display: grid; place-items: center; }
body.auth main { padding: 32px 16px; width: 100%; max-width: 440px; }
.auth-corner { position: fixed; top: 14px; right: 16px; }
.auth-panel { background: var(--surface); border-radius: 24px; box-shadow: var(--shadow); padding: 34px 32px 28px; }
.auth-brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 20px; letter-spacing: -.02em; margin-bottom: 26px; }
.auth-panel h1 { font-size: 26px; }
.auth-panel .sub { margin-bottom: 22px; }
.auth-form { display: grid; gap: 14px; }
.auth-form label, .stack label { display: grid; gap: 5px; font-size: 12.5px; color: var(--muted); }
.auth-form input { padding: 11px 14px; font-size: 15px; }
.btn.wide { width: 100%; justify-content: center; padding: 12px 18px; font-size: 15px; margin-top: 4px; }
.auth-foot { text-align: center; color: var(--muted); font-size: 12.5px; margin: 20px 0 0; }
.banner.bad { background: var(--bad-soft); color: var(--bad); }

/* ------------------------------------------------------------- account & team */
.stack { display: grid; gap: 14px; }
.narrow { max-width: 460px; }
.team-grid { grid-template-columns: 3fr 2fr; align-items: start; }
.people { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; align-items: center; gap: 12px; padding: 12px 0; flex-wrap: wrap; }
.people li + li { border-top: 1px solid var(--line); }
.people li.off { opacity: .55; }
.people .who { display: grid; flex: 1; min-width: 160px; }
.people .who span { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.row-actions { display: flex; gap: 4px; width: 100%; padding-left: 48px; }
button.link { font: inherit; font-size: 13px; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 2px 6px; border-radius: 6px; }
button.link:hover { background: var(--accent-soft); }
.handover { margin-bottom: 14px; border: 2px dashed var(--accent); box-shadow: none; }
.handover p { margin: 4px 0 10px; font-size: 14px; }
.secret { display: inline-block; font-size: 18px; padding: 8px 14px; letter-spacing: .04em; user-select: all; }
.table-wrap { overflow-x: auto; }
table.log { width: 100%; border-collapse: collapse; font-size: 14px; }
table.log th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 10px; border-bottom: 1px solid var(--line); }
table.log td { padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.log tr:last-child td { border-bottom: 0; }
.reviewer { display: flex; align-items: center; gap: 10px; font-size: 14px; line-height: 1.3; }

@media (max-width: 760px) {
  .team-grid { grid-template-columns: 1fr; }
  .auth-panel { padding: 28px 22px 22px; }
}

dl.details { grid-template-columns: 150px 1fr; font-size: 14px; }
dl.details dt { font-size: 13px; }
.inline-form { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 200px; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; }
.label-row a { font-size: 12.5px; }
a.btn.wide { text-decoration: none; }

.auth-maker { text-align: center; font-size: 12.5px; color: var(--muted); margin: 18px 0 0; }
.auth-maker a { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
