:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #1f2422;
  --muted: #69716d;
  --line: #e2dfd8;
  --accent: #4a7a69;
  --accent-soft: #e0ece7;
  --on-accent: #ffffff;
  --danger: #b5483c;
  --danger-soft: #f6e4e1;
  --warn: #a8641c;
  --shadow: 0 6px 24px rgba(30, 40, 35, 0.14);
  --radius: 14px;
  --tabs-h: 58px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121413;
    --surface: #1c1f1e;
    --surface-2: #262a28;
    --text: #e8ebe9;
    --muted: #98a19c;
    --line: #2f3432;
    --accent: #7fb5a1;
    --accent-soft: #223029;
    --on-accent: #0f1a15;
    --danger: #e08a7e;
    --danger-soft: #3a2420;
    --warn: #e0a468;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html.lock, html.lock body { overflow: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1, h2, p, ul { margin: 0; padding: 0; }
ul { list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.noscript { padding: 24px; }

/* ---------- вход ---------- */
.login {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: calc(24px + var(--sat)) calc(20px + var(--sar)) calc(24px + var(--sab)) calc(20px + var(--sal));
}
.login-card { width: 100%; max-width: 380px; display: grid; gap: 16px; }
.login-card h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
.code-input { text-align: center; font-size: 28px; letter-spacing: 0.35em; padding-left: 0.35em; font-variant-numeric: tabular-nums; min-height: 60px; }

/* ---------- каркас ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  padding: calc(14px + var(--sat)) calc(18px + var(--sar)) 10px calc(18px + var(--sal));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.top h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.top .muted { font-size: 15px; margin-top: 2px; }

.view {
  padding: 4px calc(16px + var(--sar)) calc(var(--tabs-h) + var(--sab) + 96px) calc(16px + var(--sal));
  max-width: 640px; margin: 0 auto; outline: none;
}
.top { max-width: none; }
.top-text { max-width: 640px; margin: 0 auto; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 0 var(--sar) var(--sab) var(--sal);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--tabs-h); background: none; border: 0; color: var(--muted); font-size: 11.5px; font-weight: 500;
}
.tab[aria-current="page"] { color: var(--accent); }

.fab {
  position: fixed; z-index: 9;
  right: calc(18px + var(--sar)); bottom: calc(var(--tabs-h) + var(--sab) + 16px);
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
}
.fab:active { transform: scale(0.96); }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-weight: 600; font-size: 16px; text-decoration: none; text-align: center;
}
.btn:active { filter: brightness(0.96); }
.btn:disabled { opacity: 0.55; }
.btn-block { display: flex; width: 100%; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--accent); font-weight: 500; }
.btn-danger { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.btn-danger.armed { background: var(--danger); color: #fff; }

.input {
  width: 100%; min-height: 48px; padding: 10px 14px; font-size: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; color: var(--text);
  -webkit-appearance: none; appearance: none;
}
select.input {
  padding-right: 38px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 55%, calc(100% - 15px) 55%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
textarea.input { resize: vertical; line-height: 1.4; }
input[type="date"].input, input[type="time"].input { min-width: 0; text-align: left; }
.input:focus-visible, .btn:focus-visible, .chip:focus-visible, .row-main:focus-visible, .check:focus-visible, .tab:focus-visible, .fab:focus-visible, .swatch:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.input:disabled { opacity: 0.5; }
.search { margin-bottom: 4px; }

.form { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field-label { font-size: 14px; font-weight: 600; color: var(--muted); }
.field-hint { font-size: 13px; color: var(--muted); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error { color: var(--danger); font-size: 15px; background: var(--danger-soft); padding: 10px 12px; border-radius: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll-x { flex-wrap: nowrap; overflow-x: auto; margin: 0 calc(-16px - var(--sar)) 0 calc(-16px - var(--sal)); padding: 4px calc(16px + var(--sar)) 4px calc(16px + var(--sal)); scrollbar-width: none; }
.chips.scroll-x::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; flex: none;
  min-height: 44px; padding: 0 16px; border-radius: 22px;
  background: var(--surface); border: 1px solid var(--line); font-size: 15px; color: var(--text);
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip-toggle { font-size: 14px; }
.toolbar { display: flex; margin: 4px 0 0; }
.toolbar .input { flex: 1; }

.seg { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; margin-bottom: 16px; background: var(--surface-2); border-radius: 12px; }
.seg-btn { min-height: 44px; border: 0; background: transparent; border-radius: 10px; font-weight: 600; color: var(--muted); }
.seg-btn[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

.switch-row { display: flex; align-items: center; justify-content: space-between; min-height: 48px; }
.switch-input { appearance: none; -webkit-appearance: none; width: 51px; height: 31px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line); position: relative; flex: none; transition: background 0.15s; }
.switch-input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 25px; height: 25px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.15s; }
.switch-input:checked { background: var(--accent); border-color: var(--accent); }
.switch-input:checked::after { transform: translateX(20px); }

/* ---------- списки ---------- */
.group { margin-top: 18px; display: grid; gap: 8px; }
.group-title { font-size: 13px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.group-late .group-title { color: var(--danger); }
.count { font-weight: 500; opacity: 0.7; }
.list { display: grid; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list > .row + .row { border-top: 1px solid var(--line); }
.list.card { margin-bottom: 8px; }

.row { display: flex; align-items: stretch; min-height: 56px; content-visibility: auto; contain-intrinsic-size: auto 60px; }
.row-main {
  flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 3px;
  padding: 10px 14px 10px 4px; background: none; border: 0; text-align: left; min-height: 44px;
}
.note-row .row-main, .row-cat { padding-left: 14px; }
.row-title { font-size: 17px; font-weight: 500; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.row-preview { font-size: 14px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.row-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--muted); }
.meta-when { color: var(--text); opacity: 0.75; font-variant-numeric: tabular-nums; }
.meta-when.late { color: var(--danger); opacity: 1; font-weight: 600; }
.meta-agent { color: var(--accent); }
.meta-cat { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--muted)); display: inline-block; flex: none; }
.dot-lg { width: 14px; height: 14px; margin-right: 12px; }
.row-cat { flex-direction: row; align-items: center; justify-content: flex-start; }
.is-done .row-title { text-decoration: line-through; color: var(--muted); }

.check { flex: none; width: 52px; display: flex; align-items: center; justify-content: center; background: none; border: 0; padding: 0; min-height: 44px; }
.check-box { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--muted); display: flex; align-items: center; justify-content: center; transition: background 0.12s, border-color 0.12s; }
.check[aria-checked="true"] .check-box { background: var(--accent); border-color: var(--accent); }
.check[aria-checked="true"] .check-box::after { content: ""; width: 6px; height: 11px; border: solid var(--on-accent); border-width: 0 2.4px 2.4px 0; transform: translateY(-1px) rotate(45deg); }

.fold > summary { cursor: pointer; min-height: 44px; list-style: none; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::before { content: ""; width: 7px; height: 7px; border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(-45deg); transition: transform 0.15s; margin-right: 4px; }
.fold[open] > summary::before { transform: rotate(45deg); }
.fold[open] > summary { margin-bottom: 8px; }

.empty { text-align: center; padding: 56px 16px; display: grid; gap: 8px; justify-items: center; }
.empty-title { font-size: 19px; font-weight: 600; }

.notice { background: var(--accent-soft); border-radius: 12px; padding: 12px; display: grid; gap: 10px; font-size: 15px; }

/* ---------- нижний лист ---------- */
.scrim { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.42); opacity: 0; transition: opacity 0.2s; }
.scrim.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; margin: 0 auto; max-width: 640px;
  max-height: 92vh; max-height: 92dvh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 20px 20px 0 0; box-shadow: var(--shadow);
  transform: translateY(100%); transition: transform 0.22s ease;
  padding-bottom: var(--sab);
}
.sheet.open { transform: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 4px 20px; flex: none; }
.sheet-title { font-size: 19px; font-weight: 700; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 8px calc(18px + var(--sar)) 24px calc(18px + var(--sal)); }
.sheet-extra { display: grid; gap: 10px; margin-top: 12px; }
.sheet-body > .muted { margin-top: 14px; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 44px; height: 44px; border-radius: 50%; border: 3px solid transparent; background: var(--c); box-shadow: inset 0 0 0 2px var(--bg); }
.swatch[aria-pressed="true"] { border-color: var(--text); }

/* ---------- уведомления ---------- */
.toasts {
  position: fixed; left: 0; right: 0; z-index: 40; display: grid; gap: 8px; justify-items: center; pointer-events: none;
  bottom: calc(var(--tabs-h) + var(--sab) + 86px); padding: 0 16px;
}
.toast {
  pointer-events: auto; max-width: 480px; display: flex; align-items: center; gap: 12px;
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 14px; font-size: 15px; box-shadow: var(--shadow);
}
.toast-error { background: var(--danger); color: #fff; }
.toast-btn { background: none; border: 0; color: inherit; font-weight: 700; min-height: 44px; margin: -8px -8px -8px 0; padding: 0 10px; text-decoration: underline; }

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