:root {
  --bg: #f5f6f8; --panel: #ffffff; --line: #e4e7ec; --text: #1d2433; --muted: #667085;
  --brand: #1f6feb; --brand-weak: #e8f0fe; --ok: #12805c; --ok-weak: #e3f5ee; --warn: #b25e09; --warn-weak: #fdf1e1;
  --bad: #c4320a; --bad-weak: #fdeceb; --side: #101828; --side-text: #d0d5dd;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218; --panel: #171b23; --line: #2a303c; --text: #e6e8ec; --muted: #98a2b3;
    --brand: #5b9bff; --brand-weak: #1b2a44; --ok: #3ccb8f; --ok-weak: #15302a; --warn: #f2a54a; --warn-weak: #33261a;
    --bad: #ff7a59; --bad-weak: #3a1f1a; --side: #0b0e13; --side-text: #c4cad4;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif; }
a { color: var(--brand); text-decoration: none; cursor: pointer; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; width: 100%; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-weak); border-color: var(--brand); }
button, a.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 14px; cursor: pointer; white-space: nowrap; }
button:hover, a.btn:hover { border-color: var(--brand); }
button.primary, a.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.danger { color: var(--bad); }
button.small { padding: 2px 10px; font-size: 13px; }
button.icon { border: none; background: none; font-size: 20px; padding: 0 6px; }
button:disabled { opacity: .5; cursor: default; }

.layout { display: flex; min-height: 100vh; align-items: flex-start; }
.side { width: 200px; background: var(--side); color: var(--side-text); padding: 18px 10px; flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow: auto; }
.side .brand { font-weight: 700; color: #fff; font-size: 16px; padding: 0 10px 14px; }
.side .brand small { display: block; font-weight: 400; color: var(--side-text); opacity: .7; font-size: 12px; }
.side a { display: block; color: var(--side-text); padding: 8px 12px; border-radius: 8px; margin: 2px 0; }
.side a.on, .side a:hover { background: rgba(255,255,255,.08); color: #fff; }
.side .me { margin-top: 18px; padding: 10px 12px; font-size: 12px; opacity: .8; border-top: 1px solid rgba(255,255,255,.1); }
.main { flex: 1; min-width: 0; padding: 20px 24px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; margin: 0; flex: 1; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card h3 { margin: 0 0 10px; font-size: 15px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(320px, 1fr); gap: 16px; align-items: start; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 140px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { margin-left: auto; }

.stat { padding: 14px 16px; }
.stat .v { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 13px; }
.stat .s { color: var(--muted); font-size: 12px; }

.tag { display: inline-block; padding: 0 8px; border-radius: 99px; font-size: 12px; background: var(--brand-weak); color: var(--brand); margin: 1px 2px; white-space: nowrap; }
.tag.ok { background: var(--ok-weak); color: var(--ok); }
.tag.warn { background: var(--warn-weak); color: var(--warn); }
.tag.bad { background: var(--bad-weak); color: var(--bad); }
.tag.gray { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; background: var(--bg); }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--brand-weak); }
.table-wrap { overflow-x: auto; }
.clip { max-width: 420px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.on { color: var(--brand); border-color: var(--brand); }

.chat { max-height: 460px; overflow-y: auto; padding: 4px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 78%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; }
.bubble.in { background: var(--bg); border: 1px solid var(--line); align-self: flex-start; }
.bubble.out { background: var(--brand-weak); align-self: flex-end; }
.bubble .t { font-size: 11px; color: var(--muted); margin-top: 2px; }

.todo { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; background: var(--panel); }
.todo .head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.todo .head b { font-size: 15px; }
.todo .say { background: var(--bg); border-radius: 8px; padding: 8px 10px; margin-top: 8px; white-space: pre-wrap; }
.kv { display: grid; grid-template-columns: 76px 1fr; gap: 4px 8px; }
.kv .k { color: var(--muted); }

.bars { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: 10px; }
.bars .b { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; min-width: 0; height: 100%; }
.bars .b i { display: block; width: 70%; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 1px; }
.bars .b i.in { background: var(--ok); }
.bars .b span { font-size: 10px; color: var(--muted); margin-top: 4px; white-space: nowrap; }
.hbar { display: grid; grid-template-columns: 80px 1fr 40px; gap: 8px; align-items: center; margin: 6px 0; }
.hbar .track { background: var(--bg); border-radius: 99px; height: 10px; overflow: hidden; }
.hbar .fill { background: var(--brand); height: 100%; border-radius: 99px; }

.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.cal .day { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; min-height: 120px; }
.cal .day.today { border-color: var(--brand); }
.cal .day .d { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.cal .day .wkd { display: none; }
@media (max-width: 900px) { .cal .day .wkd { display: inline; } }
.cal .item { font-size: 12px; padding: 2px 6px; border-radius: 6px; margin: 2px 0; background: var(--bg); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal .item.done { text-decoration: line-through; opacity: .6; }
.cal .item.cadence { border-left: 3px solid var(--brand); }
.cal .item.sop { border-left: 3px solid var(--ok); }
.cal .item.manual, .cal .item.ai { border-left: 3px solid var(--warn); }
.cal .item.campaign { border-left: 3px dashed var(--muted); font-weight: 500; }

.hit { background: var(--bad-weak); color: var(--bad); border-radius: 4px; padding: 0 2px; }
.hit.warn { background: var(--warn-weak); color: var(--warn); }
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.form label.inline { display: flex; align-items: center; gap: 6px; }
.form label.inline input { width: auto; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }
pre.code { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow-x: auto; font-size: 12px; white-space: pre; }

.login { max-width: 360px; margin: 12vh auto; }
.login h2 { margin: 0 0 4px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow: auto; }
.modal[hidden] { display: none; }
.modal-card { background: var(--panel); border-radius: 12px; width: min(640px, 100%); padding: 16px 18px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--side); color: #fff; padding: 8px 16px; border-radius: 8px; z-index: 60; max-width: 90vw; }
.toast[hidden] { display: none; }

.sidebar-mode .side { display: none; }
.sidebar-mode .main { padding: 10px; }

@media (max-width: 900px) {
  .layout { flex-direction: column; align-items: stretch; }
  .side { width: 100%; height: auto; position: static; display: flex; flex-wrap: wrap; gap: 2px; padding: 8px; }
  .side .brand, .side .me { width: 100%; padding: 4px 8px; margin: 0; border: none; }
  .side a { padding: 4px 10px; }
  .main { padding: 14px 16px 40px; }
  .split, .g2, .g3 { grid-template-columns: minmax(0, 1fr); }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cal { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cal .wk { display: none; }
}
[hidden] { display: none !important; }
.side .me a { display: inline-block; padding: 2px 0; margin: 6px 14px 0 0; border-radius: 0; background: none; }
a.btn { text-decoration: none; display: inline-block; }
.main-wrap { flex: 1; min-width: 0; }
.shadow-bar { background: var(--warn-weak); color: var(--warn); border-bottom: 1px solid var(--warn); padding: 8px 24px; font-size: 13px; font-weight: 600; }

.tabs a { cursor: pointer; }
tr.on td { background: var(--brand-weak); }
