:root {
  --bg: #120d1a;
  --bg-soft: #1a1226;
  --panel: #1f1630;
  --panel-2: #2b1f42;
  --line: #3a2b56;
  --text: #f1e9f8;
  --muted: #a99bc2;
  /* Work is purple, Private is pink; body[data-tab] swaps --accent below. */
  --accent: #a855f7;
  --accent-soft: rgba(168, 85, 247, 0.12);
  --accent-ink: #1c0733;
  --on-accent-2: #2d0a1e;
  --accent-2: #f472b6;
  --danger: #f4566b;
  --warn: #f0b429;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);

  --header-h: 56px;
  --composer-h: 62px;
  --nav-h: 60px;
  --control-h: 46px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

/* Per-list accent: purple for Work, pink for Private. setTab() sets body[data-tab]. */
body[data-tab="work"], body[data-tab="files"] {
  --accent: #a855f7;
  --accent-soft: rgba(168, 85, 247, 0.12);
  --accent-2: #c084fc;
  --accent-ink: #1c0733;
  --on-accent-2: #23063b;
}
body[data-tab="private"] {
  --accent: #ec4899;
  --accent-soft: rgba(236, 72, 153, 0.12);
  --accent-2: #f9a8d4;
  --accent-ink: #2d0620;
  --on-accent-2: #3d0620;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
h2 { font-size: 17px; margin: 0; }

/* Inputs must be >=16px on iOS or Safari zooms the page on focus. */
input, select, textarea { font-size: 16px; }

.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.mobile-only { display: none; }
.spacer { margin-left: auto; }

/* --------------------------------------------------------------- login -- */

.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }

.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 32px 26px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card img { border-radius: 18px; }
.login-card h1 { margin: 16px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.login-card input {
  width: 100%; text-align: center;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; outline: none;
}
.login-card input:focus { border-color: var(--accent); }

/* -------------------------------------------------------------- header -- */

header.top {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  height: calc(var(--header-h) + var(--safe-t));
  padding: var(--safe-t) 14px 0;
  background: rgba(18, 13, 26, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; }
.brand img { border-radius: 9px; }

.tabs { display: flex; gap: 4px; margin-left: auto; background: var(--bg-soft); padding: 4px; border-radius: 12px; border: 1px solid var(--line); }
.tab {
  border: 0; background: transparent; color: var(--muted);
  padding: 7px 14px; border-radius: 9px; font-weight: 600;
  display: flex; align-items: center; gap: 7px;
}
.tab.active { background: var(--panel-2); color: var(--text); }
.count { font-size: 12px; background: var(--panel-2); color: var(--muted); padding: 1px 7px; border-radius: 999px; }
.tab.active .count { background: var(--accent); color: var(--accent-ink); }

main {
  max-width: 780px;
  margin: 0 auto;
  padding: 18px 16px 60px;
}

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }

/* ------------------------------------------------------------ controls -- */

.list-head { display: flex; align-items: center; gap: 10px; margin: 0 2px 12px; }
.list-foot { display: flex; justify-content: center; margin-top: 14px; }

.segmented { display: flex; gap: 3px; background: var(--bg-soft); border: 1px solid var(--line); padding: 3px; border-radius: 11px; }
.segmented button {
  border: 0; background: transparent; color: var(--muted);
  padding: 7px 12px; border-radius: 8px; font-size: 13px; font-weight: 600;
}
.segmented button.active { background: var(--panel-2); color: var(--text); }
.segmented.wide { width: 100%; }
.segmented.wide button { flex: 1; padding: 11px; font-size: 14px; }

.btn {
  border: 1px solid transparent; background: var(--accent); color: var(--accent-ink);
  padding: 12px 18px; border-radius: 12px; font-weight: 620;
}
.btn:active { transform: scale(0.97); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn.small { padding: 8px 14px; font-size: 13px; }
.btn.danger-outline { background: transparent; border-color: rgba(244, 86, 107, 0.4); color: var(--danger); width: 100%; }
.btn:disabled { opacity: 0.55; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 10px; }

.icon-btn {
  border: 0; background: transparent; color: var(--muted);
  width: 40px; height: 40px; min-width: 40px; border-radius: 10px;
  display: grid; place-items: center; font-size: 16px; text-decoration: none;
}
.icon-btn:active { background: var(--panel-2); color: var(--text); }

/* --------------------------------------------------------------- tasks -- */

ul.tasks { list-style: none; margin: 0; padding: 6px; }

/* The row is a clipping window; .task-inner slides over the action layer so a
   swipe reveals complete / delete the way a native list does. */
li.task {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  touch-action: pan-y;
}
li.task.dragging { opacity: 0.4; }

.task-inner {
  position: relative; z-index: 1;
  display: flex; align-items: flex-start; gap: 12px;
  padding: 13px 12px;
  background: var(--panel);
  will-change: transform;
}
li.task:active .task-inner { background: var(--panel-2); }
li.task.swiping .task-inner { background: var(--panel-2); }
.task-inner.springing { transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.3, 1); }
.task-inner.flying { transition: transform 0.2s ease-in; }

.swipe-layer {
  position: absolute; inset: 0; z-index: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  font-size: 13px; font-weight: 650; color: #fff;
}
.swipe-layer .side { display: flex; align-items: center; gap: 8px; opacity: 0.55; transition: opacity 0.12s; }
.swipe-layer .side .glyph { font-size: 17px; }
.swipe-layer.armed .side.active { opacity: 1; }
li.task.swipe-right .swipe-layer { background: var(--accent-2); color: var(--on-accent-2); }
li.task.swipe-left  .swipe-layer { background: var(--danger); }
li.task.swipe-right .side.delete, li.task.swipe-left .side.complete { visibility: hidden; }

.check {
  flex: none;
  width: 26px; height: 26px;
  margin: -2px 0;
  border-radius: 9px;
  border: 2px solid var(--line);
  background: transparent;
  display: grid; place-items: center;
  color: transparent; font-size: 13px;
}
li.task.done .check { background: var(--accent-2); border-color: var(--accent-2); color: var(--on-accent-2); }

.task-body { flex: 1; min-width: 0; }
.task-title { word-break: break-word; }
li.task.done .task-title { text-decoration: line-through; color: var(--muted); }

.task-meta { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; margin-top: 6px; font-size: 12px; color: var(--muted); }
.pill { padding: 2px 9px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); }
.pill.high { color: var(--danger); border-color: rgba(244, 86, 107, 0.4); }
.pill.due-soon { color: var(--warn); border-color: rgba(240, 180, 41, 0.4); }
.pill.overdue { color: var(--danger); border-color: rgba(244, 86, 107, 0.45); }
.pill.attach { color: var(--accent-2); }
.note-preview { display: block; margin-top: 5px; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chev { flex: none; color: var(--muted); align-self: center; font-size: 18px; }
.drag-handle { flex: none; color: var(--line); cursor: grab; align-self: center; padding: 0 2px; }

/* --------------------------------------------------------------- files -- */

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 26px 20px; margin-bottom: 18px;
  color: var(--muted); text-align: center;
}
.dropzone:active, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon { font-size: 24px; }
.dropzone strong { color: var(--text); }
.dz-sub, .dz-limit { font-size: 12.5px; }
.dz-limit { opacity: 0.7; }

.file-row { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px; }
.file-row:active { background: var(--panel-2); }
.file-ico {
  flex: none; width: 40px; height: 40px; border-radius: 11px;
  display: grid; place-items: center; font-size: 18px;
  background: var(--panel-2); border: 1px solid var(--line);
}
.file-main { flex: 1; min-width: 0; }
.file-name { word-break: break-word; }
.file-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.file-actions { display: flex; gap: 2px; flex: none; }

.progress { height: 4px; background: var(--panel-2); border-radius: 999px; overflow: hidden; margin: -8px 0 14px; display: none; }
.progress.on { display: block; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.15s; }

.empty { padding: 38px 20px; text-align: center; color: var(--muted); }
.empty .big { font-size: 30px; display: block; margin-bottom: 8px; }

/* ------------------------------------------------------------ composer -- */

/* Desktop: sits directly above the list, where the eye already is.
   Phones: re-pinned above the tab bar in the narrow media query below. */
.composer {
  display: flex; gap: 10px; align-items: stretch;
  margin-bottom: 16px;
}
/* Field and button share one explicit height so their edges line up exactly;
   letting padding + line-height decide leaves them a few px apart. */
.composer input {
  flex: 1; min-width: 0;
  height: var(--control-h);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 0 15px; outline: none;
  font-size: 15px;
}
.composer input::placeholder { color: var(--muted); }
.composer input:focus { border-color: var(--accent); background: var(--bg-soft); }
.composer .add {
  flex: none; height: var(--control-h); padding: 0 18px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  font-size: 14px; white-space: nowrap;
}
.composer .add-plus { font-size: 17px; }
.composer.hidden-composer { display: none; }

/* ---------------------------------------------------------- bottom nav -- */

/* No `display` here on purpose: .mobile-only owns it, so the bar cannot leak
   onto desktop by winning the cascade on source order. */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 26;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(18, 13, 26, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.bnav {
  position: relative;
  flex: 1; border: 0; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; font-weight: 600;
}
.bnav .bico { font-size: 19px; filter: grayscale(0.6) opacity(0.75); }
.bnav.active { color: var(--text); }
.bnav.active .bico { filter: none; }
.bnav.active::before {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 30px; height: 2.5px; border-radius: 0 0 3px 3px; background: var(--accent);
}
.bdot {
  position: absolute; top: 8px; left: calc(50% + 9px);
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 999px; background: var(--accent); color: var(--accent-ink);
  font-size: 10px; line-height: 17px; text-align: center;
}

/* --------------------------------------------------------------- sheet -- */

.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, 0.55);
  animation: fade 0.18s ease;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: fixed; z-index: 41;
  left: 0; right: 0; bottom: 0;
  max-height: 92dvh;
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow);
  animation: rise 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes rise { from { transform: translateY(100%); } }

.sheet-grip { width: 38px; height: 4px; border-radius: 99px; background: var(--line); margin: 9px auto 0; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
}
.sheet-head strong { font-size: 15px; }
.sheet-body {
  padding: 16px 16px calc(20px + var(--safe-b));
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 15px;
  -webkit-overflow-scrolling: touch;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12.5px; color: var(--muted); font-weight: 600; letter-spacing: 0.02em; }
.field input, .field select, .field textarea {
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 13px; outline: none; width: 100%;
  resize: vertical; font-family: inherit;
}
/* A date input and a select have different intrinsic heights - pin them so the
   Due/Priority row lines up. */
.field input:not([type="file"]), .field select { height: 50px; padding: 0 13px; }
.field select { appearance: none; background-image:
  linear-gradient(45deg, transparent 50%, var(--muted) 50%),
  linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 22px, calc(100% - 12px) 22px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; min-width: 0; }
#f-list button.active { background: var(--panel-2); color: var(--text); }

.attach-list { display: flex; flex-direction: column; gap: 6px; }
.attach-row {
  display: flex; align-items: center; gap: 9px;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 11px; padding: 8px 10px; font-size: 13.5px;
}
.attach-row .grow { flex: 1; min-width: 0; word-break: break-all; }
.attach-empty { font-size: 13px; color: var(--muted); }

/* --------------------------------------------------------------- toast -- */

.toast {
  position: fixed; left: 50%; z-index: 60;
  bottom: 26px;
  transform: translate(-50%, 14px);
  max-width: calc(100vw - 32px);
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 11px 18px; border-radius: 999px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* -------------------------------------------------------------- phones -- */

@media (max-width: 760px) {
  .mobile-only { display: flex; }
  .desktop-only { display: none; }

  main { padding: 14px 12px calc(var(--composer-h) + var(--nav-h) + 24px); }

  .composer {
    position: fixed; left: 0; right: 0; z-index: 25;
    bottom: calc(var(--nav-h) + var(--safe-b));
    margin: 0; padding: 10px 12px;
    background: rgba(18, 13, 26, 0.94);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
  }
  /* 16px keeps iOS from zooming the page when the field takes focus. */
  .composer input { background: var(--bg-soft); font-size: 16px; padding: 0 14px; }
  .composer .add { width: var(--control-h); padding: 0; border-radius: 13px; }
  .composer .add-plus { font-size: 22px; }
  .composer .add-label { display: none; }

  .toast { bottom: calc(var(--nav-h) + var(--composer-h) + var(--safe-b) + 12px); }

  .list-head { flex-wrap: wrap; }
  .list-head .segmented { width: 100%; order: 3; }
  .list-head .segmented button { flex: 1; }

  .task-inner { padding: 14px 10px; }
  .drag-handle { display: none; }
  .sheet { max-height: 88dvh; }
}

@media (min-width: 761px) {
  .sheet {
    left: 50%; bottom: auto; top: 50%;
    transform: translate(-50%, -50%);
    width: min(520px, calc(100vw - 40px));
    max-height: 86vh;
    border-radius: 20px;
    animation: pop 0.18s ease;
  }
  @keyframes pop { from { opacity: 0; transform: translate(-50%, -46%); } }

}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* -------------------------------------------------------------- modal -- */

.modal { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.6); animation: fade 0.15s ease; }

.modal-card {
  position: relative;
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px;
  box-shadow: var(--shadow);
  animation: pop-in 0.16s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes pop-in { from { opacity: 0; transform: scale(0.94); } }

.modal-card h3 { margin: 0 0 8px; font-size: 17px; }
.modal-card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.modal-card p:empty { display: none; }
.modal-card #modal-input {
  width: 100%; height: 46px; margin-top: 14px;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 12px; padding: 0 14px; outline: none;
}
.modal-card #modal-input:focus { border-color: var(--accent); }

.modal-actions { display: flex; gap: 9px; margin-top: 20px; }
.modal-actions .btn { flex: 1; padding: 12px 14px; }
/* Stack when there are more than two choices, so it reads as a list. */
.modal-actions.stacked { flex-direction: column-reverse; }
.modal-actions.stacked .btn { width: 100%; }
.btn.danger-solid { background: var(--danger); color: #fff; }

@media (max-width: 760px) {
  .modal { align-items: flex-end; padding: 0; }
  .modal-card {
    width: 100%;
    border-radius: 22px 22px 0 0;
    padding: 22px 18px calc(22px + var(--safe-b));
    animation: rise 0.2s cubic-bezier(0.2, 0.8, 0.3, 1);
  }
}

/* --------------------------------------------------------- toast action -- */

.toast { display: flex; align-items: center; gap: 14px; }
.toast-action {
  border: 0; background: transparent; color: var(--accent);
  font-weight: 650; font-size: 14px; padding: 2px 2px; margin: -2px 0;
}
.toast.show { pointer-events: auto; }

/* -------------------------------------------------- pull to refresh -- */

.pull {
  position: fixed; left: 50%; z-index: 28;
  top: calc(var(--header-h) + var(--safe-t) + 6px);
  width: 34px; height: 34px; margin-left: -17px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--panel-2); border: 1px solid var(--line);
  box-shadow: var(--shadow);
  color: var(--muted); font-size: 15px;
  opacity: 0; transform: translateY(-24px) scale(0.8);
  pointer-events: none;
}
.pull.settling { transition: opacity 0.2s, transform 0.2s; }
.pull.armed { color: var(--accent); border-color: var(--accent); }
.pull.spinning .pull-icon { animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.pull-icon { display: block; transition: transform 0.15s; }
.pull.armed .pull-icon { transform: rotate(180deg); }
.pull.spinning .pull-icon { transform: none; }
