:root {
  --bg: #FBFAF8;
  --surface: #FFFFFF;
  --field: #F3F2EF;
  --text: #15161A;
  --hint: #5E6068;
  --muted: #7A7C84;
  --line: #F0EEEA;
  --group-ring: #EEECE7;
  --ring: #8D9099;
  --accent: #2F5BEA;
  --accent-press: #2449C9;
  --accent-text: #2F5BEA;
  --accent-soft: #EAF0FE;
  --on-accent: #FFFFFF;
  --danger: #C8303A;
  --danger-soft: #FBEAEB;
  --work: #5145B8;
  --home: #0E7A57;
  --snack-bg: #1F2024;
  --snack-text: #FFFFFF;
  --snack-act: #9DB8FF;
  --shadow: rgba(21, 22, 26, .08);
  --ease: cubic-bezier(.3, .75, .2, 1);
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #111214;
  --surface: #1B1C20;
  --field: #24252B;
  --text: #EDEDF0;
  --hint: #A3A5AD;
  --muted: #8A8C94;
  --line: #26272C;
  --group-ring: #24252A;
  --ring: #6E7079;
  --accent: #3F5FE0;
  --accent-press: #3452CC;
  --accent-text: #8FA6FF;
  --accent-soft: #1E2640;
  --danger: #FF6B6B;
  --danger-soft: #3A1E21;
  --work: #B3AAFF;
  --home: #6FD8AE;
  --snack-bg: #2A2B31;
  --shadow: rgba(0, 0, 0, .35);
  color-scheme: dark;
}

/* Смена темы: цвета плавно перетекают, пока висит класс .theming */
.theming *, .theming *::before, .theming *::after {
  transition: background-color .35s ease, color .35s ease, border-color .35s ease, box-shadow .35s ease !important;
}
.theming body { transition: background-color .35s ease; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); overflow-x: hidden; }
body {
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic-s { width: 13px; height: 13px; stroke-width: 2.2; }

/* --- шапка --- */

.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 18px 16px 12px; }
.head-text { min-width: 0; }
.date { margin: 0; font-size: 13px; color: var(--hint); }
/* Справа три кнопки (~192 px с отступами), а самый длинный день («Воскресенье») ~6,2 em:
   на узком экране заголовок плавно мельчает, а если шрифт телефона шире — обрезается, не наезжая на кнопки */
.ttl {
  margin: 2px 0 0; font-size: clamp(20px, calc((100vw - 192px) / 6.6), 30px); line-height: 1.1; font-weight: 700;
  letter-spacing: -.015em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ttl.swap { animation: title-in .4s var(--ease-out); }
@keyframes title-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.head-actions { display: flex; gap: 8px; flex: none; }
.theme-btn {
  position: relative; width: 44px; height: 44px; border: 0; border-radius: 22px;
  background: var(--surface); color: var(--text); display: grid; place-items: center;
  box-shadow: 0 0 0 1px var(--group-ring); transition: transform .15s, background .15s;
}
.theme-btn:hover { background: var(--field); }
.theme-btn:active { transform: scale(.92); }
.theme-btn .ic { position: absolute; transition: transform .45s var(--ease), opacity .25s; }
.theme-btn .sun { opacity: 0; transform: rotate(-90deg) scale(.4); }
:root[data-theme="dark"] .theme-btn .moon { opacity: 0; transform: rotate(90deg) scale(.4); }
:root[data-theme="dark"] .theme-btn .sun { opacity: 1; transform: none; }

.add {
  width: 44px; height: 44px; flex: none; border: 0; border-radius: 22px;
  background: var(--accent); color: var(--on-accent); display: grid; place-items: center;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 30%, transparent);
  transition: transform .15s, background .15s;
}
.add:hover { background: var(--accent-press); }
.add:active { transform: scale(.92); }

/* --- лента дней --- */

.week { position: relative; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); height: 66px; margin: 0 12px 6px; }
.pill {
  position: absolute; left: 0; top: 0; width: calc(100% / 7); height: 100%; border-radius: 16px;
  background: var(--accent); box-shadow: 0 6px 14px color-mix(in srgb, var(--accent) 28%, transparent);
  transition: transform .38s var(--ease), opacity .3s;
}
.week:not(.ready) .pill { opacity: 0; }
.day-sk { align-self: center; justify-self: center; width: 30px; height: 40px; border-radius: 10px; }
.day {
  position: relative; border: 0; background: transparent; border-radius: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transition: color .25s;
}
.day:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.day.on { color: var(--on-accent); }
.day.on:hover { background: transparent; }
.wd { font-size: 12px; opacity: .75; }
.dn { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; transition: transform .15s; }
.day:active .dn { transform: scale(.86); }
.dot { width: 5px; height: 5px; border-radius: 3px; background: transparent; transition: background .25s; }
.day.has .dot { background: var(--accent-text); animation: dot-pop .35s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes dot-pop { from { transform: scale(0); } to { transform: scale(1); } }
.day.on .dot { background: var(--on-accent); }

/* --- список --- */

.list { padding: 2px 16px calc(96px + env(safe-area-inset-bottom)); touch-action: pan-y; }
.loading { color: var(--hint); text-align: center; padding: 40px 0; margin: 0; }

/* Скелетон загрузки: блики бегут слева направо */
.sk {
  display: block; border-radius: 8px;
  background: linear-gradient(90deg, var(--field) 30%, color-mix(in srgb, var(--field) 30%, var(--surface)) 50%, var(--field) 70%);
  background-size: 250% 100%; animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -150% 0; } }
.skel { padding-top: 6px; }
.sk-lbl { width: 30%; height: 12px; margin: 16px 4px 10px; }
.skel-card { background: var(--surface); border-radius: 16px; box-shadow: 0 0 0 1px var(--group-ring); padding: 4px 0; }
.skel-row { display: flex; align-items: center; gap: 12px; height: 54px; padding: 0 16px; }
.sk-dot { width: 22px; height: 22px; border-radius: 11px; flex: none; }
.sk-txt { height: 14px; width: 70%; }
.sk-txt.short { width: 45%; }

.sec { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .35s ease .55s, opacity .3s ease .55s; }
.sec.gone { grid-template-rows: 0fr; opacity: 0; }
.sec-in { min-height: 0; overflow: hidden; }
.lbl { margin: 16px 4px 8px; font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--hint); }
.lbl.late { color: var(--danger); }
.group { background: var(--surface); border-radius: 16px; box-shadow: 0 1px 2px var(--shadow), 0 0 0 1px var(--group-ring); }

.wrap { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .35s ease .55s, opacity .3s ease .55s; }
.wrap.gone { grid-template-rows: 0fr; opacity: 0; }
.wrap-in { min-height: 0; overflow: hidden; }
.row { display: flex; align-items: center; min-height: 58px; padding: 0 4px; border-top: 1px solid var(--line); }
.wrap:first-child .row { border-top: 0; }
.enter .row { animation: row-in .42s var(--ease-out) backwards; animation-delay: var(--delay, 0ms); }
.enter.from-left .row { animation-name: row-in-left; }
.wrap.pop .row { animation: row-in .42s var(--ease-out); }
@keyframes row-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes row-in-left { from { opacity: 0; transform: translateX(-24px); } to { opacity: 1; transform: none; } }
/* Новая или исправленная задача мягко подсвечивается */
.wrap.flash .wrap-in { border-radius: 14px; animation: flash 1.6s ease .25s backwards; }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }

.chk { position: relative; width: 44px; height: 44px; flex: none; border: 0; background: transparent; border-radius: 22px; display: grid; place-items: center; }
.chk.burst::after {
  content: ""; position: absolute; inset: 11px; border-radius: 50%; border: 2px solid var(--accent);
  pointer-events: none; animation: burst .55s var(--ease-out) forwards;
}
@keyframes burst { from { transform: scale(.8); opacity: .9; } to { transform: scale(2.1); opacity: 0; } }
.ring {
  width: 22px; height: 22px; border-radius: 11px; border: 2px solid var(--ring);
  display: grid; place-items: center;
  transition: background .2s, border-color .2s, transform .25s cubic-bezier(.3, 1.6, .5, 1);
}
.chk:hover .ring { border-color: var(--accent-text); }
.tick { width: 14px; height: 14px; fill: none; stroke: var(--on-accent); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 24; stroke-dashoffset: 24; transition: stroke-dashoffset .3s ease .1s; }
.is-done .ring { background: var(--accent); border-color: var(--accent); transform: scale(1.12); }
.is-done .tick { stroke-dashoffset: 0; }

.body {
  flex: 1; min-width: 0; align-self: stretch; display: flex; align-items: center; gap: 10px;
  border: 0; background: transparent; text-align: left; padding: 8px 10px 8px 2px; border-radius: 12px;
  transition: background .15s;
}
.body:active { background: var(--field); }
.text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.title { align-self: flex-start; font-size: 15px; line-height: 1.3; word-break: break-word; transition: color .3s; }
/* Линия — фоном строчного элемента: у inline фон режется по строкам, и каждая строка
   перечёркивается по своей середине (у блока линия была одна — между строками) */
.title-in {
  background: linear-gradient(currentColor, currentColor) no-repeat 0 58% / 0 1.5px;
  -webkit-box-decoration-break: slice; box-decoration-break: slice;
  transition: background-size .35s ease;
}
.is-done .title { color: var(--muted); }
.is-done .title-in { background-size: 100% 1.5px; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; font-size: 12px; color: var(--hint); }
.meta .work { color: var(--work); }
.meta .home { color: var(--home); }
.badge { padding: 1px 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.time { flex: none; max-width: 40%; font-size: 13px; color: var(--hint); font-variant-numeric: tabular-nums; text-align: right; }
.time.late { color: var(--danger); font-weight: 600; }

.foot {
  display: flex; align-items: center; gap: 6px; margin: 14px 0 0; padding: 0 4px; min-height: 44px;
  border: 0; background: transparent; color: var(--hint); font-size: 13px; border-radius: 12px;
}
.foot .chev { width: 14px; height: 14px; transition: transform .3s var(--ease); }
.foot[aria-expanded="true"] .chev { transform: rotate(90deg); }
.cnt { display: inline-block; font-weight: 600; color: var(--text); }
.cnt.bump { animation: bump .45s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes bump { 40% { transform: scale(1.45); color: var(--accent-text); } }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 56px 24px 0; animation: fade-up .45s var(--ease-out); }
@keyframes fade-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.empty-ic {
  width: 72px; height: 72px; border-radius: 36px; background: var(--accent-soft); color: var(--accent-text);
  display: grid; place-items: center; margin-bottom: 16px;
  animation: ic-pop .55s cubic-bezier(.3, 1.5, .5, 1) .08s backwards;
}
@keyframes ic-pop { from { transform: scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
.empty-check .empty-ic path { stroke-dasharray: 24; stroke-dashoffset: 24; animation: draw .45s ease .4s forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.empty-ic .ic { width: 30px; height: 30px; stroke-width: 1.8; }
.empty h2 { margin: 0 0 6px; font-size: 18px; font-weight: 600; }
.empty p { margin: 0; font-size: 14px; color: var(--hint); max-width: 260px; }

/* --- плашка внизу --- */

.snack {
  position: fixed; left: 12px; right: 12px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 20;
  display: flex; align-items: center; gap: 10px; max-width: 520px; margin: 0 auto;
  background: var(--snack-bg); color: var(--snack-text); border-radius: 16px; padding: 6px 6px 6px 14px; min-height: 52px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  transform: translateY(140%); opacity: 0; pointer-events: none;
  transition: transform .4s var(--ease), opacity .3s;
}
.snack.on { transform: none; opacity: 1; pointer-events: auto; }
/* Полоска внизу плашки тает, пока можно нажать «Отменить» */
.snack { overflow: hidden; }
.snack-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--snack-act); opacity: 0; transform-origin: left; }
.snack.timed .snack-bar { opacity: .7; animation: drain var(--snack-ms, 6000ms) linear forwards; }
@keyframes drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.snack-ok { color: #7EE2A8; }
.snack.error .snack-ok { display: none; }
.snack-text { flex: 1; min-width: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.snack-act { height: 40px; border: 0; border-radius: 12px; background: transparent; color: var(--snack-act); font-weight: 600; padding: 0 12px; }
.snack-act:hover { background: rgba(255, 255, 255, .08); }

/* --- запись голоса --- */

.rec {
  position: fixed; inset: 0; z-index: 15; display: flex; align-items: flex-end;
  background: rgba(0, 0, 0, .35); opacity: 0; visibility: hidden;
  transition: opacity .3s, visibility 0s linear .45s;
}
.rec.on { opacity: 1; visibility: visible; transition: opacity .3s; }
.rec-card {
  width: 100%; max-width: 560px; margin: 0 auto; background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform .45s cubic-bezier(.32, .72, 0, 1);
}
.rec.on .rec-card { transform: none; }
.rec-top { display: flex; align-items: center; gap: 10px; min-height: 24px; }
.rec-dot { width: 10px; height: 10px; border-radius: 5px; background: var(--danger); animation: rec-pulse 1.2s ease-in-out infinite; }
@keyframes rec-pulse { 50% { opacity: .35; transform: scale(.75); } }
.rec-time { font-weight: 600; font-variant-numeric: tabular-nums; }
.rec-hint { color: var(--hint); font-size: 14px; }
.rec-bars { display: flex; align-items: center; justify-content: center; gap: 4px; height: 64px; margin: 16px 0 18px; }
.rec-bars span {
  width: 5px; height: 56px; border-radius: 3px; background: var(--accent);
  transform: scaleY(.08); transition: transform .09s linear;
}
/* Пока сервер распознаёт — полоски бегут волной */
.rec.sending .rec-bars span { animation: rec-wave 1s ease-in-out infinite; animation-delay: calc(var(--i) * 45ms); }
@keyframes rec-wave { 0%, 100% { transform: scaleY(.12); } 50% { transform: scaleY(.55); } }
.rec.sending .rec-dot { animation: none; background: var(--accent-text); }
.rec-actions { display: flex; gap: 10px; }
.rec-actions button {
  flex: 1; min-height: 50px; border: 0; border-radius: 14px; font-size: 16px; font-weight: 600;
  transition: transform .15s, opacity .2s, background .15s;
}
.rec-actions button:active { transform: scale(.97); }
.rec-cancel { background: var(--field); color: var(--text); }
.rec-done { background: var(--accent); color: var(--on-accent); }
.rec-done:hover { background: var(--accent-press); }
.rec.sending .rec-actions button { opacity: .45; pointer-events: none; }
.mic-btn.on { background: var(--danger-soft); color: var(--danger); }

/* --- шторка --- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end;
  background: rgba(0, 0, 0, .4); opacity: 0; visibility: hidden;
  transition: opacity .3s, visibility 0s linear .5s;
}
.sheet-backdrop.open { opacity: 1; visibility: visible; transition: opacity .3s; }
.sheet {
  width: 100%; max-width: 560px; margin: 0 auto; background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto;
  transform: translateY(105%); transition: transform .5s cubic-bezier(.32, .72, 0, 1);
}
.sheet-backdrop.open .sheet { transform: none; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet textarea, .sheet input {
  width: 100%; font: inherit; color: var(--text); background: var(--field); border: 2px solid transparent;
  border-radius: 12px; padding: 10px 12px; outline: none; transition: border-color .2s;
}
.sheet textarea { font-size: 16px; resize: none; }
.sheet textarea:focus, .sheet input:focus { border-color: var(--accent); }
.field-label { font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--hint); margin: 16px 0 8px; }
.seg { position: relative; display: flex; background: var(--field); border-radius: 12px; padding: 3px; }
.seg-thumb {
  position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc((100% - 6px) / var(--n, 2));
  border-radius: 9px; background: var(--surface); box-shadow: 0 1px 3px var(--shadow);
  transform: translateX(calc(var(--i, 0) * 100%)); transition: transform .35s var(--ease);
}
.seg button { position: relative; flex: 1; min-height: 40px; border: 0; background: transparent; border-radius: 9px; font-size: 14px; color: var(--hint); transition: color .2s; }
.seg button.on { color: var(--text); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chips button {
  min-height: 36px; border: 0; background: var(--field); border-radius: 18px; padding: 0 13px; font-size: 14px;
  transition: background .2s, color .2s, transform .15s;
}
.chips button:active { transform: scale(.95); }
.chips button.on { background: var(--accent); color: var(--on-accent); animation: chip-pop .3s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes chip-pop { 50% { transform: scale(1.08); } }
.due-row { display: grid; grid-template-columns: 1.4fr 1fr; gap: 8px; margin-bottom: 8px; }
.error { color: var(--danger); font-size: 13px; margin: 6px 0 0; }
.sheet-actions { display: flex; gap: 10px; margin-top: 20px; }
.sheet-actions button { flex: 1; min-height: 50px; border: 0; border-radius: 14px; font-size: 16px; font-weight: 600; transition: transform .15s, background .15s; }
.sheet-actions button:active { transform: scale(.97); }
.primary { background: var(--accent); color: var(--on-accent) !important; }
.primary:hover { background: var(--accent-press); }
.danger { background: var(--danger-soft); color: var(--danger) !important; }

/* «Уменьшить движение»: без сдвигов и пружин, остаётся мягкое проявление */
@media (prefers-reduced-motion: reduce) {
  .enter .row, .enter.from-left .row, .wrap.pop .row, .ttl.swap, .empty, .empty-ic {
    animation: fade-in .25s ease backwards !important;
  }
  .pill, .sheet, .snack, .seg-thumb, .theme-btn .ic, .ring, .dn { transition-duration: .01ms !important; }
  .chk.burst::after, .sk, .day.has .dot, .chips button.on, .cnt.bump, .rec-dot, .rec-bars span { animation: none !important; }
  .rec-card { transition-duration: .01ms !important; }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
