/* ============ Colors & sizes ============ */
:root {
  --bg: #ebebeb;
  --surface: #f6f6f6;
  --card: #ffffff;
  --field: #f2f2f4;
  --line: #ececee;
  --track: #ebebed;
  --text: #18181b;
  --muted: #8a8a90;
  --faint: #bdbdc2;
  --dark: #1b1b1d;
  --green: #22b14c;
  --orange: #f2811d;
  --blue: #4c6ef5;
  --red: #e5484d;
  --purple: #8b5cf6;
  --pink: #e64980;
  --r-lg: 22px;
  --r-md: 16px;
  --soft-shadow: 0 1px 2px rgba(0, 0, 0, .05);
  --dock-space: calc(env(safe-area-inset-bottom) + 104px);
  color-scheme: light;
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; letter-spacing: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
h1, h2, p { margin: 0; }
button:focus { outline: none; }
button:focus-visible { outline: 2px solid rgba(27, 27, 29, .35); outline-offset: 2px; }

main { position: relative; height: 100dvh; }
.view {
  position: absolute;
  inset: 0;
  display: none;
  overflow-y: auto;
  padding: calc(env(safe-area-inset-top) + 18px) 20px var(--dock-space);
  -webkit-overflow-scrolling: touch;
}
.view.active { display: block; }
.view > * { max-width: 560px; margin-left: auto; margin-right: auto; }

/* ============ Shared pieces ============ */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; min-height: 40px; }
.top h1 { font-size: 23px; font-weight: 600; letter-spacing: -0.02em; }

.sq-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--soft-shadow);
  color: var(--text);
}
.sq-btn.sm { width: 34px; height: 34px; border-radius: 10px; }
.sq-btn.sm svg { width: 18px; height: 18px; }
.sq-btn:active, .pill-btn:active, .chip:active { transform: scale(.96); }

.pill-btn {
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--soft-shadow);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.pill-btn.dark { background: var(--dark); color: #fff; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: 0 2px 12px; }
.section-head h2 { font-size: 17px; font-weight: 600; }
.see-all { display: inline-flex; align-items: center; gap: 2px; font-size: 14px; font-weight: 500; }
.see-all svg { width: 16px; height: 16px; }

/* Outer grey container with a header row and a white inner card (like the goal cards) */
.box {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 6px;
  margin-bottom: 12px;
  box-shadow: var(--soft-shadow);
}
.box.flat { box-shadow: none; padding: 0; background: none; }
.box-head { display: flex; align-items: center; gap: 12px; padding: 8px 8px 12px; }
.goal .box-head, .goal .box-body { cursor: pointer; }
.box-title { flex: 1; min-width: 0; font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.box-body {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px;
}
.box-body.list { padding: 0 14px; }

.tile {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--card);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
}
.tile svg { width: 20px; height: 20px; }
.c-green { color: var(--green); }
.c-orange { color: var(--orange); }
.c-blue { color: var(--blue); }
.c-red { color: var(--red); }
.c-purple { color: var(--purple); }
.c-pink { color: var(--pink); }
.c-dark { color: var(--dark); }
.c-muted { color: var(--muted); }

.count {
  min-width: 28px;
  height: 28px;
  padding: 0 9px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--soft-shadow);
  font-size: 13px;
  font-weight: 600;
}

.empty { padding: 26px 18px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 16px; font-weight: 600; margin-bottom: 4px; }

/* ============ Hero (dark card) ============ */
.hero {
  position: relative;
  overflow: hidden;
  padding: 18px 16px 20px;
  margin-bottom: 26px;
  border-radius: 26px;
  text-align: center;
  color: #fff;
  background: radial-gradient(120% 95% at 50% 0%, #3a3a3e 0%, #232326 48%, #141416 100%);
  box-shadow: 0 18px 30px -14px rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255, 255, 255, .08);
}
.hero > * { position: relative; }
.hero .hero-lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 24px 24px, transparent 0 6px, rgba(255, 255, 255, .1) 6px 7px, transparent 7px),
    radial-gradient(circle at calc(100% - 24px) 24px, transparent 0 6px, rgba(255, 255, 255, .1) 6px 7px, transparent 7px);
}
.hero-lines::before {
  content: "";
  position: absolute;
  left: 22%;
  right: 22%;
  top: -1px;
  height: 56px;
  border: 1px solid rgba(255, 255, 255, .07);
  border-top: 0;
  border-radius: 0 0 20px 20px;
}
.hero-lines::after {
  content: "";
  position: absolute;
  inset: 44px 12px 12px;
  border: 1px solid rgba(255, 255, 255, .05);
  border-radius: 20px;
}
.hero-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .08);
  font-size: 13px;
  font-weight: 600;
}
.chip-dot { width: 16px; height: 11px; border-radius: 3px; background: var(--green); }
.chip-dot.alert { background: var(--red); }
.hero-label { margin-top: 14px; font-size: 13px; color: rgba(255, 255, 255, .55); }
.hero-num { font-size: 40px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.15; }
.hero-num span { color: rgba(255, 255, 255, .45); font-weight: 600; }
.hero-sub { margin-top: 2px; font-size: 13px; color: rgba(255, 255, 255, .6); }
.hero-actions { display: grid; grid-template-columns: repeat(4, 1fr); margin-top: 20px; }
.hero-actions button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: rgba(255, 255, 255, .72);
}
.orb {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--dark);
  background: linear-gradient(180deg, #fbfbfb 0%, #d2d2d5 100%);
  box-shadow: inset 0 1px 0 #fff, 0 4px 10px rgba(0, 0, 0, .35);
}
.orb svg { width: 20px; height: 20px; stroke-width: 2; }
.hero-actions button:active .orb { transform: scale(.94); }

/* ============ Up next (goal-style cards) ============ */
.g-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 14px; }
.g-row b { font-weight: 600; }
.g-row .muted { color: var(--muted); }
.g-row.small { font-size: 13px; font-weight: 500; }
.g-row .late { color: var(--red); }
.g-row .flag-high { color: var(--orange); }
.bar { height: 6px; margin: 10px 0 9px; border-radius: 999px; background: var(--track); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: inherit; }

/* ============ Next 7 days chart ============ */
.chart-card {
  background: var(--card);
  border-radius: var(--r-lg);
  padding: 16px;
  margin: 14px 0 26px;
  box-shadow: var(--soft-shadow);
}
.chart-card h3 { margin: 0; font-size: 16px; font-weight: 600; }
.chart-card .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.chart-card .sub b { color: var(--text); font-weight: 600; }
.chart {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  height: 170px;
  margin-top: 14px;
  align-items: end;
  background:
    linear-gradient(90deg, #e3e3e6 50%, transparent 0) 0 0 / 8px 1px repeat-x,
    linear-gradient(90deg, #e3e3e6 50%, transparent 0) 0 33.3% / 8px 1px repeat-x,
    linear-gradient(90deg, #e3e3e6 50%, transparent 0) 0 66.6% / 8px 1px repeat-x;
}
.bar-col { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; }
.bar-col .n { font-size: 12px; font-weight: 600; color: var(--muted); }
.pillar {
  width: 100%;
  max-width: 36px;
  min-height: 24px;
  border-radius: 999px;
  background: repeating-linear-gradient(135deg, #2a2a2d 0 4px, #38383c 4px 6px);
}
.pillar.zero { background: var(--track); }
.bar-labels { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; margin-top: 8px; text-align: center; font-size: 13px; color: var(--muted); }
.bar-labels .today { color: var(--text); font-weight: 600; }

/* ============ Task row ============ */
.task { display: flex; align-items: flex-start; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.task:last-child { border-bottom: 0; }
.task-body { flex: 1; min-width: 0; cursor: pointer; }
.task-title { font-weight: 500; overflow-wrap: anywhere; }
.task-meta { display: flex; flex-wrap: wrap; gap: 2px 8px; font-size: 13px; color: var(--muted); }
.task-meta .late { color: var(--red); font-weight: 600; }
.task-meta .flag-high { color: var(--orange); font-weight: 600; }
.task.done .task-title { color: var(--muted); text-decoration: line-through; }
.check {
  flex: none;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1.8px solid #c7c7cc;
}
.task.p-high .check { border-color: var(--orange); }
.check svg { width: 13px; height: 13px; stroke-width: 3; opacity: 0; }
.task.done .check { background: var(--green); border-color: var(--green); color: #fff; }
.task.done .check svg { opacity: 1; }

/* ============ Calendar ============ */
.cal-body { padding: 12px 6px 8px; }
.cal-weekdays, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-weekdays div { text-align: center; font-size: 12px; font-weight: 500; color: var(--muted); padding-bottom: 6px; }
.cal-day { display: flex; flex-direction: column; align-items: center; padding: 3px 0 4px; font-size: 15px; font-weight: 500; }
.cal-day .num { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; }
.cal-day.other { color: var(--faint); }
.cal-day.today .num { background: var(--field); font-weight: 700; }
.cal-day.selected .num { background: var(--dark); color: #fff; }
.dots { display: flex; gap: 3px; height: 5px; margin-top: 3px; }
.dot { width: 5px; height: 5px; border-radius: 50%; background: var(--dark); }
.dot.high { background: var(--orange); }
.dot.low { background: var(--faint); }
.dot.done { background: transparent; box-shadow: inset 0 0 0 1.3px var(--green); }

/* ============ Chat ============ */
#view-chat.active { display: flex; flex-direction: column; overflow: hidden; }
#view-chat > * { width: 100%; }
.chat-log { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 2px 0 12px; }
.msg { max-width: 86%; padding: 11px 15px; overflow-wrap: anywhere; }
.msg-text { white-space: pre-line; }
.msg.me { align-self: flex-end; background: var(--dark); color: #fff; border-radius: 20px 20px 6px 20px; }
.msg.bot { align-self: flex-start; background: var(--card); border-radius: 20px 20px 20px 6px; box-shadow: var(--soft-shadow); }
.msg .mini { margin-top: 10px; padding: 0 12px; border-radius: 14px; background: var(--surface); }
.msg .task { padding: 10px 0; }
.chips { flex: none; display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--soft-shadow);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}
.composer {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 18px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .06);
}
.composer input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 16px; /* 16px stops iPhone zooming in */ }
.send-btn { width: 42px; height: 42px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--dark); color: #fff; }
.send-btn svg { width: 20px; height: 20px; stroke-width: 2.2; }

/* ============ Floating tab bar ============ */
.dock {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  padding: 6px;
  border-radius: 999px;
  background: #121214;
  box-shadow: 0 14px 30px rgba(0, 0, 0, .28);
  z-index: 5;
}
.dock button { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 50%; color: #9d9da3; }
.dock button svg { width: 24px; height: 24px; }
.dock button.active { background: #fff; color: #121214; }

/* ============ Sheets (add/edit, settings) ============ */
.sheet {
  width: 100%;
  max-width: 520px;
  margin: auto auto 0;
  padding: 18px 20px calc(18px + env(safe-area-inset-bottom));
  border: 0;
  border-radius: 28px 28px 0 0;
  background: var(--card);
  color: var(--text);
}
.sheet::backdrop { background: rgba(20, 20, 22, .35); }
@media (min-width: 600px) { .sheet { margin: auto; border-radius: 28px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sheet-head h2 { font-size: 20px; font-weight: 600; }
.sheet .sq-btn { background: var(--field); box-shadow: none; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
.field input:not([type=radio]) {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  border: 1.5px solid transparent;
  border-radius: 14px;
  background: var(--field);
  font-size: 16px;
  outline: none;
}
.field input:focus { border-color: var(--dark); background: var(--card); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); padding: 4px; border-radius: 14px; background: var(--field); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 9px; border-radius: 11px; text-align: center; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; }
.segmented input:checked + span { background: var(--card); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .1); }
.segmented input[value=high]:checked + span { color: var(--orange); }
.big-btn {
  width: 100%;
  height: 56px;
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  background: linear-gradient(180deg, #303034 0%, #141416 100%);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  box-shadow: 0 12px 22px -10px rgba(0, 0, 0, .5);
}
.big-btn svg { width: 20px; height: 20px; stroke-width: 2.2; }
.big-btn:active { transform: scale(.98); }
.text-danger { display: block; width: 100%; margin-top: 8px; padding: 12px; color: var(--red); font-weight: 600; }
.text-danger[hidden] { display: none; }

.menu-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 0; text-align: left; border-bottom: 1px solid var(--line); }
.menu-row:last-child { border-bottom: 0; }
.menu-row .tile { background: var(--field); box-shadow: none; }
.menu-text { flex: 1; min-width: 0; }
.menu-text b { display: block; font-weight: 600; }
.menu-text small { display: block; font-size: 13px; color: var(--muted); }
.menu-row .chev { width: 18px; height: 18px; color: var(--faint); }

/* ============ Passcode screen ============ */
html.locked main, html.locked .dock { visibility: hidden; }
.lock {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: env(safe-area-inset-top) 24px env(safe-area-inset-bottom);
  border: 0;
  background: var(--bg);
  color: var(--text);
}
.lock[open] { display: flex; align-items: center; justify-content: center; }
.lock::backdrop { background: var(--bg); }
.lock-inner { display: flex; flex-direction: column; align-items: center; }
.lock-icon {
  width: 64px;
  height: 64px;
  margin-bottom: 18px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  color: #fff;
  background: radial-gradient(120% 95% at 50% 0%, #3a3a3e 0%, #141416 100%);
  box-shadow: 0 10px 22px -10px rgba(0, 0, 0, .5);
}
.lock-icon svg { width: 28px; height: 28px; }
.lock h2 { font-size: 20px; font-weight: 600; }
.pin-dots { display: flex; gap: 18px; margin: 22px 0 10px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--dark); }
.pin-dots i.on { background: var(--dark); }
.pin-dots.shake { animation: shake .35s; }
@keyframes shake {
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
.lock-hint { min-height: 20px; font-size: 14px; color: var(--muted); }
.lock-hint.bad { color: var(--red); }
.keypad { display: grid; grid-template-columns: repeat(3, 72px); gap: 16px 26px; margin-top: 16px; }
.keypad [data-key] {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--soft-shadow);
  font-size: 28px;
  font-weight: 500;
}
.keypad [data-key]:active { background: var(--dark); color: #fff; }
.keypad [data-key=del] { background: none; box-shadow: none; }
.keypad [data-key=del]:active { background: var(--field); color: var(--text); }
.key-slot { display: grid; place-items: center; }
.lock-text { font-size: 15px; font-weight: 600; color: var(--muted); }
.lock-text[hidden] { display: none; }
#lock-forgot { margin-top: 28px; }

/* ============ Toast ============ */
.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  top: calc(env(safe-area-inset-top) + 12px);
  max-width: 460px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-radius: 999px;
  background: #121214;
  color: #fff;
  box-shadow: 0 10px 26px rgba(0, 0, 0, .25);
  z-index: 10;
}
.toast[hidden] { display: none; }
.toast span { flex: 1; font-size: 14px; }
.toast button { color: #7ee2a0; font-weight: 700; }
