/* ADHD-C Planner — mobile-first, dark-mode aware, big tap targets. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #1b1e24;
  --text-dim: #6b7280;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.14);
  --green: #16a34a;
  --amber-bg: #fef3c7;
  --amber-text: #92400e;
  --border: #e2e5ea;
  --nowline: #ef4444;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141a;
    --surface: #1c1f27;
    --surface-2: #262a34;
    --text: #e8eaef;
    --text-dim: #9aa1ad;
    --accent: #60a5fa;
    --accent-soft: rgba(96, 165, 250, 0.16);
    --green: #4ade80;
    --amber-bg: #3a2e12;
    --amber-text: #fbbf24;
    --border: #2c313c;
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); }

#screens {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 14px calc(84px + env(safe-area-inset-bottom));
}

.screen > * + * { margin-top: 14px; }

h2 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 18px 0 8px;
}

/* ---------- Capture bar ---------- */
#capture-form {
  position: sticky;
  top: 10px;
  z-index: 20;
  display: flex;
  gap: 8px;
}
#capture-input {
  flex: 1;
  height: 52px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 1rem;
}
#capture-input:focus { outline: 2px solid var(--accent); border-color: transparent; }
#capture-form button {
  width: 52px;
  height: 52px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 1.5rem;
  box-shadow: var(--shadow);
}

/* ---------- Cards & rows ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.banner {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.95rem;
  padding: 10px 14px;
}
.banner strong { color: var(--text); font-weight: 600; }

.task-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 6px 0;
}
.task-row + .task-row { border-top: 1px solid var(--border); }

.check {
  flex: none;
  width: 30px;
  height: 30px;
  border: 2px solid var(--text-dim);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: transparent;
}
.task-row.done .check { background: var(--green); border-color: var(--green); color: #fff; }

.task-main { flex: 1; min-width: 0; }
.task-title { overflow-wrap: anywhere; }
.task-row.done .task-title { text-decoration: line-through; color: var(--text-dim); }
.task-meta { font-size: 0.8rem; color: var(--text-dim); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
}
.pill.ghost { background: var(--surface-2); color: var(--text-dim); font-weight: 400; }
.pill.area { background: color-mix(in srgb, var(--area) 16%, transparent); color: var(--area); }

/* Area picker/filter chips tinted with the area's color */
.chip.area-chip.active { background: var(--area); border-color: var(--area); color: #fff; }
.chip.swatch { width: 40px; padding: 0; background: var(--area); border: 3px solid transparent; }
.chip.swatch.active { border-color: var(--text); }
.area-filter {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 0 6px;
  scrollbar-width: none;
}
.area-filter::-webkit-scrollbar { display: none; }
.area-filter .chip { flex: none; }

.hint { color: var(--text-dim); font-size: 0.875rem; text-align: center; padding: 10px 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: var(--radius);
  background: var(--surface-2);
  font-weight: 600;
  font-size: 0.9rem;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { color: #ef4444; }
.btn.block { width: 100%; }

.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  background: var(--surface-2);
}

.row-actions { display: flex; gap: 6px; flex: none; }

/* ---------- Routines ---------- */
.routine-card { margin-top: 10px; }
.routine-head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  text-align: left;
}
.routine-name { flex: 1; font-weight: 600; }
.routine-count { color: var(--text-dim); font-size: 0.85rem; }
.ring { flex: none; transform: rotate(-90deg); }
.ring .track { stroke: var(--surface-2); }
.ring .fill { stroke: var(--green); transition: stroke-dashoffset 0.25s; }

.routine-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  width: 100%;
  text-align: left;
  border-top: 1px solid var(--border);
}
.routine-item .check { width: 26px; height: 26px; font-size: 0.85rem; }
.routine-item.done .check { background: var(--green); border-color: var(--green); color: #fff; }
.routine-item.done span:last-child { color: var(--text-dim); text-decoration: line-through; }

/* ---------- Mini timeline strip ---------- */
.ministrip {
  position: relative;
  height: 34px;
  border-radius: 10px;
  background: var(--surface-2);
  overflow: hidden;
  width: 100%;
  display: block;
}
.ministrip .mini-block { position: absolute; top: 6px; bottom: 6px; border-radius: 5px; background: var(--accent); opacity: 0.75; }
.ministrip .mini-now { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--nowline); }
.ministrip-labels { display: flex; justify-content: space-between; font-size: 0.7rem; color: var(--text-dim); margin-top: 3px; }

/* ---------- Plan: timeline ---------- */
.timeline { display: flex; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.tl-gutter { flex: none; width: 52px; border-right: 1px solid var(--border); }
.tl-gutter div { height: 48px; font-size: 0.7rem; color: var(--text-dim); text-align: right; padding: 2px 6px 0 0; }
.tl-body {
  position: relative;
  flex: 1;
  background-image: repeating-linear-gradient(to bottom, var(--border) 0, var(--border) 1px, transparent 1px, transparent 48px);
}
.tl-past { position: absolute; left: 0; right: 0; top: 0; background: var(--surface-2); opacity: 0.45; pointer-events: none; }
.tl-block {
  position: absolute;
  left: 8px;
  right: 8px;
  border-radius: 8px;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  padding: 3px 8px;
  font-size: 0.82rem;
  overflow: hidden;
  text-align: left;
}
.tl-block small { color: var(--text-dim); display: block; font-size: 0.72rem; }
.tl-now { position: absolute; left: 0; right: 0; height: 2px; background: var(--nowline); pointer-events: none; }
.tl-now::before {
  content: attr(data-label);
  position: absolute;
  right: 4px;
  top: -17px;
  font-size: 0.7rem;
  color: var(--nowline);
  font-weight: 600;
}

.amber {
  background: var(--amber-bg);
  color: var(--amber-text);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.85rem;
  margin-top: 6px;
}

.due-group { margin-top: 12px; }
.due-group-head { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 4px; }
.due-group-head strong { color: var(--text); }

/* ---------- Inbox ---------- */
details.fold summary {
  list-style: none;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-weight: 600;
  cursor: pointer;
}
details.fold summary::before { content: "▸"; transition: transform 0.15s; }
details.fold[open] summary::before { transform: rotate(90deg); }

/* ---------- Settings ---------- */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 4px 0;
}
.setting-row + .setting-row { border-top: 1px solid var(--border); }
.setting-row select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; }
.switch .knob {
  position: absolute; inset: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  transition: background 0.15s;
  pointer-events: none;
}
.switch .knob::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
}
.switch input:checked + .knob { background: var(--accent); }
.switch input:checked + .knob::after { transform: translateX(22px); }

/* ---------- Tab bar ---------- */
#tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 30;
}
#tabbar button {
  flex: 1;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.72rem;
  color: var(--text-dim);
}
#tabbar button.active { color: var(--accent); font-weight: 600; }
#tabbar .tab-icon { font-size: 1.25rem; }

/* ---------- Bottom sheet ---------- */
#sheet-backdrop[hidden] { display: none; }
#sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
#sheet {
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
#sheet h3 { font-size: 1.05rem; margin-bottom: 12px; }
#sheet label { display: block; font-size: 0.8rem; color: var(--text-dim); margin: 12px 0 4px; }
#sheet input[type="text"], #sheet input[type="date"], #sheet input[type="time"],
#sheet input[type="number"], #sheet textarea, #sheet select {
  width: 100%;
  min-height: 46px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}
#sheet textarea { min-height: 80px; resize: vertical; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.sheet-actions { display: flex; gap: 8px; margin-top: 18px; }
.sheet-actions .btn { flex: 1; }
.weekday-chips { display: flex; gap: 4px; flex-wrap: wrap; }
.weekday-chips .chip { padding: 6px 10px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  bottom: calc(76px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 8px 18px;
  border-radius: 99px;
  font-size: 0.85rem;
  z-index: 50;
  white-space: nowrap;
}

.empty-state { text-align: center; color: var(--text-dim); padding: 28px 16px; }
.empty-state .big { font-size: 2rem; display: block; margin-bottom: 6px; }
