/* LifeOS — общая дизайн-система для Milpa и Ritmo
   Mobile-first, тёмная тема по умолчанию, светлая по переключателю. */

:root {
  /* нейтральная шкала (тёмная тема) */
  --bg:        #0b0d10;
  --bg-2:      #12151a;
  --surface:   #171b21;
  --surface-2: #1f242c;
  --line:      #272d36;
  --line-soft: #1d222a;

  --text:      #e8ecf2;
  --text-2:    #9aa4b2;
  --text-3:    #6b7480;

  /* семантика */
  --pos:       #34d399;
  --pos-bg:    rgba(52,211,153,.12);
  --neg:       #f87171;
  --neg-bg:    rgba(248,113,113,.12);
  --warn:      #fbbf24;
  --warn-bg:   rgba(251,191,36,.12);
  --info:      #60a5fa;

  /* акцент — приложение переопределяет */
  --accent:    #34d399;
  --accent-ink:#04120c;
  --accent-bg: rgba(52,211,153,.12);

  /* категории привычек / графики */
  --c1: #34d399; --c2: #60a5fa; --c3: #a78bfa; --c4: #fbbf24;
  --c5: #f472b6; --c6: #22d3ee; --c7: #fb923c; --c8: #94a3b8;

  --r-sm: 10px; --r: 14px; --r-lg: 20px; --r-full: 999px;
  --pad: 16px;
  --shadow: 0 8px 24px rgba(0,0,0,.35);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.25);

  --tap: 44px;               /* минимальная зона касания */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 62px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;

  color-scheme: dark;
}

[data-theme="light"] {
  --bg:        #f4f6f9;
  --bg-2:      #eef1f6;
  --surface:   #ffffff;
  --surface-2: #f5f7fa;
  --line:      #e2e7ee;
  --line-soft: #edf0f5;
  --text:      #111823;
  --text-2:    #5a6676;
  --text-3:    #8a95a3;
  --pos: #059669; --pos-bg: rgba(5,150,105,.10);
  --neg: #dc2626; --neg-bg: rgba(220,38,38,.10);
  --warn:#b45309; --warn-bg: rgba(180,83,9,.10);
  --info:#2563eb;
  --accent-ink:#ffffff;
  --shadow: 0 8px 24px rgba(16,24,40,.10);
  --shadow-sm: 0 1px 4px rgba(16,24,40,.08);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
body { min-height: 100dvh; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: var(--accent); text-decoration: none; }
h1,h2,h3,h4 { margin: 0; font-weight: 650; letter-spacing: -0.015em; }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }

/* ─────────── Каркас экрана ─────────── */

.app {
  min-height: 100dvh;
  display: flex; flex-direction: column;
  max-width: 560px; margin: 0 auto;
  background: var(--bg);
}

.topbar {
  position: sticky; top: 0; z-index: 30;
  padding: calc(var(--safe-top) + 10px) var(--pad) 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: 10px; min-height: 52px;
}
.topbar__title { font-size: 19px; font-weight: 680; flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__sub { font-size: 12px; color: var(--text-2); font-weight: 500; }

.screen {
  flex: 1;
  padding: 14px var(--pad) calc(var(--tabbar-h) + var(--safe-bottom) + 90px);
  display: flex; flex-direction: column; gap: 14px;
}

/* ─────────── Нижняя панель вкладок ─────────── */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: center;
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--line-soft);
}
.tabbar__inner { display: flex; width: 100%; max-width: 560px; }
.tab {
  flex: 1; height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--text-3); font-size: 10.5px; font-weight: 600;
  transition: color .15s;
}
.tab svg { width: 23px; height: 23px; stroke-width: 1.9; }
.tab[aria-current="page"] { color: var(--accent); }

/* ─────────── Карточки ─────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: var(--pad);
}
.card--flat { background: var(--surface-2); border-color: transparent; }
.card__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px;
}
.card__title { font-size: 13px; font-weight: 650; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .05em; }

.section-title {
  font-size: 13px; font-weight: 650; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .05em;
  padding: 4px 2px 0;
}

/* ─────────── Типографика чисел ─────────── */

.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.amount { font-weight: 660; letter-spacing: -0.02em; }
.amount--xl { font-size: 34px; letter-spacing: -0.03em; }
.amount--lg { font-size: 22px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--text-2); }
.muted-3 { color: var(--text-3); }
.small { font-size: 13px; }
.tiny { font-size: 11.5px; }

/* ─────────── Кнопки ─────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px;
  border-radius: var(--r-full);
  background: var(--surface-2); color: var(--text);
  font-size: 15px; font-weight: 600;
  border: 1px solid var(--line);
  transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn--ghost { background: transparent; border-color: var(--line); }
.btn--danger { background: var(--neg-bg); color: var(--neg); border-color: transparent; }
.btn--block { width: 100%; }
.btn--sm { min-height: 34px; padding: 0 13px; font-size: 13.5px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.icon-btn {
  width: var(--tap); height: var(--tap); flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: var(--r-full); color: var(--text-2);
  transition: background .15s;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; stroke-width: 2; }

/* плавающая кнопка «добавить» */
.fab {
  position: fixed; z-index: 35;
  right: max(var(--pad), calc(50vw - 280px + var(--pad)));
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  width: 58px; height: 58px; border-radius: var(--r-full);
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 38%, transparent);
  transition: transform .1s;
}
.fab:active { transform: scale(.93); }
.fab svg { width: 27px; height: 27px; stroke-width: 2.4; }

/* ─────────── Сегментированный переключатель ─────────── */

.seg {
  display: flex; gap: 3px; padding: 3px;
  background: var(--surface-2); border-radius: var(--r-full);
  border: 1px solid var(--line-soft);
}
.seg button {
  flex: 1; min-height: 36px; padding: 0 12px;
  border-radius: var(--r-full);
  font-size: 14px; font-weight: 600; color: var(--text-2);
  white-space: nowrap; transition: background .15s, color .15s;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.seg--accent button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* горизонтальная прокрутка чипов */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px; margin: -2px;
  scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; min-height: 34px; padding: 0 14px;
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: var(--r-full); border: 1px solid var(--line);
  background: var(--surface); color: var(--text-2);
  font-size: 13.5px; font-weight: 600; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* ─────────── Строки списка ─────────── */

.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 9px 0;
  border-bottom: 1px solid var(--line-soft);
  text-align: left; width: 100%;
}
.row:last-child { border-bottom: 0; }
.row__main { flex: 1; min-width: 0; }
.row__title { font-size: 15.5px; font-weight: 570;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row__sub { font-size: 12.5px; color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row__end { text-align: right; flex: 0 0 auto; }

.avatar {
  width: 40px; height: 40px; flex: 0 0 auto;
  border-radius: 12px; display: grid; place-items: center;
  font-size: 19px; background: var(--surface-2);
}

/* ─────────── Поля ввода ─────────── */

.field { display: flex; flex-direction: column; gap: 7px; }
.label { font-size: 12.5px; font-weight: 620; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .04em; }
.input, .select, .textarea {
  width: 100%; min-height: 48px; padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  font-size: 16px; /* 16px — иначе iOS зумит при фокусе */
  outline: none; transition: border-color .15s, background .15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  background: var(--surface);
}
.textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239aa4b2' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat; background-position: right 13px center;
  padding-right: 40px;
}
.input--amount {
  font-size: 32px; font-weight: 660; letter-spacing: -0.02em;
  text-align: center; min-height: 68px;
  font-variant-numeric: tabular-nums;
}
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; min-height: 52px;
  border-bottom: 1px solid var(--line-soft);
}
.switch-row:last-child { border-bottom: 0; }

.switch { position: relative; width: 50px; height: 30px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; z-index: 1; }
.switch span {
  position: absolute; inset: 0; border-radius: var(--r-full);
  background: var(--line); transition: background .2s;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff; transition: transform .2s; box-shadow: var(--shadow-sm);
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }

/* ─────────── Модальное окно (лист снизу) ─────────── */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(3px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease;
}
.sheet {
  width: 100%; max-width: 560px;
  max-height: 92dvh; overflow-y: auto;
  background: var(--bg-2);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  border-top: 1px solid var(--line);
  padding: 10px var(--pad) calc(var(--safe-bottom) + 20px);
  animation: slideup .26s cubic-bezier(.22,.9,.3,1);
}
.sheet__grip {
  width: 38px; height: 4px; border-radius: var(--r-full);
  background: var(--line); margin: 4px auto 12px;
}
.sheet__head {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px; position: sticky; top: 0;
  background: var(--bg-2); padding: 4px 0 8px; z-index: 2;
}
.sheet__title { font-size: 18px; font-weight: 680; flex: 1; }
.sheet__body { display: flex; flex-direction: column; gap: 14px; }
.sheet__actions { display: flex; gap: 10px; margin-top: 6px; }
.sheet__actions .btn { flex: 1; }

@keyframes fade { from { opacity: 0 } }
@keyframes slideup { from { transform: translateY(100%) } }

/* ─────────── Тост ─────────── */

.toast-host {
  position: fixed; z-index: 120; left: 0; right: 0;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 20px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; padding: 0 var(--pad);
}
.toast {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line);
  padding: 11px 18px; border-radius: var(--r-full);
  font-size: 14px; font-weight: 570; box-shadow: var(--shadow);
  animation: toastin .22s ease;
  max-width: 100%;
}
.toast--err { border-color: var(--neg); color: var(--neg); }
@keyframes toastin { from { opacity: 0; transform: translateY(8px) } }

/* ─────────── Пустые состояния ─────────── */

.empty {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 42px 20px; text-align: center; color: var(--text-3);
}
.empty__icon { font-size: 38px; opacity: .55; }
.empty__title { font-size: 16px; font-weight: 620; color: var(--text-2); }
.empty__text { font-size: 13.5px; max-width: 32ch; line-height: 1.5; }

/* ─────────── Прогресс ─────────── */

.bar { height: 8px; border-radius: var(--r-full); background: var(--surface-2); overflow: hidden; }
.bar__fill { height: 100%; border-radius: var(--r-full); background: var(--accent);
  transition: width .35s cubic-bezier(.3,.9,.3,1); }

.ring { transform: rotate(-90deg); }
.ring__track { stroke: var(--surface-2); }
.ring__fill { stroke: var(--accent); stroke-linecap: round;
  transition: stroke-dashoffset .5s cubic-bezier(.3,.9,.3,1); }

/* ─────────── Сетка ─────────── */

.grid { display: grid; gap: 10px; }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.hstack { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }

/* доступность */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; }

/* ─────────── Большой экран ───────────
   На компьютере телефонная колонка обрамляется, чтобы читалась как
   отдельное окно приложения, а не как растянутая страница. */

@media (min-width: 760px) {
  body { background: var(--bg-2); }

  .app {
    border-left: 1px solid var(--line-soft);
    border-right: 1px solid var(--line-soft);
    box-shadow: 0 0 60px rgba(0,0,0,.28);
  }

  /* полоса вкладок больше не тянется через весь экран */
  .tabbar {
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-top: 0;
  }
  .tabbar__inner {
    background: color-mix(in srgb, var(--bg) 94%, transparent);
    backdrop-filter: saturate(180%) blur(18px);
    -webkit-backdrop-filter: saturate(180%) blur(18px);
    border-top: 1px solid var(--line-soft);
    border-left: 1px solid var(--line-soft);
    border-right: 1px solid var(--line-soft);
  }

  /* на мыши курсор должен подсказывать, что строки нажимаются */
  .row:hover .row__title { color: var(--text); }
  button.row:hover, .tile:hover { background: var(--surface-2); }
  .btn:hover { filter: brightness(1.08); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
