:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f0f0ed;
  --border: #e2e2dd;
  --text: #1c1c1a;
  --muted: #71716c;
  --accent: #2f6f4f;
  --accent-text: #ffffff;
  --danger: #b3402f;
  --warn-bg: #fdf1e7;
  --warn-border: #e9c9a8;
  --warn-text: #8a4b16;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --surface: #1e1e23;
    --surface-2: #26262c;
    --border: #33333b;
    --text: #ececea;
    --muted: #9a9a95;
    --accent: #7bbd94;
    --accent-text: #10241a;
    --danger: #e58270;
    --warn-bg: #2e2318;
    --warn-border: #4d3a24;
    --warn-text: #e8bd8c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

/* The `hidden` attribute hides an element via `display: none` in the browser's
 * default stylesheet, which any author `display` rule silently overrides.
 * .lock and .sheet both set display, so without this they stay on screen
 * forever - a fixed, opaque overlay covering the whole app. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: max(12px, env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
  max-width: 720px;
  margin-inline: auto;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.55rem; letter-spacing: -.02em; }
p { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); font-size: .875rem; margin-top: 8px; }
.empty { padding: 20px 4px; }

/* topbar ------------------------------------------------------------------ */
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0 20px;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 38px; height: 38px;
  border-radius: 10px;
  display: grid; place-items: center;
  cursor: pointer;
  flex: none;
  font-size: 15px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.section-label {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 10px;
}

/* folders ------------------------------------------------------------------ */
.folders {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 11px;
  margin-bottom: 24px;
}

.folder {
  flex: 1;
  font: inherit;
  font-size: .9rem;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.folder:hover { color: var(--text); }
.folder.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.folder-count {
  font-size: .75rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg);
  border-radius: 999px;
  padding: 1px 7px;
  min-width: 20px;
}
.folder.is-active .folder-count { background: var(--surface-2); }
.folder-count:empty { display: none; }

.chip.folder-work { background: #3d5a80; color: #fff; }
.chip.folder-personal { background: #6b5b95; color: #fff; }
@media (prefers-color-scheme: dark) {
  .chip.folder-work { background: #7fa3cc; color: #10202e; }
  .chip.folder-personal { background: #b0a2d4; color: #1d1730; }
}

/* add form ---------------------------------------------------------------- */
.add-toggle {
  width: 100%;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  padding: 13px;
  font-size: .95rem;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}
.add-toggle:hover { border-color: var(--accent); color: var(--text); }
.plus { font-size: 1.05rem; margin-right: 4px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
}

.form { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 0; }
.field > span {
  font-size: .78rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
}
.field.grow { flex: 2; }

input, textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 11px;
  width: 100%;
  min-width: 0;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

.row { display: flex; gap: 10px; }
.row.tight { gap: 10px; margin-top: 14px; }
@media (max-width: 520px) {
  .row { flex-wrap: wrap; }
  .row .field { flex-basis: 100%; }
}

.quick-picks { display: flex; gap: 6px; flex-wrap: wrap; margin-top: -4px; }

.quick {
  font: inherit;
  font-size: .82rem;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
}
.quick:hover { border-color: var(--accent); color: var(--text); }
.quick.is-set { background: var(--accent); color: var(--accent-text); border-color: transparent; }

.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  font: inherit;
  font-weight: 500;
  padding: 10px 16px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.danger-ghost { background: transparent; color: var(--danger); border-color: transparent; }
.btn.danger-ghost:hover { background: var(--surface-2); }
.btn.full { width: 100%; margin-top: 10px; }
.btn:disabled { opacity: .55; cursor: default; }

/* list -------------------------------------------------------------------- */
.list-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin: 30px 0 10px;
}
.list-head .section-label { margin: 0; }

.tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 9px; }
.tab {
  font: inherit; font-size: .85rem;
  border: none; background: transparent; color: var(--muted);
  padding: 5px 11px; border-radius: 7px; cursor: pointer;
}
.tab.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.task-list { display: flex; flex-direction: column; gap: 6px; }

.swipe-hint { margin: -4px 0 10px; }
@media (hover: hover) and (pointer: fine) {
  /* On a mouse the buttons appear on hover, so the swipe wording would mislead. */
  .swipe-hint::after { content: ' On a trackpad, two-finger swipe, or just hover.'; }
}

/* The left-hand strip: swipe right to defer. */
.task-later {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--later-width);
  display: flex;
  z-index: 2;
  transform: translateX(-100%);
  transition: transform .22s cubic-bezier(.22,.61,.36,1);
  box-shadow: 10px 0 18px rgba(0, 0, 0, .14);
  border-radius: var(--radius) 0 0 var(--radius);
  overflow: hidden;
}
.task-row.is-dragging .task-later { transition: none; }
.task-later button {
  flex: 1; border: none; font: inherit; font-size: .88rem; font-weight: 500;
  cursor: pointer; background: #8a6d3b; color: #fff;
}
.task-later button:hover { filter: brightness(1.08); }

.chip.snoozed { background: var(--surface-2); color: var(--muted); font-style: italic; }
.chip.repeats { background: var(--surface-2); color: var(--muted); }

/* Each row is a window onto the action buttons sitting behind the card. */
.task-row {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  --actions-width: 168px;
  --later-width: 100px;
}

/* The buttons ride in over the row rather than pushing it aside, so the task
 * text stays readable while you decide what to do with it. */
.task-actions {
  position: absolute;
  inset: 0 0 0 auto;
  width: var(--actions-width);
  display: flex;
  z-index: 2;
  transform: translateX(100%);
  transition: transform .22s cubic-bezier(.22,.61,.36,1);
  box-shadow: -10px 0 18px rgba(0, 0, 0, .14);
  border-radius: 0 var(--radius) var(--radius) 0;
  overflow: hidden;
}
.task-row.is-dragging .task-actions { transition: none; }

/* Mice cannot swipe comfortably, so hovering brings the buttons in. */
@media (hover: hover) and (pointer: fine) {
  .task-row:not(.is-dragging):not(.is-open):hover .task-actions {
    transform: translateX(0);
  }
}

.swipe-action {
  flex: 1;
  border: none;
  font: inherit;
  font-size: .88rem;
  font-weight: 500;
  cursor: pointer;
  color: #fff;
}
.swipe-action.edit { background: #5a6b7d; }
.swipe-action.complete { background: var(--accent); color: var(--accent-text); }
.swipe-action:hover { filter: brightness(1.08); }

.task {
  position: relative;
  display: flex; gap: 11px; align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 13px;
  /* Vertical scrolling stays with the browser; we only take horizontal drags. */
  touch-action: pan-y;
}

.task:hover { border-color: var(--muted); }
.task.is-overdue { border-color: var(--warn-border); background: var(--warn-bg); }

/* Rank badge — carries over the old "what to work on" signal. */
.rank {
  flex: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: .75rem;
  font-weight: 700;
  display: grid; place-items: center;
  margin-top: 1px;
}
.rank-none { background: transparent; }
.task.is-overdue .rank { background: var(--warn-text); color: var(--warn-bg); }


.task-main { flex: 1; min-width: 0; cursor: pointer; }
.task-title { font-weight: 500; word-wrap: break-word; }
.task.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-notes {
  font-size: .85rem; color: var(--muted); margin-top: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.task-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }

.chip {
  font-size: .75rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.chip.due-soon { background: var(--warn-bg); color: var(--warn-text); }
.chip.overdue { background: var(--danger); color: #fff; }
.chip.p1 { background: var(--accent); color: var(--accent-text); }

/* settings sheet ----------------------------------------------------------- */
.sheet {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
  overflow-y: auto;
}
@media (min-width: 640px) { .sheet { align-items: center; padding: 24px; } }

.sheet-card {
  background: var(--bg);
  width: 100%;
  max-width: 520px;
  border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(28px + env(safe-area-inset-bottom));
  max-height: 92vh;
  overflow-y: auto;
}
@media (min-width: 640px) { .sheet-card { border-radius: 18px; } }

.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.setting-block { padding: 18px 0; border-top: 1px solid var(--border); }
.setting-block h3 { font-size: 1rem; margin-bottom: 6px; }

.status-pill {
  display: inline-block;
  font-size: .85rem;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  margin: 12px 0 4px;
}
.status-pill.on { background: var(--accent); color: var(--accent-text); }
.status-pill.off { background: var(--warn-bg); color: var(--warn-text); }

.hint {
  font-size: .85rem;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
  padding: 11px 13px;
  border-radius: 10px;
  margin-top: 10px;
}

.device-list { display: flex; flex-direction: column; gap: 6px; }
.device {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; font-size: .9rem;
}
.device-remove {
  background: transparent; border: none; color: var(--danger);
  cursor: pointer; font-size: .85rem; font-family: inherit;
}

/* lock -------------------------------------------------------------------- */
.lock {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: var(--bg); padding: 24px; z-index: 100;
}
.lock-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px;
  width: 100%; max-width: 340px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow);
}
.lock-card h1 { margin-bottom: 2px; }

/* toast ------------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(22px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg);
  padding: 11px 18px; border-radius: 999px;
  font-size: .88rem; z-index: 200;
  box-shadow: var(--shadow);
  max-width: calc(100% - 32px);
}

.footer { margin-top: 28px; text-align: center; }

/* workout ------------------------------------------------------------------ */
.workout {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 22px;
  box-shadow: var(--shadow);
}
.workout.is-rest { border-style: dashed; box-shadow: none; }
.workout.is-logged { opacity: .72; }

.workout-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 10px;
}
.workout-label {
  font-size: .74rem; text-transform: uppercase; letter-spacing: .07em;
  font-weight: 600; color: var(--muted);
}
.streak {
  font-size: .78rem; font-weight: 600;
  background: var(--accent); color: var(--accent-text);
  padding: 2px 9px; border-radius: 999px;
}
.streak:empty { display: none; }

.workout-title { font-size: 1.08rem; font-weight: 600; }
.workout-meta { font-size: .86rem; color: var(--muted); margin-top: 3px; }
.workout-notes { font-size: .86rem; color: var(--muted); margin-top: 7px; }
.workout-notes:empty { display: none; }

.workout-actions { display: flex; gap: 8px; margin-top: 14px; }
.workout-actions .btn { flex: 1; }
.workout-logged { font-size: .88rem; color: var(--muted); margin-top: 12px; }

.chip.folder-fitness { background: #8a5a2b; color: #fff; }
@media (prefers-color-scheme: dark) {
  .chip.folder-fitness { background: #d8a76a; color: #2a1c0c; }
}

/* weekly plan editor -------------------------------------------------------- */
.plan-editor { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

.plan-day {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 12px;
}
.plan-day.is-today { border-color: var(--accent); }

.plan-day-name {
  font-size: .74rem; text-transform: uppercase; letter-spacing: .06em;
  font-weight: 600; color: var(--muted); margin-bottom: 7px;
  display: flex; justify-content: space-between; gap: 8px;
}
.plan-row { display: flex; gap: 7px; margin-bottom: 7px; }
.plan-row:last-child { margin-bottom: 0; }
.plan-row input, .plan-row select { font-size: .88rem; padding: 7px 9px; }
.plan-row .grow { flex: 2; }
.plan-row .shrink { flex: 1; min-width: 0; }

.linkish {
  background: none; border: none; padding: 0;
  font: inherit; color: var(--accent);
  text-decoration: underline; cursor: pointer;
}

.task.is-snoozed { opacity: .6; }
.task.is-snoozed .task-title { font-style: italic; }

/* quick add ---------------------------------------------------------------- */
.quick-add { display: flex; gap: 8px; margin-bottom: 8px; }
.quick-add input { flex: 1; }
.quick-preview {
  font-size: .82rem; color: var(--muted);
  background: var(--surface-2);
  border-radius: 9px; padding: 8px 11px; margin-bottom: 8px;
}
.quick-preview b { color: var(--text); font-weight: 600; }
.quick-preview .tok {
  display: inline-block; background: var(--surface); border-radius: 999px;
  padding: 1px 8px; margin-left: 6px; font-size: .76rem;
}

/* search ------------------------------------------------------------------- */
.search { margin-bottom: 10px; }

/* workload ----------------------------------------------------------------- */
.workload {
  font-size: .85rem; color: var(--muted);
  background: var(--surface-2);
  border-radius: 9px; padding: 8px 12px; margin-bottom: 18px;
}
.workload.is-over {
  background: var(--warn-bg); color: var(--warn-text);
  border: 1px solid var(--warn-border);
}

/* subtasks ----------------------------------------------------------------- */
.subtask-list { display: flex; flex-direction: column; gap: 5px; }
.subtask {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 9px; font-size: .9rem;
}
.subtask.is-done span { text-decoration: line-through; color: var(--muted); }
.subtask span { flex: 1; }
.subtask button {
  background: none; border: none; cursor: pointer; color: var(--muted);
  font: inherit; font-size: .85rem; padding: 0 3px;
}
.subtask input[type="checkbox"] { width: auto; margin: 0; }
.subtask-add { display: flex; gap: 6px; margin-top: 6px; }
.subtask-add input { flex: 1; }

.chip.progress { background: var(--surface-2); color: var(--muted); }

/* upcoming ----------------------------------------------------------------- */
.day-heading {
  font-size: .76rem; text-transform: uppercase; letter-spacing: .06em;
  font-weight: 600; color: var(--muted);
  margin: 14px 0 4px; padding-left: 2px;
}
.day-heading:first-child { margin-top: 0; }
