/* Taskflow web. Colors follow the native app (Theme.swift). */
:root {
  --bg: #F5F6FA;
  --surface: #FFFFFF;
  --hover: #F1F2F7;
  --border: #E5E7EB;
  --text: #1F2430;
  --muted: #64748B;
  --faint: #94A3B8;
  --accent: #6366F1;
  --accent-2: #8B5CF6;
  --accent-soft: rgba(99, 102, 241, .12);
  --green: #22C55E;
  --amber: #F59E0B;
  --red: #EF4444;
  --red-soft: rgba(239, 68, 68, .12);
  --blue: #3B82F6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-lg: 0 20px 50px rgba(16, 24, 40, .18);
  --radius: 14px;
  --sidebar: 260px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0F1117; --surface: #1B1F2B; --hover: #232838; --border: #2A3040;
  --text: #E8EAF0; --muted: #9AA3B5; --faint: #6B7488;
  --accent-soft: rgba(99, 102, 241, .2); --red-soft: rgba(239, 68, 68, .18);
  --shadow: none; --shadow-lg: 0 20px 50px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1117; --surface: #1B1F2B; --hover: #232838; --border: #2A3040;
    --text: #E8EAF0; --muted: #9AA3B5; --faint: #6B7488;
    --accent-soft: rgba(99, 102, 241, .2); --red-soft: rgba(239, 68, 68, .18);
    --shadow: none; --shadow-lg: 0 20px 50px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  -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); text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

/* ---------- buttons and inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: 8px 14px; font-weight: 550; min-height: 38px; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.icon { padding: 0; width: 38px; }
.btn:disabled { opacity: .5; cursor: default; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: 9px 12px; min-height: 40px; outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; min-height: 80px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 13px; transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }

/* ---------- auth screens ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 28px; box-shadow: var(--shadow); }
.auth-card .logo { width: 56px; height: 56px; border-radius: 14px; display: block; margin: 0 auto 14px; }
.auth-card h1 { text-align: center; font-size: 22px; margin: 0 0 4px; }
.auth-card p.lead { text-align: center; color: var(--muted); margin: 0 0 22px; }
.auth-card .btn.primary { width: 100%; margin-top: 6px; }
.error { color: var(--red); font-size: 14px; min-height: 20px; margin: 4px 0; }

/* ---------- layout ---------- */
#root { height: 100%; }
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; height: 100vh; height: 100dvh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto;
  padding: calc(16px + var(--safe-top)) 12px calc(16px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 4px 10px 12px; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.side-section { margin-top: 10px; }
.side-title { display: flex; align-items: center; justify-content: space-between; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); padding: 6px 10px; }
.side-item {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; text-align: left;
  padding: 8px 10px; border-radius: 9px; color: var(--text); min-height: 38px;
}
.side-item:hover { background: var(--hover); }
.side-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-item .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item .count { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--hover); border-radius: 999px; padding: 1px 8px; }
.side-item.active .count { background: transparent; color: var(--accent); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.side-spacer { flex: 1; }
.side-item.add { color: var(--accent); }

.main { overflow-y: auto; height: 100%; position: relative; }
.main-inner { max-width: 860px; margin: 0 auto; padding: calc(24px + var(--safe-top)) 24px calc(100px + var(--safe-bottom)); }
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.topbar h1 { font-size: 28px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: -.01em; }
.menu-btn { display: none; }
.subtitle { color: var(--muted); font-size: 14px; margin-bottom: 18px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; }
.toolbar .search { flex: 1; }
.toolbar select { width: auto; }

.quick {
  display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 6px 6px 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.quick:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.quick input { flex: 1; border: 0; outline: 0; background: transparent; min-height: 38px; min-width: 0; }
.quick .plus { color: var(--accent); }

/* ---------- task rows ---------- */
.tasks { display: flex; flex-direction: column; gap: 10px; }
.task {
  position: relative; display: flex; gap: 14px; align-items: flex-start; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 14px 24px; box-shadow: var(--shadow);
}
.task::before { content: ""; position: absolute; left: 10px; top: 14px; bottom: 14px; width: 4px; border-radius: 2px; background: var(--prio, var(--accent)); }
.task.done { opacity: .6; }
.task .check {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--faint); background: transparent; flex: none;
  display: grid; place-items: center; margin-top: 1px; padding: 0; color: #fff;
}
.task .check:hover { border-color: var(--accent); }
.task.done .check { background: var(--accent); border-color: var(--accent); }
.task .check svg { width: 14px; height: 14px; stroke-width: 3; opacity: 0; }
.task.done .check svg { opacity: 1; }
.task .body { flex: 1; min-width: 0; cursor: pointer; }
.task .title { font-weight: 600; font-size: 16px; word-wrap: break-word; }
.task.done .title { text-decoration: line-through; }
.task .notes { color: var(--muted); font-size: 14px; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--hover); color: var(--muted); }
.tag svg { width: 12px; height: 12px; }
.tag.overdue { background: var(--red-soft); color: var(--red); }
.tag.today { background: var(--accent-soft); color: var(--accent); }
.subs { margin-top: 8px; font-size: 13px; color: var(--muted); }
.subs .sub { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.subs .sub.done span { text-decoration: line-through; color: var(--faint); }
.mini-check { width: 15px; height: 15px; border-radius: 4px; border: 1.5px solid var(--faint); background: transparent; padding: 0; flex: none; display: grid; place-items: center; color: #fff; }
.mini-check svg { width: 10px; height: 10px; stroke-width: 3.5; opacity: 0; }
.sub.done .mini-check { background: var(--accent); border-color: var(--accent); }
.sub.done .mini-check svg { opacity: 1; }
.task .more { opacity: 0; transition: opacity .15s; }
.task:hover .more { opacity: 1; }
@media (hover: none) { .task .more { opacity: 1; } }

.done-header { display: flex; align-items: center; gap: 8px; margin: 22px 0 10px; color: var(--muted); }
.done-header button.toggle { display: flex; align-items: center; gap: 8px; border: 0; background: transparent; color: inherit; font-weight: 600; padding: 4px 0; }
.done-header .chev { transition: transform .15s; }
.done-header.open .chev { transform: rotate(90deg); }
.done-header .count { font-size: 12px; font-weight: 600; background: var(--hover); border-radius: 999px; padding: 1px 8px; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty svg { width: 44px; height: 44px; color: var(--faint); margin-bottom: 10px; }
.empty h3 { color: var(--text); margin: 0 0 4px; }

.fab {
  display: none; position: fixed; right: 20px; bottom: calc(20px + var(--safe-bottom)); width: 56px; height: 56px; border-radius: 50%;
  border: 0; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 8px 24px rgba(99,102,241,.45); z-index: 20;
}
.fab svg { width: 26px; height: 26px; }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.cal-head h2 { margin: 0; font-size: 20px; flex: 1; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-wd { font-size: 12px; font-weight: 700; color: var(--faint); text-align: center; padding: 4px 0; text-transform: uppercase; }
.cal-day {
  min-height: 92px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px;
  text-align: left; display: flex; flex-direction: column; gap: 3px; overflow: hidden; cursor: pointer;
}
.cal-day:hover { border-color: var(--accent); }
.cal-day.other { opacity: .45; }
.cal-day.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.cal-day .num { font-size: 13px; font-weight: 600; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; }
.cal-day.today .num { background: var(--accent); color: #fff; }
.cal-chip { font-size: 11.5px; padding: 1px 6px; border-radius: 5px; background: var(--hover); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 3px solid var(--c, var(--accent)); }
.cal-chip.done { text-decoration: line-through; opacity: .6; }
.cal-more { font-size: 11px; color: var(--muted); padding-left: 4px; }
.cal-dots { display: none; gap: 3px; flex-wrap: wrap; }
.cal-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--c, var(--accent)); }
.cal-list { margin-top: 20px; }
.cal-list h3 { font-size: 17px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }

/* ---------- settings ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card h2 { font-size: 17px; margin: 0 0 4px; display: flex; align-items: center; gap: 8px; }
.card > p.muted { margin: 0 0 14px; font-size: 14px; }
.set-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.set-row:first-of-type { border-top: 0; }
.set-row .lbl { flex: 1; min-width: 0; }
.set-row .lbl small { display: block; color: var(--muted); font-size: 13px; }
.seg { display: inline-flex; background: var(--hover); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-weight: 550; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.copy-box { display: flex; gap: 8px; align-items: center; }
.copy-box input { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
ol.steps { padding-left: 20px; margin: 10px 0 0; font-size: 14px; }
ol.steps li { margin-bottom: 6px; }
.note { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 10px 0; }
.note.warn { background: rgba(245, 158, 11, .14); }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 6px 8px; }
table.list td { padding: 8px; border-top: 1px solid var(--border); vertical-align: middle; }
.badge { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); }
.badge.off { background: var(--red-soft); color: var(--red); }

/* ---------- dialogs ---------- */
dialog {
  border: 0; padding: 0; border-radius: 18px; background: var(--surface); color: var(--text);
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 40px); box-shadow: var(--shadow-lg);
}
dialog:focus { outline: none; }
.dlg-head h2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
dialog::backdrop { background: rgba(15, 17, 23, .45); backdrop-filter: blur(2px); }
.dlg { display: flex; flex-direction: column; max-height: calc(100dvh - 40px); }
.dlg-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.dlg-head h2 { margin: 0; font-size: 17px; flex: 1; text-align: center; }
.dlg-body { padding: 18px; overflow-y: auto; }
.dlg-foot { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.title-input { font-size: 18px; font-weight: 600; border: 0; outline: 0; width: 100%; background: transparent; padding: 4px 0 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sub-edit { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.sub-edit input[type="text"] { flex: 1; border: 0; border-bottom: 1px solid var(--border); background: transparent; padding: 6px 2px; outline: 0; min-width: 0; }
.sub-edit input[type="text"]:focus { border-bottom-color: var(--accent); }
.sub-edit.done input[type="text"] { text-decoration: line-through; color: var(--faint); }
.colors { display: flex; flex-wrap: wrap; gap: 10px; }
.colors button { width: 32px; height: 32px; border-radius: 50%; border: 3px solid transparent; outline: 2px solid transparent; }
.colors button.on { outline-color: var(--text); border-color: var(--surface); }


/* ---------- swipe rows ---------- */
.swipe { position: relative; border-radius: var(--radius); }
.swipe .task { position: relative; z-index: 1; touch-action: pan-y; }
.swipe-bg {
  position: absolute; inset: 0; border-radius: var(--radius); display: none; align-items: center; gap: 8px;
  padding: 0 22px; font-weight: 700; color: #fff; font-size: 14px;
}
.swipe-bg svg { width: 20px; height: 20px; }
.swipe .done-bg { background: var(--green); justify-content: flex-start; }
.swipe .del-bg { background: var(--red); justify-content: flex-end; }
.swipe[data-dir="right"] .done-bg, .swipe[data-dir="left"] .del-bg { display: flex; opacity: .55; }
.swipe.armed[data-dir="right"] .done-bg, .swipe.armed[data-dir="left"] .del-bg { opacity: 1; }

/* ---------- tab bar (phones only) ---------- */
.tabbar { display: none; }
.grabber { display: none; }
dialog.compact { width: min(420px, calc(100vw - 24px)); }
dialog.compact .dlg { height: auto; }

/* ---------- toasts ---------- */
#toasts { position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none; }
.toast { background: #1F2430; color: #fff; padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow-lg); font-size: 14px; display: flex; gap: 12px; align-items: center; pointer-events: auto; animation: tin .2s ease-out; }
.toast.err { background: var(--red); }
.toast button { background: transparent; border: 0; color: #A5B4FC; font-weight: 700; padding: 0; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

/* ---------- mobile ---------- */
.scrim { display: none; }
@media (max-width: 820px) {
  :root { --tabbar: 58px; }
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 85vw); z-index: 40; transform: translateX(-105%);
    transition: transform .22s ease; box-shadow: var(--shadow-lg);
  }
  .app.drawer .sidebar { transform: none; }
  .app.drawer .scrim { display: block; position: fixed; inset: 0; background: rgba(15,17,23,.4); z-index: 30; }
  .menu-btn { display: inline-flex; margin-left: -8px; }
  .main-inner { padding: calc(10px + var(--safe-top)) 12px calc(var(--tabbar) + 96px + var(--safe-bottom)); }
  .topbar h1 { font-size: 26px; }
  .subtitle { margin-bottom: 12px; font-size: 13px; }
  .topbar .new-btn { display: none; }

  /* bottom tab bar */
  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    height: calc(var(--tabbar) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
    background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px);
    border-top: 1px solid var(--border);
  }
  .tab { border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--faint); font-size: 10.5px; font-weight: 600; padding: 0; }
  .tab.active { color: var(--accent); }
  .tab-ic { position: relative; display: grid; place-items: center; }
  .tab-ic svg { width: 24px; height: 24px; }
  .tab-badge { position: absolute; top: -5px; left: 15px; min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px; background: var(--red); color: #fff; font-size: 10.5px; line-height: 17px; text-align: center; }
  .fab { display: grid; place-items: center; bottom: calc(var(--tabbar) + 16px + var(--safe-bottom)); right: 16px; width: 54px; height: 54px; }
  #toasts { bottom: calc(var(--tabbar) + 84px + var(--safe-bottom)); }

  /* compact list */
  .quick { padding: 4px 4px 4px 12px; margin-bottom: 10px; }
  .toolbar { margin-bottom: 10px; }
  .tasks { gap: 8px; }
  .task { gap: 12px; padding: 11px 12px 11px 20px; }
  .task::before { left: 8px; top: 11px; bottom: 11px; width: 3px; }
  .task .check { width: 22px; height: 22px; }
  .task .title { font-size: 15px; line-height: 1.35; }
  .task .notes { font-size: 13px; -webkit-line-clamp: 1; }
  .tags { gap: 4px; margin-top: 6px; }
  .tag { font-size: 11px; padding: 1px 6px; }
  .subs { margin-top: 5px; font-size: 12px; }
  .subs .sub, .subs .muted { display: none; }
  .task .more { display: none; }
  .tag.prio-mid { display: none; }
  .done-header { margin: 16px 0 8px; }

  /* calendar */
  .cal-day { min-height: 54px; padding: 4px; align-items: center; }
  .cal-day .cal-chip, .cal-day .cal-more { display: none; }
  .cal-day .cal-dots { display: flex; justify-content: center; }
  .cal-grid { gap: 4px; }
  .grid2 { grid-template-columns: 1fr; }

  /* dialogs as sheets from the bottom */
  dialog, dialog.compact {
    width: 100vw; max-width: 100vw; margin: auto 0 0; height: auto; max-height: 92dvh;
    border-radius: 20px 20px 0 0; animation: sheet-up .26s cubic-bezier(.2, .8, .2, 1);
  }
  dialog::backdrop { animation: fade-in .2s ease; }
  .dlg, dialog.compact .dlg { height: auto; max-height: calc(92dvh - 20px); padding-bottom: var(--safe-bottom); }
  .grabber { display: block; width: 38px; height: 5px; border-radius: 3px; background: var(--border); margin: 8px auto 0; }
  .dlg-head { border-bottom: 0; padding-top: 6px; }
  .hide-mobile { display: none; }
  table.list .hide-mobile { display: none; }
}
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes fade-in { from { opacity: 0; } }
