:root {
  --bg: #f5f5f7; --card: #ffffff; --text: #1d1d1f; --muted: #86868b; --line: rgba(0,0,0,.08);
  --fill: rgba(118,118,128,.12); --accent: #0071e3; --accent-text: #fff; --red: #ff3b30; --green: #34c759;
  --bar: rgba(250,250,252,.78); --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #000; --card: #1c1c1e; --text: #f5f5f7; --muted: #8e8e93; --line: rgba(255,255,255,.1);
    --fill: rgba(118,118,128,.24); --accent: #0a84ff; --bar: rgba(22,22,24,.78); --shadow: none; --red: #ff453a; --green: #30d158; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; letter-spacing: -.01em; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); font-size: 14px; min-height: 1em; margin: 0; }

/* layout */
#view { max-width: 720px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 20px) 16px calc(env(safe-area-inset-bottom) + 100px); }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 18px; }
.head h1 { font-size: 34px; line-height: 1.1; font-weight: 700; letter-spacing: -.025em; margin: 0; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: var(--accent); background: var(--fill); }
.icon-btn:active { opacity: .6; }

/* tab bar */
.tabbar { position: fixed; inset: auto 0 0 0; display: flex; justify-content: space-around; padding: 6px 4px calc(env(safe-area-inset-bottom) + 6px);
  background: var(--bar); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-top: .5px solid var(--line); z-index: 10; }
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; font-weight: 500; color: var(--muted); padding: 4px 8px; min-width: 60px; }
.tabbar button svg { width: 25px; height: 25px; }
.tabbar button.on { color: var(--accent); }
@media (min-width: 900px) {
  .tabbar { inset: 0 auto 0 0; width: 220px; flex-direction: column; justify-content: flex-start; gap: 2px; padding: 28px 12px; border-top: 0; border-right: .5px solid var(--line); }
  .tabbar button { flex-direction: row; gap: 12px; font-size: 15px; padding: 9px 12px; border-radius: 10px; color: var(--text); }
  .tabbar button.on { background: var(--fill); color: var(--accent); }
  #view { padding-left: 236px; max-width: 956px; padding-bottom: 40px; }
}

/* segmented */
.seg { display: flex; background: var(--fill); border-radius: 9px; padding: 2px; margin-bottom: 14px; }
.seg button { flex: 1; padding: 6px 8px; font-size: 14px; font-weight: 500; border-radius: 7px; }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* lists */
.group { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 22px; }
.group-title { font-size: 13px; text-transform: uppercase; letter-spacing: .02em; color: var(--muted); margin: 0 16px 6px; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 16px; min-height: 48px; position: relative; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--line); }
.row .main { flex: 1; min-width: 0; }
.row .title { overflow-wrap: anywhere; }
.row .sub { font-size: 13px; color: var(--muted); margin-top: 1px; }
.row.done .title { color: var(--muted); text-decoration: line-through; }
.row.tap:active { background: var(--fill); }
.check { width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid var(--muted); display: grid; place-items: center; flex: none; }
.check svg { width: 15px; height: 15px; stroke-width: 2.5; opacity: 0; color: #fff; }
.done .check { background: var(--accent); border-color: var(--accent); }
.done .check svg { opacity: 1; }
.badge { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; color: var(--muted); }
.badge svg { width: 13px; height: 13px; }
.kcal { font-size: 13px; color: var(--muted); white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty svg { width: 40px; height: 40px; stroke-width: 1.2; display: block; margin: 0 auto 10px; }

/* inputs */
input, select, textarea { width: 100%; background: var(--card); border: .5px solid var(--line); border-radius: 11px; padding: 12px 14px; outline: none; }
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.search { display: flex; align-items: center; gap: 8px; background: var(--fill); border-radius: 11px; padding: 0 10px; margin-bottom: 12px; color: var(--muted); }
.search input { background: transparent; border: 0; padding: 9px 0; box-shadow: none !important; color: var(--text); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 6px 13px; border-radius: 999px; background: var(--fill); font-size: 14px; }
.chip.on { background: var(--text); color: var(--bg); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.btn { display: inline-flex; justify-content: center; align-items: center; gap: 6px; padding: 12px 18px; border-radius: 12px; font-weight: 600; background: var(--fill); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--red); }
.btn:active { opacity: .7; }
.btn svg { width: 18px; height: 18px; }
.link { color: var(--accent); font-size: 15px; }
.bar { display: flex; gap: 10px; margin-bottom: 16px; }
.bar .btn { flex: 1; white-space: nowrap; padding: 11px 12px; font-size: 15px; }

/* visibility toggle */
.vis { display: flex; background: var(--fill); border-radius: 9px; padding: 2px; }
.vis label { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 7px; border-radius: 7px; font-size: 14px; cursor: pointer; }
.vis input { display: none; }
.vis label:has(input:checked) { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.vis svg { width: 16px; height: 16px; }

/* auth */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 340px; text-align: center; }
.auth-card h1 { font-size: 30px; margin: 14px 0 4px; letter-spacing: -.02em; }
.auth-card .stack { margin: 26px 0 14px; }
.logo { width: 64px; height: 64px; margin: 0 auto; border-radius: 16px; background: linear-gradient(135deg, #5e5ce6, #0a84ff); display: grid; place-items: center; color: #fff; }
.logo svg { width: 34px; height: 34px; fill: #fff; stroke: none; }

/* sheet */
dialog { border: 0; padding: 0; background: transparent; width: 100%; max-width: 520px; margin: auto auto 0; color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.35); }
#sheet-form { background: var(--bg); border-radius: 18px 18px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px); max-height: 90dvh; overflow: auto; }
@media (min-width: 600px) { dialog { margin: auto; } #sheet-form { border-radius: 18px; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.sheet-head h2 { font-size: 17px; margin: 0; }
.field label { display: block; font-size: 13px; color: var(--muted); margin: 0 4px 5px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.qty { display: flex; align-items: center; gap: 8px; }
.qty button { width: 40px; height: 40px; border-radius: 50%; background: var(--fill); font-size: 22px; }

/* chat */
.chat { display: flex; flex-direction: column; gap: 4px; }
.msg { max-width: 78%; padding: 8px 13px; border-radius: 18px; background: var(--card); box-shadow: var(--shadow); align-self: flex-start; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--accent); color: #fff; }
.msg time { display: block; font-size: 11px; opacity: .6; margin-top: 2px; text-align: right; }
.day { text-align: center; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
.composer { position: fixed; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 62px); padding: 8px 16px; background: var(--bar); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); display: flex; gap: 8px; align-items: flex-end; z-index: 9; }
.composer textarea { min-height: 38px; max-height: 140px; border-radius: 19px; padding: 8px 14px; resize: none; }
.composer button { width: 38px; height: 38px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
@media (min-width: 900px) { .composer { left: 220px; bottom: 0; } }

/* calendar */
.cal { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; margin-bottom: 22px; }
.cal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; padding: 0 4px; }
.cal-head b { font-size: 17px; }
.cal-head .nav { display: flex; gap: 4px; color: var(--accent); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; gap: 2px; }
.cal-grid .wd { font-size: 12px; color: var(--muted); padding: 4px 0; }
.cal-grid button { aspect-ratio: 1; border-radius: 50%; font-size: 16px; position: relative; max-width: 44px; margin: 0 auto; width: 100%; }
.cal-grid button.out { color: var(--muted); opacity: .45; }
.cal-grid button.today { color: var(--accent); font-weight: 600; }
.cal-grid button.sel { background: var(--text); color: var(--bg); }
.cal-grid button.has::after { content: ""; position: absolute; bottom: 5px; left: 50%; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 90px); transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 15px; opacity: 0; transition: .25s; pointer-events: none; z-index: 100; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
