:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --text: #1b1a18;
  --muted: #77736a;
  --line: #e6e3dc;
  --accent: #1f5c4d;
  --on-accent: #ffffff;
  --hot: #c2410c;
  --hot-bg: #fdeee4;
  --shadow: 0 1px 2px rgba(27, 26, 24, .05), 0 6px 20px rgba(27, 26, 24, .05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131312;
    --surface: #1d1d1b;
    --text: #edebe5;
    --muted: #96928a;
    --line: #2c2b28;
    --accent: #58b79f;
    --on-accent: #0c1f1a;
    --hot: #f59e6c;
    --hot-bg: #3a2216;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; touch-action: manipulation; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

#app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 0 16px calc(150px + env(safe-area-inset-bottom));
}

/* шапка */
.top { display: flex; align-items: center; gap: 4px; padding: calc(18px + env(safe-area-inset-top)) 0 10px; }
.top h1 { margin: 0; font-size: 28px; line-height: 1.15; letter-spacing: -.02em; font-weight: 700; }
.top p { margin: 2px 0 0; color: var(--muted); font-size: 15px; }
.top p:empty { display: none; }
.back { width: 40px; height: 44px; margin-left: -10px; display: grid; place-items: center; color: var(--muted); }

/* секции и строки */
.section { margin-top: 18px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; padding: 0 4px 8px; }
.section-head h2 { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.section-head.hot h2 { color: var(--hot); }
.link { color: var(--accent); font-size: 14px; font-weight: 600; padding: 4px; }

.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: stretch; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.check { flex: none; width: 52px; display: grid; place-items: center; }
.check i { width: 24px; height: 24px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--muted) 55%, transparent); display: grid; place-items: center; transition: background .15s, border-color .15s; }
.check i svg { width: 14px; height: 14px; stroke: var(--on-accent); stroke-width: 3; opacity: 0; }
.row.done .check i { background: var(--accent); border-color: var(--accent); }
.row.done .check i svg { opacity: 1; }
.row-body { flex: 1; min-width: 0; text-align: left; padding: 13px 14px 13px 0; display: block; }
.row.plain .row-body { padding-left: 16px; }
.row-title { display: block; overflow-wrap: anywhere; }
.row.done .row-title { color: var(--muted); text-decoration: line-through; }
.row-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 3px; font-size: 13px; color: var(--muted); }
.row-meta:empty { display: none; }
.proj { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--muted)); flex: none; }
.due.hot { color: var(--hot); background: var(--hot-bg); padding: 1px 7px; border-radius: 6px; font-weight: 600; }
.row-action { flex: none; align-self: center; margin-right: 10px; padding: 8px 12px; border-radius: 10px; background: var(--bg); font-size: 14px; font-weight: 600; color: var(--accent); }

.empty { margin: 48px 12px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }
.progress { height: 4px; border-radius: 2px; background: var(--line); margin: 4px 4px 0; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); border-radius: 2px; transition: width .25s; }

/* проекты */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.card { text-align: left; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 14px; min-height: 104px; display: flex; flex-direction: column; border-top: 4px solid var(--c); }
.card-name { font-weight: 650; font-size: 17px; }
.card-count { color: var(--muted); font-size: 14px; margin-top: 2px; }
.card-hot { margin-top: auto; align-self: flex-start; }

/* нижняя панель */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 10px max(16px, calc((100vw - 608px) / 2)) env(safe-area-inset-bottom);
}
#quick { display: flex; gap: 8px; }
#quick input { flex: 1; min-width: 0; height: 46px; padding: 0 16px; border-radius: 23px; border: 1px solid var(--line); background: var(--surface); outline: none; }
#quick input:focus { border-color: var(--accent); }
#quick button { flex: none; width: 46px; height: 46px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; }
#quick button svg { stroke-width: 2.4; }
.tabs { display: flex; }
.tabs button { flex: 1; height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 11px; font-weight: 600; position: relative; }
.tabs button[aria-current="page"] { color: var(--accent); }
.badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--hot); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }

/* карточка записи */
dialog#sheet {
  width: 100%; max-width: 640px; max-height: 92dvh; margin: auto auto 0; padding: 0; border: 0;
  border-radius: 22px 22px 0 0; background: var(--surface); color: var(--text); overflow-y: auto;
}
dialog#sheet::backdrop { background: rgba(0, 0, 0, .4); }
@media (min-width: 700px) { dialog#sheet { margin: auto; border-radius: 22px; } }
.sheet { padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); display: grid; gap: 16px; }
.sheet textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); padding: 11px 13px; resize: none; outline: none; }
.sheet textarea:focus, .sheet input[type="date"]:focus { border-color: var(--accent); }
.sheet .t-title { font-size: 19px; font-weight: 600; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 2px 7px; letter-spacing: .02em; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip { height: 38px; padding: 0 14px; border-radius: 19px; border: 1px solid var(--line); background: var(--bg); display: inline-flex; align-items: center; gap: 7px; font-size: 15px; }
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); font-weight: 600; }
.sheet input[type="date"] { height: 38px; padding: 0 12px; border-radius: 19px; border: 1px solid var(--line); background: var(--bg); outline: none; min-width: 140px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 4px; }
.btn { height: 48px; padding: 0 20px; border-radius: 14px; font-weight: 600; }
.btn.primary { flex: 1; background: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--hot); background: var(--hot-bg); }

/* вход */
.login { max-width: 320px; margin: 22dvh auto 0; padding: 0 20px; display: grid; gap: 10px; }
.login h1 { margin: 0 0 12px; font-size: 28px; letter-spacing: -.02em; }
.login label { font-size: 13px; font-weight: 600; color: var(--muted); }
.login input { height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); outline: none; }
.login input:focus { border-color: var(--accent); }
.login button { height: 48px; border-radius: 12px; background: var(--accent); color: var(--on-accent); font-weight: 600; }
.login-error { color: var(--hot); margin: 0; min-height: 1.4em; font-size: 14px; }

#toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100vw - 32px);
}

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

/* ---------- этап 2: привычки, вложения, настройки ---------- */
.top-text { flex: 1; min-width: 0; }
.gear { flex: none; width: 44px; height: 44px; margin-right: -10px; display: grid; place-items: center; color: var(--muted); }

.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { height: 40px; padding: 0 14px 0 10px; border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); display: inline-flex; align-items: center; gap: 8px; font-size: 15px; max-width: 100%; }
.pill > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill i { flex: none; width: 20px; height: 20px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--muted) 55%, transparent); display: grid; place-items: center; }
.pill i svg { width: 12px; height: 12px; stroke: var(--on-accent); stroke-width: 3.2; opacity: 0; }
.pill[aria-pressed="true"] { color: var(--muted); }
.pill[aria-pressed="true"] i { background: var(--accent); border-color: var(--accent); }
.pill[aria-pressed="true"] i svg { opacity: 1; }
.pill small { color: var(--muted); font-size: 13px; flex: none; }

.row.habit { flex-wrap: wrap; }
.week { flex-basis: 100%; display: flex; gap: 6px; padding: 0 14px 13px 52px; }
.wd { flex: 1; max-width: 40px; height: 32px; border-radius: 10px; background: var(--bg); color: var(--muted); font-size: 11px; font-weight: 600; text-transform: lowercase; }
.wd.on { background: var(--accent); color: var(--on-accent); }
.wd.off { opacity: .45; }
.wd.today { box-shadow: inset 0 0 0 1.5px var(--accent); }
.streak { font-weight: 600; color: var(--text); }

details.later { margin-top: 18px; }
details.later > summary { list-style: none; cursor: pointer; padding: 0 4px 8px; font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
details.later > summary::-webkit-details-marker { display: none; }
details.later > summary::after { content: " ›"; }
details.later[open] > summary::after { content: " ⌄"; }

.files { display: grid; gap: 8px; }
.files img { display: block; max-width: 100%; max-height: 320px; border-radius: 12px; background: var(--bg); }
.files audio, .files video { width: 100%; border-radius: 12px; }
.file-link { display: flex; align-items: center; gap: 10px; padding: 11px 13px; border-radius: 12px; background: var(--bg); color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.file-link small { color: var(--muted); flex: none; margin-left: auto; }

.sheet input[type="time"], .sheet input[type="text"] { height: 38px; padding: 0 12px; border-radius: 19px; border: 1px solid var(--line); background: var(--bg); outline: none; }
.sheet input[type="text"] { width: 100%; height: 46px; border-radius: 12px; font-size: 19px; font-weight: 600; }
.sheet input:focus { border-color: var(--accent); }
.sheet h2 { margin: 0; font-size: 20px; }
.hint { margin: 0; color: var(--muted); font-size: 14px; }
.btn.ghost { background: var(--bg); }

.week-chips { flex-wrap: nowrap; gap: 6px; }
.week-chips .chip { flex: 1; padding: 0; justify-content: center; }

/* фильтры */
#filters { display: flex; gap: 8px; padding: 0 16px 4px; }
#filters[hidden] { display: none; }
#filters select { flex: 1; min-width: 0; height: 36px; padding: 0 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 14px; outline: none; }

/* приоритеты и долгосрочные в списках */
.pri.hi { color: var(--hot); background: var(--hot-bg); padding: 1px 7px; border-radius: 6px; font-weight: 600; }
.pri.lo { color: var(--muted); }
.lt { color: var(--muted); border: 1px solid var(--line); padding: 0 6px; border-radius: 6px; }

/* редактор проектов в настройках */
.settings-sub { margin-top: 10px; }
.proj-row { display: grid; grid-template-columns: 34px 1fr; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.proj-row input[type="color"] { width: 34px; height: 38px; padding: 2px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.proj-row .proj-name { grid-column: 2; }
.proj-row .proj-aliases { grid-column: 1 / -1; height: 34px !important; font-size: 14px !important; font-weight: 400 !important; border-radius: 10px !important; }
.proj-row .btn.mini { grid-column: span 1; height: 34px; padding: 0 12px; border-radius: 10px; font-size: 13px; justify-self: start; }
.proj-row .btn.mini.danger { justify-self: end; padding: 0 14px; }
.proj-row [data-proj-add], .proj-row [data-proj-save] { grid-column: 1; }

/* доска (канбан) */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 300px); gap: 10px; overflow-x: auto; padding: 2px 16px 16px; scroll-snap-type: x proximity; align-items: start; -webkit-overflow-scrolling: touch; }
.bcol { background: var(--bg); border: 1px solid var(--line); border-radius: 16px; padding: 10px; scroll-snap-align: start; }
.bcol h3 { margin: 2px 4px 10px; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); display: flex; justify-content: space-between; }
.bcol h3 small { font-weight: 600; }
.blist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.bempty { color: var(--muted); font-size: 13px; text-align: center; padding: 14px 0; }
.bcard { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); display: flex; align-items: stretch; overflow: hidden; }
.bcard.done { opacity: .65; }
.bcard-body { flex: 1; min-width: 0; text-align: left; padding: 10px 4px 10px 12px; display: grid; gap: 4px; }
.bcard .row-title { font-size: 15px; }
.bcard .mv { display: flex; flex-direction: column; justify-content: space-between; }
.bcard .mv button { width: 34px; flex: 1; font-size: 20px; color: var(--muted); }
.bcard .mv button:active { color: var(--accent); }
.bcard .mv i { width: 34px; }

/* лента событий */
.feed { list-style: none; margin: 0; padding: 0 16px; display: grid; gap: 8px; }
.frow { display: flex; gap: 10px; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); padding: 10px 12px; border-left: 3px solid var(--line); }
.frow.lv-warn { border-left-color: #d97706; }
.frow.lv-error { border-left-color: var(--hot); }
.ftime { flex: none; color: var(--muted); font-size: 12px; padding-top: 2px; min-width: 74px; }
.fbody { font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }
.fbody .dot { display: inline-block; margin-right: 4px; vertical-align: 1px; }
.fkind { color: var(--muted); font-size: 12px; }
.more { display: block; margin: 12px auto 0; }

/* 6 вкладок — чуть компактнее */
.tabs button span { font-size: 10px; }
