:root {
  --bg: #FFFFFF;
  --bg-elev: #F7F7F5;
  --bg-card: #FFFFFF;
  --bg-soft: #F3F2EE;
  --line: rgba(20, 18, 14, 0.08);
  --text: #1C1915;
  --muted: #6F6A62;
  --faint: #A39E94;
  --accent: #B0894A;
  --accent-2: #8A6A32;
  --high: #D45D42;
  --med: #C9A227;
  --low: #5E8A56;
  --ok: #2F9E62;
  --danger: #D45D42;
  --blue: #4A7CA8;
  --radius: 18px;
  --radius-sm: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --nav-h: calc(72px + var(--safe-b));
  --font: "SF Pro Display", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  overflow: hidden;
  letter-spacing: -0.01em;
}
button, input, textarea, select { font-family: inherit; color: inherit; color-scheme: light; }
button { cursor: pointer; border: none; background: none; }
img { display: block; }

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  background: var(--bg);
}

.screen {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: calc(16px + var(--safe-t)) 18px calc(var(--nav-h) + 24px);
  -webkit-overflow-scrolling: touch;
}
.screen.active { display: block; }
.screen.active[data-screen="ai"] { display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 22px;
  gap: 12px;
}
.eyebrow {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.h1 {
  font-size: 28px;
  font-weight: 650;
  letter-spacing: -0.035em;
  line-height: 1.15;
  margin-top: 4px;
}
.h2 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--text);
  flex-shrink: 0;
}
.icon-btn svg { width: 18px; height: 18px; }

.section { margin-bottom: 26px; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.section-head .h2 { color: var(--text); }
.count-pill {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg-soft);
  padding: 4px 9px;
  border-radius: 999px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px;
}
.list { display: flex; flex-direction: column; gap: 8px; }

.item {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  text-align: left;
  width: 100%;
}
.item.done {
  background: var(--bg-soft);
}
.item:active { transform: scale(0.99); }

.check {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1.5px solid var(--faint);
  flex-shrink: 0;
  margin-top: 0;
  display: grid;
  place-items: center;
  padding: 0;
  background: transparent;
}
.item > .item-body {
  background: transparent;
  border: 0;
  text-align: left;
  width: 100%;
  padding: 0;
  min-width: 0;
  color: inherit;
}
.check svg { width: 14px; height: 14px; }
.check.done {
  background: var(--ok);
  border-color: var(--ok);
  color: #FFFFFF;
}
.prio {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 7px;
}
.prio.high { background: var(--high); }
.prio.medium { background: var(--med); }
.prio.low { background: var(--low); }

.item-body { flex: 1; min-width: 0; }
.item-title {
  font-size: 15px;
  font-weight: 550;
  letter-spacing: -0.02em;
}
.item-title.done { color: var(--muted); text-decoration: line-through; }
.item-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.time-chip {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--accent-2);
  font-weight: 600;
  min-width: 44px;
  padding-top: 2px;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.stat {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
}
.stat .n {
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.04em;
}
.stat .l { font-size: 12px; color: var(--muted); margin-top: 2px; }

.capacity {
  margin-top: 10px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
}
.capacity-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}
.bar {
  height: 6px;
  background: var(--bg-soft);
  border-radius: 99px;
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 99px;
}
.bar.over > span { background: var(--high); width: 100% !important; }

.week-days { display: flex; flex-direction: column; gap: 8px; }
.week-day-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.week-day-card.today { border-color: rgba(196, 165, 116, 0.4); }
.week-day-head {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 14px 8px;
  text-align: left;
}
.week-day-tasks { padding: 0 10px 10px; }
.week-day-tasks .empty { padding: 8px 4px 4px; font-size: 13px; }
.move-day {
  flex-shrink: 0;
  max-width: 92px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}
.day-row {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  text-align: left;
}
.day-row.today { border-color: rgba(196, 165, 116, 0.4); }
.day-name { font-size: 13px; font-weight: 600; }
.day-date { font-size: 11px; color: var(--muted); }
.day-load { font-size: 12px; color: var(--muted); text-align: right; }
.mini-dots { display: flex; gap: 4px; flex-wrap: wrap; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.dot.appt { background: var(--blue); }
.dot.task { background: var(--accent); }
.dot.routine { background: var(--low); }
.dot.warn { background: var(--high); }

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.month-wd {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  padding: 6px 0 10px;
  font-weight: 600;
}
.month-cell {
  aspect-ratio: 1;
  min-height: 44px;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 13px;
}
.month-cell.out { opacity: 0.28; }
.month-cell.today { border-color: var(--accent); color: var(--accent-2); }
.month-marks { display: flex; gap: 2px; height: 5px; }
.mark { width: 4px; height: 4px; border-radius: 50%; }
.mark.a { background: var(--blue); }
.mark.t { background: var(--accent); }
.mark.l { background: var(--high); }

.progress {
  height: 4px;
  background: var(--bg-soft);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 8px;
}
.progress > span { display: block; height: 100%; background: var(--accent); }

.habit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.streak {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
}
.habit-track {
  display: flex;
  gap: 5px;
}
.habit-d {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  flex-shrink: 0;
}
.habit-d.on { background: var(--ok); border-color: var(--ok); }
.habit-d.miss { background: transparent; border-color: var(--high); }

.nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 480px;
  height: var(--nav-h);
  padding: 8px 10px var(--safe-b);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 20;
}
.nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--faint);
  font-size: 10px;
  font-weight: 600;
  padding: 6px 0;
  min-height: 44px;
}
.nav button.active { color: var(--accent-2); }
.nav svg { width: 22px; height: 22px; }

.fab {
  position: fixed;
  right: calc(50% - 240px + 18px);
  bottom: calc(var(--nav-h) + 12px);
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: var(--text);
  color: var(--bg);
  display: grid;
  place-items: center;
  z-index: 25;
  box-shadow: 0 10px 24px rgba(28, 25, 21, 0.14);
}
.fab svg { width: 24px; height: 24px; }
@media (max-width: 480px) {
  .fab { right: 18px; }
}
@media (min-width: 768px) {
  .app { max-width: 520px; }
  .nav, .sheet, .fab { max-width: 520px; }
  .fab { right: calc(50% - 260px + 18px); }
}

.sheet-backdrop, .modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40;
  display: none;
}
.sheet-backdrop.show, .modal-backdrop.show { display: block; }
.sheet {
  position: fixed;
  left: 50%;
  transform: translateX(-50%) translateY(110%);
  bottom: 0;
  width: 100%;
  max-width: 480px;
  background: #FFFFFF;
  border-radius: 24px 24px 0 0;
  padding: 12px 18px calc(24px + var(--safe-b));
  z-index: 50;
  transition: transform 0.28s ease;
  max-height: 88vh;
  overflow-y: auto;
}
.sheet.show { transform: translateX(-50%) translateY(0); }
.handle {
  width: 40px;
  height: 4px;
  background: #D8D4CC;
  border-radius: 99px;
  margin: 4px auto 16px;
}
.sheet h3 { font-size: 20px; letter-spacing: -0.03em; margin-bottom: 14px; }

.create-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}
.create-opt {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 14px;
  text-align: left;
}
.create-opt .k { font-size: 13px; color: var(--muted); margin-top: 6px; }
.create-opt .t { font-size: 16px; font-weight: 600; }

.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}
.field input, .field textarea, .field select {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 12px;
  font-size: 16px;
  outline: none;
  min-height: 44px;
}
.field input[type="date"], .field input[type="time"], .field input[type="number"] {
  min-height: 44px;
}
.field textarea { min-height: 80px; resize: vertical; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.days {
  display: flex;
  gap: 6px;
}
.days button {
  flex: 1;
  height: 36px;
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.days button.on { background: var(--text); color: var(--bg); }

.btn {
  width: 100%;
  height: 48px;
  border-radius: 14px;
  background: var(--text);
  color: var(--bg);
  font-weight: 650;
  font-size: 15px;
}
.btn.ghost {
  background: var(--bg-soft);
  color: var(--text);
  margin-top: 8px;
}
.btn.danger { background: var(--high); color: #fff; margin-top: 8px; }

.plan-banner {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
}
.plan-banner p { color: var(--muted); font-size: 13px; margin: 6px 0 14px; }
.plan-actions { display: flex; gap: 8px; }
.plan-actions .btn { height: 42px; font-size: 13px; }
.plan-actions .btn.ghost { margin-top: 0; }

.chip-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.chip {
  flex-shrink: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }

.ai-log { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; flex: 1; overflow-y: auto; min-height: 160px; }
.bubble {
  max-width: 88%;
  padding: 11px 13px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
}
.bubble.bot {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.bubble.me {
  align-self: flex-end;
  background: var(--text);
  color: var(--bg);
  border-bottom-right-radius: 6px;
}
.ai-input {
  display: flex;
  gap: 8px;
  position: sticky;
  bottom: 0;
}
.ai-input input {
  flex: 1;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 16px;
}
.ai-input button {
  width: 48px;
  border-radius: 14px;
  background: var(--text);
  color: var(--bg);
  display: grid;
  place-items: center;
}

.conflict {
  border: 1px solid rgba(224, 122, 95, 0.45);
  background: rgba(224, 122, 95, 0.08);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 10px;
  font-size: 13px;
}
.conflict strong { display: block; margin-bottom: 6px; color: var(--high); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
  font-size: 14px;
}

.suggest-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 8px;
}
.suggest-card .when { font-size: 12px; color: var(--accent); font-weight: 600; margin-bottom: 4px; }

.inbox-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.muted { color: var(--muted); }
.tiny { font-size: 12px; color: var(--muted); }

.install-hint {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--muted);
}
.install-hint b { color: var(--text); }

.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.project-card .item-title { margin-bottom: 2px; }

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  bottom: calc(var(--nav-h) + 76px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: 0.25s;
  z-index: 80;
  max-width: 90%;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.detail-actions { display: flex; gap: 8px; margin-top: 8px; }
.detail-actions .btn { height: 42px; }

body.auth-loading .app,
body.auth-guest .app { display: none; }
body.auth-loading .fab,
body.auth-guest .fab,
body.auth-loading .nav,
body.auth-guest .nav,
body.auth-loading .sheet,
body.auth-guest .sheet,
body.auth-loading .sheet-backdrop,
body.auth-guest .sheet-backdrop { display: none !important; }
body.auth-authed .auth-gate { display: none; }

.auth-gate {
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: calc(28px + var(--safe-t)) 22px calc(28px + var(--safe-b));
  overflow-y: auto;
  background: var(--bg);
}
.auth-brand { margin-bottom: 28px; }
.auth-panel { max-width: 420px; }
.auth-error {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 12px;
}
.auth-switch {
  margin-top: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
.auth-switch button {
  color: var(--accent-2);
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: 3px;
}
#user-greet { margin-top: 6px; }
#btn-logout { margin-top: 24px; }
