:root {
  color-scheme: light;
  --page: #f7f7fb;
  --surface: #ffffff;
  --text: #16162a;
  --text-2: #5b5b74;
  --muted: #9696ac;
  --border: #eaeaf2;
  --border-strong: #dcdce8;
  --brand: #332f84;
  --brand-ink: #ffffff;
  --brand-soft: #f0eefb;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok: #067647;
  --ok-soft: #e7f6ec;
  --warn: #a15c07;
  --warn-soft: #fef4e6;
  --info: #175cd3;
  --info-soft: #eaf2fe;
  --shadow: 0 1px 2px rgba(23,23,50,.04), 0 8px 24px rgba(23,23,50,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #131320;
    --surface: #191927;
    --text: #f2f2fa;
    --text-2: #b9b9cf;
    --muted: #83839c;
    --border: #26263a;
    --border-strong: #33334a;
    --brand: #9b95f0;
    --brand-ink: #131320;
    --brand-soft: #23213f;
    --danger: #ff8a80;
    --danger-soft: #3a1d1d;
    --ok: #6ce9a6;
    --ok-soft: #12321f;
    --warn: #fdb022;
    --warn-soft: #3a2a10;
    --info: #84adff;
    --info-soft: #18243f;
    --shadow: 0 1px 2px rgba(0,0,0,.2), 0 8px 24px rgba(0,0,0,.28);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
a { color: var(--brand); }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.topbar .brand span { color: var(--brand); }
.topbar .spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-2); }
.role-badge {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand);
}
.btn-link { font-size: 14px; color: var(--text-2); text-decoration: none; }
.btn-link:hover { color: var(--brand); }

/* ---------- Home ---------- */
.container { max-width: 1080px; margin: 0 auto; padding: 32px 24px 64px; }
.hero h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: -.02em; }
.hero p { margin: 0; color: var(--text-2); }
.group { margin-top: 36px; }
.group h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 0 0 12px; font-weight: 600;
}
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card {
  display: block; padding: 18px 20px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  text-decoration: none; color: var(--text); transition: border-color .15s, transform .15s;
}
.card-featured {
  position: relative; overflow: hidden;
  background: linear-gradient(110deg, var(--brand-soft), var(--surface) 72%);
  border-color: color-mix(in srgb, var(--brand) 32%, var(--border));
}
.card-featured::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 4px;
  background: var(--brand); opacity: .72;
}
.card-featured .title { color: var(--brand); font-weight: 700; }
.card:hover { border-color: var(--brand); transform: translateY(-1px); }
.card-featured:hover { border-color: var(--brand); }
.card .title { font-weight: 600; margin-bottom: 6px; }
.card .meta { font-size: 13px; color: var(--muted); }
.empty { color: var(--muted); font-size: 14px; padding: 16px 0; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; padding: 32px 28px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.login-card h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
.login-card .sub { color: var(--text-2); font-size: 14px; margin: 0 0 24px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-2); }
.field input {
  width: 100%; padding: 10px 12px; font-size: 15px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--page); color: var(--text);
}
.field input:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
.btn-primary {
  width: 100%; padding: 11px; margin-top: 8px; border: 0; border-radius: 10px;
  background: var(--brand); color: var(--brand-ink); font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn-primary:disabled { opacity: .6; cursor: progress; }
.alert {
  padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-bottom: 16px;
  background: var(--danger-soft); color: var(--danger);
}
.hint { font-size: 12px; color: var(--muted); margin-top: 18px; }

@media (max-width: 600px) {
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .container { padding: 24px 16px 48px; }
  .user-chip .name { display: none; }
}

/* ---------- Navigation ---------- */
.mainnav { display: flex; gap: 4px; margin-left: 12px; }
.mainnav a {
  padding: 6px 12px; border-radius: 8px; font-size: 14px; text-decoration: none; color: var(--text-2); white-space: nowrap;
}
.mainnav a:hover { background: var(--brand-soft); color: var(--brand); }
.mainnav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

/* ---------- Shared bits ---------- */
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hero-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.container.narrow { max-width: 820px; }
.panel {
  margin-top: 20px; padding: 20px 22px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.panel h3 { margin: 0 0 12px; font-size: 16px; }
.btn-secondary {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 500; text-decoration: none; cursor: pointer;
}
.btn-secondary:hover { border-color: var(--brand); color: var(--brand); }
.btn-secondary.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.btn-primary.inline { width: auto; padding: 9px 18px; margin-top: 0; }
button.btn-link { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; font-size: 14px; }
.btn-link.danger { color: var(--danger); }
.msg { min-height: 1em; font-size: 14px; }
.msg.error { color: var(--danger); }
.card-tag { margin-top: 10px; font-size: 12px; font-weight: 600; color: var(--brand); }

/* ---------- Home feedback strip ---------- */
.fb-strip {
  margin-top: 24px; padding: 18px 20px; border-radius: 14px; display: flex; gap: 20px;
  align-items: center; justify-content: space-between; flex-wrap: wrap;
  background: var(--brand-soft); border: 1px solid var(--border);
}
.fb-strip-text { display: flex; flex-direction: column; gap: 4px; max-width: 560px; }
.fb-strip-text span { font-size: 14px; color: var(--text-2); }
.fb-strip-stats { display: flex; gap: 10px; flex-wrap: wrap; }
.fb-strip-stats a {
  display: flex; flex-direction: column; align-items: center; min-width: 92px; padding: 8px 12px;
  border-radius: 10px; background: var(--surface); text-decoration: none; color: var(--text);
}
.fb-strip-stats b { font-size: 22px; color: var(--brand); }
.fb-strip-stats span { font-size: 12px; color: var(--muted); }

/* ---------- Filters & list ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 24px; }
.filters input, .filters select, .edit-form input, .edit-form select, .edit-form textarea {
  padding: 8px 10px; font: inherit; font-size: 14px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
}
.filters input[type=search] { flex: 1 1 240px; }
.result-count { font-size: 13px; color: var(--muted); margin: 16px 0 8px; }
.fb-list { display: flex; flex-direction: column; gap: 8px; }
.fb-row {
  display: flex; justify-content: space-between; gap: 16px; padding: 14px 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); text-decoration: none; color: var(--text);
}
.fb-row:hover { border-color: var(--brand); }
.fb-row-main { min-width: 0; }
.fb-row-title { font-weight: 600; margin-bottom: 4px; }
.fb-id { color: var(--muted); font-weight: 500; }
.fb-row-meta { font-size: 13px; color: var(--muted); }
.fb-row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.fb-counts { font-size: 13px; color: var(--muted); }

.status {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--brand-soft); color: var(--brand);
}
.status-reviewing { background: var(--info-soft); color: var(--info); }
.status-need_info { background: var(--warn-soft); color: var(--warn); }
.status-approved, .status-applied { background: var(--ok-soft); color: var(--ok); }
.status-rejected { background: var(--danger-soft); color: var(--danger); }
.status-withdrawn { background: var(--page); color: var(--muted); }

/* ---------- Detail ---------- */
.crumbs { margin: 0 0 4px; font-size: 14px; }
.crumbs a { text-decoration: none; }
.detail-head { display: flex; gap: 10px; align-items: center; }
.detail-title { font-size: 22px; margin: 10px 0 4px; letter-spacing: -.01em; }
.quote {
  margin: 16px 0; padding: 10px 14px; border-left: 3px solid var(--brand);
  background: var(--brand-soft); border-radius: 0 10px 10px 0; color: var(--text-2); white-space: pre-wrap;
}
.prose { white-space: pre-wrap; color: var(--text); }
.panel h3 + .prose { margin-bottom: 16px; }
.detail-actions { display: flex; gap: 12px; align-items: center; margin-top: 18px; flex-wrap: wrap; }
.edit-form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.edit-form[hidden] { display: none; }
.edit-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.edit-form label[hidden] { display: none; }
.edit-form textarea { resize: vertical; font-family: inherit; }
.row-actions { display: flex; gap: 12px; align-items: center; }
.review-box { border-left: 4px solid var(--brand); }
.status-border-approved, .status-border-applied { border-left-color: var(--ok); }
.status-border-rejected { border-left-color: var(--danger); }
.status-border-need_info { border-left-color: var(--warn); }
.comment { padding: 10px 0; border-bottom: 1px solid var(--border); }
.timeline { margin: 0; padding-left: 18px; font-size: 14px; display: flex; flex-direction: column; gap: 8px; }

/* ---------- Stats ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 24px; }
.kpi {
  display: flex; flex-direction: column; padding: 16px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.kpi b { font-size: 26px; letter-spacing: -.02em; }
.kpi span { font-size: 13px; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 0 20px; }
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(110px, 38%) 1fr 36px; gap: 10px; align-items: center; font-size: 13px; }
.bar-label { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; border-radius: 4px; background: var(--page); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 4px; background: var(--brand); }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table a { text-decoration: none; }

@media (max-width: 600px) {
  .mainnav { order: 3; width: 100%; margin-left: 0; overflow-x: auto; }
  .fb-row { flex-direction: column; }
  .fb-row-side { flex-direction: row; align-items: center; }
  .grid-2 { grid-template-columns: 1fr; }
}

/* ---------- Report jobs ---------- */
.job-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 0 16px; }
.job-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.job-head h3 { margin-bottom: 8px; }
.job-meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 4px 0 14px; font-size: 13px; }
.job-meta dt { color: var(--muted); }
.job-meta dd { margin: 0; }
.job .btn-secondary[disabled] { opacity: .55; cursor: progress; }
.run-queued { background: var(--page); color: var(--text-2); }
.run-running { background: var(--info-soft); color: var(--info); }
.run-success { background: var(--ok-soft); color: var(--ok); }
.run-failed { background: var(--danger-soft); color: var(--danger); }
.log {
  max-height: 320px; overflow: auto; margin: 8px 0 0; padding: 10px 12px; border-radius: 8px;
  background: var(--page); font: 12px/1.5 ui-monospace, "Cascadia Code", Consolas, monospace; white-space: pre-wrap;
}
details summary { cursor: pointer; color: var(--brand); font-size: 13px; }
.group-note { font-size: 13px; color: var(--muted); margin: -6px 0 12px; }
.group-note a { text-decoration: none; }

/* ---------- Change packs (P5) ---------- */
.pack-waiting_ai { background: var(--warn-soft); color: var(--warn); }
.pack-ai_done { background: var(--info-soft); color: var(--info); }
.pack-published { background: var(--ok-soft); color: var(--ok); }
.pack-cancelled { background: var(--page); color: var(--muted); }
.outcome-applied { background: var(--ok-soft); color: var(--ok); }
.outcome-partial { background: var(--warn-soft); color: var(--warn); }
.outcome-skipped { background: var(--danger-soft); color: var(--danger); }
.outcome-none { background: var(--page); color: var(--muted); }
.steps ol { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 12px; }
.steps li.done > b::after { content: " ✓"; color: var(--ok); }
.copy-row { display: flex; gap: 8px; align-items: center; margin: 8px 0 4px; flex-wrap: wrap; }
.copy-row code { padding: 8px 12px; border-radius: 8px; background: var(--page); border: 1px solid var(--border); font-size: 14px; }
code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .92em; }
.pick-list { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.pick { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.pick span { display: flex; flex-direction: column; gap: 2px; }
.pick input { margin-top: 4px; }
.diff {
  margin-top: 12px; max-height: 640px; overflow: auto; border: 1px solid var(--border); border-radius: 10px;
  font: 12px/1.55 ui-monospace, "Cascadia Code", Consolas, monospace; white-space: pre-wrap; word-break: break-word;
}
.diff > div { padding: 0 10px; }
.diff .d-add { background: var(--ok-soft); color: var(--ok); }
.diff .d-del { background: var(--danger-soft); color: var(--danger); }
.diff .d-hunk { background: var(--brand-soft); color: var(--brand); margin-top: 6px; }
.diff .d-ctx { color: var(--text-2); }

/* ---------- Home 3-column layout ---------- */
.container.home {
  max-width: 1400px; display: grid; gap: 0 28px; align-items: start;
  grid-template-columns: 300px minmax(0, 1fr) 320px;
  grid-template-areas: "left hero right" "left main right";
  grid-template-rows: auto 1fr;
}
.home-hero { grid-area: hero; }
.home-left { grid-area: left; }
.home-main { grid-area: main; }
.home-right { grid-area: right; }
.home-left .fb-strip { flex-direction: column; align-items: stretch; gap: 14px; }
.home-left .fb-strip:first-child { margin-top: 0; }
.home-left .fb-strip-stats a { flex: 1; min-width: 72px; }
.home-right .group:first-child { margin-top: 0; }
.home-right .cards { grid-template-columns: 1fr; }
.home-main .group:first-child { margin-top: 24px; }
@media (max-width: 1100px) {
  .container.home { grid-template-columns: minmax(0, 1fr); grid-template-areas: "hero" "left" "main" "right"; grid-template-rows: auto; }
  .home-left .fb-strip:first-child { margin-top: 24px; }
  .home-right .group:first-child { margin-top: 36px; }
}
