/* Tasks: Ari's task app. Phone first; a sidebar layout from 900px. Light/dark follow the system.
   Ari's purple #590896, its light partner #cbb2e6, pale #f7f1fc. */
:root {
  --accent: #590896; --accent-2: #cbb2e6; --pale: #f7f1fc;
  --bg: #ffffff; --surface: #ffffff; --surface-2: #f7f1fc; --line: #ece4f3; --text: #1d1622; --muted: #6f6578;
  --on-accent: #ffffff; --green: #1f8a4c; --warn: #a2540b; --danger: #b3261e; --scrim: rgba(20, 8, 28, .38);
  --chip: #f1e8f8; --chip-text: #4a1e66; --shadow: 0 6px 24px rgba(40, 10, 60, .16), 0 1px 3px rgba(40, 10, 60, .12);
  --radius: 14px; --row-h: 56px; --tabs-h: 64px; --top-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent: #cbb2e6; --bg: #141017; --surface: #1d1722; --surface-2: #251d2c; --line: #30273a; --text: #f1eaf6;
    --muted: #a99db4; --on-accent: #2a0b3f; --green: #5fd18e; --warn: #f0b36a; --danger: #ffb4ab; --scrim: rgba(0, 0, 0, .55);
    --chip: #2f2338; --chip-text: #e3d2f2; --pale: #251d2c; --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text);
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sm svg.i, svg.i.sm { width: 15px; height: 15px; stroke-width: 2.1; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- buttons ---------- */
.btn { border: 0; border-radius: 999px; padding: 10px 18px; background: var(--surface-2); font-weight: 600; display: inline-flex; align-items: center; gap: 8px; justify-content: center; }
.btn.primary { background: #590896; color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { background: var(--accent-2); color: #2a0b3f; } }
.btn.wide { width: 100%; padding: 13px; }
.btn.round { width: 44px; height: 44px; padding: 0; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn { border: 0; background: transparent; width: 44px; height: 44px; border-radius: 50%; display: inline-grid; place-items: center; flex: none; }
.icon-btn:active { background: var(--surface-2); }
.link { color: var(--accent); }

/* ---------- gate ---------- */
.gate { min-height: 100%; display: grid; place-items: center; padding: 24px; background: var(--surface-2); }
.gate-card { width: min(380px, 100%); background: var(--surface); border-radius: 24px; padding: 32px 24px; text-align: center; box-shadow: var(--shadow); display: grid; gap: 14px; }
.gate-logo { justify-self: center; border-radius: 18px; }
.gate h1 { margin: 0; font-size: 26px; }
.gate p { margin: 0; color: var(--muted); }
.gate input { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); }
.err { color: var(--danger) !important; min-height: 1.2em; }

/* ---------- layout ---------- */
.app { min-height: 100%; }
.main { min-height: 100vh; padding-bottom: calc(var(--tabs-h) + var(--safe-b) + 84px); }
.topbar {
  position: sticky; top: 0; z-index: 5; height: calc(var(--top-h) + var(--safe-t)); padding: var(--safe-t) 4px 0;
  display: flex; align-items: center; gap: 2px; background: var(--bg); border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.title { flex: 1; margin: 0 6px; font-size: 21px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.keel-btn { font-size: 19px; filter: grayscale(1); opacity: .5; }
.keel-btn[aria-pressed="true"] { filter: none; opacity: 1; background: var(--chip); }
.subbar { padding: 0 16px 8px; color: var(--muted); font-size: 14px; }
.view { outline: none; }

/* drawer: an overlay on phones, a sidebar on wide screens */
.drawer {
  position: fixed; inset: 0 auto 0 0; width: min(304px, 84vw); z-index: 30; background: var(--surface);
  transform: translateX(-102%); transition: transform .22s ease; display: flex; flex-direction: column;
  padding: var(--safe-t) 0 var(--safe-b); box-shadow: var(--shadow); overflow-y: auto;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 18px 20px 10px; font-weight: 700; font-size: 19px; }
.drawer-head img { border-radius: 9px; }
.drawer-section { padding: 16px 24px 6px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.drawer-nav, .drawer-projects { display: grid; padding: 0 10px; }
.drawer-item {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 46px; padding: 0 14px; border: 0; border-radius: 999px;
  background: transparent; text-align: left; font-weight: 500;
}
.drawer-item .emoji { width: 22px; text-align: center; flex: none; }
.drawer-item .count { margin-left: auto; color: var(--muted); font-size: 13px; }
.drawer-item.active { background: var(--chip); color: var(--chip-text); font-weight: 650; }
.drawer-item.sub { padding-left: 34px; }
.drawer-item.sub2 { padding-left: 54px; }
.drawer-foot { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); }
.scrim { position: fixed; inset: 0; z-index: 25; background: var(--scrim); animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; } }

/* bottom tabs */
.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 10; height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface-2); border-top: 1px solid var(--line);
}
.tabs button { border: 0; background: transparent; display: grid; justify-items: center; align-content: center; gap: 3px; font-size: 12px; font-weight: 600; color: var(--muted); }
.tabs button svg { padding: 3px 18px; width: 60px; height: 30px; border-radius: 999px; }
.tabs button.active { color: var(--text); }
.tabs button.active svg { background: var(--accent-2); color: #2a0b3f; }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--tabs-h) + var(--safe-b) + 18px); z-index: 11; width: 58px; height: 58px;
  border-radius: 18px; border: 0; background: #590896; color: #fff; display: grid; place-items: center; box-shadow: var(--shadow);
}
.fab svg.i { width: 28px; height: 28px; stroke-width: 2.2; }
@media (prefers-color-scheme: dark) { .fab { background: var(--accent-2); color: #2a0b3f; } }

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 290px 1fr; }
  .drawer { position: sticky; top: 0; height: 100vh; transform: none; box-shadow: none; border-right: 1px solid var(--line); width: auto; z-index: 1; background: var(--surface-2); }
  .drawer-item.active { background: var(--accent-2); color: #2a0b3f; }
  #menu-btn, .tabs, .scrim.for-drawer { display: none !important; }
  .main { padding-bottom: 96px; }
  .topbar, .subbar, .view { max-width: 780px; margin: 0 auto; width: 100%; }
  .topbar { padding-left: 14px; }
  .fab { bottom: 28px; right: 32px; }
}

/* ---------- lists ---------- */
.list { display: grid; }
.day-head { position: sticky; top: calc(var(--top-h) + var(--safe-t)); z-index: 2; background: var(--bg); padding: 16px 16px 6px; font-size: 14px; font-weight: 700; color: var(--text); border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: baseline; }
.day-head .sub { color: var(--muted); font-weight: 500; }
.section-head { padding: 18px 16px 6px; font-size: 15px; font-weight: 700; border-bottom: 1px solid var(--line); }
.row {
  position: relative; display: flex; align-items: flex-start; gap: 12px; min-height: var(--row-h); padding: 10px 14px 10px 10px;
  border-bottom: 1px solid var(--line); background: var(--bg); cursor: pointer; touch-action: pan-y; user-select: none;
}
.row:active { background: var(--surface-2); }
.row.swiping { transition: none; }
.row.gone { transition: opacity .25s, transform .25s; opacity: 0; transform: translateX(40%); }
.swipe-bg { position: absolute; inset: 0; background: var(--green); color: #fff; display: flex; align-items: center; padding-left: 20px; z-index: -1; }
.check {
  flex: none; width: 36px; height: 36px; margin-top: -4px; border: 0; background: transparent; display: grid; place-items: center; border-radius: 50%;
}
.check::before { content: ""; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--muted); transition: background .15s, border-color .15s; }
.check.p4::before { border-color: #d1453b; } .check.p3::before { border-color: #eb8909; } .check.p2::before { border-color: #246fe0; }
.check:hover::before { background: var(--chip); }
.check.done::before { background: var(--green); border-color: var(--green); box-shadow: inset 0 0 0 3px var(--bg); }
.check.occ::before { border-style: dashed; opacity: .6; }
.row .body { flex: 1; min-width: 0; padding-top: 2px; }
.row .t { overflow-wrap: anywhere; }
.row.jot .t { font-style: italic; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 3px; font-size: 13px; color: var(--muted); }
.meta span { display: inline-flex; align-items: center; gap: 3px; }
.meta .today { color: var(--green); font-weight: 600; }
.meta .hint { font-style: italic; opacity: .85; }
.meta .jot-tag { background: var(--chip); color: var(--chip-text); border-radius: 6px; padding: 0 6px; font-size: 12px; }
.chip-r { flex: none; max-width: 38%; margin-top: 2px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 56px 24px; text-align: center; color: var(--muted); display: grid; gap: 8px; justify-items: center; }
.empty .big { font-size: 40px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* projects */
.prow { display: flex; align-items: center; gap: 14px; min-height: 52px; padding: 0 16px; border-bottom: 1px solid var(--line); cursor: pointer; background: var(--bg); border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; }
.prow:active { background: var(--surface-2); }
.prow .emoji { width: 24px; text-align: center; font-size: 18px; }
.prow .name { flex: 1; font-weight: 500; }
.prow .count { color: var(--muted); font-size: 14px; }
.prow.l1 { padding-left: 46px; } .prow.l2 { padding-left: 76px; }
.newproj { display: flex; gap: 8px; padding: 16px; }
.newproj input { flex: 1; }

/* search */
.searchbox { display: flex; align-items: center; gap: 8px; margin: 4px 12px 8px; padding: 0 14px; border-radius: 999px; background: var(--surface-2); height: 48px; }
.searchbox input { flex: 1; border: 0; background: transparent; outline: none; height: 100%; }
.searchbox label { font-size: 13px; color: var(--muted); display: flex; gap: 5px; align-items: center; white-space: nowrap; }

/* inputs */
.field, input[type=text], input[type=date], input[type=search], select, textarea {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 9px 11px; min-width: 0;
}
textarea { resize: none; }

/* ---------- task sheet ---------- */
.sheet {
  position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; max-height: 94vh; background: var(--surface); border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow); display: flex; flex-direction: column; animation: up .22s ease; padding-bottom: var(--safe-b);
}
@keyframes up { from { transform: translateY(40%); opacity: .4; } }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 10px auto 2px; flex: none; touch-action: none; cursor: grab; }
.sheet-handle::before { content: ""; display: block; margin: -14px -40px; height: 33px; }
.sheet-body { overflow-y: auto; padding: 4px 18px 22px; overscroll-behavior: contain; }
@media (min-width: 900px) {
  .sheet { left: auto; top: 0; width: 480px; max-height: none; border-radius: 0; animation: side .2s ease; }
  @keyframes side { from { transform: translateX(30%); opacity: .4; } }
  .sheet-handle { display: none; }
  .sheet-body { padding-top: 14px; }
}
.s-head { display: flex; align-items: flex-start; gap: 6px; }
.s-head .check { margin-top: 2px; }
.s-title { flex: 1; border: 0 !important; padding: 6px 2px !important; font-size: 20px; font-weight: 650; background: transparent !important; line-height: 1.3; }
.s-crumb { margin: 0 0 6px 44px; font-size: 13px; color: var(--muted); }
.s-fields { display: grid; margin-top: 6px; border-top: 1px solid var(--line); }
.s-field { display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.s-field > svg, .s-field > .ico { margin-top: 9px; color: var(--muted); }
.s-field .lab { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.s-field input, .s-field select, .s-field textarea { width: 100%; }
.s-field .two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.preview { font-size: 13px; margin-top: 5px; color: var(--muted); min-height: 1.2em; }
.preview.ok { color: var(--green); }
.preview.bad { color: var(--warn); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px 4px; font-size: 14px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--chip); color: var(--chip-text); font-weight: 650; }
.s-notes { min-height: 70px; }
.s-comments { margin-top: 18px; }
.s-comments h3 { font-size: 15px; margin: 0 0 8px; }
.comment { padding: 9px 12px; border-radius: 14px; background: var(--surface-2); margin-bottom: 8px; }
.comment .who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.comment .txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.comment.ari { background: var(--chip); }
.c-new { display: flex; gap: 8px; align-items: flex-end; }
.c-new textarea { flex: 1; }
.s-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.s-foot { margin-top: 14px; font-size: 12px; color: var(--muted); }

/* ---------- quick add ---------- */
.adder { position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; background: var(--surface); border-radius: 20px 20px 0 0; box-shadow: var(--shadow); padding: 14px 14px calc(12px + var(--safe-b)); animation: up .18s ease; }
@media (min-width: 900px) { .adder { left: 50%; bottom: auto; top: 18vh; width: 600px; transform: translateX(-50%); border-radius: 18px; animation: none; } }
.add-form { display: grid; gap: 10px; }
#add-text { border: 0; background: transparent; font-size: 18px; padding: 4px 2px; outline: none; max-height: 30vh; }
.add-row { display: flex; align-items: center; gap: 8px; }
.chips { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; border-radius: 8px; padding: 5px 9px; font-size: 13px; background: var(--chip); color: var(--chip-text); border: 0; }
.chip.date { color: var(--green); }
.chip.muted { background: transparent; border: 1px solid var(--line); color: var(--muted); }

/* ---------- settings ---------- */
.page { padding: 4px 16px 40px; }
.card { background: var(--surface-2); border-radius: var(--radius); padding: 6px 0; margin: 10px 0 18px; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 10px 16px 4px; }
.card p { margin: 4px 16px 10px; font-size: 14px; color: var(--muted); }
.opt { display: flex; align-items: center; gap: 12px; min-height: 50px; padding: 0 16px; width: 100%; border: 0; background: transparent; text-align: left; }
.opt .radio { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--muted); flex: none; }
.opt[aria-checked="true"] .radio { border-color: var(--accent); box-shadow: inset 0 0 0 4px var(--surface-2), inset 0 0 0 10px var(--accent); }
.opt .grow { flex: 1; }
.opt .small { font-size: 13px; color: var(--muted); }
.dev { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.dev .grow { flex: 1; min-width: 0; }
.dev .small { font-size: 13px; color: var(--muted); }
.switch { width: 46px; height: 28px; border-radius: 999px; background: var(--line); position: relative; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .15s; }
[aria-checked="true"] > .switch { background: #590896; }
[aria-checked="true"] > .switch::after { left: 21px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; z-index: 60; left: 12px; right: 12px; bottom: calc(var(--tabs-h) + var(--safe-b) + 14px); margin: 0 auto; max-width: 560px;
  background: #2b2231; color: #fff; border-radius: 12px; padding: 4px 6px 4px 16px; min-height: 48px; display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow); animation: up .18s ease;
}
@media (prefers-color-scheme: dark) { .toast { background: #efe6f6; color: #1d1622; } .toast button { color: #590896 !important; } }
#toast-text { flex: 1; }
.toast button { border: 0; background: transparent; color: var(--accent-2); font-weight: 700; padding: 10px 12px; border-radius: 8px; }
@media (min-width: 900px) { .toast { bottom: 24px; left: 290px; } }
.sheet-open .toast, .adder-open .toast { bottom: calc(14px + var(--safe-b)); }
