/* ---------- Colours & sizes (change these to restyle everything) ---------- */
:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e7e9ee;
  --muted: #8b93a1;
  --accent: #7c9cff;
  --danger: #f87171;
  --ok: #34d399;
  --warn: #fbbf24;
  --radius: 14px;
  --sidebar-width: 232px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

svg {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.muted { color: var(--muted); }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  position: sticky; top: env(safe-area-inset-top, 0px);
  width: var(--sidebar-width); height: 100vh; flex-shrink: 0;
  display: flex; flex-direction: column; gap: 24px;
  padding: 24px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px; font-weight: 650; font-size: 16px; white-space: nowrap; }
.brand-mark { color: var(--accent); }

/* Sync status: a coloured dot plus a short label */
.sync {
  display: flex; align-items: center; gap: 8px;
  margin-top: -14px; padding: 0 10px;
  border: none; background: none; text-align: left;
  font-size: 12px; color: var(--muted);
}
.sync-dot { flex-shrink: 0; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.sync[data-status="synced"] .sync-dot { background: var(--ok); }
.sync[data-status="connecting"] .sync-dot,
.sync[data-status="saving"] .sync-dot { background: var(--warn); }
.sync[data-status="error"] .sync-dot { background: var(--danger); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--muted); text-decoration: none;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--surface-2); color: var(--text); }
.nav-link.active .nav-icon { color: var(--accent); }
.nav-icon { display: flex; }
.nav-label-short { display: none; }
.nav-link { position: relative; }
.nav-badge {
  margin-left: auto; min-width: 20px; padding: 1px 6px; border-radius: 99px;
  background: var(--danger); color: #0b0d12; font-size: 11px; font-weight: 700; text-align: center;
  font-variant-numeric: tabular-nums;
}
.nav-soon {
  margin-left: auto; font-size: 11px; padding: 1px 7px;
  border: 1px solid var(--border); border-radius: 99px; color: var(--muted);
}

.data-actions { margin-top: auto; display: flex; flex-direction: column; gap: 4px; }

.main {
  flex: 1; min-width: 0;
  max-width: 980px; margin: 0 auto;
  padding: 36px 32px 64px;
}

/* ---------- Buttons, inputs, cards ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid transparent;
  background: none; white-space: nowrap;
}
a.btn { text-decoration: none; }
.btn-primary { background: var(--accent); color: #0b0d12; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { background: var(--danger); color: #0b0d12; font-weight: 600; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-ghost { justify-content: flex-start; color: var(--muted); padding: 9px 12px; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-ghost svg { width: 18px; height: 18px; }

.icon-btn {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 9px;
  border: none; background: none; color: var(--muted);
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.delete:hover { color: var(--danger); background: rgba(248, 113, 113, .1); }

input[type="text"], input[type="email"], input[type="password"], select {
  min-width: 0; padding: 10px 12px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--border);
}
input[type="text"]:focus, input[type="email"]:focus, input[type="password"]:focus, select:focus { outline: none; border-color: var(--accent); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ---------- Page header ---------- */
.page-header {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 24px;
}
.page-header h1 { margin: 0; font-size: 28px; letter-spacing: -.02em; }
.page-header p { margin: 2px 0 0; }

.progress-card { min-width: 200px; }
.progress-text { font-size: 14px; color: var(--muted); margin-bottom: 6px; text-align: right; }
.progress-text strong { color: var(--text); font-size: 18px; }
.progress-bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }

/* ---------- Empty states ---------- */
.empty { padding: 40px 24px; text-align: center; }
.empty p { margin: 4px 0; }
.empty-icon { color: var(--muted); margin-bottom: 8px; }
.empty-icon svg { width: 36px; height: 36px; stroke-width: 1.5; }

/* ---------- Small shared bits ---------- */
.small { font-size: 13px; }
.spacer { flex: 1; }
.danger-text { color: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.active { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.dot { flex-shrink: 0; width: 9px; height: 9px; border-radius: 50%; background: var(--cat); display: inline-block; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper .icon-btn { border: 1px solid var(--border); }
.stepper-value { min-width: 32px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-width: 44px; padding: 7px 10px; border-radius: 99px;
  border: 1px solid var(--border); background: none; color: var(--muted); font-size: 13px;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #0b0d12; font-weight: 600; }

/* ---------- Habits ---------- */
.add-form { display: flex; flex-direction: column; gap: 14px; padding: 12px; margin-bottom: 24px; }
.add-row { display: flex; gap: 10px; }
.add-row input { flex: 1; }
.add-options { display: flex; flex-wrap: wrap; gap: 20px 32px; padding: 4px 4px 2px; }

.toolbar { display: flex; justify-content: flex-end; margin: -8px 0 8px; }

.group { margin-bottom: 28px; }
.group-title {
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 10px 4px; font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
}
.group-count { margin-left: auto; font-weight: 500; text-transform: none; letter-spacing: 0; }

.habit {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 12px 12px 14px;
}
.habit + .habit { border-top: 1px solid var(--border); }

/* The big tick button. --p is how much of today's target is done (0-1). */
.check {
  flex-shrink: 0; display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 10px;
  border: 2px solid var(--border); color: transparent;
  background: linear-gradient(to top, color-mix(in srgb, var(--cat) 45%, transparent) calc(var(--p) * 100%), transparent 0);
  transition: background .15s, border-color .15s, color .15s;
}
.check:hover { border-color: var(--cat); }
.check.partial { border-color: var(--cat); }
.check.full { background: var(--cat); border-color: var(--cat); color: #0b0d12; }
.check svg { stroke-width: 3; width: 18px; height: 18px; }
.check-count { color: var(--text); font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.not-due .check { opacity: .5; }

.habit-info { flex: 1; min-width: 0; }
.habit-name {
  display: block; max-width: 100%; padding: 0; border: none; background: none;
  font-weight: 550; text-align: left; overflow-wrap: anywhere;
}
.habit-name:hover { text-decoration: underline; text-underline-offset: 3px; }
.habit.full .habit-name { color: var(--muted); }
.habit-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.streak { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.streak .flame { display: flex; }
.streak .flame svg { width: 14px; height: 14px; }
.streak.on .flame { color: #fb923c; }
.streak .meta-item { margin-left: 2px; }
.meta-item { white-space: nowrap; }
.streak .meta-item::before { content: "·"; margin: 0 4px 0 2px; }
.habit-meta > *:not(:last-child):not(:has(+ .rest-tag)):not(.status-pill)::after { content: "·"; margin: 0 2px 0 6px; color: var(--muted); }
.habit-meta > .status-pill { margin-right: 4px; }
.rest-tag {
  margin-left: 4px; padding: 0 7px; border-radius: 99px;
  border: 1px dashed var(--border); font-size: 11px;
}
.reorder { display: flex; gap: 4px; }

/* Day squares in the week grid and the calendar */
.week { display: flex; gap: 4px; }
.day {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 2px; border: none; background: none; border-radius: 8px;
}
.day-letter { font-size: 11px; color: var(--muted); line-height: 1; }
.day.today .day-letter { color: var(--text); font-weight: 700; }
.day-box {
  display: grid; place-items: center;
  width: 24px; height: 24px; border-radius: 6px;
  border: 1px solid var(--border);
  background: linear-gradient(to top, var(--cat) calc(var(--p) * 100%), var(--surface-2) 0);
  font-size: 12px; font-variant-numeric: tabular-nums; color: var(--text);
  transition: background .15s;
}
.day:hover .day-box { border-color: var(--cat); }
.day.partial .day-box { border-color: var(--cat); }
.day.full .day-box { border-color: var(--cat); color: #0b0d12; font-weight: 600; }
.day.rest .day-box { background: transparent; border-style: dashed; color: var(--muted); }
.day.rest.full .day-box, .day.rest.partial .day-box {
  background: linear-gradient(to top, var(--cat) calc(var(--p) * 100%), transparent 0);
}
.day.today .day-box { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--muted); }

/* ---------- Habits tabs ---------- */
.tabs {
  display: flex; gap: 4px; padding: 4px; margin-bottom: 20px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
}
.tab {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 12px; border: none; border-radius: 9px; background: none;
  color: var(--muted); font-weight: 600; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { background: var(--surface-2); color: var(--text); }
.tab-badge {
  min-width: 20px; padding: 1px 6px; border-radius: 99px;
  background: var(--danger); color: #0b0d12; font-size: 11px; font-weight: 700;
}

/* ---------- Recurring tasks ---------- */
.task { display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 16px; }
.task + .task { border-top: 1px solid var(--border); }
.task-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.task-name { font-weight: 550; overflow-wrap: anywhere; }
.task-bar { height: 4px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 4px; max-width: 320px; }
.task-bar-fill { height: 100%; border-radius: 99px; background: var(--muted); }
.task.soon .task-bar-fill { background: var(--warn); }
.task.due .task-bar-fill, .task.overdue .task-bar-fill { background: var(--danger); }
.status-pill {
  padding: 0 8px; border-radius: 99px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); color: var(--muted); white-space: nowrap;
}
.status-pill.soon { border-color: var(--warn); color: var(--warn); }
.status-pill.due, .status-pill.overdue { border-color: var(--danger); color: var(--danger); }
.btn.outline { border-color: var(--border); }
.num-input { width: 72px; }
.inline { display: flex; gap: 8px; }
.field-hint { margin: 0; font-size: 12px; color: var(--muted); }
input[type="number"], input[type="date"] {
  min-width: 0; padding: 10px 12px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--border);
}
input[type="number"]:focus, input[type="date"]:focus { outline: none; border-color: var(--accent); }

/* ---------- Notes ---------- */
.header-actions { display: flex; gap: 8px; }
.tab-count { font-size: 12px; font-weight: 500; color: var(--muted); }

.picker { display: flex; flex-direction: column; gap: 12px; padding: 18px; margin-bottom: 20px; }
.picker-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.picker-source { display: flex; align-items: center; gap: 8px; }
.small-select { padding: 6px 10px; font-size: 13px; }
.pick { display: flex; flex-direction: column; gap: 2px; }
.pick-field { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.pick-topic { margin: 0; font-size: 22px; font-weight: 700; line-height: 1.3; text-wrap: balance; }
.picker-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.picker-actions .link-btn { margin-left: 4px; align-self: center; }
.picker-done { margin: 0; color: var(--ok); font-size: 14px; }
.picker-done a { color: var(--text); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filters select { padding: 8px 10px; font-size: 14px; }
.search-box {
  flex: 1 1 220px; display: flex; align-items: center; gap: 8px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--muted);
}
.search-box:focus-within { border-color: var(--accent); }
.search-box svg { width: 16px; height: 16px; flex-shrink: 0; }
.search-box input { flex: 1; min-width: 0; padding: 9px 0; border: none; background: none; outline: none; }

.table { overflow: hidden; }
.table .row {
  display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 1.4fr) minmax(0, 1.6fr) 90px;
  gap: 12px; align-items: center; padding: 11px 16px;
  color: inherit; text-decoration: none; border-top: 1px solid var(--border);
}
.table .row.head { border-top: none; padding-block: 9px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.table a.row:hover { background: var(--surface-2); }
.cell-title { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-width: 0; font-weight: 550; }
.cell-title-text { min-width: 0; overflow-wrap: anywhere; }
.snippet { flex-basis: 100%; font-weight: 400; padding-left: 16px; }
.type-dot { flex-shrink: 0; width: 8px; height: 8px; border-radius: 2px; background: var(--muted); }
.type-dot.learning { background: var(--accent); border-radius: 50%; }
.cell-field, .cell-date { font-size: 14px; overflow-wrap: anywhere; }
.cell-date { font-variant-numeric: tabular-nums; }
.cell-tags { display: flex; flex-wrap: wrap; gap: 4px; min-width: 0; }
.tag {
  display: inline-flex; align-items: center; gap: 2px; padding: 1px 8px; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; color: var(--text);
}
.tags { display: flex; flex-wrap: wrap; gap: 4px; }

/* note page */
.note-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.note-bar .btn svg { width: 16px; height: 16px; }
.seg { display: flex; padding: 3px; border: 1px solid var(--border); border-radius: 9px; }
.seg button { padding: 5px 12px; border: none; border-radius: 6px; background: none; color: var(--muted); font-size: 13px; font-weight: 600; }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }
.note-title, .note-title-read {
  width: 100%; margin: 0 0 14px; padding: 0; border: none; background: none;
  font-size: 30px; font-weight: 750; letter-spacing: -.02em; line-height: 1.2; text-wrap: balance;
}
input.note-title { border: none; border-radius: 0; background: none; padding: 0; }
.note-title:focus { outline: none; }
.note-title::placeholder { color: var(--border); }
.props { display: flex; flex-direction: column; gap: 2px; padding: 8px 0 18px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.prop { display: grid; grid-template-columns: 90px minmax(0, 1fr); align-items: center; gap: 12px; min-height: 40px; }
.prop-label { font-size: 13px; color: var(--muted); }
.prop-value { min-width: 0; font-size: 14px; }
.prop-value input, .prop-value select { padding: 7px 10px; font-size: 14px; max-width: 100%; }
.tag-editor { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tag-editor input { width: 120px; }
.tag-x { padding: 0 0 0 4px; border: none; background: none; color: var(--muted); font-size: 14px; line-height: 1; }
.tag-x:hover { color: var(--danger); }
.review-banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 18px; padding: 10px 12px 10px 16px; border-radius: 12px;
  border: 1px solid var(--warn); background: var(--surface); font-size: 14px;
}
.note-block { margin-bottom: 22px; }
.block-label { margin: 0 0 8px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.note-text {
  display: block; width: 100%; min-height: 60px; padding: 12px 14px; resize: none;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
  font: inherit; line-height: 1.6; color: var(--text);
}
.note-text:focus { outline: none; border-color: var(--accent); }
.note-block input[type="text"] { width: 100%; }
.toolbar-row { display: flex; gap: 2px; margin-bottom: 6px; }
.tool {
  min-width: 32px; height: 30px; padding: 0 8px; border: 1px solid transparent; border-radius: 7px;
  background: none; color: var(--muted); font-weight: 700; font-size: 13px; display: grid; place-items: center;
}
.tool:hover { background: var(--surface-2); color: var(--text); }
.tool svg { width: 16px; height: 16px; }
.prose { line-height: 1.7; overflow-wrap: anywhere; max-width: 70ch; }
.prose > :first-child { margin-top: 0; }
.prose p { margin: 0 0 .8em; }
.prose h3 { margin: 1.2em 0 .4em; font-size: 20px; }
.prose h4 { margin: 1.1em 0 .4em; font-size: 17px; }
.prose h5 { margin: 1em 0 .3em; font-size: 15px; }
.prose ul, .prose ol { margin: 0 0 .8em; padding-left: 1.4em; }
.prose li { margin: .2em 0; }
.prose code { padding: 1px 5px; border-radius: 5px; background: var(--surface-2); font-size: .92em; }
.prose a { color: var(--accent); }
.note-link { color: var(--accent); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 50%, transparent); }
button.note-link { padding: 0; border: none; border-bottom: 1px dashed var(--muted); background: none; color: var(--muted); font: inherit; }
.takeaways { padding-left: 1.4em; }
.link-chip { text-decoration: none; color: var(--text); }
.pick-list { display: flex; flex-direction: column; max-height: 50vh; overflow-y: auto; margin: 10px 0; }
.pick-item {
  display: flex; justify-content: space-between; gap: 12px; padding: 10px 8px; border: none; border-radius: 8px;
  background: none; text-align: left; color: var(--text);
}
.pick-item:hover { background: var(--surface-2); }
.dialog > input { width: 100%; }

/* ---------- Habit history pop-up ---------- */
.dialog.dialog-wide { width: min(480px, calc(100vw - 32px)); }
.history { display: flex; flex-direction: column; gap: 18px; }
.history-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.history-head p { margin: 0 !important; }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
  padding: 10px 12px; border-radius: 10px; background: var(--surface-2);
}
.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stat-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--muted); }
.cal-nav { display: flex; align-items: center; justify-content: space-between; }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-head { text-align: center; font-size: 11px; font-weight: 600; color: var(--muted); }
.calendar .day { padding: 0; }
.calendar .day-box { width: 100%; height: auto; aspect-ratio: 1; max-width: 100%; border-radius: 8px; }
.cal-off { display: grid; place-items: center; aspect-ratio: 1; font-size: 12px; color: var(--border); }
.history > p { margin: 0 !important; }

/* ---------- Today page ---------- */
.overview { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.span-2 { grid-column: span 2; }
.tile { display: flex; flex-direction: column; gap: 12px; padding: 18px; }
.tile-title {
  margin: 0; font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
}
.tile-big { margin: 0; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile p { margin: 0; }
.delta { display: block; margin-top: 2px; font-size: 13px; font-weight: 500; color: var(--muted); }
.delta.up { color: var(--ok); }

.ring-row { display: flex; align-items: center; gap: 18px; }
.ring { position: relative; flex-shrink: 0; width: 88px; height: 88px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 8; }
.ring-track { stroke: var(--surface-2); }
.ring-fill { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .4s; }
.ring-label {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-weight: 700; font-variant-numeric: tabular-nums;
}

.bars { display: flex; gap: 8px; height: 96px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.bar-track { flex: 1; width: 100%; max-width: 28px; display: flex; align-items: flex-end; border-bottom: 1px solid var(--border); }
.bar-fill { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; }
.bar:hover .bar-fill { filter: brightness(1.15); }
.bar-label { font-size: 11px; color: var(--muted); line-height: 1; }
.bar.today .bar-label { color: var(--text); font-weight: 700; }

.todo-list { display: flex; flex-direction: column; }
.todo { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.todo + .todo { border-top: 1px solid var(--border); }
.next-up { display: flex; flex-direction: column; gap: 6px; padding-top: 4px; }
.link-btn { align-self: flex-start; }
.streak-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.streak-list li { display: flex; align-items: center; gap: 10px; }
.streak-list .habit-name { flex: 1; min-width: 0; }

/* ---------- Confirm dialog ---------- */
.dialog {
  width: min(400px, calc(100vw - 32px));
  padding: 20px; border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dialog p { margin: 0 0 20px; overflow-wrap: anywhere; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-actions .btn-ghost { justify-content: center; }

.dialog-title { margin: 0 0 6px; font-size: 18px; }
.dialog .muted { margin-bottom: 16px; font-size: 14px; }
.dialog .stack { display: flex; flex-direction: column; gap: 10px; }
.dialog .stack .dialog-actions { margin-top: 6px; }
.dialog-actions.wrap { flex-wrap: wrap; align-items: center; }
.dialog-actions .link-btn { margin-right: auto; }
.form-message { margin: 0 !important; min-height: 1.5em; font-size: 14px; color: var(--danger); }
.form-message.ok { color: var(--ok); }
.link-btn { border: none; background: none; padding: 4px 0; color: var(--muted); font-size: 14px; text-decoration: underline; }
.link-btn:hover { color: var(--text); }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- "Sign in to sync" banner ---------- */
.banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 24px; padding: 12px 12px 12px 16px;
  border: 1px solid var(--accent); border-radius: var(--radius);
  background: var(--surface);
}

/* ---------- Toast message ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast { display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 32px); }
.toast.has-action { pointer-events: auto; }
.toast-action { padding: 2px 4px; border: none; background: none; color: var(--accent); font-weight: 700; }

/* ---------- Phone layout ---------- */
@media (max-width: 760px) {
  .layout { flex-direction: column; }

  /* Sidebar becomes a top bar (brand + export/import)... */
  .sidebar {
    position: sticky; z-index: 20;
    width: auto; height: auto;
    flex-direction: row; align-items: center; justify-content: space-between;
    padding: 10px 16px;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .brand { padding: 0; }
  .sync { margin: 0 auto 0 0; padding: 8px; }
  .sync-label { display: none; }
  .data-actions { margin: 0; flex-direction: row; }
  .data-actions .btn-ghost { padding: 8px 10px; }

  /* ...and the section links move to a bar along the bottom. */
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    flex-direction: row; justify-content: space-around;
    padding: 6px 4px; padding-bottom: max(6px, env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .nav-link { flex: 1; min-width: 0; flex-direction: column; gap: 2px; padding: 6px 2px; font-size: 10px; }
  .nav-label { display: none; }
  .nav-label-short { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .progress-card { flex-basis: 100%; }
  .progress-text { text-align: left; }
  .nav-link.active { background: none; }
  .nav-soon { display: none; }
  .nav-badge { position: absolute; top: 2px; left: calc(50% + 6px); margin: 0; padding: 0 5px; min-width: 16px; font-size: 10px; }

  .main { padding: 24px 16px 110px; }
  .toast { bottom: 90px; }

  .add-row { flex-wrap: wrap; }
  .add-row input { flex-basis: 100%; }
  .add-row select { flex: 1; }

  /* Habit row: tick, name, edit on top; the 7-day grid underneath. */
  .habit { flex-wrap: wrap; row-gap: 10px; }
  .habit .habit-info { order: 1; }
  .habit .edit, .habit .reorder { order: 2; }
  .week { order: 3; flex-basis: 100%; justify-content: space-between; padding-left: 48px; }
  .day-box { width: 28px; height: 28px; }

  .overview { grid-template-columns: minmax(0, 1fr); }

  /* Notes list: stacked rows instead of a table */
  .table .row.head { display: none; }
  .table .row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "title date" "meta meta"; gap: 4px 12px; }
  .cell-title { grid-area: title; }
  .cell-date { grid-area: date; font-size: 13px; }
  .cell-field { grid-area: meta; font-size: 13px; }
  .cell-field:empty { display: none; }
  .cell-tags { grid-column: 1 / -1; }
  .cell-tags:empty { display: none; }
  .note-title, .note-title-read { font-size: 26px; }
  .prop { grid-template-columns: 70px minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .brand-name { display: none; }
}

@media (max-width: 340px) {
  .data-actions span { display: none; }
  .week { padding-left: 0; }
}
