:root {
  --yellow: #f5c238; --blue: #61ade8; --coral: #e86661; --lavender: #a39cde;
  --bg: #f2f2f7; --card: #ffffff; --text: #1c1c1e; --muted: #6c6c70; --line: #e3e3e8;
  --danger: #d93a35; --field: #f2f2f7;
  --radius: 18px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #000; --card: #1c1c1e; --text: #f2f2f7; --muted: #98989f; --line: #2c2c2e; --field: #2c2c2e; --danger: #ff5a52; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#app { max-width: 760px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 6px; position: sticky; top: 0; z-index: 5; background: var(--bg); }
.top h1 { font-size: 28px; margin: 0; letter-spacing: -.4px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.sync-state { font-size: 13px; color: var(--muted); }
.sync-state.err { color: var(--danger); }
main { flex: 1; padding: 4px 16px 110px; outline: none; }

.chip { border: 0; background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 14px; }
.chip.on { background: var(--lavender); color: #fff; }

.tabbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 6px);
  width: min(736px, calc(100% - 24px)); display: flex; gap: 2px; padding: 8px 8px 5px; background: var(--card);
  border-radius: 26px; box-shadow: 0 5px 16px rgba(0,0,0,.09); border: .7px solid rgba(128,128,128,.12); z-index: 10; }
.tabbar button { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 11px; color: var(--muted); padding: 0; }
.tabbar .ti { width: 34px; height: 28px; border-radius: 14px; display: grid; place-items: center; font-weight: 700;
  color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); font-size: 16px; }
.tabbar button.on { color: var(--c); font-weight: 700; }
.tabbar button.on .ti { background: var(--c); color: #fff; }

.card { background: var(--card); border-radius: var(--radius); padding: 12px; margin: 0 0 12px; }
.folder-head { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; padding: 2px 2px 6px; text-align: left; }
.folder-head .name { flex: 1; font-weight: 650; font-size: 17px; }
.folder-head .count { color: var(--muted); font-size: 14px; }
.chev { color: var(--muted); transition: transform .2s; }
.collapsed .chev { transform: rotate(-90deg); }
.collapsed .tiles { display: none; }
.icon { display: inline-grid; place-items: center; width: 1.6em; height: 1.6em; font-size: 20px; line-height: 1; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(6, 1fr); } }
.tile { border: 0; background: color-mix(in srgb, var(--c) 13%, var(--card)); border-radius: 14px; padding: 10px 4px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 4px; min-height: 86px; }
.tile .icon { font-size: 26px; }
.tile .label { font-size: 12px; line-height: 1.15; text-align: center; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile:active { transform: scale(.96); }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filters select, .filters button, .filters input { border: 0; background: var(--card); border-radius: 12px; padding: 8px 12px; font-size: 15px; }
.day { margin-bottom: 12px; padding: 4px 0; }
.day-title { font-size: 13px; color: var(--muted); padding: 0 14px 4px; }
.day-title::first-letter { text-transform: uppercase; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border: 0; background: none; width: 100%; text-align: left; }
.row + .row { border-top: .5px solid var(--line); }
.row .main { flex: 1; min-width: 0; }
.row .t1 { font-weight: 600; }
.row .t2 { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.row .right { color: var(--muted); font-size: 14px; white-space: nowrap; }
.badge { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; flex: none;
  background: color-mix(in srgb, var(--c) 18%, var(--card)); font-size: 21px; }
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.section-title { font-size: 13px; text-transform: uppercase; color: var(--muted); margin: 18px 14px 6px; letter-spacing: .3px; }
.stat-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.more { display: block; margin: 8px auto 0; }

.btn { border: 0; border-radius: 12px; padding: 10px 14px; background: var(--field); }
.btn.small { padding: 6px 10px; font-size: 14px; }
.primary { border: 0; border-radius: 12px; padding: 12px 16px; background: var(--coral); color: #fff; font-weight: 650; }
.danger { color: var(--danger); }
.btn.danger { color: var(--danger); }
.icon-btn { border: 0; background: none; padding: 6px; color: var(--muted); font-size: 18px; }
.actions { display: flex; gap: 6px; align-items: center; }

dialog { border: 0; border-radius: 20px; padding: 0; width: min(460px, calc(100% - 24px)); max-height: calc(100dvh - 40px);
  background: var(--card); color: var(--text); box-shadow: 0 12px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.35); }
#modal-form { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
#modal-form h2 { margin: 0; font-size: 20px; display: flex; align-items: center; gap: 8px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: 16px; }
input:not([type=checkbox]):not([type=range]), select, textarea { border: 0; border-radius: 12px; padding: 10px 12px;
  background: var(--field); color: var(--text); font-size: 16px; width: 100%; }
textarea { min-height: 90px; resize: vertical; }
input[type=range] { width: 100%; accent-color: var(--c, var(--coral)); }
.big-value { text-align: center; font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stepper { display: flex; gap: 10px; justify-content: center; }
.stepper .btn { min-width: 64px; font-size: 22px; }
.buttons { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.buttons .spacer { flex: 1; }
.colors { display: flex; gap: 10px; }
.colors button { width: 38px; height: 38px; border-radius: 50%; border: 3px solid transparent; background: var(--c); }
.colors button.on { border-color: var(--text); }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 4px; max-height: 210px; overflow: auto; }
.emoji-grid button { border: 0; background: var(--field); border-radius: 10px; font-size: 22px; padding: 4px 0; }
.emoji-grid button.on { outline: 2px solid var(--coral); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.note { color: var(--muted); font-size: 13px; margin: 0; }
.error { color: var(--danger); font-size: 14px; min-height: 1em; margin: 0; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 13px; overflow-wrap: anywhere; }
a { color: var(--blue); }

#toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 96px); transform: translateX(-50%) translateY(20px);
  background: rgba(30,30,32,.92); color: #fff; padding: 10px 18px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: .2s; z-index: 50; font-weight: 600; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }

/* вход */
body.auth { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.auth-box { width: min(380px, 100%); background: var(--card); border-radius: 24px; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.auth-box h1 { margin: 0; text-align: center; }
.auth-logo { width: 72px; height: 72px; border-radius: 16px; align-self: center; }
.auth-box form { display: flex; flex-direction: column; gap: 12px; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
