:root {
  --bg: #f3f5ef;
  --surface: #ffffff;
  --surface-2: #eef1ea;
  --text: #1b2119;
  --muted: #6b7466;
  --line: #e2e6dc;
  --accent: #2f8f5b;
  --accent-ink: #ffffff;
  --accent-soft: #dcf0e2;
  --late: #d9480f;
  --late-soft: #ffe8dc;
  --today: #1971c2;
  --today-soft: #dbeafe;
  --soon: #8a6d00;
  --soon-soft: #fdf3c4;
  --shadow: 0 1px 2px rgba(20, 30, 15, .05), 0 6px 20px rgba(20, 30, 15, .06);
  --r: 20px;
  --tab-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121512;
    --surface: #1b1f1a;
    --surface-2: #252a23;
    --text: #e9eee6;
    --muted: #9aa494;
    --line: #2d332b;
    --accent: #4cc283;
    --accent-ink: #0d1a12;
    --accent-soft: #1d3a29;
    --late: #ff8a5c;
    --late-soft: #3d2117;
    --today: #6cb4ff;
    --today-soft: #172c45;
    --soon: #f1d26b;
    --soon-soft: #3a3214;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 28px; line-height: 1.15; letter-spacing: -.02em; margin: 0; }
p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }

.i { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- каркас ---------- */
body.app { padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px); }
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 20px 12px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.edit .top h1 { font-size: 20px; }
.wrap { max-width: 720px; margin: 0 auto; padding: 4px 20px 0; }
.wrap.narrow { max-width: 480px; }
.count { min-width: 32px; height: 32px; padding: 0 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); display: grid; place-items: center; font-weight: 600; font-size: 14px; }

.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 0;
  display: grid; place-items: center;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.icon-btn:active { transform: scale(.94); }
.top form { margin: 0; }
.home .top h1 { margin-right: auto; }
.home .top { justify-content: flex-start; }
.install-btn {
  height: 38px; padding: 0 14px 0 10px; border: 0; border-radius: 99px;
  display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 650;
  background: var(--accent-soft); color: var(--accent);
}
.install-btn .i { width: 20px; height: 20px; }
.tabbar, .btn, .water-btn, .cd, .chip { -webkit-user-select: none; user-select: none; }

.card { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); }
.card.note { padding: 16px 18px; margin-bottom: 16px; color: var(--muted); }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 52px; padding: 0 22px; border-radius: 16px; border: 0;
  background: var(--surface-2); color: var(--text); font-weight: 600;
  transition: transform .12s, opacity .12s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn.wide { width: 100%; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--late); }

/* ---------- формы ---------- */
.form { display: grid; gap: 16px; }
.card.form { padding: 18px; }
.field { display: grid; gap: 8px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field input, .field textarea {
  width: 100%; height: 50px; padding: 0 14px;
  border: 1.5px solid var(--line); border-radius: 14px;
  background: var(--surface-2); outline: none;
  transition: border-color .15s, background .15s;
}
.field textarea { height: auto; min-height: 90px; padding: 12px 14px; resize: vertical; line-height: 1.4; }
.field input:focus, .field textarea:focus { border-color: var(--accent); background: var(--surface); }
.field input[type=date] { appearance: none; -webkit-appearance: none; min-width: 0; display: flex; align-items: center; }
.error { color: var(--late); background: var(--late-soft); padding: 12px 14px; border-radius: 14px; font-size: 15px; display: grid; gap: 4px; }

.stepper { display: grid; grid-template-columns: 50px 1fr 50px; gap: 8px; align-items: center; }
.stepper > button {
  height: 50px; border-radius: 14px; border: 0; background: var(--surface-2);
  font-size: 24px; font-weight: 500; color: var(--accent);
}
.stepper > button:active { transform: scale(.94); }
.stepper label {
  height: 50px; border-radius: 14px; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--muted);
}
.stepper input {
  width: 3.2ch; height: auto; padding: 0; border: 0; background: transparent;
  text-align: center; font-size: 22px; font-weight: 700; color: var(--text);
  -moz-appearance: textfield;
}
.stepper input:focus { background: transparent; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  height: 34px; padding: 0 14px; border-radius: 99px; border: 1.5px solid var(--line);
  background: transparent; font-size: 14px; color: var(--muted);
}
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- фото ---------- */
.photo-frame {
  position: relative; display: block; aspect-ratio: 4 / 3; overflow: hidden;
  border-radius: 24px; background: var(--surface-2);
  border: 2px dashed var(--line);
}
.photo-frame.has { border: 0; box-shadow: var(--shadow); }
.photo-frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.photo-empty {
  position: absolute; inset: 0 0 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  color: var(--muted); font-weight: 600;
}
.photo-empty .i { width: 44px; height: 44px; stroke-width: 1.3; color: var(--accent); }
.photo-frame.has .photo-empty { display: none; }
.photo-actions { position: absolute; left: 0; right: 0; bottom: 12px; display: flex; justify-content: center; gap: 10px; }
.photo-btn {
  position: relative; height: 42px; padding: 0 16px 0 12px; border-radius: 99px; cursor: pointer;
  display: flex; align-items: center; gap: 6px; font-size: 15px; font-weight: 650;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 12px rgba(0, 0, 0, .15);
  -webkit-user-select: none; user-select: none;
}
.photo-btn + .photo-btn { background: var(--surface); color: var(--accent); }
.photo-frame.has .photo-btn { background: rgba(0, 0, 0, .55); color: #fff; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.photo-btn .i { width: 20px; height: 20px; stroke-width: 2; }
.photo-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.photo-btn:active { transform: scale(.96); }
.photo-frame.busy::after {
  content: ""; position: absolute; inset: 0; background: color-mix(in srgb, var(--surface) 60%, transparent);
  animation: pulse 1s ease-in-out infinite alternate;
}
@keyframes pulse { to { opacity: .3; } }

.danger-zone { margin-top: 28px; display: flex; justify-content: center; }

/* ---------- сетка цветов ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.tile {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow);
  transition: transform .15s;
}
.tile:active { transform: scale(.97); }
.tile-img { position: relative; aspect-ratio: 1; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.tile-img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile-img > .i { width: 44px; height: 44px; stroke-width: 1.3; opacity: .7; }
.tile-img .badge { position: absolute; left: 8px; bottom: 8px; }
.tile-body { padding: 10px 12px 12px; display: grid; gap: 2px; }
.tile-body b { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-body small { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 4px; }
.tile-body small .i { width: 14px; height: 14px; }

.badge {
  display: inline-flex; align-items: center; height: 24px; padding: 0 9px; border-radius: 99px;
  font-size: 12px; font-weight: 650; white-space: nowrap;
  background: var(--accent-soft); color: var(--accent);
}
.badge.late { background: var(--late-soft); color: var(--late); }
.badge.today { background: var(--today-soft); color: var(--today); }
.badge.soon { background: var(--soon-soft); color: var(--soon); }
.tile-img .badge { box-shadow: 0 2px 8px rgba(0, 0, 0, .15); }

/* ---------- строки списка ---------- */
.rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 10px; background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); }
.thumb { width: 52px; height: 52px; border-radius: 14px; overflow: hidden; flex: none; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.row-main { flex: 1; min-width: 0; display: grid; }
.row-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-main small { color: var(--muted); font-size: 13px; }

.empty { text-align: center; padding: 56px 20px; color: var(--muted); display: grid; justify-items: center; gap: 14px; }
.empty > .i { width: 56px; height: 56px; color: var(--accent); stroke-width: 1.2; }

/* ---------- плавающая кнопка и таббар ---------- */
.fab {
  position: fixed; right: 20px; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px); z-index: 6;
  width: 58px; height: 58px; border-radius: 20px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 10px 24px color-mix(in srgb, var(--accent) 40%, transparent);
}
.fab .i { width: 28px; height: 28px; stroke-width: 2.2; }
.fab:active { transform: scale(.94); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  display: flex; justify-content: center; gap: 8px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 0 1 160px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; font-weight: 600; color: var(--muted);
}
.tabbar a .i { width: 26px; height: 26px; padding: 2px 14px; box-sizing: content-box; border-radius: 99px; transition: background .15s; }
.tabbar a.on { color: var(--accent); }
.tabbar a.on .i { background: var(--accent-soft); }

/* ---------- вход и простые страницы ---------- */
body.center { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-box { width: 100%; max-width: 380px; text-align: center; display: grid; gap: 8px; }
.login-box .logo {
  width: 72px; height: 72px; margin: 0 auto 8px; border-radius: 24px;
  display: grid; place-items: center; background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 12px 30px color-mix(in srgb, var(--accent) 35%, transparent);
}
.login-box .logo .i { width: 38px; height: 38px; }
.login-box form { margin-top: 20px; text-align: left; }
main.card.note { max-width: 380px; text-align: center; display: grid; gap: 12px; color: var(--text); }

/* ---------- календарь ---------- */
.btn.small { height: 38px; padding: 0 14px; border-radius: 12px; font-size: 14px; }
.cal { padding: 12px 10px 10px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; padding: 0 2px 8px; }
.cal-title {
  border: 0; background: none; padding: 6px 12px; border-radius: 12px;
  font-size: 18px; font-weight: 700; letter-spacing: -.01em; text-transform: capitalize;
}
.cal-title.away { color: var(--accent); }
.cal-title.away::after { content: " · сегодня"; font-size: 13px; font-weight: 600; text-transform: none; opacity: .8; }
.cal-nav { width: 40px; height: 40px; border: 0; border-radius: 12px; background: var(--surface-2); color: var(--text); display: grid; place-items: center; }
.cal-nav .i { width: 20px; height: 20px; }
.cal-nav.next .i { transform: rotate(180deg); }
.cal-nav:disabled { opacity: .3; }
.cal-dow, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow span { text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); padding: 4px 0 6px; }
.cal-dow span:nth-child(n+6) { color: color-mix(in srgb, var(--late) 70%, var(--muted)); }

.cd {
  position: relative; min-width: 0; height: 58px; padding: 6px 0 0; border: 0; border-radius: 14px;
  background: transparent; display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: background .15s;
}
.cd .n { font-size: 15px; font-weight: 600; line-height: 1; width: 26px; height: 22px; display: grid; place-items: center; border-radius: 99px; }
.cd.out { opacity: .35; }
.cd.past .n { color: var(--muted); font-weight: 500; }
.cd.today .n { background: var(--accent); color: var(--accent-ink); }
.cd.today.has-late .n { background: var(--late); color: #fff; }
.cd.sel { background: var(--accent-soft); }
.cd:active { transform: scale(.95); }

.stack { display: flex; justify-content: center; padding-left: 7px; }
.av {
  width: 20px; height: 20px; margin-left: -7px; border-radius: 50%; overflow: hidden; flex: none;
  display: grid; place-items: center; font-size: 10px; font-weight: 700;
  background: var(--accent-soft); color: var(--accent);
  box-shadow: 0 0 0 2px var(--surface);
}
.cd.sel .av { box-shadow: 0 0 0 2px var(--accent-soft); }
.av img { width: 100%; height: 100%; object-fit: cover; }
.av.late { box-shadow: 0 0 0 2px var(--late); }
.av.done { opacity: .45; filter: grayscale(.6); }
.av.more { background: var(--surface-2); color: var(--muted); font-size: 9px; }

/* ---------- список дня ---------- */
.day { margin-top: 22px; scroll-margin-top: 80px; }
.day-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; min-height: 38px; }
.day-head h2 { margin: 0; font-size: 20px; letter-spacing: -.01em; }
.day-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.day-empty { padding: 26px 16px; text-align: center; color: var(--muted); background: var(--surface); border-radius: 18px; border: 1.5px dashed var(--line); }

.fl {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; column-gap: 12px; padding: 12px;
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow);
  animation: fl-in .25s ease both;
}
@keyframes fl-in { from { opacity: 0; transform: translateY(6px); } }
.fl.late { box-shadow: var(--shadow), inset 3px 0 0 var(--late); }
.fl.done { opacity: .7; }
.fl-photo .av { width: 56px; height: 56px; margin: 0; border-radius: 16px; font-size: 22px; box-shadow: none; }
.fl-main { min-width: 0; display: grid; gap: 4px; }
.fl-name { font-weight: 650; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fl-meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tag { white-space: nowrap; font-size: 12px; font-weight: 650; padding: 1px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.tag.late { background: var(--late-soft); color: var(--late); }
.tag.due { background: var(--today-soft); color: var(--today); }
.fl-comment {
  grid-column: 1 / -1; margin-top: 10px; font-size: 14px; color: var(--text); white-space: pre-line;
  padding: 8px 10px; background: var(--surface-2); border-radius: 10px;
}
.water-btn { height: 44px; padding: 0 14px; border: 0; border-radius: 14px;
  display: flex; align-items: center; gap: 6px; font-weight: 650; font-size: 14px;
  background: var(--accent); color: var(--accent-ink);
}
.water-btn .i { width: 18px; height: 18px; }
.water-btn:active { transform: scale(.95); }
.water-btn.busy, .btn.busy { opacity: .6; }

/* ---------- плашка с отменой ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 14px); z-index: 9;
  width: min(440px, calc(100% - 32px)); transform: translate(-50%, 20px); opacity: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 12px 12px 18px; border-radius: 16px;
  background: #1f2a20; color: #f0f5ee; box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  transition: transform .22s, opacity .22s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast button { border: 0; background: none; color: #7ee2a8; font-weight: 700; padding: 6px 8px; flex: none; }
