
:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1c2330;
  --muted: #5d6879;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --accent-soft: #e6effd;
  --ok: #1a7f37;
  --ok-soft: #e3f4e8;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --bad: #c62828;
  --bad-soft: #fde8e8;
  --info: #0b6aa8;
  --info-soft: #e2f1fb;
  --focus: #1f6feb;
  --radius: 8px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #171d24;
    --surface-2: #1e252e;
    --border: #2d3640;
    --text: #e4e8ee;
    --muted: #98a3b3;
    --accent: #4c94f5;
    --accent-text: #0b1220;
    --accent-soft: #1a2a42;
    --ok: #4cc472;
    --ok-soft: #15301f;
    --warn: #e3b341;
    --warn-soft: #352b10;
    --bad: #f47067;
    --bad-soft: #3a1a1a;
    --info: #58b2e8;
    --info-soft: #12293a;
    --focus: #79b8ff;
    --shadow: none;
  }
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; line-height: 1.25; }
h2 { font-size: 1.1rem; margin: 1.75rem 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .4rem; }
p { margin: .4rem 0; }
code, .mono { font-family: var(--mono); font-size: .92em; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Header */
.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.25rem;
  padding: .55rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.brand span { color: var(--muted); font-weight: 500; }
.top nav ul { display: flex; flex-wrap: wrap; gap: .15rem; list-style: none; margin: 0; padding: 0; }
.top nav a { display: block; padding: .3rem .6rem; border-radius: 6px; color: var(--muted); text-decoration: none; font-weight: 500; }
.top nav a:hover { color: var(--text); background: var(--surface-2); }
.top nav a[aria-current="page"] { color: var(--text); background: var(--accent-soft); }
.who { margin-left: auto; display: flex; align-items: center; gap: .6rem; color: var(--muted); font-size: .9em; }
.who form { margin: 0; }
.dry-run {
  background: var(--warn); color: var(--surface); font-weight: 800; letter-spacing: .06em;
  padding: .2rem .55rem; border-radius: 4px; text-decoration: none; font-size: .85em;
}
main { max-width: 1240px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

/* Page head */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.page-head .sub { color: var(--muted); margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.actions form { margin: 0; }

/* Buttons and forms */
.btn, button.btn {
  display: inline-flex; align-items: center; gap: .35rem; cursor: pointer;
  padding: .45rem .85rem; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; line-height: 1.3;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary, button.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--bad); }
.btn[disabled], button[disabled] { opacity: .6; cursor: progress; }
.btn-link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
label { display: block; font-weight: 600; margin: .9rem 0 .3rem; }
.hint { color: var(--muted); font-weight: 400; font-size: .92em; margin: .2rem 0 0; }
input[type=text], input[type=month], input[type=number], select, textarea {
  width: 100%; max-width: 46rem; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit;
}
input[type=month] { max-width: 14rem; }
textarea { min-height: 10rem; resize: vertical; line-height: 1.45; }
input[type=file] { font: inherit; max-width: 100%; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.check input { width: 1.05rem; height: 1.05rem; margin: 0; }
.form-foot { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-top: 1.1rem; }
.form-status { color: var(--muted); }
.form-status.tone-bad { color: var(--bad); }

/* Cards, tiles */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.card + .card { margin-top: .75rem; }
.grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.tile { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem .95rem; color: var(--text); text-decoration: none; box-shadow: var(--shadow); }
a.tile:hover { border-color: var(--accent); }
.tile .num { display: block; font-size: 1.6rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile .lbl { color: var(--muted); font-size: .92em; }
.tile.tone-warn { border-left: 4px solid var(--warn); }
.tile.tone-bad { border-left: 4px solid var(--bad); }
.status-row { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin-bottom: .75rem; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.facts code { overflow-wrap: anywhere; word-break: break-all; }

/* Badges and notices */
.badge { display: inline-block; padding: .08rem .5rem; border-radius: 999px; font-size: .82em; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.tone-ok { color: var(--ok); background: var(--ok-soft); }
.tone-warn { color: var(--warn); background: var(--warn-soft); }
.tone-bad { color: var(--bad); background: var(--bad-soft); }
.tone-info { color: var(--info); background: var(--info-soft); }
.tone-muted { color: var(--muted); background: var(--surface-2); }
.notice { padding: .6rem .85rem; border-radius: 6px; margin: 0 0 1rem; }
.note { color: var(--muted); font-size: .92em; }
.muted { color: var(--muted); }
.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .35rem; vertical-align: baseline; }
.dot.tone-ok { background: var(--ok); }
.dot.tone-warn { background: var(--warn); }
.dot.tone-bad { background: var(--bad); }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
caption { text-align: left; padding: .6rem .75rem; font-weight: 600; }
th, td { padding: .45rem .7rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
thead th { background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: .86em; white-space: nowrap; }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
td.num, th.num { text-align: right; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
td.wide { min-width: 16rem; }
.empty { padding: 1.25rem; color: var(--muted); text-align: center; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin: 0 0 .75rem; }
.chip { padding: .2rem .65rem; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); text-decoration: none; background: var(--surface); font-size: .9em; }
.chip[aria-current="true"] { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }
.filters { display: flex; flex-wrap: wrap; gap: .25rem 1.5rem; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: .75rem; color: var(--muted); }
.progress { display: inline-block; width: 5rem; height: .45rem; border-radius: 999px; background: var(--surface-2); vertical-align: middle; margin-right: .4rem; overflow: hidden; border: 1px solid var(--border); }
.progress i { display: block; height: 100%; background: var(--ok); }
.w-0 { width: 0 } .w-10 { width: 10% } .w-20 { width: 20% } .w-30 { width: 30% } .w-40 { width: 40% } .w-50 { width: 50% }
.w-60 { width: 60% } .w-70 { width: 70% } .w-80 { width: 80% } .w-90 { width: 90% } .w-100 { width: 100% }

/* Task conversation */
.thread { display: grid; gap: .75rem; }
.thread > * { min-width: 0; }
.msg { min-width: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: .85rem 1rem; box-shadow: var(--shadow); }
.msg.staff { border-left: 4px solid var(--accent); }
.msg.agent { border-left: 4px solid var(--muted); }
.msg.agent.st-done { border-left-color: var(--ok); }
.msg.agent.st-question { border-left-color: var(--warn); }
.msg.agent.st-error { border-left-color: var(--bad); }
.msg-head { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .75rem; margin-bottom: .45rem; color: var(--muted); font-size: .92em; }
.msg-head strong { color: var(--text); }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: .3rem 0; }
.files { list-style: none; padding: 0; margin: .4rem 0 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.files li { max-width: 100%; min-width: 0; }
.files a { display: inline-block; max-width: 100%; overflow-wrap: anywhere; word-break: break-all; padding: .2rem .55rem; border: 1px solid var(--border); border-radius: 6px; text-decoration: none; background: var(--surface-2); font-size: .92em; }
.steps { list-style: none; padding: 0; margin: .5rem 0; display: grid; gap: .2rem; }
.step { display: grid; grid-template-columns: 1.2rem 1fr auto; gap: .5rem; align-items: baseline; }
.step::before { content: "✓"; color: var(--ok); font-weight: 700; text-align: center; }
.step.state-failed::before { content: "✗"; color: var(--bad); }
.step.state-running::before { content: "•"; color: var(--info); animation: pulse 1.2s ease-in-out infinite; }
.step.state-pending::before { content: "○"; color: var(--muted); }
.step.state-skipped::before { content: "–"; color: var(--muted); }
.step.state-skipped, .step.state-pending { color: var(--muted); }
.step .t { color: var(--muted); font-size: .85em; font-variant-numeric: tabular-nums; }
.step .d { grid-column: 2 / 4; color: var(--muted); font-size: .9em; }
.live { display: flex; align-items: center; gap: .5rem; color: var(--info); font-weight: 600; }
.live::before { content: ""; width: .55rem; height: .55rem; border-radius: 50%; background: var(--info); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .live::before, .step.state-running::before { animation: none; } }
.action-list { list-style: none; padding: 0; margin: .3rem 0; }
.action-list li { padding: .1rem 0; }
.mark-done { color: var(--ok); font-weight: 700; }
.mark-failed { color: var(--bad); font-weight: 700; }
.mark-dry-run { color: var(--warn); font-weight: 700; }
.meta { display: flex; flex-wrap: wrap; gap: .25rem 1rem; color: var(--muted); font-size: .88em; margin-top: .6rem; }
.quick { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0 0; }
.quick form { margin: 0; }
details summary { cursor: pointer; color: var(--accent); }
details[open] summary { margin-bottom: .3rem; }
.split { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.templates { display: flex; flex-wrap: wrap; gap: .4rem; margin: .25rem 0 1rem; }
.po-group { margin-bottom: 1.25rem; }
.po-group .head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem 1rem; margin-bottom: .45rem; }
.po-group h2 { margin: 0; }
.login { max-width: 26rem; margin: 12vh auto 0; text-align: center; }
.login .btn { margin-top: 1rem; font-size: 1.02rem; padding: .65rem 1.2rem; }
.login p { color: var(--muted); }
.error-page { max-width: 38rem; margin: 8vh auto 0; }

@media (max-width: 720px) {
  main { padding: 1rem .75rem 2.5rem; }
  .who { margin-left: 0; width: 100%; justify-content: space-between; }
  .top nav ul { gap: 0; }
  .top nav a { padding: .3rem .45rem; }
  .split { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr; }
  .facts dt { margin-top: .35rem; }
  .hide-sm { display: none; }
  th, td { padding: .4rem .5rem; }
}
