/* ============================================================================
 * AI ассистент для мамы — стили Telegram Mini App (светлая тема, моб. вёрстка)
 * Палитра: фон #F3F4FB, карточки белые, акцент #7C6FE8, блоки лаванда/мята/персик/роза.
 * ==========================================================================*/

:root {
  --bg: #F3F4FB;
  --card: #FFFFFF;
  --accent: #7C6FE8;
  --accent-dark: #6A5CD9;
  --lav: #EDEAFB;   /* лавандовый */
  --mint: #E8F7EF;  /* мятный */
  --peach: #FDF0E7; /* персиковый */
  --pink: #FDEAEA;  /* розовый */
  --text: #23264B;
  --muted: #8B8FAF;
  --danger: #E45A6F;
  --radius: 16px;
  --shadow: 0 6px 24px rgba(35, 38, 75, .08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "Noto Sans", "Droid Sans", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

button { font-family: inherit; color: inherit; cursor: pointer; }
input, select { font-family: inherit; font-size: 16px; color: var(--text); }

.hidden { display: none !important; }

/* --------------------------- каркас приложения ---------------------------- */

#app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  background: rgba(243, 244, 251, .92);
  backdrop-filter: blur(8px);
}

.topbar-title { font-size: 20px; font-weight: 800; letter-spacing: -.2px; }
.topbar-sub { font-size: 12.5px; color: var(--muted); }
.topbar-emoji { font-size: 26px; }

main { padding: 4px 16px 20px; }

.page { display: flex; flex-direction: column; gap: 12px; }

.greeting { font-size: 18px; font-weight: 800; padding: 2px 2px 0; }
.greet-emoji { font-weight: 400; }

.hint-line { text-align: center; color: var(--muted); font-size: 13px; margin: 2px 0 0; }
.version { text-align: center; color: var(--muted); font-size: 12px; margin: 4px 0 0; }

/* ------------------------------- карточки ---------------------------------- */

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.bg-lav { background: var(--lav); box-shadow: none; }
.bg-mint { background: var(--mint); box-shadow: none; }
.bg-peach { background: var(--peach); box-shadow: none; }
.bg-pink { background: var(--pink); box-shadow: none; }

.sec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.sec-title {
  font-size: 15px;
  font-weight: 800;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.sec-actions { flex: none; }

/* Компактные счётчики-карточки (как в дашборде) */
.counters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.counter {
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  min-height: 88px;
}
.counter-icon { font-size: 18px; }
.counter-value { font-size: 26px; font-weight: 800; line-height: 1.1; margin-top: 2px; }
.counter-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }

.hint-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 14px;
}
.hint-icon { font-size: 20px; line-height: 1.3; }

/* --------------------------------- строки ----------------------------------- */

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid #F0F1F9;
  min-height: 48px;
}
.sec-head + .row, .seg + .row { border-top: 0; }
.row:first-of-type { border-top: 0; }

.row-when {
  flex: none;
  width: 34px;
  text-align: center;
  font-size: 16px;
}
.row-main { flex: 1; min-width: 0; }
.row-title {
  font-size: 14.5px;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.row-sub {
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.row-actions { flex: none; display: flex; gap: 2px; }

/* Зачёркивание выполненных задач (оптимистичное обновление) */
.task-row.done .row-title,
.list-row.done .row-title,
.ev-row.done .row-title {
  text-decoration: line-through;
  color: var(--muted);
  font-weight: 500;
}
.task-row.done .row-when,
.ev-row.done .row-when { opacity: .5; }
.ev-row.done { opacity: .68; }
.ev-check { color: var(--green, #2e9e5b); font-weight: 700; }

.chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 999px;
}
.chip-red { background: var(--pink); color: var(--danger); }
.chip-mint { background: var(--mint); color: #2E9E6B; }
.chip-accent { background: var(--lav); color: var(--accent); }

/* ------------------------------- кнопки ------------------------------------- */

.btn {
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 700;
  transition: transform .06s ease, filter .15s ease;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-dark); }
.btn-soft { background: var(--lav); color: var(--accent); }
.btn-sm { padding: 7px 12px; font-size: 13.5px; border-radius: 10px; }
.btn-block { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .6; cursor: default; }

.icon-btn {
  background: none;
  border: 0;
  font-size: 17px;
  padding: 6px 7px;
  border-radius: 10px;
  line-height: 1;
}
.icon-btn:active { background: var(--lav); }

/* Чекбоксы — акцентного цвета системным способом (без библиотек) */
.check {
  flex: none;
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Переключатель «тумблер» для рутин */
.switch { position: relative; flex: none; width: 46px; height: 28px; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track {
  position: absolute;
  inset: 0;
  background: #D9DBEC;
  border-radius: 999px;
  transition: background .2s ease;
  pointer-events: none;
}
.switch .track::before {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(35, 38, 75, .25);
  transition: transform .2s ease;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::before { transform: translateX(18px); }

/* Сегментированный переключатель (Сегодня/Неделя/Все, Месяц/Неделя) */
.seg {
  display: flex;
  background: #ECEEF8;
  border-radius: 12px;
  padding: 3px;
  margin-bottom: 6px;
}
.seg-btn {
  flex: 1;
  border: 0;
  background: none;
  padding: 7px 4px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--muted);
}
.seg-btn.active { background: #fff; color: var(--accent); box-shadow: 0 2px 8px rgba(35, 38, 75, .10); }

/* ------------------------------ пустые состояния ----------------------------- */

.empty { padding: 22px 10px; text-align: center; color: var(--muted); }
.empty .big { font-size: 36px; margin-bottom: 6px; }
.empty-title { color: var(--text); font-weight: 800; font-size: 15px; margin: 0 0 4px; }
.empty-sub { margin: 0 0 10px; font-size: 13.5px; }
.empty-sub:last-child { margin-bottom: 0; }

.day-empty { color: var(--muted); font-size: 13.5px; padding: 8px 0 2px; margin: 0; }

.skeleton {
  background: linear-gradient(90deg, #ECEEF8 25%, #F6F7FC 37%, #ECEEF8 63%);
  background-size: 400% 100%;
  animation: shimmer 1.2s ease infinite;
  border-radius: 12px;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ------------------------------ нижняя навигация ------------------------------ */

#nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(480px, 100%);
  display: flex;
  gap: 2px;
  background: #fff;
  box-shadow: 0 -6px 24px rgba(35, 38, 75, .10);
  border-radius: 18px 18px 0 0;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  z-index: 40;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  border: 0;
  background: none;
  color: var(--muted);
  padding: 7px 0 5px;
  border-radius: 12px;
}
.nav-item .nav-icon { font-size: 20px; line-height: 1.2; }
.nav-item .nav-label { font-size: 10.5px; font-weight: 700; }
.nav-item.active { background: var(--lav); color: var(--accent); }

/* -------------------------------- модалки ------------------------------------ */

#modal-root { position: fixed; inset: 0; z-index: 60; }
#modal-root.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(35, 38, 75, .42);
}
.modal-sheet {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(480px, 100%);
  max-height: 82vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(18px + env(safe-area-inset-bottom));
  animation: slide-up .22s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
@keyframes slide-up { from { transform: translate(-50%, 40px); opacity: .6; } to { transform: translate(-50%, 0); opacity: 1; } }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.sheet-head h3 { margin: 0; font-size: 17px; font-weight: 800; }

/* --------------------------------- формы -------------------------------------- */

.form { display: flex; flex-direction: column; gap: 10px; }
.form label, .settings-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}
.form input, .form select, .settings-form input[type="time"], .add-line input {
  border: 1.5px solid #E4E6F2;
  border-radius: 12px;
  padding: 11px 12px;
  background: #FBFBFE;
  outline: none;
  width: 100%;
}
.form input:focus, .form select:focus, .settings-form input:focus, .add-line input:focus {
  border-color: var(--accent);
}
.form input[readonly] { color: var(--muted); background: #F2F3FA; }
.form-row { display: flex; gap: 10px; }
.form-row label { flex: 1; min-width: 0; }
.check-line {
  flex-direction: row !important;
  align-items: center;
  gap: 10px !important;
  font-size: 14.5px !important;
  color: var(--text) !important;
  font-weight: 600 !important;
}
.check-line input { width: auto; }

.settings-form { display: flex; flex-direction: column; gap: 8px; }
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-top: 1px solid #F0F1F9;
}
.settings-row:first-child { border-top: 0; }
.settings-row label { flex: 1; font-size: 14px; font-weight: 600; color: var(--text); }
.settings-row input[type="time"], .settings-row input[readonly] {
  flex: none;
  border: 1.5px solid #E4E6F2;
  border-radius: 12px;
  padding: 9px 10px;
  background: #FBFBFE;
  width: 128px;
}
.settings-row input.readonly { color: var(--muted); background: #F2F3FA; width: 170px; }
.settings-form .btn-block { margin-top: 10px; }

/* Строчка добавления позиции в список */
.add-line { display: flex; gap: 8px; margin-top: 10px; }
.add-line input { flex: 1; min-width: 0; }

/* -------------------------------- календарь ----------------------------------- */

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.cal-title { font-size: 16px; font-weight: 800; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}
.cal-wd-row { margin-bottom: 4px; }
.cal-wd {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  padding: 2px 0;
}
.cal-cell {
  border: 0;
  background: none;
  border-radius: 10px;
  padding: 6px 0 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-height: 42px;
}
.cal-cell:active { background: var(--lav); }
.cal-empty { pointer-events: none; }
.cal-num { font-size: 13.5px; font-weight: 600; }
.cal-cell.today { background: var(--accent); }
.cal-cell.today .cal-num { color: #fff; font-weight: 800; }
.cal-cell.today .dot-ev { background: #fff; }
.cal-dots { display: flex; gap: 2px; min-height: 6px; }
.cal-dots i { width: 5px; height: 5px; border-radius: 50%; display: block; }

.dot-ev, .cal-legend .dot-ev { background: var(--accent); }
.dot-task, .cal-legend .dot-task { background: #3FBD85; }

.cal-legend {
  display: flex;
  gap: 14px;
  justify-content: center;
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--muted);
}
.cal-legend span { display: inline-flex; align-items: center; gap: 5px; }
.cal-legend i { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }

.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px 8px;
}
.week-range { font-size: 14.5px; font-weight: 800; }

.day-block { padding: 12px 14px; }
.day-today { outline: 2px solid var(--lav); }

/* ------------------------------ семья / профиль -------------------------------- */

.family-card { display: flex; align-items: center; gap: 12px; }
.family-emoji { font-size: 34px; }
.family-name { font-size: 16px; font-weight: 800; }
.family-tz { font-size: 12.5px; color: var(--muted); }

.avatar {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 14px;
  background: var(--lav);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.routine-row .row-sub { flex-wrap: wrap; }

/* ---------------------------------- вход --------------------------------------- */

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  max-width: 480px;
  margin: 0 auto;
}
.login-card {
  width: 100%;
  text-align: center;
  padding: 34px 24px;
}
.login-emoji { font-size: 48px; margin-bottom: 8px; }
.login-title { font-size: 21px; font-weight: 800; margin: 0 0 8px; }
.login-text { color: var(--muted); font-size: 14.5px; margin: 0 0 18px; }

/* --------------------------------- тосты ---------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: var(--text);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(35, 38, 75, .3);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 80;
  max-width: min(420px, calc(100vw - 40px));
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- форма повтора: выбор дней недели ---- */
.wd-picker { display: flex; flex-wrap: wrap; gap: 8px; margin: 2px 0 6px; }
.wd-chip { flex: 0 0 auto; }
.wd-chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.wd-chip span {
  display: inline-block; min-width: 40px; text-align: center;
  padding: 8px 10px; border-radius: 999px; border: 1.5px solid var(--line, #E4E6F1);
  background: #fff; color: var(--muted); font-weight: 600; font-size: 14px; cursor: pointer;
}
.wd-chip input:checked + span {
  border-color: var(--accent); background: var(--accent-soft, #EEE9FF); color: var(--accent);
}
.wd-chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.form .hint { color: var(--muted); font-size: 12.5px; margin: 6px 2px 0; text-align: center; }
