:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1c2430;
  --muted: #5d6878;
  --brand: #1f5fbf;
  --brand-ink: #ffffff;
  --brand-soft: #e6eefb;
  --ok: #1d7a4a;
  --ok-soft: #e3f4ea;
  --warn: #9a6200;
  --warn-soft: #fbf0dc;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b; --surface: #171d26; --surface-2: #1d2530; --border: #2b3542; --text: #e6ebf2; --muted: #9aa6b5;
    --brand: #5b9bff; --brand-ink: #0b1220; --brand-soft: #1b2b45; --ok: #49c288; --ok-soft: #13301f;
    --warn: #f0b64f; --warn-soft: #3a2c10; --danger: #ff7b6e; --danger-soft: #3a1814;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.45; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .6rem; line-height: 1.2; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }
.hidden { display: none !important; }
.boot { display: grid; place-items: center; min-height: 100vh; }
.boot-msg { color: var(--muted); }

/* layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; padding: 4px 8px 16px; }
.brand-mark { width: 40px; height: 40px; border-radius: 10px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 800; font-size: .95rem; letter-spacing: .01em; flex-shrink: 0; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); margin-bottom: 2px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav .section { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; margin: 14px 10px 6px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar .grow { flex: 1; }
.content { padding: 20px; max-width: 1280px; width: 100%; }
.menu-btn { display: none; }

/* components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.kpi .v { font-size: 1.6rem; font-weight: 700; }
.kpi .l { color: var(--muted); font-size: .85rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.btn { appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 12px; border-radius: 8px; cursor: pointer; font: inherit; font-size: .9rem; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.small { padding: 4px 8px; font-size: .8rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.link { border: none; background: none; color: var(--brand); padding: 0; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field .err { color: var(--danger); font-size: .8rem; margin-top: 3px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
.checkbox { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: .9rem; }
.checkbox input { width: auto; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; color: var(--muted); font-size: .85rem; gap: 8px; flex-wrap: wrap; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--brand-soft); color: var(--brand); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: none; padding: 9px 12px; cursor: pointer; color: var(--muted); font: inherit; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.list-item { padding: 10px 0; border-bottom: 1px solid var(--border); display: flex; gap: 10px; justify-content: space-between; align-items: flex-start; }
.list-item:last-child { border-bottom: none; }
.empty { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }
.loading { color: var(--muted); padding: 18px; }
.alert { padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; font-size: .9rem; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--brand-soft); color: var(--brand); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.column { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.column h4 { margin: 0 0 8px; font-size: .85rem; display: flex; justify-content: space-between; }
.pcard { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; font-size: .9rem; }
.timeline { border-left: 2px solid var(--border); padding-left: 12px; }
.timeline .t { margin-bottom: 10px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: .9rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; font-size: .8rem; display: inline-flex; gap: 6px; align-items: center; }
.chip button { border: none; background: none; cursor: pointer; color: var(--muted); padding: 0; }
.score { font-weight: 700; }
.bar { height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--brand); }
.proposal { border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 8px; }
.proposal.conflict { border-color: var(--warn); }
pre.value { white-space: pre-wrap; margin: 4px 0; font-size: .85rem; background: var(--surface-2); padding: 6px 8px; border-radius: 6px; max-height: 180px; overflow: auto; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 420px; }

/* toasts & modal */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; font-size: .9rem; }
.toast.error { background: var(--danger); color: #fff; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 15, 25, .45); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; padding: 18px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal .row.end { margin-top: 10px; }

@media (max-width: 960px) {
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 30; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .content { padding: 14px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .kv dt { margin-top: 6px; }
  .topbar { padding: 8px 12px; }
}

/* refinements */
.btn.menu-btn { display: none; }
.org-switch { max-width: 360px; width: auto; }
.card-head select, .row select, .row input { width: auto; }
#cq { width: 100%; }
@media (max-width: 760px) {
  .btn.menu-btn { display: inline-flex; }
  .org-switch { max-width: 55vw; }
}
.topbar .org-switch { flex: 1 1 auto; min-width: 0; }
@media (max-width: 760px) {
  .topbar { gap: 6px; }
  .topbar > .small.muted, .topbar .grow { display: none; }
  .org-switch { max-width: none; }
}
@media (max-width: 760px) { .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
