:root {
  --ink: #111418;
  --ink2: #344054;
  --muted: #667085;
  --line: #E6E8EB;
  --line2: #D0D5DD;
  --soft: #F5F6F8;
  --accent: #166534;
  --accent-ink: #14532D;
  --accent-soft: #E9F4EC;
  --high: #B42318;
  --med: #B54708;
  --low: #667085;
  --event: #EEF0F3;
  --danger: #B42318;
  --hour: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, system-ui, sans-serif;
  color: var(--ink); background: #fff; -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Buttons and controls ---------- */
.btn { height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line2); background: #fff; font-weight: 600; font-size: 13px; white-space: nowrap; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #2b3038; }
.btn.green { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.green:hover { background: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink2); }
.btn.ghost:hover { background: var(--soft); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 6px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; font-size: 13px; }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { border: 0; border-left: 1px solid var(--line2); background: transparent; padding: 0 12px; height: 30px; font-size: 13px; color: var(--ink2); }
.seg button:first-child { border-left: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; font-weight: 600; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line2); border-radius: 8px; padding: 8px 10px; background: #fff; min-height: 36px; }
textarea.input { resize: vertical; min-height: 72px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Top bar ---------- */
.top { position: sticky; top: 0; z-index: 20; height: 56px; display: flex; align-items: center; gap: 16px; padding: 0 20px; border-bottom: 1px solid var(--line); background: #fff; }
.brand { font-weight: 700; font-size: 16px; min-width: 90px; }
.week { display: flex; align-items: center; gap: 4px; margin: 0 auto; }
.week .nav { width: 30px; height: 30px; border-radius: 15px; border: 0; background: transparent; font-size: 18px; color: var(--ink2); }
.week .nav:hover { background: var(--soft); }
.day-chip { width: 46px; height: 42px; border-radius: 10px; border: 0; background: transparent; display: grid; place-items: center; line-height: 1.1; padding: 4px 0; color: var(--ink2); }
.day-chip b { font-size: 15px; }
.day-chip span { font-size: 11px; color: var(--muted); }
.day-chip:hover { background: var(--soft); }
.day-chip.today b { color: var(--accent); }
.day-chip[aria-current="date"] { background: var(--ink); color: #fff; }
.day-chip[aria-current="date"] span, .day-chip[aria-current="date"] b { color: #fff; }
.top .right { display: flex; align-items: center; gap: 10px; }

/* ---------- Desktop layout ---------- */
.cols { display: grid; grid-template-columns: 320px minmax(0, 1fr) 320px; height: calc(100dvh - 56px); }
.left, .right-panel { overflow-y: auto; }
.left { border-right: 1px solid var(--line); padding: 16px 16px 40px; display: flex; flex-direction: column; gap: 18px; }
.right-panel { border-left: 1px solid var(--line); padding: 18px 18px 40px; display: flex; flex-direction: column; gap: 18px; }
.daycol { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* Capture */
.capture { display: flex; align-items: center; gap: 6px; height: 46px; border: 1px solid var(--line2); border-radius: 12px; padding: 0 5px 0 12px; background: #fff; }
.capture:focus-within { border-color: var(--ink); }
.capture .plus { color: var(--accent); font-size: 22px; line-height: 1; }
.capture input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 15px; height: 100%; }
.mic { width: 36px; height: 36px; border-radius: 18px; border: 0; background: var(--ink); color: #fff; display: grid; place-items: center; flex: none; }
.mic svg { width: 18px; height: 18px; }
.mic.rec { background: var(--danger); animation: pulse 1.2s infinite; }
.mic.busy { background: var(--muted); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(180, 35, 24, .18); } }
.capture-hint { font-size: 12px; color: var(--muted); margin-top: -10px; padding: 0 4px; }

/* Sections and task rows */
.sec h2 { display: flex; align-items: baseline; gap: 8px; margin: 0 0 6px; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.sec h2 .count { font-weight: 500; letter-spacing: 0; }
.sec h2 .link { margin-left: auto; text-transform: none; letter-spacing: 0; }
.sec h3 { margin: 10px 0 2px; font-size: 12px; font-weight: 600; }
.p-high { color: var(--high); } .p-medium { color: var(--med); } .p-low { color: var(--low); }
.empty { color: var(--muted); font-size: 13px; padding: 6px 0; }
.trow { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 8px; margin: 0 -8px; border-radius: 8px; cursor: pointer; }
.trow:hover { background: var(--soft); }
.trow.sel { background: var(--accent-soft); }
.trow .tx { flex: 1; min-width: 0; }
.trow .tt { font-weight: 500; overflow-wrap: anywhere; }
.trow .tm { font-size: 12px; color: var(--muted); }
.trow.draft .tt { color: var(--ink2); }
.trow[draggable="true"] { cursor: grab; }
.dur { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 10px; padding: 1px 7px; white-space: nowrap; }
.tagw { font-size: 11px; color: var(--muted); }
.chk { width: 20px; height: 20px; border-radius: 10px; border: 1.5px solid #98A2B3; background: #fff; flex: none; padding: 0; display: grid; place-items: center; }
.chk:hover { border-color: var(--accent); }
.chk.on { background: var(--accent); border-color: var(--accent); }
.chk.on::after { content: ""; width: 9px; height: 5px; border: solid #fff; border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg); }
.chk.dash { border-style: dashed; border-color: #B0B7C3; }
.keep { height: 26px; padding: 0 10px; border-radius: 6px; border: 1px solid var(--ink); background: var(--ink); color: #fff; font-size: 12px; font-weight: 600; }
.x { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line2); background: #fff; color: var(--muted); font-size: 12px; }

/* ---------- Day timeline ---------- */
.dayhead { display: flex; align-items: center; gap: 12px; padding: 14px 20px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.dayhead h1 { margin: 0; font-size: 20px; font-weight: 700; }
.allday { display: flex; gap: 6px; flex-wrap: wrap; }
.allday span { font-size: 12px; background: var(--event); border-radius: 6px; padding: 2px 8px; color: var(--ink2); }
.scroller { flex: 1; overflow-y: auto; position: relative; }
.tl { position: relative; margin: 8px 16px 40px 64px; }
.hr { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.hr span { position: absolute; left: -56px; top: -8px; width: 48px; text-align: right; font-size: 11px; color: var(--muted); }
.hr.half { border-top-style: dashed; border-top-color: #F0F1F3; }
.hr.half span { display: none; }
.off { position: absolute; left: 0; right: 0; background: repeating-linear-gradient(-45deg, #FAFAFB, #FAFAFB 6px, #F4F5F7 6px, #F4F5F7 7px); pointer-events: none; }
.blk { position: absolute; border-radius: 8px; padding: 4px 8px; overflow: hidden; font-size: 12px; line-height: 1.3; user-select: none; -webkit-user-select: none; }
.blk .bt { font-weight: 600; }
.blk .bm { color: var(--muted); font-size: 11px; }
.blk.ev { background: var(--event); color: var(--ink2); border: 1px solid #E2E5E9; }
.blk.ev.free { background: #fff; border-style: dashed; }
.blk.tk { background: #fff; border: 1px solid var(--line2); border-left: 3px solid var(--low); box-shadow: 0 1px 2px rgba(16, 24, 40, .05); display: flex; gap: 8px; align-items: flex-start; cursor: grab; touch-action: pan-y; }
.blk.tk.ph { border-left-color: var(--high); }
.blk.tk.pm { border-left-color: var(--med); }
.blk.tk .chk { width: 16px; height: 16px; margin-top: 1px; }
.blk.tk .chk.on::after { width: 7px; height: 4px; }
.blk.tk.done { opacity: .55; }
.blk.tk.done .bt { text-decoration: line-through; }
.blk.tk.sel { outline: 2px solid var(--accent); outline-offset: 1px; }
.blk.tk.dragging { opacity: .85; box-shadow: 0 8px 24px rgba(16, 24, 40, .18); z-index: 10; cursor: grabbing; }
.blk.ghost { background: var(--accent-soft); border: 1.5px dashed var(--accent); color: var(--accent-ink); }
.blk.tiny { padding: 0 8px; font-size: 11px; line-height: 15px; }
.blk.tiny .chk { width: 12px; height: 12px; margin-top: 1px; }
.blk .handle { position: absolute; left: 0; right: 0; bottom: 0; height: 8px; cursor: ns-resize; }
.nowline { position: absolute; left: -8px; right: 0; border-top: 2px solid var(--danger); z-index: 5; pointer-events: none; }
.nowline::before { content: ""; position: absolute; left: -4px; top: -5px; width: 8px; height: 8px; border-radius: 4px; background: var(--danger); }
.droptarget { outline: 2px dashed var(--accent); outline-offset: 4px; border-radius: 8px; }
.dropmark { position: absolute; left: 0; right: 0; height: 0; border-top: 2px solid var(--accent); pointer-events: none; z-index: 6; }

/* ---------- Right panel ---------- */
.card { border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 10px; }
.card h2 { margin: 0; font-size: 15px; }
.card p { margin: 0; color: var(--ink2); font-size: 13px; }
.card.plan { background: var(--accent-soft); border-color: #CDE5D4; }
.card .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.load { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.load div { background: var(--soft); border-radius: 10px; padding: 8px 10px; }
.load b { display: block; font-size: 15px; }
.load span { font-size: 11px; color: var(--muted); }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }
.bar .m { background: #98A2B3; } .bar .t { background: var(--accent); }
.risk { border-color: #F5C2BD; background: #FFF6F5; }
.risk .trow { margin: 0 -6px; }
.detail { display: grid; gap: 14px; position: relative; }
.detail .titlebox { font-size: 17px; font-weight: 600; border: 1px solid transparent; border-radius: 8px; padding: 6px 8px; margin: -6px -8px; width: calc(100% + 16px); resize: none; background: transparent; line-height: 1.35; }
.detail .titlebox:hover, .detail .titlebox:focus { border-color: var(--line2); outline: 0; background: #fff; }
.detail .kicker { font-size: 12px; font-weight: 600; color: var(--accent); }
.detail .why { background: var(--soft); border-radius: 10px; padding: 10px 12px; font-size: 13px; color: var(--ink2); }
.detail .bigactions { display: flex; gap: 8px; }
.detail .bigactions .btn { flex: 1; height: 40px; font-size: 14px; }
.detail .foot { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); padding-top: 12px; }
.close { position: absolute; right: -8px; top: -8px; }

/* ---------- Login and setup ---------- */
.center { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login { width: 100%; max-width: 360px; display: grid; gap: 14px; }
.login h1 { margin: 0 0 4px; font-size: 26px; }
.login .btn { height: 44px; font-size: 15px; }
.login .input { height: 46px; font-size: 16px; }
.setup { max-width: 760px; margin: 0 auto; padding: 24px 20px 120px; display: grid; gap: 18px; }
.setup h1 { margin: 0; font-size: 24px; }
.setup .card h2 { font-size: 16px; }
.setup ol { margin: 0; padding-left: 20px; color: var(--ink2); display: grid; gap: 6px; }
.copyrow { display: flex; gap: 8px; align-items: center; }
.copyrow code, pre.code { flex: 1; min-width: 0; background: var(--soft); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; white-space: pre-wrap; }
pre.code { margin: 0; max-height: 220px; overflow: auto; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 4px; background: #98A2B3; }
.status.ok::before { background: var(--accent); }
.log { display: grid; gap: 6px; font-size: 12px; }
.log div { border-bottom: 1px solid var(--line); padding-bottom: 6px; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; width: min(520px, calc(100vw - 24px)); pointer-events: none; }
.toast { pointer-events: auto; background: var(--ink); color: #fff; border-radius: 12px; padding: 10px 14px; display: flex; align-items: center; gap: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .2); font-size: 13px; }
.toast .tmsg { flex: 1; }
.toast button { background: transparent; border: 0; color: #9FE0B4; font-weight: 700; }
.toast.err { background: #7A271A; }

/* ---------- Mobile ---------- */
.m-only { display: none; }
.tabbar, .mcapture, .sheet-back { display: none; }
@media (max-width: 979px) {
  :root { --hour: 56px; }
  .d-only { display: none !important; }
  .m-only { display: block; }
  body { background: #fff; }
  .top { height: auto; flex-wrap: wrap; padding: calc(var(--safe-t) + 10px) 14px 8px; gap: 8px; border-bottom: 0; }
  .brand { flex: 1; font-size: 26px; min-width: 0; }
  .brand small { display: block; font-size: 13px; font-weight: 500; color: var(--muted); }
  .week { order: 3; width: 100%; justify-content: space-between; margin: 0; }
  .week .nav { display: none; }
  .day-chip { width: auto; flex: 1; height: 48px; }
  .top .right .seg button { padding: 0 9px; }
  .cols { display: block; height: auto; }
  .left, .daycol, .right-panel { border: 0; }
  .left { padding: 8px 14px calc(150px + var(--safe-b)); }
  .daycol { min-height: calc(100dvh - 200px); }
  .dayhead { padding: 6px 14px 8px; border-bottom: 1px solid var(--line); }
  .dayhead h1 { font-size: 16px; }
  .scroller { overflow: visible; }
  .tl { margin: 8px 12px calc(150px + var(--safe-b)) 52px; }
  .hr span { left: -48px; width: 42px; }
  body[data-tab="day"] .left, body[data-tab="day"] .right-panel { display: none; }
  body[data-tab="list"] .daycol, body[data-tab="drafts"] .daycol { display: none; }
  body[data-tab="list"] .sec.drafts, body[data-tab="drafts"] .sec.backlog { display: none; }
  body:not([data-sheet]) .right-panel { display: none !important; }
  body[data-sheet] .right-panel { display: flex !important; position: fixed; left: 0; right: 0; bottom: 0; max-height: 86dvh; z-index: 60; background: #fff; border-radius: 18px 18px 0 0; padding: 20px 18px calc(24px + var(--safe-b)); box-shadow: 0 -10px 40px rgba(0, 0, 0, .18); }
  body[data-sheet] .sheet-back { display: block; position: fixed; inset: 0; background: rgba(16, 24, 40, .35); z-index: 55; }
  .left .capture, .left .capture-hint { display: none; }
  .mcapture { display: flex; position: fixed; left: 12px; right: 12px; bottom: calc(66px + var(--safe-b)); z-index: 30; box-shadow: 0 6px 20px rgba(16, 24, 40, .12); height: 50px; border-radius: 25px; }
  .mcapture .mic { width: 40px; height: 40px; border-radius: 20px; }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: #fff; border-top: 1px solid var(--line); padding: 6px 6px calc(6px + var(--safe-b)); }
  .tabbar button { flex: 1; border: 0; background: transparent; height: 44px; font-size: 13px; font-weight: 600; color: var(--muted); }
  .tabbar button[aria-current="page"] { color: var(--ink); }
  .trow { min-height: 52px; }
  .trow .tt { font-size: 15px; }
  #toasts { bottom: calc(130px + var(--safe-b)); }
  .mplan { margin: 10px 14px 0; }
}
