:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --line: #e4e1da;
  --text: #1d1c1a;
  --muted: #6f6b63;
  --accent: #1f3a5f;
  --accent-soft: #e3e9f2;
  --ok: #2f7d4f;
  --ok-soft: #e2f1e7;
  --warn: #a8621a;
  --warn-soft: #f7ead9;
  --bad: #b23b3b;
  --bad-soft: #f6e1e1;
  --shadow: 0 1px 2px rgba(20, 18, 14, .05), 0 4px 16px rgba(20, 18, 14, .04);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131416;
    --surface: #1b1d20;
    --surface-2: #23262a;
    --line: #2e3237;
    --text: #ecebe8;
    --muted: #9a978f;
    --accent: #8fb3e6;
    --accent-soft: #1f2b3b;
    --ok: #6cc28f;
    --ok-soft: #1b2e23;
    --warn: #e0a463;
    --warn-soft: #33281b;
    --bad: #ec8a8a;
    --bad-soft: #3a2020;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131416; --surface: #1b1d20; --surface-2: #23262a; --line: #2e3237; --text: #ecebe8; --muted: #9a978f;
  --accent: #8fb3e6; --accent-soft: #1f2b3b; --ok: #6cc28f; --ok-soft: #1b2e23; --warn: #e0a463; --warn-soft: #33281b;
  --bad: #ec8a8a; --bad-soft: #3a2020; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.3; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 26px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 16px 64px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.pad { padding: 48px 0; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.tnum { font-variant-numeric: tabular-nums; }

/* topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px;
  padding: 10px max(16px, calc((100% - 1180px) / 2 + 16px));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 20px; height: 20px; border-radius: 5px; background: var(--accent); position: relative; }
.brand-mark::after { content: ""; position: absolute; left: 5px; top: 5px; width: 3px; height: 10px; border-radius: 2px; background: var(--surface); box-shadow: 5px 0 0 0 color-mix(in srgb, var(--surface) 70%, transparent); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); }
.nav a:hover { text-decoration: none; background: var(--surface-2); color: var(--text); }
.nav a.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* controls */
button, .btn {
  font: inherit; font-size: 14px; cursor: pointer;
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--surface);
}
button.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
button.ghost:hover { color: var(--text); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

/* login */
.login { max-width: 360px; margin: 12vh auto 0; background: var(--surface); padding: 32px; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.login form { display: grid; gap: 12px; margin-top: 20px; }
.err { color: var(--bad); font-size: 13px; min-height: 1em; }

/* overview */
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin: 8px 0 20px; }
.page-head p { margin: 4px 0 0; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi b { display: block; font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 9px; }
.tabs button { background: transparent; border: 0; color: var(--muted); padding: 5px 12px; border-radius: 7px; }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
}
a.card { color: inherit; transition: border-color .15s; }
a.card:hover { text-decoration: none; border-color: var(--accent); }
.card-head { display: flex; gap: 10px; align-items: flex-start; }
.card-head h2 { flex: 1; }
.card .desc { color: var(--muted); font-size: 13px; margin: 2px 0 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.active { background: var(--accent-soft); color: var(--accent); }
.chip.done { background: var(--ok-soft); color: var(--ok); }
.chip.paused { background: var(--warn-soft); color: var(--warn); }
.chip.blocked, .chip.stale { background: var(--bad-soft); color: var(--bad); }
.chip.doing { background: var(--accent-soft); color: var(--accent); }

.progress { display: flex; align-items: center; gap: 10px; }
.bar { flex: 1; height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.done i { background: var(--ok); }
.progress b { font-size: 14px; font-variant-numeric: tabular-nums; min-width: 40px; text-align: right; }

.mini-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.mini-list li { display: flex; gap: 8px; align-items: baseline; }
.mini-list li .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; transform: translateY(-1px); }
.dot.doing { background: var(--accent); }
.dot.blocked { background: var(--bad); }
.dot.done { background: var(--ok); }
.label { font-size: 12px; color: var(--muted); text-transform: none; margin-bottom: 4px; }
.card-foot { border-top: 1px solid var(--line); padding-top: 10px; font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.card-foot .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }

/* detail */
.back { display: inline-block; margin-bottom: 12px; color: var(--muted); font-size: 14px; }
.detail-head { display: grid; grid-template-columns: 1fr 300px; gap: 20px; margin-bottom: 28px; }
.detail-head .meta { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel .row + .row { margin-top: 10px; }
.panel label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 4px; }
.panel input, .panel select { width: 100%; }
.panel .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.section-head { display: flex; align-items: center; gap: 12px; margin: 28px 0 12px; }

.board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.col h3 { font-size: 13px; color: var(--muted); font-weight: 600; display: flex; gap: 6px; align-items: center; padding: 2px 4px 8px; }
.col h3 .n { margin-left: auto; font-variant-numeric: tabular-nums; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 10px; margin-bottom: 8px; font-size: 14px; }
.item .t { margin-bottom: 6px; word-break: break-word; }
.item .note { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.item .row { gap: 6px; }
.item select { padding: 2px 6px; font-size: 12px; }
.item .x { background: none; border: 0; color: var(--muted); padding: 2px 6px; font-size: 12px; margin-left: auto; }
.item .x:hover { color: var(--bad); }
.add { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.add input[name=title] { flex: 1; min-width: 200px; }

.timeline { display: grid; gap: 12px; }
.report { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.report-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.report-head h3 { flex: 1; min-width: 200px; }
.report .summary { margin: 8px 0 0; color: var(--text); white-space: pre-wrap; }
.report .cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 12px; }
.report ul { margin: 0; padding-left: 18px; font-size: 13px; }
.report .cols .label { font-weight: 600; }
.report .cols .risks .label { color: var(--bad); }
.empty { padding: 32px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

/* categories */
.cats { display: flex; gap: 6px; flex-wrap: wrap; margin: -8px 0 16px; }
.cats button { background: var(--surface); color: var(--muted); border: 1px solid var(--line); padding: 4px 12px; border-radius: 99px; font-size: 13px; }
.cats button.on { background: var(--accent); color: var(--surface); border-color: var(--accent); }
.cats .n { opacity: .7; font-variant-numeric: tabular-nums; margin-left: 2px; }
.chip.cat { background: var(--surface-2); color: var(--text); }
.chip.cat-client { background: var(--ok-soft); color: var(--ok); }
.chip.cat-presales { background: var(--accent-soft); color: var(--accent); }
.chip.cat-product { background: var(--warn-soft); color: var(--warn); }
.chip.cat-none { background: var(--bad-soft); color: var(--bad); }
.chip.prio { font-variant-numeric: tabular-nums; }
.chip.prio-P0 { background: var(--bad); color: var(--surface); }
.chip.prio-P1 { background: var(--bad-soft); color: var(--bad); }

/* advisor */
.advice-banner { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; padding: 14px 18px; margin-bottom: 16px; border-radius: var(--radius); background: var(--accent-soft); color: var(--text); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); }
.advice-banner:hover { text-decoration: none; border-color: var(--accent); }
.advice-banner .label { margin: 0; color: var(--accent); font-weight: 600; }
.advice-banner b { flex: 1; min-width: 200px; }
.advisor { display: grid; grid-template-columns: 1fr 260px; gap: 20px; align-items: start; }
.brief { padding: 24px 28px; }
.md { line-height: 1.75; }
.md h1 { font-size: 20px; margin: 1.2em 0 .5em; }
.md h2 { font-size: 17px; margin: 1.4em 0 .5em; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.md h3 { font-size: 15px; margin: 1.2em 0 .4em; }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); }
.md blockquote { margin: 1em 0; padding: 4px 14px; border-left: 3px solid var(--accent); color: var(--muted); }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.history { display: grid; gap: 2px; position: sticky; top: 70px; }
.history a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--text); font-size: 14px; }
.history a span { display: block; color: var(--muted); font-size: 12px; }
.history a:hover { background: var(--surface-2); text-decoration: none; }
.history a.on { background: var(--surface); box-shadow: var(--shadow); }

@media (max-width: 860px) {
  .advisor { grid-template-columns: 1fr; }
  .history { position: static; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .detail-head { grid-template-columns: 1fr; }
  .board { grid-template-columns: 1fr 1fr; }
  .report .cols { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .board { grid-template-columns: 1fr; }
  .topbar { gap: 10px; }
  h1 { font-size: 22px; }
}
