:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #16202c;
  --ink-2: #4a5666;
  --ink-3: #8592a3;
  --line: #e2e6ec;
  --line-2: #eef1f5;
  --brand: #0b4f86;
  --brand-ink: #ffffff;
  --os: #0a5f99;
  --aisr: #1d4f9c;
  --lab: #0f6e78;
  --weekend: #f6f7f9;
  --today: #fff8e6;
  --warn: #b45309;
  --warn-bg: #fff4e0;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --ok: #157f3c;
  --ok-bg: #e6f5ec;
  --chip: #eef3f9;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 10px;
  --hour: 60px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --panel: #161d26; --ink: #e8edf3; --ink-2: #b2bccb; --ink-3: #7c889a;
    --line: #273140; --line-2: #1d2531; --brand: #3f8fd8; --os: #1f6fae; --aisr: #3460b0; --lab: #1f7f89;
    --weekend: #131a22; --today: #2a2516; --warn: #f0a640; --warn-bg: #33270f; --bad: #f2776b; --bad-bg: #3a1c1a;
    --ok: #5fcf8b; --ok-bg: #15301f; --chip: #1f2a38; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  --bg: #0f141b; --panel: #161d26; --ink: #e8edf3; --ink-2: #b2bccb; --ink-3: #7c889a;
  --line: #273140; --line-2: #1d2531; --brand: #3f8fd8; --os: #1f6fae; --aisr: #3460b0; --lab: #1f7f89;
  --weekend: #131a22; --today: #2a2516; --warn: #f0a640; --warn-bg: #33270f; --bad: #f2776b; --bad-bg: #3a1c1a;
  --ok: #5fcf8b; --ok-bg: #15301f; --chip: #1f2a38;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
h2 { font-size: 20px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h3 { font-size: 14px; margin: 0; font-weight: 650; }
.muted { color: var(--ink-2); }
.small { font-size: 12px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px; padding: 10px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 34px; height: 34px; border-radius: 8px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; }
.brand-title { font-weight: 700; }
.brand-sub { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 2px; margin-left: auto; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 8px 12px; border-radius: 8px; color: var(--ink-2); cursor: pointer; white-space: nowrap; font-weight: 500; }
.tabs button:hover { background: var(--line-2); }
.tabs button.active { background: var(--chip); color: var(--brand); font-weight: 600; }
.sync { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); padding: 6px 10px; border: 1px solid var(--line); border-radius: 99px; white-space: nowrap; }
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.sync.ok .dot { background: var(--ok); }
.sync.busy .dot { background: var(--warn); }
.sync.err .dot { background: var(--bad); }

main { padding: 16px 20px 40px; max-width: 1600px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* buttons */
.primary, .ghost, .icon, .link, .btnlink { border-radius: 8px; cursor: pointer; padding: 7px 12px; font-weight: 500; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.primary { background: var(--brand); color: #fff; border: 1px solid var(--brand); }
.primary:hover { filter: brightness(1.08); }
.ghost, .btnlink { background: var(--panel); border: 1px solid var(--line); color: var(--ink); }
.ghost:hover, .btnlink:hover { background: var(--line-2); }
.icon { background: var(--panel); border: 1px solid var(--line); width: 34px; justify-content: center; padding: 6px 0; font-size: 18px; line-height: 1; }
.link { background: none; border: 0; color: var(--brand); padding: 0; font-size: 12px; }
.danger { color: var(--bad); }
.row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.row.wrap { flex-wrap: wrap; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.card-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }

/* week bar */
.weekbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.weeknav { display: flex; gap: 6px; align-items: center; }
.weeknav h2 { margin-left: 8px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw.os { background: var(--os); } .sw.aisr { background: var(--aisr); } .sw.lab { background: var(--lab); }

.weekwrap { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }

/* calendar grid */
.calendar { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; }
.cal { display: grid; grid-template-columns: 56px repeat(7, minmax(110px, 1fr)); min-width: 840px; }
.cal .hd { position: sticky; top: 0; z-index: 3; background: var(--panel); border-bottom: 1px solid var(--line); border-left: 1px solid var(--line-2); padding: 10px 6px 8px; text-align: center; font-size: 12px; font-weight: 600; letter-spacing: .02em; }
.cal .hd .dn { font-size: 18px; font-weight: 650; display: block; margin-top: 2px; }
.cal .hd.weekend { color: var(--bad); }
.cal .hd.today .dn { background: var(--brand); color: #fff; border-radius: 99px; width: 32px; height: 32px; line-height: 32px; margin: 2px auto 0; }
.cal .corner { border-left: 0; }
.cal .allday-l { font-size: 10px; color: var(--ink-3); text-align: right; padding: 6px 6px 0 0; border-bottom: 1px solid var(--line); font-weight: 600; }
.cal .allday { border-left: 1px solid var(--line-2); border-bottom: 1px solid var(--line); padding: 4px; min-height: 34px; display: flex; flex-direction: column; gap: 3px; }
.cal .allday.weekend { background: var(--weekend); }
.ev { font-size: 12px; padding: 3px 7px; border-radius: 5px; background: var(--chip); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev.holiday { background: #2196f3; color: #fff; font-weight: 500; }
.ev.range { background: var(--warn-bg); color: var(--warn); }
.ev.exam { background: var(--bad-bg); color: var(--bad); font-weight: 600; }
.cal .times { position: relative; }
.cal .tl { height: var(--hour); font-size: 11px; color: var(--ink-2); text-align: right; padding-right: 8px; transform: translateY(-7px); font-weight: 600; }
.cal .col { position: relative; border-left: 1px solid var(--line-2); background-image: linear-gradient(var(--line-2) 1px, transparent 1px); background-size: 100% var(--hour); }
.cal .col.weekend { background-color: var(--weekend); }
.cal .col.today { background-color: var(--today); }
.nowline { position: absolute; left: 0; right: 0; height: 2px; background: var(--bad); z-index: 2; }
.nowline::before { content: ''; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); }

.slot { position: absolute; left: 4px; right: 4px; border-radius: 6px; color: #fff; padding: 5px 7px; cursor: pointer; overflow: hidden; font-size: 12px; line-height: 1.35;
  border: 0; text-align: left; display: flex; flex-direction: column; gap: 1px; box-shadow: 0 1px 2px rgba(0,0,0,.15); transition: transform .08s, box-shadow .08s; }
.slot:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.slot:focus-visible { outline: 3px solid var(--warn); outline-offset: 1px; }
.slot.os { background: var(--os); } .slot.aisr { background: var(--aisr); } .slot.lab { background: var(--lab); }
.slot.cancelled { opacity: .55; text-decoration: line-through; }
.slot .c1 { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot .c2, .slot .c3 { opacity: .92; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot .c3 { opacity: .8; }
.slot .badges { position: absolute; right: 5px; bottom: 4px; display: flex; gap: 3px; }
.slot .b { font-size: 10px; font-weight: 700; padding: 0 5px; border-radius: 99px; background: rgba(255,255,255,.22); line-height: 16px; }
.slot .b.done { background: #2fbf6a; }
.slot .b.need { background: #f59e0b; color: #1d1300; }
.slot .b.task { background: rgba(255,255,255,.9); color: #7a2e00; }

/* rail */
.rail { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 72px; }
.item { padding: 9px 0; border-top: 1px solid var(--line-2); display: flex; gap: 10px; align-items: flex-start; }
.item:first-child { border-top: 0; padding-top: 0; }
.item .t { font-weight: 550; line-height: 1.35; }
.item .m { font-size: 12px; color: var(--ink-2); margin-top: 2px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.item.clickable { cursor: pointer; }
.item.clickable:hover .t { color: var(--brand); }
.empty { color: var(--ink-3); font-size: 13px; padding: 4px 0; }
.chk { width: 18px; height: 18px; flex: 0 0 18px; margin-top: 1px; accent-color: var(--brand); cursor: pointer; }

.pill { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--chip); color: var(--ink-2); white-space: nowrap; }
.pill.high { background: var(--bad-bg); color: var(--bad); }
.pill.medium { background: var(--warn-bg); color: var(--warn); }
.pill.low { background: var(--chip); }
.pill.over { background: var(--bad); color: #fff; }
.pill.nodate { background: var(--warn-bg); color: var(--warn); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }

/* pages */
.pagehead { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
select, input, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
textarea { width: 100%; resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-top: 12px; }
label input { display: block; width: 100%; margin-top: 4px; font-weight: 400; }

.addtask { display: grid; grid-template-columns: 1fr 210px 150px 110px auto; gap: 8px; margin-bottom: 14px; padding: 10px; }
.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.board .card h3 { display: flex; justify-content: space-between; align-items: center; }
.board .card h3 .cnt { font-size: 12px; color: var(--ink-3); font-weight: 500; }
.task-notes { font-size: 12px; color: var(--ink-2); margin-top: 3px; }
.task-actions { margin-left: auto; display: flex; gap: 4px; }
.task-actions button { border: 0; background: none; color: var(--ink-3); cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.task-actions button:hover { background: var(--line-2); color: var(--ink); }
.done .t { text-decoration: line-through; color: var(--ink-3); }

.list .item { padding: 12px 0; }
.remark-meta { font-size: 12px; color: var(--ink-2); }

.report { max-width: 900px; padding: 24px 28px; }
.report h1 { font-size: 20px; margin: 0 0 4px; }
.report h2 { font-size: 15px; margin: 22px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.report table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report th, .report td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.report th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-top: 14px; }
.kpi { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.kpi .v { font-size: 22px; font-weight: 700; }
.kpi .l { font-size: 12px; color: var(--ink-2); }
.repweek { font-weight: 600; min-width: 190px; text-align: center; }

.settings-grid { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 16px; align-items: start; }
.steps { padding-left: 20px; margin: 10px 0; }
.steps li { margin: 6px 0; }
.code { background: var(--line-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; max-height: 420px; overflow: auto; white-space: pre; }
.filebtn { margin: 0; font-size: 14px; color: var(--ink); }

/* drawer */
.scrim { position: fixed; inset: 0; background: rgba(10, 16, 24, .35); opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 40; }
.scrim.open { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--panel); z-index: 50; box-shadow: -8px 0 30px rgba(0,0,0,.18);
  transform: translateX(100%); transition: transform .2s ease; overflow-y: auto; }
.drawer.open { transform: none; }
.dh { padding: 18px 20px 14px; color: #fff; position: sticky; top: 0; z-index: 2; }
.dh.os { background: var(--os); } .dh.aisr { background: var(--aisr); } .dh.lab { background: var(--lab); }
.dh .x { position: absolute; right: 12px; top: 12px; background: rgba(255,255,255,.18); border: 0; color: #fff; width: 32px; height: 32px; border-radius: 8px; font-size: 18px; cursor: pointer; }
.dh .k { font-size: 12px; opacity: .85; font-weight: 500; }
.dh h2 { font-size: 18px; margin: 4px 40px 6px 0; }
.dh .meta { display: flex; gap: 6px; flex-wrap: wrap; font-size: 12px; }
.dh .meta span { background: rgba(255,255,255,.18); border-radius: 99px; padding: 2px 9px; }
.ds { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.ds h3 { margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.plan-topic { font-weight: 600; }
.plan-sub { margin: 6px 0 0; padding-left: 18px; color: var(--ink-2); font-size: 13px; }
.plan-sub li { margin: 4px 0; }
.reading { font-size: 12px; color: var(--ink-3); margin-top: 6px; }
.prog { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; font-size: 12px; }
.prog div { background: var(--line-2); border-radius: 8px; padding: 8px 10px; }
.prog b { display: block; font-size: 11px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 6px 11px; cursor: pointer; border-left: 1px solid var(--line); font-size: 13px; }
.seg button:first-child { border-left: 0; }
.seg button.on { background: var(--brand); color: #fff; }
.grid2 { display: grid; grid-template-columns: 1fr 120px; gap: 8px; margin-top: 8px; }
.inline-add { display: grid; grid-template-columns: 1fr 140px 100px auto; gap: 6px; margin-top: 10px; }
.cohorts { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 8px; }
.cohorts span { font-size: 11px; background: rgba(255,255,255,.14); border-radius: 4px; padding: 1px 6px; }
.saved { font-size: 12px; color: var(--ok); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--panel); padding: 10px 16px; border-radius: 8px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 60; }
.toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 1100px) {
  .weekwrap { grid-template-columns: 1fr; }
  .rail { position: static; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 16px; }
  .tabs { order: 3; width: 100%; margin-left: 0; }
  .sync { margin-left: auto; }
  main { padding: 12px 16px 32px; }
  .addtask { grid-template-columns: 1fr 1fr; }
  .addtask input[name=title] { grid-column: 1 / -1; }
  .inline-add { grid-template-columns: 1fr 1fr; }
  .inline-add input[type=text] { grid-column: 1 / -1; }
  .report { padding: 16px; }
  .weeknav h2 { font-size: 16px; }
}
@media print {
  .topbar, .pagehead .filters, .weekbar, .rail { display: none !important; }
  body { background: #fff; }
  .report { box-shadow: none; border: 0; max-width: none; }
}
