/* sb-tasks — mobile-first, iOS-friendly. Light/dark via prefers-color-scheme. */
:root {
  --bg: #f5f5f4; --card: #ffffff; --card2: #f0efec;
  --text: #1a1a19; --text2: #6b6a63; --muted: #9c9b93; --line: #e6e5e0;
  --accent: #2a78d6; --accent-soft: #e3eefb;
  --danger: #c93a39; --danger-soft: #fbe5e5;
  --warn: #b67a00; --warn-soft: #fff1d6;
  --ok: #007a2f; --ok-soft: #dff5e6;
  --q1: #e34948; --q2: #2a78d6; --q3: #eda100; --q4: #9c9b93;
  --sat: env(safe-area-inset-top); --sab: env(safe-area-inset-bottom);
  --tab-h: 54px; --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a19; --card: #262624; --card2: #2f2f2c;
    --text: #ffffff; --text2: #c3c2b7; --muted: #86857c; --line: #3a3a37;
    --accent: #3987e5; --accent-soft: #1d3554;
    --danger: #e66767; --danger-soft: #4a2323;
    --warn: #e0a83a; --warn-soft: #443512;
    --ok: #4cc471; --ok-soft: #173d25;
    --q1: #e66767; --q2: #3987e5; --q3: #c98500; --q4: #86857c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-user-select: none; user-select: none;
  -webkit-text-size-adjust: 100%;
}
input, textarea { -webkit-user-select: text; user-select: text; font: inherit; color: inherit; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }

/* ---------- login ---------- */
#login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--bg); }
#login form { width: 100%; max-width: 320px; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
#login img { border-radius: 16px; margin-bottom: 4px; }
#login h1 { font-size: 26px; }
#login p { color: var(--text2); font-size: 15px; }
#login input { width: 100%; padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: 17px; text-align: center; }
#login .err { color: var(--danger); font-size: 14px; min-height: 18px; }

/* ---------- layout ---------- */
#app { display: flex; flex-direction: column; height: 100dvh; }
#top { padding: calc(var(--sat) + 10px) 16px 8px; background: var(--bg); flex: none; }
#top .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
#top h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
#top .sub { color: var(--text2); font-size: 14px; margin-top: 2px; }
#top .state { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
#top .state.offline { color: var(--warn); }
#top .state i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; }
#top .state.offline i { background: var(--warn); }
#main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 16px calc(var(--sab) + 120px); }
.m-matrix #main { padding: 4px 10px calc(var(--sab) + 12px); display: flex; flex-direction: column; overflow: hidden; }

#tabs { flex: none; display: flex; border-top: 1px solid var(--line); background: var(--card); padding-bottom: var(--sab); }
#tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: 11px; color: var(--muted); }
#tabs button.on { color: var(--accent); }
#tabs svg { width: 24px; height: 24px; }

#fab { position: fixed; right: 18px; bottom: calc(var(--tab-h) + var(--sab) + 18px); width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: #fff; box-shadow: 0 6px 18px rgba(0,0,0,.25); display: flex; align-items: center; justify-content: center; z-index: 5; }
#fab svg { width: 26px; height: 26px; stroke-width: 2.4; }
.m-matrix #fab { display: none; }
.has-timer #fab { bottom: calc(var(--tab-h) + var(--sab) + 70px); }

#timerbar { flex: none; display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--card); border-top: 1px solid var(--line); font-size: 15px; }
#timerbar .dot { width: 10px; height: 10px; }
#timerbar .what { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#timerbar .what small { display: block; color: var(--text2); font-size: 12px; }
#timerbar .tick { font-variant-numeric: tabular-nums; font-weight: 600; }
#timerbar .stop { width: 36px; height: 36px; border-radius: 50%; background: var(--danger); color: #fff; display: flex; align-items: center; justify-content: center; }
#timerbar .stop svg { width: 14px; height: 14px; fill: #fff; stroke: none; }

/* ---------- chips / segmented ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 6px 0 10px; scrollbar-width: none; -ms-overflow-style: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-size: 14px; color: var(--text2); white-space: nowrap; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .dot { width: 9px; height: 9px; }
.chip.wrap { }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }
.seg { display: flex; background: var(--card2); border-radius: 10px; padding: 3px; margin: 4px 0 10px; }
.seg button { flex: 1; padding: 7px 0; border-radius: 8px; font-size: 14px; color: var(--text2); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }

/* ---------- sections & task rows ---------- */
.sec { margin: 14px 0 6px; display: flex; align-items: baseline; justify-content: space-between; }
.sec h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text2); }
.sec h2.red { color: var(--danger); }
.sec .n { font-size: 13px; color: var(--muted); }
.sec.link h2 { color: var(--accent); text-transform: none; letter-spacing: 0; }
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.empty { color: var(--muted); font-size: 14px; padding: 28px 12px; text-align: center; }
.task { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-bottom: 1px solid var(--line); min-height: 54px; }
.task:last-child { border-bottom: 0; }
.task .check { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--muted); flex: none; display: flex; align-items: center; justify-content: center; }
.task.q1 .check { border-color: var(--q1); }
.task.q2 .check { border-color: var(--q2); }
.task.q3 .check { border-color: var(--q3); }
.task .check svg { width: 14px; height: 14px; stroke: #fff; stroke-width: 3; opacity: 0; }
.task.done .check { background: var(--ok); border-color: var(--ok); }
.task.done .check svg { opacity: 1; }
.task .body { flex: 1; min-width: 0; }
.task .title { font-size: 16px; line-height: 1.3; overflow-wrap: anywhere; }
.task.done .title { color: var(--muted); text-decoration: line-through; }
.task .meta { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 3px; font-size: 12.5px; color: var(--text2); }
.task .meta .pj { display: inline-flex; align-items: center; gap: 5px; }
.due { font-weight: 600; }
.due.over { color: var(--danger); }
.due.today { color: var(--warn); }
.due.soon { color: var(--text); }
.doing { color: var(--accent); font-weight: 600; }
.qb { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px; flex: none; }
.qb1 { color: var(--q1); background: var(--danger-soft); }
.qb2 { color: var(--q2); background: var(--accent-soft); }
.qb3 { color: var(--q3); background: var(--warn-soft); }
.task .play { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--muted); flex: none; }
.task .play svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.task .play.on { background: var(--danger); color: #fff; }

/* ---------- agenda strip ---------- */
.strip { display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 3px; margin: 4px 0 8px; }
.strip .day { background: var(--card); border-radius: 8px; padding: 6px 0 5px; text-align: center; font-size: 10px; color: var(--muted); line-height: 1.2; min-width: 0; overflow: hidden; }
.strip .day.today { outline: 2px solid var(--accent); }
.strip .day.we { background: var(--card2); }
.strip .day b { display: block; font-size: 13px; color: var(--text); margin: 1px 0 3px; }
.strip .dots { display: flex; justify-content: center; gap: 2px; min-height: 6px; }
.strip .dots i { width: 5px; height: 5px; border-radius: 50%; display: inline-block; }
.strip .day.over { color: var(--danger); }
.dayhead { margin: 16px 0 6px; display: flex; justify-content: space-between; align-items: baseline; }
.dayhead h2 { font-size: 15px; font-weight: 700; }
.dayhead span { font-size: 13px; color: var(--text2); }
.dayhead.red h2, .dayhead.red span { color: var(--danger); }

/* ---------- matrix ---------- */
.matrix { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 8px; }
.cell { background: var(--card); border-radius: 12px; display: flex; flex-direction: column; min-height: 0; overflow: hidden; border-top: 4px solid var(--q4); }
.cell.c1 { border-color: var(--q1); } .cell.c2 { border-color: var(--q2); } .cell.c3 { border-color: var(--q3); }
.cell header { padding: 7px 8px 5px 10px; display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--line); }
.cell header b { font-size: 13px; }
.cell header small { color: var(--muted); font-size: 10.5px; flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cell header .n { font-size: 12px; color: var(--muted); }
.cell header .add { width: 26px; height: 26px; border-radius: 50%; background: var(--card2); display: flex; align-items: center; justify-content: center; color: var(--text2); }
.cell header .add svg { width: 14px; height: 14px; stroke-width: 2.4; }
.cell .rows { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.mrow { padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 13.5px; line-height: 1.25; }
.mrow:last-child { border-bottom: 0; }
.mrow .m { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text2); margin-top: 2px; }
.mrow .m .dot { width: 7px; height: 7px; }
.mrow .m .due { margin-left: auto; }

/* ---------- projects ---------- */
.pcard { background: var(--card); border-radius: var(--radius); padding: 14px 14px 12px; margin-bottom: 10px; border-left: 5px solid var(--line); }
.pcard .h { display: flex; align-items: center; justify-content: space-between; }
.pcard .h b { font-size: 17px; }
.pcard .h span { color: var(--muted); font-size: 13px; }
.pcard .stats { display: flex; gap: 16px; margin-top: 8px; font-size: 13px; color: var(--text2); }
.pcard .stats b { color: var(--text); font-weight: 600; }
.pcard .stats .over b { color: var(--danger); }
.pcard .bar { height: 5px; border-radius: 3px; background: var(--card2); margin-top: 10px; overflow: hidden; display: flex; gap: 2px; }
.pcard .bar i { display: block; height: 100%; }
.phead { display: flex; align-items: center; gap: 10px; margin: 6px 0 8px; }
.phead .back { width: 36px; height: 36px; border-radius: 50%; background: var(--card); display: flex; align-items: center; justify-content: center; flex: none; }
.phead h1 { font-size: 24px; flex: 1; display: flex; align-items: center; gap: 10px; }
.phead h1 .dot { width: 14px; height: 14px; }
.phead .ic { width: 36px; height: 36px; border-radius: 50%; background: var(--card); display: flex; align-items: center; justify-content: center; }
.phead .ic.on { background: var(--danger); color: #fff; }
.phead .ic svg.fill { fill: currentColor; stroke: none; width: 16px; height: 16px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 6px; }
.kpi { background: var(--card); border-radius: 12px; padding: 10px 12px; }
.kpi b { display: block; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 12px; color: var(--text2); }
.kpi.over b { color: var(--danger); }

/* ---------- time ---------- */
.hero { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; }
.hero b { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.hero span { color: var(--text2); font-size: 14px; margin-left: 8px; }
.bars { background: var(--card); border-radius: var(--radius); padding: 6px 14px; }
.brow { display: grid; grid-template-columns: 84px 1fr 62px; align-items: center; gap: 10px; padding: 8px 0; }
.brow .lbl { display: flex; align-items: center; gap: 6px; font-size: 14px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.brow .track { height: 14px; background: var(--card2); border-radius: 4px; overflow: hidden; }
.brow .track i { display: block; height: 100%; border-radius: 0 4px 4px 0; min-width: 3px; }
.brow .val { text-align: right; font-size: 14px; font-variant-numeric: tabular-nums; color: var(--text); }
.brow .val small { display: block; color: var(--muted); font-size: 11px; }
.entry { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
.entry:last-child { border-bottom: 0; }
.entry .b { flex: 1; min-width: 0; }
.entry .t { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.entry .s { color: var(--text2); font-size: 12px; }
.entry .d { font-variant-numeric: tabular-nums; font-weight: 600; }
.entry.run .d { color: var(--danger); }

/* ---------- sheet ---------- */
#backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
#sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--bg); border-radius: 18px 18px 0 0; max-height: 92dvh; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 16px calc(var(--sab) + 20px); box-shadow: 0 -8px 30px rgba(0,0,0,.2); animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .5 } to { transform: none; opacity: 1 } }
.sh { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 10px; }
.sh h3 { font-size: 17px; }
.sh button { color: var(--accent); font-weight: 600; font-size: 16px; padding: 4px 2px; }
.sh button.danger { color: var(--danger); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text2); margin-bottom: 6px; }
.field input[type=text], .field input[type=number], .field input[type=date], .field input[type=datetime-local], .field textarea, .ttl {
  width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: 17px;
}
.field textarea { min-height: 72px; resize: vertical; font-size: 16px; }
.ttl { font-size: 19px; font-weight: 600; margin-bottom: 10px; }
.row2 { display: flex; gap: 8px; align-items: center; }
.row2 > * { flex: 1; }
.mini { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.mini button { padding: 10px 8px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); text-align: left; font-size: 14px; }
.mini button small { display: block; font-size: 11px; color: var(--muted); }
.mini button.on { border-color: var(--text); background: var(--text); color: var(--bg); }
.mini button.on small { color: var(--bg); opacity: .8; }
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 13px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); font-weight: 600; width: 100%; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.rec { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn svg.fill { fill: currentColor; stroke: none; width: 14px; height: 14px; }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 10px; line-height: 1.5; }
.preview { display: flex; flex-wrap: wrap; gap: 6px; min-height: 22px; margin: 8px 0 4px; font-size: 13px; color: var(--text2); }
.preview span { background: var(--card2); border-radius: 6px; padding: 2px 8px; display: inline-flex; align-items: center; gap: 5px; }
.logged { font-size: 14px; color: var(--text2); text-align: center; margin: -6px 0 12px; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatches button { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; }
.swatches button.on { border-color: var(--text); }
.small { font-size: 13px; color: var(--text2); }

#toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--sab) + 84px); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-size: 14px; z-index: 30; max-width: 85vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (min-width: 700px) {
  #app { max-width: 640px; margin: 0 auto; }
  #sheet { max-width: 640px; margin: 0 auto; }
  #fab { right: calc(50% - 320px + 18px); }
}
