/* ---------------------------------------------------------------- tokens */
:root {
  --bg: #faf7f5;
  --surface: #ffffff;
  --surface-2: #f3eeeb;
  --line: #e7dfda;
  --text: #2c2521;
  --muted: #8a7c74;
  --accent: #b8697f;
  --accent-soft: #f6e8ec;
  --accent-ink: #ffffff;
  --green: #4f8a72;
  --amber: #b7802f;
  --red: #b4544b;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(44, 37, 33, .06), 0 8px 24px rgba(44, 37, 33, .07);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17131a;
    --surface: #211c24;
    --surface-2: #2b242f;
    --line: #382f3d;
    --text: #f0e9ec;
    --muted: #a396a5;
    --accent: #e298ad;
    --accent-soft: #3a2a31;
    --accent-ink: #1a1015;
    --green: #7cc4a6;
    --amber: #e0b164;
    --red: #e58a80;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 ui-rounded, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

h1, h2, h3 { margin: 0; line-height: 1.25; }

/* ---------------------------------------------------------------- layout */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(var(--safe-t) + 12px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -.02em;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.view {
  flex: 1;
  padding: 14px 16px calc(150px + var(--safe-b));
}

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 6px 8px calc(6px + var(--safe-b));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}

.tabbar button {
  flex: 1;
  max-width: 130px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 4px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.tabbar button svg { width: 22px; height: 22px; }
.tabbar button[aria-selected="true"] { color: var(--accent); background: var(--accent-soft); }

/* --------------------------------------------------------------- controls */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-ghost { background: none; border-color: transparent; color: var(--muted); }
.btn-danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 35%, transparent); background: none; }
.btn-icon { padding: 8px; border-radius: 12px; line-height: 0; }
.btn-icon svg { width: 20px; height: 20px; }
.btn-block { width: 100%; justify-content: center; padding: 13px; font-size: 16px; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .05em; }

input[type="text"], input[type="email"], input[type="password"],
input[type="date"], input[type="time"], textarea, select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  outline: none;
}

input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 70px; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

/* ------------------------------------------------------------ list chips */
.chips {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.chip[aria-selected="true"] { background: var(--accent); border-color: transparent; color: var(--accent-ink); }

/* -------------------------------------------------------------- progress */
.progress-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 14px;
}

.ring { flex: none; width: 54px; height: 54px; }
.ring circle { fill: none; stroke-width: 7; }
.ring .track { stroke: var(--surface-2); }
.ring .bar { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .5s ease; }
.ring text { fill: var(--text); font-size: 15px; font-weight: 700; text-anchor: middle; }

.progress-copy strong { display: block; font-size: 15px; }
.progress-copy span { font-size: 13px; color: var(--muted); }

/* ----------------------------------------------------------------- tasks */
.section-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: none;
  padding: 16px 2px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.section-head .count { margin-left: auto; font-weight: 700; letter-spacing: 0; }
.section-head .caret { transition: transform .2s; }
.section-head[aria-expanded="false"] .caret { transform: rotate(-90deg); }

.tasks { display: flex; flex-direction: column; gap: 8px; }

.task {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.task.done { opacity: .55; }
.task.done .task-title { text-decoration: line-through; }

.check {
  flex: none;
  width: 26px;
  height: 26px;
  margin-top: 1px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: none;
  display: grid;
  place-items: center;
  padding: 0;
  transition: background .15s, border-color .15s;
}

.check svg { width: 15px; height: 15px; stroke: transparent; }
.check[aria-checked="true"] { background: var(--green); border-color: var(--green); }
.check[aria-checked="true"] svg { stroke: #fff; }

.task-main { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 0; }
.task-title { font-size: 15.5px; overflow-wrap: anywhere; }
.task-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 5px; font-size: 12.5px; color: var(--muted); }
.task-meta .due.overdue { color: var(--red); font-weight: 700; }
.task-meta .due.soon { color: var(--amber); font-weight: 700; }

.who {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* -------------------------------------------------------------- composer */
.composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(58px + var(--safe-b));
  z-index: 25;
  padding: 8px 12px;
  display: flex;
  gap: 8px;
  max-width: 720px;
  margin: 0 auto;
}

.composer input {
  box-shadow: var(--shadow);
  border-radius: 999px;
  padding: 13px 18px;
}

.composer .btn { box-shadow: var(--shadow); padding: 12px 16px; }

/* -------------------------------------------------------------- calendar */
.cal-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.cal-head h2 { flex: 1; font-size: 17px; }

.weekdays, .grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.weekdays div {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  padding-bottom: 6px;
}

.day {
  aspect-ratio: 1;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 0;
  font-size: 14px;
  font-weight: 600;
}

.day.outside { background: none; color: var(--muted); opacity: .45; }
.day.today { border-color: var(--accent); color: var(--accent); }
.day[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
.day .dots { display: flex; gap: 3px; height: 6px; }
.day .dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); display: block; }
.day[aria-selected="true"] .dots i { background: var(--accent-ink); }

.agenda { margin-top: 18px; }
.agenda h3 { font-size: 15px; margin-bottom: 10px; }

.event {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  width: 100%;
  text-align: left;
}

.event .when { font-size: 12.5px; color: var(--muted); margin-top: 3px; }

/* ----------------------------------------------------------------- sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(20, 14, 18, .45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade .2s ease;
}

.sheet {
  width: 100%;
  max-width: 720px;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(24px + var(--safe-b));
  animation: rise .25s cubic-bezier(.2, .8, .3, 1);
}

.grabber { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 14px; }

.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.sheet-head h2 { flex: 1; font-size: 18px; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }

/* ----------------------------------------------------------- misc / auth */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 20px;
}

.empty .big { font-size: 40px; margin-bottom: 10px; }

.auth {
  max-width: 400px;
  margin: 0 auto;
  padding: 10vh 22px 40px;
}

.auth h1 { font-size: 26px; margin-bottom: 6px; letter-spacing: -.02em; }
.auth p.sub { color: var(--muted); margin: 0 0 24px; }
.auth .person { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; background: var(--surface); }
.auth .person h3 { font-size: 14px; margin-bottom: 10px; color: var(--accent); }

.error { color: var(--red); font-size: 14px; margin: 10px 0; min-height: 20px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 10px;
}

.sync i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.countdown { border-color: transparent; background: var(--accent-soft); color: var(--accent); }
.sync.offline i { background: var(--amber); }
.sync.offline { color: var(--amber); }

.filter-row { display: flex; gap: 6px; margin: 12px 0 4px; }

.tag {
  background: var(--surface-2);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 11.5px;
  font-weight: 600;
}

.section-head.danger { color: var(--red); }
.pill.countdown { cursor: pointer; }

.seg {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 600;
}

.seg[aria-selected="true"] { background: var(--surface-2); color: var(--text); }

.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.list-row .name { flex: 1; }

.drag-handle {
  flex: none;
  width: 22px;
  margin: 2px -4px 0 -4px;
  color: var(--line);
  line-height: 0;
  cursor: grab;
  touch-action: none;
}

.drag-handle svg { width: 18px; height: 18px; }
.drag-handle:active { cursor: grabbing; color: var(--muted); }

.task.dragging {
  position: relative;
  z-index: 5;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .28);
  border-color: var(--accent);
}

.week-day {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
}

.week-day.today { border-color: var(--accent); }

.week-day-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 13px;
}

.week-day-head strong { font-size: 13px; }
.week-day-head span { color: var(--muted); }
.week-day .event { margin-bottom: 6px; }
.week-empty { color: var(--muted); font-size: 13px; margin: 2px 0 4px; }

.activity {
  display: flex;
  align-items: baseline;
  gap: 9px;
  padding: 7px 2px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--line);
}

.activity:last-of-type { border-bottom: 0; }
.activity .name { flex: 1; min-width: 0; color: var(--muted); }
.activity .name strong { color: var(--text); font-weight: 600; }
.activity .ago { color: var(--muted); font-size: 12px; white-space: nowrap; }

.toast-action {
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 800;
  padding: 0 0 0 14px;
  font-size: 14px;
}

.toast {
  display: flex;
  align-items: center;
  position: fixed;
  left: 50%;
  bottom: calc(120px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 60;
  max-width: calc(100vw - 32px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: fade .2s ease;
}

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