:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --border: #e2e5ee;
  --text: #171a26;
  --muted: #646b80;
  --accent: var(--pcolor, #4f46e5);
  --accent-ink: #ffffff;
  --accent-soft: color-mix(in srgb, var(--accent) 13%, #ffffff);
  --high: #e5484d;
  --high-soft: #fde8e8;
  --medium: #e38a07;
  --medium-soft: #fdf0dc;
  --low: #2f8f6a;
  --low-soft: #dff3ea;
  --overdue: #d6323a;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 4px 16px rgba(20, 24, 40, .06);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #181b24;
    --surface-2: #222632;
    --border: #2b3040;
    --text: #eef0f6;
    --muted: #9aa1b5;
    --accent: color-mix(in srgb, var(--pcolor, #4f46e5) 62%, #ffffff);
    --accent-ink: #11131a;
    --accent-soft: color-mix(in srgb, var(--accent) 20%, #181b24);
    --high: #ff6b6f;
    --high-soft: #3a1f23;
    --medium: #f5a623;
    --medium-soft: #3a2d17;
    --low: #4cc296;
    --low-soft: #183027;
    --overdue: #ff6b6f;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.app { min-height: 100vh; min-height: 100dvh; }
.sidebar { display: none; }
.main {
  max-width: 760px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 120px);
}

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 260px 1fr; }
  .sidebar {
    display: flex; flex-direction: column; gap: 6px;
    position: sticky; top: 0; height: 100vh;
    padding: 20px 14px; border-right: 1px solid var(--border);
    background: var(--surface); overflow-y: auto;
  }
  .main { padding: 28px 40px 60px; width: 100%; }
  .mobile-only { display: none !important; }
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 4px 8px 14px; }
.brand img { border-radius: 8px; }
.side-heading { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 18px 10px 6px; font-weight: 600; }
.side-views, .side-cats { display: flex; flex-direction: column; gap: 2px; }
.side-cats { flex: 1; }
.side-link {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: 0; background: none; text-align: left;
  padding: 9px 10px; border-radius: 10px; color: var(--text); font-size: 15px;
}
.side-link:hover { background: var(--surface-2); }
.side-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-link .count { margin-left: auto; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.side-link.active .count { color: var(--accent); }
.side-link.muted { color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--muted)); flex: none; }

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.eyebrow { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
h1 { margin: 2px 0 0; font-size: 30px; letter-spacing: -.02em; line-height: 1.1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.sync-pill { font-size: 12px; padding: 4px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.sync-pill.warn { background: var(--medium-soft); color: var(--medium); }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0;
  display: inline-grid; place-items: center;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.icon-btn:hover { background: var(--surface-2); }

/* ---------- Notice ---------- */
.notice {
  display: flex; gap: 12px; align-items: center;
  background: var(--accent-soft); color: var(--text);
  padding: 12px 14px; border-radius: var(--radius); margin-bottom: 14px; font-size: 14px;
}
.notice svg { color: var(--accent); }
.notice .grow { flex: 1; }
.notice .btn { white-space: nowrap; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.stat {
  border: 0; text-align: left; background: var(--surface); border-radius: var(--radius);
  padding: 10px 12px; box-shadow: var(--shadow); min-width: 0;
}
.stat .n { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; display: block; }
.stat .l { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.stat.overdue .n { color: var(--overdue); }
.stat.active { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- Category chips (mobile) ---------- */
.cat-chips {
  display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 10px; padding: 2px 16px 4px;
  scrollbar-width: none;
}
.cat-chips::-webkit-scrollbar { display: none; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 6px 12px; border-radius: 999px; font-size: 14px;
}
.chip-btn.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- Filters ---------- */
.filters { display: flex; gap: 8px; margin-bottom: 16px; }
.search {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0 12px;
  color: var(--muted);
}
.search input { border: 0; outline: 0; background: none; width: 100%; padding: 10px 0; color: var(--text); font-size: 16px; }
.filters select {
  border: 1px solid var(--border); background: var(--surface); border-radius: 12px; padding: 0 10px;
  font-size: 14px; min-width: 0; max-width: 140px; height: 42px;
}
@media (max-width: 520px) {
  .filters { flex-wrap: wrap; }
  .search { flex-basis: 100%; }
  .filters select { flex: 1; max-width: none; }
}

/* ---------- List ---------- */
.group { margin-bottom: 20px; }
.group-head {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  padding: 0 4px 8px;
}
.group-head.overdue { color: var(--overdue); }
.group-head .c { font-weight: 600; opacity: .8; }

.task {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px 12px 12px; margin-bottom: 8px; position: relative; overflow: hidden;
  transition: opacity .25s, transform .25s;
}
.task::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--pc); }
.task.p-high { --pc: var(--high); }
.task.p-medium { --pc: var(--medium); }
.task.p-low { --pc: var(--low); }
.task.leaving { opacity: 0; transform: translateX(20px); }

.check {
  width: 26px; height: 26px; border-radius: 50%; flex: none; margin-top: 1px;
  border: 2px solid var(--pc); background: transparent; display: grid; place-items: center; padding: 0;
  color: transparent;
}
.check svg { width: 16px; height: 16px; stroke-width: 3; }
.check:hover { background: color-mix(in srgb, var(--pc) 14%, transparent); }
.task.done .check { background: var(--pc); color: #fff; }
.task.done .t-title { text-decoration: line-through; color: var(--muted); }

.t-body { flex: 1; min-width: 0; cursor: pointer; }
.t-title { font-weight: 600; font-size: 16px; word-wrap: break-word; }
.t-notes { color: var(--muted); font-size: 14px; margin-top: 3px; white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.t-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; align-items: center; }
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.5px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.tag svg { width: 13px; height: 13px; }
.tag.due.overdue { background: var(--high-soft); color: var(--overdue); }
.tag.due.today { background: var(--accent-soft); color: var(--accent); }
.tag.cat { background: color-mix(in srgb, var(--c) 15%, transparent); color: var(--c); }
.tag.prio-high { background: var(--high-soft); color: var(--high); }
.tag.prio-medium { background: var(--medium-soft); color: var(--medium); }
.tag.prio-low { background: var(--low-soft); color: var(--low); }

.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty .big { font-size: 40px; margin-bottom: 8px; }
.empty h3 { color: var(--text); margin: 0 0 6px; font-size: 18px; }
.empty p { margin: 0 0 16px; }

/* ---------- Tab bar + FAB (mobile) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--border);
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
}
.tab {
  border: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; font-weight: 600; padding: 4px 0;
}
.tab svg { width: 22px; height: 22px; }
a.tab, a.side-link { text-decoration: none; }
.tab.active { color: var(--accent); }
.tab .badge { position: absolute; transform: translate(12px, -4px); background: var(--overdue); color: #fff; font-size: 10px; border-radius: 999px; padding: 0 5px; min-width: 16px; line-height: 16px; }
.tab-icon { position: relative; display: grid; place-items: center; }
.fab {
  position: fixed; right: 18px; bottom: calc(env(safe-area-inset-bottom) + 78px); z-index: 21;
  width: 58px; height: 58px; border-radius: 18px; border: 0;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 45%, transparent);
}
.fab svg { width: 26px; height: 26px; stroke-width: 2.5; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 10px 16px; font-weight: 600; font-size: 15px;
  background: var(--surface-2); color: var(--text);
}
a.btn { text-decoration: none; }
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--high); }
.btn.small { padding: 7px 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.linkish { border: 0; background: none; color: var(--muted); text-decoration: underline; font-size: 14px; padding: 8px; width: 100%; }

/* ---------- Dialogs / sheets ---------- */
dialog.sheet {
  border: 0; padding: 0; color: var(--text); background: var(--surface);
  width: min(560px, 100%); max-height: 92vh; max-height: 92dvh;
  border-radius: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog.sheet::backdrop { background: rgba(10, 12, 20, .45); }
@media (max-width: 640px) {
  dialog.sheet {
    margin: auto 0 0; width: 100%; max-width: 100%;
    border-radius: 20px 20px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  dialog.sheet[open] { animation: up .22s ease-out; }
}
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet form { display: contents; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 16px 4px 20px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet-head .icon-btn { box-shadow: none; background: var(--surface-2); width: 34px; height: 34px; border-radius: 50%; }
.sheet-body { padding: 10px 20px 8px; display: flex; flex-direction: column; gap: 14px; }
.sheet-foot { display: flex; gap: 8px; align-items: center; padding: 12px 20px 18px; border-top: 1px solid var(--border); margin-top: 6px; }
.spacer { flex: 1; }

.field { display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, .field > legend { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0; }
.field em { font-weight: 400; font-style: normal; }
.field input, .field textarea, .field select, .cat-new input {
  width: 100%; border: 1px solid var(--border); background: var(--bg); border-radius: 12px;
  padding: 11px 12px; font-size: 16px; outline: none; min-height: 46px;
  -webkit-appearance: none; appearance: none;
}
.field select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.field input:focus, .field textarea:focus, .field select:focus, .cat-new input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field textarea { resize: vertical; min-height: 60px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: -6px; }
.quick button { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 5px 11px; font-size: 13px; color: var(--muted); }
.quick button:hover { color: var(--text); }
.cat-row { display: flex; gap: 8px; }
.cat-row select { flex: 1; }
.cat-new { display: flex; gap: 8px; margin-top: -6px; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span {
  display: block; text-align: center; padding: 10px 0; border-radius: 12px; font-weight: 600; font-size: 15px;
  border: 1px solid var(--border); background: var(--bg); color: var(--muted);
}
.seg-low input:checked + span { background: var(--low-soft); color: var(--low); border-color: var(--low); }
.seg-medium input:checked + span { background: var(--medium-soft); color: var(--medium); border-color: var(--medium); }
.seg-high input:checked + span { background: var(--high-soft); color: var(--high); border-color: var(--high); }
.seg input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }
.hint { margin: -6px 0 0; font-size: 13px; color: var(--muted); }
.form-error { margin: 0; color: var(--high); font-size: 14px; }

/* Auth */
.auth-hero { text-align: center; padding: 28px 24px 4px; }
.auth-hero img { border-radius: 14px; }
.auth-hero h2 { margin: 10px 0 4px; }
.auth-hero p { margin: 0; color: var(--muted); font-size: 15px; }
dialog.auth .sheet-body { padding-bottom: 20px; }

/* Settings */
.set-card { background: var(--bg); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.set-card h3 { margin: 0; font-size: 15px; }
.set-card p { margin: 0; font-size: 14px; color: var(--muted); }
.set-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 10px; }
.status.ok { background: var(--low-soft); color: var(--low); }
.status.off { background: var(--surface-2); color: var(--muted); }
.status.warn { background: var(--medium-soft); color: var(--medium); }
.cat-edit { display: flex; align-items: center; gap: 8px; }
.cat-edit .swatch { width: 28px; height: 28px; border-radius: 8px; border: 0; background: var(--c); flex: none; }
.cat-edit input { flex: 1; min-width: 0; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 7px 10px; font-size: 15px; }
.cat-edit .icon-btn { width: 34px; height: 34px; box-shadow: none; background: transparent; color: var(--muted); }
.steps { margin: 0; padding-left: 20px; font-size: 14px; color: var(--muted); }
.steps li { margin: 2px 0; }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 100;
  bottom: calc(env(safe-area-inset-bottom) + 150px);
  background: var(--text); color: var(--bg);
  padding: 10px 12px 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 500;
  display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow); max-width: calc(100% - 32px);
}
.toast button { border: 0; background: none; color: var(--accent); font-weight: 700; padding: 4px 6px; filter: brightness(1.3); }
@media (min-width: 900px) { .toast { bottom: 28px; } }

/* ---------- Profiles ---------- */
.profile-switch {
  display: flex; gap: 4px; padding: 4px; border-radius: 14px;
  background: var(--surface-2); overflow-x: auto; scrollbar-width: none;
}
.profile-switch::-webkit-scrollbar { display: none; }
.profile-switch.top { margin-bottom: 14px; }
.profile-switch.side { margin: 0 0 10px; }
.pswitch {
  flex: 1 0 auto; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; background: transparent; color: var(--muted);
  padding: 8px 14px; border-radius: 10px; font-weight: 600; font-size: 15px; white-space: nowrap;
}
.pswitch .dot { background: var(--c); }
.pswitch.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow), inset 0 0 0 1.5px color-mix(in srgb, var(--c) 55%, transparent); }
.pswitch .pbadge { background: var(--overdue); color: #fff; font-size: 11px; border-radius: 999px; padding: 0 6px; line-height: 17px; }
.prof-edit { display: flex; flex-direction: column; gap: 6px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.prof-edit:last-child { border-bottom: 0; padding-bottom: 0; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); padding-left: 36px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.cat-edit .icon-btn:disabled { opacity: .3; cursor: default; }
.cal-row { display: flex; flex-direction: column; gap: 8px; padding: 10px 0; border-top: 1px solid var(--border); }
.cal-name { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }

/* ---------- Repeat day picker ---------- */
.days-wrap { display: flex; flex-direction: column; gap: 8px; margin-top: -6px; }
.days-wrap .hint { margin: 0; }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day {
  border: 1px solid var(--border); background: var(--bg); color: var(--muted);
  border-radius: 10px; padding: 9px 0; font-size: 13px; font-weight: 600; min-width: 0;
}
.day.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.freq-label { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 4px; }
.days.weeks { grid-template-columns: repeat(5, 1fr); }
.seg-freq span { font-size: 14px; padding: 9px 0; }
.seg-freq input:checked + span { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
#fWeekWrap { display: flex; flex-direction: column; gap: 8px; }
#fWeekWrap[hidden] { display: none; }

/* ---------- All-day switch ---------- */
.row2.single { grid-template-columns: 1fr; }
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: -4px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.switch-row em { font-style: normal; font-weight: 400; color: var(--muted); font-size: 13px; }
.switch-row input {
  -webkit-appearance: none; appearance: none; flex: none; margin: 0; cursor: pointer;
  width: 46px; height: 28px; border-radius: 999px; background: var(--border); position: relative; transition: background .15s;
}
.switch-row input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s;
}
.switch-row input:checked { background: var(--accent); }
.switch-row input:checked::after { transform: translateX(18px); }
.switch-row input:disabled { opacity: .4; cursor: default; }
.switch-row input:focus-visible { box-shadow: 0 0 0 3px var(--accent-soft); }
.switch-row[hidden] { display: none; }
