/* Колибри — mobile-first (основная цель: iPhone 14, 390×844) */

:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0efea;
  --ink: #13242b;
  --ink-2: #4d5c63;
  --muted: #86939a;
  --line: #e6e4dd;
  --brand: #0b6b72;
  --brand-strong: #08545a;
  --brand-soft: #e2f1ee;
  --brand-ink: #ffffff;
  --accent: #c2185b;
  --accent-soft: #fbe7ef;
  --danger: #c0392b;
  --income: #00869e;
  --expense: #eb6834;
  --shadow: 0 1px 2px rgba(19, 36, 43, 0.06), 0 8px 24px rgba(19, 36, 43, 0.08);
  --radius: 16px;
  --radius-sm: 10px;
  --tabbar-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #0e1416;
    --surface: #172024;
    --surface-2: #1f2a2f;
    --ink: #eef3f2;
    --ink-2: #b4c1c4;
    --muted: #7f8e93;
    --line: #26343a;
    --brand: #2bb3a3;
    --brand-strong: #46c9b9;
    --brand-soft: #173a3a;
    --brand-ink: #062a2c;
    --accent: #f06292;
    --accent-soft: #3a1d29;
    --danger: #ef6b5b;
    --income: #0098a6;
    --expense: #d95926;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0e1416;
  --surface: #172024;
  --surface-2: #1f2a2f;
  --ink: #eef3f2;
  --ink-2: #b4c1c4;
  --muted: #7f8e93;
  --line: #26343a;
  --brand: #2bb3a3;
  --brand-strong: #46c9b9;
  --brand-soft: #173a3a;
  --brand-ink: #062a2c;
  --accent: #f06292;
  --accent-soft: #3a1d29;
  --danger: #ef6b5b;
  --income: #0098a6;
  --expense: #d95926;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 var(--font);
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; overflow-x: clip; }
#app > * { animation: view-in 0.24s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes view-in { from { opacity: 0; } } /* без transform: он ломает position: fixed у FAB */

/* ---------- верхняя панель ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  display: flex; align-items: center; gap: 10px;
}
.topbar .logo { width: 34px; height: 34px; flex: none; }
.topbar h1 { font-size: 22px; line-height: 1.1; margin: 0; font-weight: 700; letter-spacing: -0.02em; }
.topbar .sub { font-size: 13px; color: var(--muted); }
.topbar .spacer { flex: 1; }
.title-btn { background: none; border: 0; padding: 0; text-align: left; display: flex; flex-direction: column; min-width: 0; }
.title-btn h1 { white-space: nowrap; }
.title-btn h1::after { content: ' ›'; color: var(--muted); font-weight: 400; }
.title-btn:active { opacity: 0.6; }
.cal-btn { background: var(--brand-soft); color: var(--brand); width: 40px; height: 40px; margin-left: -2px; }
.btn.dim { opacity: 0.45; }

.view { padding: 0 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px); }

/* ---------- кнопки ---------- */
.btn {
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 0;
  background: var(--surface-2); color: var(--ink); font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn, .icon-btn, .fab, .chip, .row, .day-pill, .appt, .month-grid button, .seg button {
  transition: transform 0.16s ease, background-color 0.2s ease, color 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}
.btn:active { transform: scale(0.96); }
.icon-btn:active { transform: scale(0.9); background: var(--surface-2); }
.chip:active { transform: scale(0.95); }
.row:active { background: var(--surface-2); }
.appt:active { transform: scale(0.97); }
.day-pill:active .num { transform: scale(0.88); }
.btn svg { width: 22px; height: 22px; flex: none; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-danger { background: transparent; color: var(--danger); }
.btn-ghost { background: transparent; color: var(--brand); padding: 0 10px; }
.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: transparent;
  display: grid; place-items: center; color: var(--ink-2);
}
.icon-btn svg { width: 22px; height: 22px; }

.fab {
  position: fixed; z-index: 25;
  right: max(16px, calc(50% - 280px + 16px));
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--brand); color: var(--brand-ink); box-shadow: var(--shadow);
  display: grid; place-items: center;
}
.fab svg { width: 26px; height: 26px; }
.fab:active { transform: scale(0.9); }

/* ---------- таб-бар ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar nav { max-width: 560px; margin: 0 auto; display: flex; height: var(--tabbar-h); }
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a[aria-current='page'] { color: var(--brand); }

/* ---------- неделя ---------- */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding: 4px 0 12px; touch-action: pan-y; }
.day-pill {
  border: 0; background: transparent; border-radius: 14px; padding: 6px 0 8px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 60px;
}
.day-pill .wd { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.day-pill .num {
  font-size: 18px; font-weight: 600; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%;
  transition: background-color 0.22s ease, color 0.22s ease, transform 0.16s ease;
}
.day-pill .dot { transition: background-color 0.2s ease; }
.day-pill .dot { width: 5px; height: 5px; border-radius: 50%; background: transparent; }
.day-pill.has .dot { background: var(--accent); }
.day-pill.today .num { color: var(--brand); }
.day-pill.sel .num { background: var(--brand); color: var(--brand-ink); animation: pop 0.3s cubic-bezier(0.3, 1.5, 0.5, 1); }
@keyframes pop { from { transform: scale(0.7); } }
.day-pill.weekend .wd { color: var(--accent); }

.day-summary { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 0 2px 10px; }
.day-summary .d { font-weight: 700; font-size: 17px; }
.day-summary .s { color: var(--muted); font-size: 14px; }

/* ---------- таймлайн дня ---------- */
.timeline {
  position: relative; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 8px 8px 8px 0; touch-action: pan-y;
}
.timeline .grid { position: relative; margin-left: 52px; }
.timeline .hour { position: absolute; left: -52px; right: 0; border-top: 1px solid var(--line); }
.timeline .hour span { position: absolute; left: 8px; top: -9px; font-size: 12px; color: var(--muted); background: var(--surface); padding-right: 4px; font-variant-numeric: tabular-nums; }
.timeline .half { position: absolute; left: 0; right: 0; border-top: 1px dashed color-mix(in srgb, var(--line) 70%, transparent); }
.timeline .now { position: absolute; left: -6px; right: 0; height: 2px; background: var(--accent); z-index: 3; pointer-events: none; }
.timeline .now::before { content: ''; position: absolute; left: -4px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline .grid.enter .appt { animation: appt-in 0.32s cubic-bezier(0.2, 0.8, 0.2, 1) both; animation-delay: calc(min(var(--i), 8) * 35ms + 60ms); }
@keyframes appt-in { from { opacity: 0; transform: translateY(8px) scale(0.97); } }
.timeline .slot-flash {
  position: absolute; left: 4px; right: 4px; z-index: 1; pointer-events: none; border-radius: 8px;
  background: color-mix(in srgb, var(--brand) 22%, transparent); animation: flash 0.6s ease-out forwards;
}
@keyframes flash { to { opacity: 0; } }
.timeline .hint {
  position: absolute; left: 4px; right: 4px; border-radius: 10px; z-index: 1; pointer-events: none;
  border: 1.5px dashed var(--brand); background: color-mix(in srgb, var(--brand-soft) 60%, transparent);
  color: var(--brand); font-size: 13px; font-weight: 600; padding: 4px 8px;
}

.appt {
  position: absolute; z-index: 2; border: 0; text-align: left;
  border-radius: 10px; padding: 5px 8px 5px 10px; overflow: hidden;
  background: var(--brand-soft); color: var(--ink);
  border-left: 3px solid var(--brand);
  display: flex; flex-direction: column; gap: 1px;
}
.appt .t { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.appt .n { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt .sv { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt.compact { flex-direction: row; align-items: center; gap: 6px; padding-top: 2px; padding-bottom: 2px; }
.appt.compact .sv { display: none; }
.appt.done { background: var(--surface-2); border-left-color: var(--muted); }
.appt.done .n::before { content: '✓ '; color: var(--brand); }
.appt.cancelled { background: transparent; border: 1px dashed var(--line); border-left: 3px solid var(--line); opacity: 0.7; }
.appt.cancelled .n { text-decoration: line-through; }
.appt.noshow { background: var(--accent-soft); border-left-color: var(--accent); }

.empty { text-align: center; color: var(--muted); padding: 24px 12px; }
.empty img { width: 56px; opacity: 0.85; }

/* ---------- карточки и списки ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 17px; margin: 0 0 4px; letter-spacing: -0.01em; }
.card .hint-text { font-size: 13px; color: var(--muted); margin: 0 0 12px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 18px 4px 8px; font-weight: 600; }

.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 14px; }
.row {
  width: 100%; border: 0; background: transparent; text-align: left;
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 56px;
}
.row + .row { border-top: 1px solid var(--line); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amount { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row .amount.income { color: var(--ink); }
.row .amount.expense { color: var(--ink); }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 6px; background: var(--brand-soft); color: var(--brand); vertical-align: 1px; }
.tx-mark { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.tx-mark.income { background: var(--income); }
.tx-mark.expense { background: var(--expense); }
.date-head { font-size: 13px; color: var(--muted); padding: 10px 16px 4px; font-weight: 600; background: var(--surface); }
.date-head + .row { border-top: 0; }

/* ---------- сегменты ---------- */
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button {
  flex: 1; border: 0; background: transparent; border-radius: 9px; min-height: 36px;
  font-size: 14px; font-weight: 600; color: var(--ink-2); padding: 0 6px;
}
.seg button[aria-pressed='true'] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.month-nav { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 12px; }
.month-nav strong { font-size: 17px; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.kpi { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); padding: 12px 10px; min-width: 0; }
.kpi .l { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.kpi .v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .d { font-size: 12px; color: var(--muted); }
.kpi.profit .v.neg { color: var(--danger); }

/* ---------- графики ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--line); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .axis-label.cur { fill: var(--ink); font-weight: 700; }
.chart .bar-income { fill: var(--income); }
.chart .bar-expense { fill: var(--expense); }
.chart .hit { fill: transparent; }
.chart .hit.active { fill: color-mix(in srgb, var(--ink) 6%, transparent); }
.chart .val-label { fill: var(--ink-2); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--ink-2); margin: 2px 0 10px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.tooltip {
  position: absolute; z-index: 5; pointer-events: none; transform: translate(-50%, -100%);
  background: var(--ink); color: var(--bg); border-radius: 10px; padding: 8px 10px;
  font-size: 13px; line-height: 1.35; white-space: nowrap; box-shadow: var(--shadow);
}
.tooltip b { display: block; margin-bottom: 2px; }
.tooltip .r { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tooltip i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.data-table th, .data-table td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--line); }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table th { color: var(--muted); font-weight: 600; font-size: 12px; }

.cat-bars { display: flex; flex-direction: column; gap: 10px; }
.cat-row .top { display: flex; justify-content: space-between; font-size: 14px; gap: 8px; }
.cat-row .top span:last-child { font-weight: 600; font-variant-numeric: tabular-nums; }
.cat-row .track { height: 8px; background: var(--surface-2); border-radius: 4px; margin-top: 4px; overflow: hidden; }
.cat-row .fill { height: 100%; border-radius: 0 4px 4px 0; }

/* ---------- формы ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); padding: 10px 12px; font-size: 16px; /* 16px — iOS не зумит поле */
  appearance: none; -webkit-appearance: none;
}
textarea.input { min-height: 72px; resize: vertical; }
.input:focus { outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 0; border-color: var(--brand); }
input[type='date'].input, input[type='time'].input { display: block; min-width: 0; }
select.input {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 10px; }
.input-row { display: flex; gap: 8px; }
.input-row .input { flex: 1; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 4px; margin: 0 -20px; padding-left: 20px; padding-right: 20px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 7px 14px; font-size: 14px; font-weight: 600; white-space: nowrap; min-height: 36px;
}
.chip small { color: var(--muted); font-weight: 500; margin-left: 4px; }
.chip[aria-pressed='true'] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip[aria-pressed='true'] small { color: inherit; opacity: 0.8; }

.form-error { color: var(--danger); font-size: 14px; min-height: 0; margin: -4px 0 10px; }

/* ---------- нижний лист (sheet) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(8, 18, 22, 0.42);
  opacity: 0; transition: opacity 0.22s ease;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-width: 560px; margin: 0 auto; max-height: calc(100dvh - var(--safe-top) - 24px);
  background: var(--bg); border-radius: 20px 20px 0 0;
  display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet.open { transform: translateY(0); }
.sheet-backdrop.open { opacity: 1; }
.sheet .grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; flex: none; }
.sheet header { display: flex; align-items: center; padding: 6px 8px 6px 20px; flex: none; }
.sheet header h3 { flex: 1; margin: 0; font-size: 18px; }
.sheet .body { overflow-y: auto; padding: 8px 20px calc(var(--safe-bottom) + 20px); -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.sheet .actions { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }

/* ---------- месяц в листе ---------- */
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.month-wrap { overflow: hidden; touch-action: pan-y; margin: 0 -4px; padding: 0 4px; }
.month-grid .wd { font-size: 11px; color: var(--muted); padding: 4px 0; text-transform: uppercase; }
.month-grid .wd.weekend { color: var(--accent); }
.month-grid { min-height: 300px; align-content: start; }
.month-grid button {
  border: 0; background: transparent; aspect-ratio: 1; border-radius: 50%; font-size: 16px; font-weight: 500;
  position: relative; max-width: 48px; justify-self: center; width: 100%;
}
.month-grid button:active { transform: scale(0.88); background: var(--surface-2); }
.month-grid button.past { color: var(--muted); }
.month-grid button.out { color: var(--muted); opacity: 0.45; }
.month-grid button.today { color: var(--brand); font-weight: 700; }
.month-grid button.sel { background: var(--brand); color: var(--brand-ink); }
.month-grid button .cnt, .month-legend .cnt {
  position: absolute; right: 0; top: 0; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; line-height: 16px; font-variant-numeric: tabular-nums;
}
.month-grid button.sel .cnt { box-shadow: 0 0 0 2px var(--bg); }
.month-legend { font-size: 13px; color: var(--muted); margin: 12px 0 0; display: flex; align-items: center; gap: 6px; }
.month-legend .cnt { position: static; display: inline-block; text-align: center; }
.sheet .chips.quick { margin-bottom: 6px; }

/* ---------- вход ---------- */
.auth { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: calc(var(--safe-top) + 24px) 24px calc(var(--safe-bottom) + 24px); }
.auth .brand { text-align: center; margin-bottom: 28px; }
.auth .brand img { width: 96px; height: 96px; }
.auth .brand h1 { font-size: 32px; margin: 8px 0 4px; letter-spacing: -0.03em; }
.auth .brand p { color: var(--muted); margin: 0; }

/* ---------- тост ---------- */
.toast {
  position: fixed; left: 50%; z-index: 70; transform: translate(-50%, 20px); opacity: 0;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 90px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  transition: opacity 0.2s, transform 0.2s; max-width: calc(100% - 32px); text-align: center; box-shadow: var(--shadow);
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.loading { text-align: center; padding: 40px; color: var(--muted); }

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