:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #15181d;
  --muted: #6b7280;
  --line: #e6e8ec;
  --accent: #0f766e;
  --accent-soft: #e3f2f0;
  --danger: #c2410c;
  --income: #15803d;
  --neutral: #6b7280;
  --savings: #2563eb;
  --mark: #fde68a;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 16px rgb(0 0 0 / .04);
  color-scheme: light;
}
/* Tema: Ayarlarda seçilir (html data-theme="light|dark"); seçilməyibsə sistemə uyğun (auto) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --bg: #0e1013;
    --surface: #181b20;
    --text: #e9ebef;
    --muted: #9aa1ac;
    --line: #2a2f37;
    --accent: #2dd4bf;
    --accent-soft: #123532;
    --danger: #fb923c;
    --income: #4ade80;
    --neutral: #9aa1ac;
    --savings: #60a5fa;
    --mark: #6b5310;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme=dark] {
  --bg: #0e1013;
  --surface: #181b20;
  --text: #e9ebef;
  --muted: #9aa1ac;
  --line: #2a2f37;
  --accent: #2dd4bf;
  --accent-soft: #123532;
  --danger: #fb923c;
  --income: #4ade80;
  --neutral: #9aa1ac;
  --savings: #60a5fa;
  --mark: #6b5310;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; overscroll-behavior-y: contain; } /* brauzerin öz "dartıb yenilə"si bizimkini təkrarlamasın */
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
h2, h3 { margin: 0; }

#view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
}
.title { font-size: 28px; margin: 8px 0 16px; }
.muted { color: var(--muted); }
.center { text-align: center; padding: 32px 0; }
.error { color: var(--danger); }
.hint { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.kind-hint { margin: -4px 0 0; font-size: 13px; }
.kind-hint:empty { display: none; }

/* ay seçici */
.monthbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 16px; }
.monthbar button[data-action=month] {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  display: grid; place-items: center; background: var(--surface); box-shadow: var(--shadow); color: var(--text);
}
/* Başlıq toxunula biləndir (dövr seçimi): kiçik ox işarəsi ilə göstərilir */
.period {
  min-width: 0; display: grid; justify-items: center; padding: 4px 12px; border: 0; border-radius: 12px;
  background: none; color: var(--text); cursor: pointer;
}
.period:active { background: var(--surface); }
.period-title { display: flex; align-items: center; gap: 6px; font-size: 22px; font-weight: 700; }
.period-title::after {
  content: ""; width: 7px; height: 7px; margin-top: -4px; border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.period small { color: var(--muted); font-size: 13px; }
.monthbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.monthbar button:disabled { opacity: .35; cursor: default; }

/* cəmlər */
.totals, .tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.totals div, .tile { background: var(--surface); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.totals span, .tile span { display: block; color: var(--muted); font-size: 13px; }
.totals b, .tile b { font-size: 20px; font-variant-numeric: tabular-nums; }

.banner {
  display: block; padding: 12px 14px; margin-bottom: 16px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent); text-decoration: none; font-weight: 600; font-size: 15px;
}

.theme-card { margin-top: 0; gap: 8px; }

/* Ayarlar → Kartlarım: ad yerindəcə redaktə olunur */
.card-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.card-row input {
  width: 100%; padding: 4px 6px; margin-left: -6px; border: 1px solid transparent; border-radius: 8px;
  background: transparent; color: var(--text); font-weight: 600; font-size: 16px;
}
.card-row input:hover { border-color: var(--line); }
.card-row input:focus { border-color: var(--accent); background: var(--bg); outline: none; }
.card-row .save {
  flex: none; border: 0; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 14px;
  padding: 8px 12px; border-radius: 10px; cursor: pointer;
}

/* filtrlər: native select (telefonda sistem seçicisi açılır), pill kimi görünür */
.filters { display: flex; gap: 8px; margin-bottom: 4px; }
.pill {
  position: relative; flex: 1; min-width: 0; display: grid; padding: 7px 30px 7px 12px; border-radius: 12px; text-align: left;
  background: var(--surface); box-shadow: var(--shadow); border: 1px solid transparent; cursor: pointer; color: var(--text);
  transition: transform .12s;
}
.pill:active { transform: scale(.97); }
.pill:disabled { opacity: 1; }
.pill.on { border-color: var(--accent); background: var(--accent-soft); }
.pill span { font-size: 11px; color: var(--muted); }
.pill b { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.filter-sum { display: flex; justify-content: space-between; align-items: center; margin: 10px 4px 0; font-size: 14px; color: var(--muted); }
.filter-sum b { color: var(--text); }
.filter-sum button { border: 0; background: none; color: var(--accent); font-weight: 600; cursor: pointer; padding: 4px; }
.bars li.selected .bar-label span { color: var(--accent); font-weight: 700; }

/* siyahı */
.day { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; color: var(--muted); margin: 18px 4px 6px; }
.day span { font-variant-numeric: tabular-nums; }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.tx {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px;
  border: 0; background: none; text-align: left; cursor: pointer;
}
.tx:active { background: var(--bg); }
.avatar {
  flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); font-size: 19px; line-height: 1;
}
.main { flex: 1; min-width: 0; }
.main b, .main small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main b { font-weight: 600; }
.main small { color: var(--muted); font-size: 13px; }
.amt { flex: none; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.amt em { display: block; font-style: normal; font-weight: 500; font-size: 11px; color: var(--danger); }
.k-income { color: var(--income); }
.k-transfer, .k-internal_transfer { color: var(--neutral); }
.k-savings { color: var(--savings); }
.avatar.k-income { background: color-mix(in srgb, var(--income) 15%, transparent); }
.avatar.k-transfer, .avatar.k-internal_transfer { background: color-mix(in srgb, var(--neutral) 15%, transparent); }
.avatar.k-savings { background: color-mix(in srgb, var(--savings) 15%, transparent); }

.fab {
  position: fixed; right: max(16px, calc(50% - 264px)); bottom: calc(80px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: 0; cursor: pointer; padding: 0;
  display: grid; place-items: center;
  background: var(--accent); color: var(--surface);
  box-shadow: 0 6px 20px rgb(0 0 0 / .2);
}
.fab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; }

/* kartlar (təsdiq) */
.section { display: flex; align-items: center; gap: 8px; font-size: 17px; margin: 24px 0 6px; }
.section span { background: var(--accent); color: var(--surface); border-radius: 10px; padding: 0 8px; font-size: 13px; }
.card { background: var(--surface); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); margin-bottom: 10px; }
.card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.card-top small { color: var(--muted); }
.card > small { display: block; margin-top: 2px; font-size: 13px; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.note-text {
  white-space: pre-wrap; word-break: break-word; font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg); border-radius: 10px; padding: 10px 12px; margin: 10px 0 0;
}
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 2px; }

/* düymələr */
.choices button, .row button, .wide, .form .primary {
  min-height: 42px; padding: 0 16px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600;
}
button.primary, .form .primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
button.danger { color: var(--danger); }
.wide { width: 100%; margin-top: 12px; }
button:disabled { opacity: .5; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* səsli giriş kartı; vəziyyət data-state ilə: idle | rec | busy | done */
/* Kartın özü düymədir; --level (səsin gücü) karta yazılır, mikrofon halqaları onu miras alır */
.voice {
  --tone: var(--accent);
  --level: 0;
  display: flex; align-items: center; gap: 16px; width: 100%; margin-top: 16px; padding: 14px 16px;
  border-radius: 18px; overflow: hidden; cursor: pointer; text-align: left; color: var(--text); font: inherit;
  background: color-mix(in srgb, var(--tone) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--tone) 22%, transparent);
  transition: background .25s, border-color .25s, transform .15s;
}
.voice:active { transform: scale(.985); }
.voice:disabled { opacity: 1; cursor: progress; }
.voice[data-state=rec] { --tone: var(--danger); }
.mic {
  position: relative; flex: none; width: 60px; height: 60px; border-radius: 50%;
  display: grid; place-items: center; background: var(--tone); color: var(--surface); isolation: isolate;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--tone) 35%, transparent);
  transition: background .25s, transform .15s;
}
.voice:active .mic { transform: scale(.94); }
.mic svg { position: relative; width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.mic .i-stop { fill: currentColor; stroke: none; }
/* Səs halqaları: ölçü səsin gücünə (--level) görə dəyişir */
.mic::before, .mic::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%; background: var(--tone); z-index: -1; opacity: 0;
  transition: transform .09s linear, opacity .2s;
}
.voice[data-state=rec] .mic::before { opacity: .22; transform: scale(calc(1.12 + var(--level) * .55)); }
.voice[data-state=rec] .mic::after { opacity: .12; transform: scale(calc(1.3 + var(--level) * 1)); }
.mic .i-stop, .mic .i-spin { display: none; }
.voice[data-state=rec] .i-mic, .voice[data-state=busy] .i-mic { display: none; }
.voice[data-state=rec] .i-stop { display: block; }
.voice[data-state=busy] .i-spin {
  display: block; width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid color-mix(in srgb, currentColor 35%, transparent); border-top-color: currentColor; animation: spin .8s linear infinite;
}
.voice-text { min-width: 0; display: grid; gap: 2px; }
.voice-text b { font-size: 16px; color: var(--tone); font-variant-numeric: tabular-nums; }
.voice-text small { color: var(--muted); font-size: 13px; line-height: 1.35; }
.voice[data-state=done] .voice-text small { color: var(--text); font-style: italic; }
.or { display: flex; align-items: center; gap: 10px; margin: 16px 0 0; color: var(--muted); font-size: 12px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
@media (prefers-reduced-motion: reduce) {
  .mic::before, .mic::after { transition: none; }
  .voice[data-state=rec] .mic::before { transform: scale(1.15); }
  .voice[data-state=rec] .mic::after { transform: scale(1.3); }
}

/* forma sahələri: seqmentli növ seçimi və kateqoriya seçici düyməsi */
.field { display: grid; gap: 6px; }
.field-label { font-size: 13px; color: var(--muted); }
.segment {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; padding: 3px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
}
.form .segment label { display: block; position: relative; font-size: inherit; color: inherit; }
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment span {
  display: block; padding: 9px 2px; border-radius: 9px; text-align: center; cursor: pointer; white-space: nowrap;
  font-size: 13px; font-weight: 600; color: var(--muted); transition: background .15s, color .15s;
}
.segment input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.segment input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.picker-field {
  position: relative; display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 6px 36px 6px 8px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text);
  font-size: 16px; text-align: left; cursor: pointer;
}
.picker-field .placeholder { color: var(--muted); }
.picker-field::after, .pill::after {
  content: ""; position: absolute; right: 14px; top: 50%; width: 7px; height: 7px; margin-top: -5px; pointer-events: none;
  border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(45deg);
}

/* seçici panel */
.picker { padding-top: 14px; }
.picker-head { display: flex; justify-content: center; align-items: center; min-height: 34px; }
.picker-head .close { top: 10px; }
.picker-search {
  width: 100%; margin-top: 12px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 16px;
}
.picker-list { list-style: none; margin: 8px -16px 0; padding: 0; }
.picker-list li + li { border-top: 1px solid var(--line); }
.picker-list button {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 54px; padding: 8px 20px;
  border: 0; background: none; color: var(--text); text-align: left; font-size: 16px; cursor: pointer;
}
.picker-list button:active, .picker-list button:hover { background: var(--bg); }
.picker-icon {
  flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); font-size: 16px; line-height: 1;
}
.picker-label { flex: 1; min-width: 0; }
.picker-label small { display: block; color: var(--muted); font-size: 13px; }
[aria-selected=true] .picker-label { font-weight: 600; color: var(--accent); }
.picker-new .picker-label { color: var(--accent); font-weight: 600; }
.check { flex: none; width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.picker-empty { padding: 20px; text-align: center; color: var(--muted); }

/* faktlar */
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 12px 0 0; font-size: 15px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* forma */
/* minmax(0, 1fr): grid sütunu içindəkinin minimum genişliyinə görə böyüməsin */
.form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; margin-top: 16px; }
.form label { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; font-size: 13px; color: var(--muted); }
.form input, .form select, .form textarea {
  width: 100%; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 16px;
}
/* iOS Safari tarix sahəsinə daxili minimum genişlik verir və sahə ekrandan daşır; görünüşü sıfırlayırıq */
.form input[type=date], .form input[type=datetime-local] {
  -webkit-appearance: none; appearance: none; display: block; min-height: 44px; text-align: left;
}
.form input::-webkit-date-and-time-value { text-align: left; }
.row { display: flex; gap: 8px; }
.row .primary { flex: 1; }

/* hesabat */
.bars { list-style: none; margin: 0; padding: 14px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); display: grid; gap: 12px; }
.bar-label { display: flex; justify-content: space-between; font-size: 15px; }
.bar-label b { font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 4px; background: var(--bg); margin: 4px 0 2px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; background: var(--accent); }
.bars small { color: var(--muted); font-size: 12px; }
.daily { width: 100%; height: auto; background: var(--surface); border-radius: 14px; padding: 14px 10px 6px; box-shadow: var(--shadow); }
.daily rect { fill: var(--accent); }
.daily text { fill: var(--muted); font-size: 8px; text-anchor: middle; }

/* sheet */
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; margin: auto auto 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  border: 0; border-radius: 20px 20px 0 0; background: var(--surface); color: var(--text); overflow-y: auto;
}
.sheet::backdrop { background: rgb(0 0 0 / .4); }
.sheet[open] { animation: sheet-up .28s cubic-bezier(.2, .8, .2, 1); }
.sheet[open]::backdrop { animation: fade-in .28s; }
@keyframes sheet-up { from { transform: translateY(60px); opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } }

/* dartıb yeniləmə göstəricisi: --pull (0..110) barmaqla birgə enir, həddə çatanda tam dolur */
.ptr {
  --pull: 0;
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 6px); z-index: 30;
  width: 38px; height: 38px; margin-left: -19px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface); box-shadow: 0 2px 12px rgb(0 0 0 / .18); pointer-events: none;
  transform: translateY(calc(var(--pull) * 1px - 56px)); opacity: min(1, calc(var(--pull) / 40));
  transition: transform .25s, opacity .25s;
}
.ptr.dragging { transition: none; }
.ptr span {
  width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--accent);
  transform: rotate(calc(var(--pull) * 4deg));
}
.ptr.ready span { border-color: var(--accent); }
.ptr.refreshing { transform: translateY(14px); opacity: 1; }
.ptr.refreshing span { border-color: var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@media (prefers-reduced-motion: reduce) {
  .sheet[open], .sheet[open]::backdrop { animation: none; }
}
.sheet-head { text-align: center; }
.sheet-head small { color: var(--muted); }
.sheet-head .big { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 2px 0; }
.close {
  position: absolute; right: 12px; top: 12px; width: 34px; height: 34px; border-radius: 50%; border: 0; padding: 0;
  display: grid; place-items: center; background: var(--bg); color: var(--muted); cursor: pointer;
}
.close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.close:active { transform: scale(.92); }

/* alt naviqasiya */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  position: relative; flex: 1; max-width: 140px; display: grid; justify-items: center; gap: 2px; padding: 8px 0 6px;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600;
}
.tabs a.active { color: var(--accent); }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.badge {
  position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

/* yüklənmə: dərhal görünür; minimum görünmə müddəti app.js-də (MIN_BAR_MS, MIN_SPINNER_MS) */
.loader {
  width: 32px; height: 32px; margin: 30vh auto 0; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
/* Zolaq: solğun iz + üzərində hərəkət edən parça, ona görə hər an görünür */
body.loading::before {
  content: ""; position: fixed; inset: env(safe-area-inset-top) 0 auto 0; height: 3px; z-index: 10;
  background:
    linear-gradient(var(--accent), var(--accent)) no-repeat,
    color-mix(in srgb, var(--accent) 25%, transparent);
  background-size: 40% 100%, 100% 100%;
  animation: bar 1s ease-in-out infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes bar { from { background-position: -70% 0, 0 0; } to { background-position: 170% 0, 0 0; } }
@media (prefers-reduced-motion: reduce) {
  .loader { animation-duration: 2.4s; }
  body.loading::before { animation: none; background: var(--accent); opacity: .6; }
}

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg);
  text-align: center;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }
