:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #16191d;
  --muted: #5d6673;
  --accent: #2f5bd3;
  --accent-soft: #e6ecfb;
  --write: #b54708;
  --write-soft: #fdf0e3;
  --read: #3b6e4f;
  --read-soft: #e6f2ea;
  --exec: #6941c6;
  --exec-soft: #efeafb;
  --danger: #c4320a;
  --danger-soft: #fdebe6;
  --add: #116329;
  --add-bg: #e7f6ea;
  --del: #a40e26;
  --del-bg: #fcebec;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%);
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f242c;
    --border: #2c333d;
    --text: #e7eaee;
    --muted: #98a2b0;
    --accent: #7c9cf5;
    --accent-soft: #1f2a44;
    --write: #f5a35b;
    --write-soft: #3a2614;
    --read: #7fc79a;
    --read-soft: #173022;
    --exec: #b9a0f5;
    --exec-soft: #2a2140;
    --danger: #ff8a6a;
    --danger-soft: #3d1c14;
    --add: #7ee2a0;
    --add-bg: #12301c;
    --del: #ff9aa6;
    --del-bg: #3a1419;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
[hidden] { display: none !important; }

/* --- layout ------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; color: var(--text); letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  color: var(--muted); padding: 6px 10px; border-radius: 6px; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { color: var(--accent); background: var(--accent-soft); }

.main { max-width: 1180px; margin: 0 auto; padding: 28px 24px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.subtitle { color: var(--muted); margin: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 18px 20px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }

.stat-label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat-value { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

/* --- tables ------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12.5px; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mono, td .mono { white-space: nowrap; }
.truncate { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- badges and bars ------------------------------------------------------ */

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 550; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.badge.write { background: var(--write-soft); color: var(--write); }
.badge.read { background: var(--read-soft); color: var(--read); }
.badge.execute { background: var(--exec-soft); color: var(--exec); }
.badge.failed { background: var(--danger-soft); color: var(--danger); }

.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; margin-bottom: 10px; }
.bar-track { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 3px; }

/* --- forms -------------------------------------------------------------- */

input, select, button { font: inherit; color: inherit; }
input[type="text"], input[type="password"], input[type="date"], select {
  background: var(--surface); border: 1px solid var(--border); border-radius: 7px;
  padding: 7px 10px; min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.button {
  background: var(--accent); color: #fff; border: none; border-radius: 7px;
  padding: 8px 14px; font-weight: 550; cursor: pointer;
}
.button.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.button:disabled { opacity: 0.6; cursor: default; }
.link-button { background: none; border: none; color: var(--muted); cursor: pointer; padding: 6px 0; white-space: nowrap; }
.link-button:hover { color: var(--text); }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 500; }
.checkbox { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); cursor: pointer; }

/* --- login -------------------------------------------------------------- */

.login { max-width: 420px; margin: 12vh auto 0; }
.login h1 { margin-bottom: 6px; }
.login form { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }
.login input[type="password"] { width: 100%; padding: 10px 12px; font-family: var(--mono); }
.error { color: var(--danger); background: var(--danger-soft); padding: 8px 12px; border-radius: 7px; }
.hint { color: var(--muted); font-size: 12.5px; }

/* --- trail -------------------------------------------------------------- */

.meta-line { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: 13px; }
.meta-line strong { color: var(--text); font-weight: 550; }
.trail { position: relative; margin-left: 8px; padding-left: 22px; border-left: 2px solid var(--border); }
.step { position: relative; margin-bottom: 14px; }
.step::before {
  content: ""; position: absolute; left: -29px; top: 14px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--border);
}
.step.write::before { border-color: var(--write); background: var(--write-soft); }
.step.prompt::before { border-color: var(--accent); background: var(--accent-soft); }
.step.failed::before { border-color: var(--danger); background: var(--danger-soft); }
.step.minor { margin-bottom: 8px; color: var(--muted); font-size: 12.5px; }
.step.minor::before { top: 5px; width: 8px; height: 8px; left: -27px; }
.step-card { padding: 12px 14px; }
.step-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.step-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.step-tool { font-weight: 600; }
.step-target { font-family: var(--mono); font-size: 12.5px; word-break: break-all; }
.why { margin-top: 6px; color: var(--muted); }
.why b { color: var(--text); font-weight: 550; }
.prompt-text { white-space: pre-wrap; margin-top: 6px; overflow-wrap: anywhere; }
.clamp { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }

details { margin-top: 10px; }
summary { cursor: pointer; color: var(--muted); font-size: 12.5px; user-select: none; }
summary:hover { color: var(--text); }
pre.block {
  margin: 8px 0 0; padding: 10px 12px; background: var(--surface-2);
  border-radius: 7px; overflow-x: auto; max-height: 420px; white-space: pre;
}
.diff { margin-top: 8px; border: 1px solid var(--border); border-radius: 7px; overflow-x: auto; }
.diff div { font-family: var(--mono); font-size: 12.5px; padding: 0 12px; white-space: pre; min-height: 1.5em; }
.diff .add { background: var(--add-bg); color: var(--add); }
.diff .del { background: var(--del-bg); color: var(--del); }
.diff .hunk { color: var(--muted); background: var(--surface-2); }

/* --- misc --------------------------------------------------------------- */

.empty { color: var(--muted); padding: 32px 20px; text-align: center; }
.loading { color: var(--muted); padding: 24px 0; }
.more { display: flex; justify-content: center; padding: 14px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

@media (max-width: 860px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 560px) {
  .topbar { padding: 0 16px; gap: 8px; }
  .brand { display: none; }
  .nav a { padding: 6px 7px; }
  .main { padding: 20px 16px 48px; }
  .grid-4 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .stat-value { font-size: 22px; }
  .hide-sm { display: none; }
  .truncate { max-width: 200px; }
  th, td { padding: 9px 10px; }
}
