:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece5;
  --ink: #1d1c1a;
  --ink-2: #5d5a54;
  --ink-3: #8f8b83;
  --line: #e3dfd6;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe5;
  --warn: #b4561e;
  --warn-soft: #f7e6d8;
  --danger: #b3261e;
  --prio-1: #c98a12;
  --prio-2: #c2410c;
  --toast-bg: #1d1c1a;
  --toast-ink: #f6f4ef;
  --toast-btn: #7fd6bd;
  --shadow: 0 1px 2px rgb(30 25 15 / .06), 0 4px 16px rgb(30 25 15 / .06);
  --radius: 14px;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151513;
    --surface: #1e1d1b;
    --surface-2: #282724;
    --ink: #ecebe7;
    --ink-2: #b3b0a8;
    --ink-3: #7f7c75;
    --line: #33312d;
    --accent: #5cc0a5;
    --accent-ink: #0d2620;
    --accent-soft: #1c3832;
    --warn: #e9a06a;
    --warn-soft: #3a2a1d;
    --danger: #f2817a;
    --prio-1: #e5b54a;
    --prio-2: #f08a5d;
    --toast-bg: #ecebe7;
    --toast-ink: #151513;
    --toast-btn: #1f6f5c;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 16px rgb(0 0 0 / .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--ink-3); }

.app {
  max-width: 680px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(var(--tabs-h) + 76px + var(--safe-b));
}

/* ---------- шапка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
}
.topbar h1 { margin: 0; font-size: 26px; line-height: 1.15; letter-spacing: -.02em; font-weight: 700; }
.topbar p { margin: 2px 0 0; font-size: 14px; }
.topbar-actions { display: flex; gap: 4px; align-items: center; }
.icon-btn {
  position: relative; width: 40px; height: 40px; border: 0; border-radius: 12px;
  background: transparent; color: var(--ink-2); display: grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.dot { position: absolute; top: 9px; right: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.chip-btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; font-size: 14px; color: var(--accent); font-weight: 600;
}

/* ---------- баннер напоминаний ---------- */
.alerts { margin: 4px 14px 6px; display: grid; gap: 8px; }
.alert {
  background: var(--warn-soft); border-radius: var(--radius); padding: 12px 14px;
  display: grid; gap: 8px; animation: pop .25s ease-out;
}
.alert-title { font-weight: 600; display: flex; gap: 8px; align-items: baseline; }
.alert-title small { color: var(--warn); font-weight: 500; font-size: 13px; margin-left: auto; white-space: nowrap; }
.alert-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.alert-actions button {
  border: 0; border-radius: 999px; padding: 6px 12px; font-size: 14px;
  background: color-mix(in srgb, var(--surface) 75%, transparent); color: var(--ink);
}
.alert-actions button.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* ---------- контент ---------- */
.view { padding: 4px 14px 24px; outline: none; }
.section { margin-top: 18px; }
.section:first-child { margin-top: 6px; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 0 4px 8px; font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3);
}
.section-head.warn { color: var(--warn); }
.section-head button { border: 0; background: none; color: var(--accent); font-size: 13px; font-weight: 600; text-transform: none; letter-spacing: 0; padding: 0; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.empty { padding: 14px 16px; color: var(--ink-3); font-size: 15px; }

.row {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; width: 100%;
  border: 0; background: none; text-align: left; position: relative;
}
.row + .row::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; border-top: 1px solid var(--line); }
.row-main { flex: 1; min-width: 0; }
.row-title { overflow-wrap: anywhere; }
.row-meta { font-size: 13.5px; color: var(--ink-3); margin-top: 1px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.row-meta .late { color: var(--danger); font-weight: 500; }
.row.done .row-title { color: var(--ink-3); text-decoration: line-through; }
.row-click { cursor: pointer; }
.row-click:hover { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }

.check {
  flex: none; width: 24px; height: 24px; margin-top: 0; border-radius: 8px;
  border: 1.7px solid var(--ink-3); background: transparent; display: grid; place-items: center; padding: 0;
}
.check svg { width: 16px; height: 16px; stroke-width: 2.4; opacity: 0; }
.check.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check.on svg { opacity: 1; }
.check.p1 { border-color: var(--prio-1); }
.check.p2 { border-color: var(--prio-2); border-width: 2.2px; }

.time {
  flex: none; width: 52px; text-align: right; font-variant-numeric: tabular-nums;
  font-weight: 600; font-size: 15px; line-height: 1.3;
}
.time small { display: block; font-weight: 400; color: var(--ink-3); font-size: 13px; }
.bar { flex: none; width: 3px; align-self: stretch; border-radius: 2px; background: var(--accent); }
.row.past .time, .row.past .row-title { color: var(--ink-3); }
.row.past .bar { background: var(--line); }
.bell { flex: none; color: var(--warn); margin-top: 1px; }
.bell svg { width: 20px; height: 20px; }
.tag { color: var(--accent); }
.recur { color: var(--ink-2); }
.prio { font-weight: 600; }
.prio.p1 { color: var(--prio-1); }
.prio.p2 { color: var(--prio-2); }

/* неделя */
.week-nav { display: flex; align-items: center; justify-content: space-between; margin: 6px 4px 4px; }
.week-nav button { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 6px 12px; font-size: 14px; }
.day-head { display: flex; align-items: baseline; gap: 8px; margin: 18px 4px 8px; }
.day-head b { font-size: 17px; }
.day-head span { color: var(--ink-3); font-size: 14px; }
.day-head.today b { color: var(--accent); }
.day-empty { margin: 0 4px; color: var(--ink-3); font-size: 14px; }

/* сегменты */
.segments { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; margin: 6px 0 2px; }
.segments button { border: 0; background: none; padding: 6px 14px; border-radius: 9px; font-size: 14px; color: var(--ink-2); }
.segments button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }

/* заметки */
.note-new { display: grid; gap: 8px; }
.note-new textarea, .field textarea {
  width: 100%; min-height: 80px; resize: vertical; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); padding: 10px 12px;
}
.note-new button { justify-self: end; }
.notes { display: grid; gap: 10px; margin-top: 14px; }
.note { padding: 12px 14px; white-space: pre-wrap; overflow-wrap: anywhere; cursor: pointer; }
.note small { display: block; color: var(--ink-3); margin-top: 6px; font-size: 12.5px; }

/* ---------- ввод ---------- */
.composer {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabs-h) + var(--safe-b)); z-index: 6;
  max-width: 680px; margin: 0 auto; padding: 8px 12px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.quick {
  display: flex; gap: 8px; align-items: center; background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px; padding: 5px 5px 5px 14px; box-shadow: var(--shadow);
}
.quick:focus-within { border-color: var(--accent); }
.quick input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; padding: 8px 0; font-size: 16px; }
.send {
  flex: none; width: 40px; height: 40px; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
}
.send svg { stroke-width: 2.2; }
.send:disabled { opacity: .4; }
.preview {
  margin: 0 4px 6px; padding: 8px 12px; border-radius: 12px; background: var(--accent-soft);
  font-size: 14px; line-height: 1.35; display: flex; gap: 10px; align-items: flex-start;
  animation: pop .15s ease-out; box-shadow: var(--shadow);
}
.preview b { font-weight: 600; }
.preview .src { margin-left: auto; color: var(--ink-3); font-size: 12px; }
.preview.err { background: var(--warn-soft); }

/* ---------- нижние вкладки ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7;
  display: grid; grid-template-columns: repeat(4, 1fr);
  max-width: 680px; margin: 0 auto;
  height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tab {
  position: relative; border: 0; background: none; color: var(--ink-3);
  display: grid; place-items: center; align-content: center; gap: 2px; font-size: 11.5px; font-weight: 500;
}
.tab.active { color: var(--accent); }
.tab.active svg { stroke-width: 2; }
.badge {
  position: absolute; top: 8px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 11px; line-height: 18px; text-align: center;
}

/* ---------- лист редактирования ---------- */
.sheet {
  border: 0; padding: 0; width: min(560px, 100vw); max-width: 100vw; max-height: 90dvh;
  border-radius: 20px 20px 0 0; margin: auto auto 0; background: var(--surface); color: var(--ink);
  box-shadow: 0 -8px 40px rgb(0 0 0 / .2);
}
@media (min-width: 700px) {
  .sheet { border-radius: 20px; margin: auto; }
  .tabs { border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0; }
}
.sheet::backdrop { background: rgb(15 14 12 / .45); }
.sheet[open] { animation: up .2s ease-out; }
.sheet form { padding: 18px 18px calc(18px + var(--safe-b)); display: grid; gap: 14px; }
.sheet h3 { margin: 0; font-size: 19px; }
.field { display: grid; gap: 5px; }
.field > span { font-size: 13px; color: var(--ink-3); font-weight: 500; }
.field input, .field select {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  padding: 10px 12px; min-height: 44px;
}
.field input:focus, .field select:focus, .field textarea:focus, .note-new textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.field input, .field select, .field textarea { min-width: 0; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 4px; }
.sheet-actions button { white-space: nowrap; }
.del-group { display: flex; gap: 16px; flex-basis: 100%; }
.sheet-actions .spacer { flex: 1; }
.primary, .ghost, .danger {
  border: 0; border-radius: 12px; padding: 10px 18px; font-weight: 600; min-height: 44px;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.ghost { background: var(--surface-2); color: var(--ink); }
.danger { background: none; color: var(--danger); padding-left: 4px; padding-right: 4px; }
.hint { font-size: 13.5px; color: var(--ink-2); background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.hint b { color: var(--ink); }

/* поиск */
.search-box input {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  padding: 10px 12px; min-height: 44px; outline: none;
}
.search-box input:focus { border-color: var(--accent); }

/* ---------- тост ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(var(--tabs-h) + 84px + var(--safe-b));
  background: var(--toast-bg); color: var(--toast-ink); border-radius: 12px; padding: 10px 14px;
  font-size: 14.5px; display: flex; gap: 14px; align-items: center; box-shadow: var(--shadow);
  width: max-content; max-width: calc(100vw - 32px); animation: pop .2s ease-out;
}
.toast button { border: 0; background: none; color: var(--toast-btn); font-weight: 700; padding: 0; }

/* вход */
.login { max-width: 360px; margin: 18vh auto 0; padding: 0 20px; text-align: center; }
.login h2 { font-size: 28px; margin: 0 0 6px; }
.login form { display: grid; gap: 10px; margin-top: 18px; text-align: left; }
.login input { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface); min-height: 46px; }
.login input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.login input[readonly] { color: var(--ink-2); background: var(--surface-2); }
.login .small { font-size: 13.5px; margin-top: 16px; }
.auth-err { margin: 2px 0 0; color: var(--danger); font-size: 14.5px; text-align: center; }
.auth-note { background: var(--warn-soft); border-radius: 12px; padding: 10px 12px; font-size: 14.5px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 6px; }
.link-btn { border: 0; background: none; padding: 4px 0; color: var(--accent); font-size: 14px; font-weight: 600; }
.link-btn.danger-link { color: var(--danger); }
.check-line { display: flex; gap: 10px; align-items: center; font-size: 15px; }
.check-line input { width: 18px; height: 18px; accent-color: var(--accent); }

@keyframes pop { from { opacity: 0; transform: translateY(4px); } }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
