/* ============ Тема ============ */
:root {
  --bg: #f4f5fb;
  --bg-soft: #eceef7;
  --card: #ffffff;
  --card-2: #f7f8fc;
  --text: #1b1f2e;
  --muted: #757b8c;
  --line: #e6e8f0;
  --accent: #6c8cff;
  --accent-ink: #ffffff;
  --teal: #24b79a;
  --amber: #f2a33c;
  --danger: #ef5b78;
  --pink: #f2799b;
  --shadow: 0 6px 22px rgba(28, 33, 61, 0.08);
  --shadow-sm: 0 2px 8px rgba(28, 33, 61, 0.06);
  --radius: 18px;
  --radius-sm: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}
[data-theme="dark"] {
  --bg: #12141d;
  --bg-soft: #191c27;
  --card: #1e2230;
  --card-2: #242938;
  --text: #e9ebf4;
  --muted: #9298ab;
  --line: #2c3143;
  --accent: #7d99ff;
  --shadow: 0 8px 26px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
button, input, select, textarea { font-family: inherit; font-size: 16px; color: inherit; }
a { color: var(--accent); text-decoration: none; }

/* ============ Каркас приложения ============ */
#app { min-height: 100vh; }
.screen { max-width: 720px; margin: 0 auto; padding: calc(var(--safe-top) + 14px) 16px 96px; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  background: linear-gradient(var(--bg) 78%, rgba(244,245,251,0));
  max-width: 720px; margin: 0 auto;
}
.topbar h1 { font-size: 24px; }
.topbar .sub { color: var(--muted); font-size: 13px; font-weight: 500; }

/* ============ Нижняя навигация ============ */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
  padding: 8px 6px calc(8px + var(--safe-bottom));
}
.tabbar button {
  flex: 1; background: none; border: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted); padding: 4px 2px; border-radius: 12px; transition: color .15s;
}
.tabbar button .ico { font-size: 21px; line-height: 1; }
.tabbar button .lbl { font-size: 11px; font-weight: 600; white-space: nowrap; }
.tabbar button.active { color: var(--accent); }

/* ============ Карточки ============ */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 16px; margin-bottom: 14px;
  border: 1px solid var(--line);
}
.card.tap { cursor: pointer; transition: transform .08s ease; }
.card.tap:active { transform: scale(0.985); }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; margin: 20px 4px 10px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.strong { font-weight: 700; }
.center { text-align: center; }
.hidden { display: none !important; }

/* ============ Кнопки ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: var(--accent-ink); border: 0; cursor: pointer;
  padding: 12px 18px; border-radius: 14px; font-weight: 600; transition: filter .15s, transform .08s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: .5; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--bg-soft); color: var(--text); }
.btn.soft { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.btn.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.btn.sm { padding: 8px 12px; font-size: 14px; border-radius: 11px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 18px;
}
.fab {
  position: fixed; right: max(16px, calc(50% - 344px)); bottom: calc(78px + var(--safe-bottom)); z-index: 35;
  width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: #fff; border: 0;
  font-size: 28px; box-shadow: 0 8px 20px rgba(108,140,255,.45); cursor: pointer; line-height: 1;
}
.fab:active { transform: scale(0.94); }

/* ============ Формы ============ */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.input, textarea.input, select.input {
  width: 100%; min-width: 0; background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 14px; border-radius: 12px; outline: none; transition: border-color .15s;
}
.input:focus, textarea.input:focus, select.input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 84px; }
/* Нативные date/time на iOS имеют фиксированную интринсик-ширину и распирают колонку — сбрасываем */
input.input[type="date"], input.input[type="time"] { -webkit-appearance: none; appearance: none; }

/* Поле пароля с кнопкой «показать» */
.pw-wrap { position: relative; display: block; }
.pw-wrap .input { padding-right: 46px; }
/* Safari/iOS рисует свою кнопку показа пароля — убираем, чтобы не дублировалась */
.pw-wrap .input::-ms-reveal, .pw-wrap .input::-ms-clear { display: none; }
.pw-eye {
  position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  background: none; border: 0; padding: 0; margin: 0; cursor: pointer;
  color: var(--muted); border-radius: 9px; transition: color .15s, background .15s;
}
.pw-eye:hover { color: var(--text); background: var(--bg-soft); }
.pw-eye:active { color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-2 > * { min-width: 0; }

/* Сегментированный переключатель */
.segmented { display: flex; background: var(--bg-soft); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented button {
  flex: 1; border: 0; background: none; color: var(--muted); font-weight: 600; padding: 9px 8px;
  border-radius: 9px; cursor: pointer; font-size: 14px;
}
.segmented button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow-sm); }

/* Чипы выбора */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 8px 12px; border-radius: 999px; cursor: pointer; font-size: 14px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.active { background: color-mix(in srgb, var(--accent) 16%, transparent); border-color: var(--accent); color: var(--accent); }

/* ============ Прогресс ============ */
.progress { height: 8px; background: var(--bg-soft); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s ease; }
.ring { --p: 0; width: 56px; height: 56px; border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--bg-soft) 0);
  display: grid; place-items: center; }
.ring > span { width: 42px; height: 42px; border-radius: 50%; background: var(--card);
  display: grid; place-items: center; font-weight: 700; font-size: 13px; }

/* Плитки статистики */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow-sm); }
.tile .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.tile .v { font-size: 22px; font-weight: 800; margin-top: 4px; letter-spacing: -0.02em; }
.tile .v.pos { color: var(--teal); }
.tile .v.neg { color: var(--danger); }

/* Значки/бэйджи */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--bg-soft); color: var(--muted); }
.badge.area { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.badge.shared { background: color-mix(in srgb, var(--teal) 15%, transparent); color: var(--teal); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* Списки */
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 700; flex: none; }

/* Чекбокс-круг */
.check {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); flex: none;
  display: grid; place-items: center; cursor: pointer; color: transparent; transition: all .15s;
}
.check.on { background: var(--teal); border-color: var(--teal); color: #fff; }

/* Сетка привычек (неделя) */
.week { display: flex; gap: 6px; }
.week .d { flex: 1; text-align: center; }
.week .d .dn { font-size: 10px; color: var(--muted); margin-bottom: 4px; }
.week .d .box { height: 30px; border-radius: 9px; background: var(--bg-soft); display: grid; place-items: center; cursor: pointer; font-size: 13px; }
.week .d .box.on { background: var(--teal); color: #fff; }
.week .d .box.today { box-shadow: 0 0 0 2px var(--accent) inset; }

/* Иконка привычки */
.hicon { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; font-size: 22px; flex: none; }

/* ============ Модалка ============ */
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(10,12,20,.45); display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s; }
.overlay.show { opacity: 1; pointer-events: auto; }
.sheet {
  background: var(--card); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0;
  padding: 8px 18px calc(20px + var(--safe-bottom)); max-height: 92vh; overflow-y: auto;
  transform: translateY(20px); transition: transform .22s ease; box-shadow: 0 -10px 40px rgba(0,0,0,.2);
}
.overlay.show .sheet { transform: translateY(0); }
.sheet .grip { width: 40px; height: 4px; border-radius: 999px; background: var(--line); margin: 8px auto 14px; }
.sheet h3 { font-size: 19px; margin-bottom: 14px; }

/* ============ Тосты ============ */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(88px + var(--safe-bottom)); z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: #23283a; color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px; font-weight: 500; box-shadow: var(--shadow);
  animation: pop .2s ease; max-width: 90%; }
.toast.err { background: var(--danger); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* Пустое состояние */
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .em { font-size: 40px; margin-bottom: 10px; }

/* Экран входа */
.auth { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; max-width: 440px; margin: 0 auto; padding: 24px; }
.auth .logo { text-align: center; margin-bottom: 22px; }
.auth .logo .mark { font-size: 46px; }
.auth .logo h1 { font-size: 26px; margin-top: 8px; }
.auth .switcher { text-align: center; margin-top: 16px; color: var(--muted); font-size: 14px; }

/* Мини-график капитала */
.spark { display: flex; align-items: flex-end; gap: 5px; height: 70px; }
.spark .bar { flex: 1; background: color-mix(in srgb, var(--accent) 55%, transparent); border-radius: 6px 6px 0 0; min-height: 4px; }
.spark .bar.neg { background: color-mix(in srgb, var(--danger) 55%, transparent); }

/* Загрузка */
.loading { display: grid; place-items: center; min-height: 60vh; color: var(--muted); }
.spin { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: sp 0.8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

.mood { font-size: 20px; }

/* ============ Калькулятор в денежных полях ============ */
.money-field { display: flex; flex-direction: column; gap: 8px; }
.calc-strip { display: flex; flex-wrap: wrap; gap: 6px; }
.calc-btn {
  flex: 1; min-width: 38px; padding: 9px 0; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--text);
  font-size: 16px; font-weight: 600; cursor: pointer; line-height: 1;
}
.calc-btn:active { background: var(--card); }
.calc-btn.eq { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ============ Выбор категории ============ */
.catpicker { display: flex; flex-direction: column; gap: 8px; }
.catlist { display: flex; flex-direction: column; gap: 4px; max-height: 190px; overflow-y: auto; }
.catopt {
  display: flex; align-items: center; gap: 9px; padding: 9px 11px; border-radius: 10px;
  background: var(--bg-soft); cursor: pointer; font-size: 14px;
}
.catopt.sel { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.catopt.add { color: var(--accent); }
.catopt > i { color: var(--muted); font-size: 13px; }
.catopt.add > i, .catopt.sel > i { color: var(--accent); }

/* ============ Pull-to-refresh ============ */
/* Контейнер ТОЛЬКО съезжает вниз по центру (translate по X всегда -50%, вращения нет).
   Крутится строго внутренний круг вокруг своего центра. */
.ptr {
  position: fixed; top: 0; left: 50%;
  transform: translate(-50%, -44px);
  z-index: 60; width: 36px; height: 36px; border-radius: 50%; background: var(--card);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3); display: grid; place-items: center;
  opacity: 0; pointer-events: none;
  transition: transform 0.28s cubic-bezier(0.2, 0.7, 0.3, 1), opacity 0.2s;
}
.ptr.show { opacity: 1; }
.ptr.drag { transition: opacity 0.12s; } /* во время перетаскивания — 1:1, без инерции */
.ptr-spin {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  transform-origin: 50% 50%;
}
.ptr.ready .ptr-spin { border-top-color: var(--teal); }
.ptr.spin .ptr-spin { animation: ptr-rot 0.8s linear infinite; }
@keyframes ptr-rot { from { transform: rotate(0); } to { transform: rotate(360deg); } }

/* ============ Задачи: вкладки и заметки ============ */
.subtabs { display: flex; gap: 6px; background: var(--card); border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.subtab {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  padding: 9px 8px; border-radius: 9px; font-weight: 600; font-size: 14px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.subtab.active { background: var(--accent); color: #fff; }
/* Вариант с прокруткой: когда вкладок больше трёх, они не влезают в ширину телефона */
.subtabs.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.subtabs.scroll::-webkit-scrollbar { display: none; }
.subtabs.scroll .subtab { flex: 0 0 auto; white-space: nowrap; padding-left: 12px; padding-right: 12px; }
.note-body {
  display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical;
  overflow: hidden; color: var(--muted);
}

/* ============ Карта и погода в поездке ============ */
.trip-map {
  position: relative; isolation: isolate; z-index: 0;
  height: 190px; width: 100%; background: var(--bg2, rgba(127, 127, 127, 0.12)); cursor: pointer;
}
.trip-map-ph { height: 100%; display: grid; place-items: center; gap: 6px; }
.trip-map .maplibregl-map { position: absolute; inset: 0; background: var(--bg2, #e8e8e8); font: inherit; }
.trip-map .maplibregl-ctrl-attrib { font-size: 9px; }
.trip-map .maplibregl-ctrl-bottom-left { display: none; } /* лого/масштаб не нужны на локаторе */
.trip-weather { padding: 11px 14px; border-top: 1px solid var(--line); }
.trip-holi { padding: 11px 14px; border-top: 1px solid var(--line); }
.trip-geo-actions { padding: 0 14px 12px; }
.badge-btn { border: 0; cursor: pointer; font-family: inherit; display: inline-flex; align-items: center; gap: 5px; }
.badge-btn .caret { font-size: 10px; opacity: 0.6; }

/* Мастер «когда ехать»: полоса месяцев */
.wiz-months { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.wiz-m {
  position: relative; text-align: center; cursor: pointer; color: var(--text);
  padding: 9px 2px; border-radius: 10px; border: 1px solid var(--line); background: var(--card-2);
}
.wiz-m.sel { outline: 2px solid var(--accent); outline-offset: 1px; }
.wiz-mn { font-size: 11px; color: var(--muted); }
.wiz-mt { font-size: 15px; font-weight: 700; }
.wiz-mp { font-size: 9px; color: var(--muted); margin-top: 1px; }
.wiz-mh { position: absolute; top: 3px; right: 4px; font-size: 8px; color: var(--accent); }
.wiz-mc { position: absolute; bottom: 3px; left: 4px; font-size: 8px; color: #e0a44e; }
.wiz-cmp-months { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.wiz-cmp-m { padding: 8px 2px; border-radius: 8px; border: 1px solid var(--line); background: var(--card-2); color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer; }
.wiz-cmp-m.sel { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ============ Календарь-сетка ============ */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-wd { text-align: center; font-size: 11px; font-weight: 600; color: var(--muted); padding: 2px 0 6px; }
.cal-day {
  position: relative; aspect-ratio: 1 / 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px; border-radius: 10px;
  cursor: pointer; font-size: 14px; color: var(--text); background: var(--bg-soft);
}
.cal-day .cal-n { line-height: 1; }
.cal-day.today { outline: 1.5px solid var(--accent); }
.cal-day.sel { background: var(--accent); color: #fff; }
.cal-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.cal-day.sel .cal-dot { background: #fff; }
.cal-day.trip { box-shadow: inset 0 -3px 0 color-mix(in srgb, var(--teal) 75%, transparent); }
.cal-day.trip.sel { box-shadow: inset 0 -3px 0 #fff; }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
