/* Кредиты — мобильный финансовый PWA. Тёмная тема по умолчанию, светлая через media. */

:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --card: #1a2029;
  --card-2: #21283280;
  --border: #2a313c;
  --text: #e7edf5;
  --text-dim: #9aa7b8;
  --text-faint: #6b7888;
  --accent: #4f8cff;
  --accent-2: #38e0a8;
  --accent-soft: #4f8cff22;
  --danger: #ff5d6c;
  --danger-soft: #ff5d6c22;
  --warn: #ffb84d;
  --good: #38e0a8;
  --interest: #ff8a5d;
  --principal: #4f8cff;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 6px 24px #0008;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --appbar-h: 52px;
  --tabbar-h: 60px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --bg-elev: #ffffff;
    --card: #ffffff;
    --card-2: #f0f2f5;
    --border: #e3e7ee;
    --text: #1a2230;
    --text-dim: #5a6678;
    --text-faint: #8a96a8;
    --accent: #2f6bff;
    --accent-soft: #2f6bff18;
    --shadow: 0 6px 20px #0000001a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
  line-height: 1.4;
  overscroll-behavior-y: none;
}
button { font-family: inherit; }
a { color: var(--accent); }

#app { min-height: 100vh; display: flex; flex-direction: column; }

/* ── App bar ─────────────────────────────────────────────── */
.appbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}
.appbar-inner {
  height: var(--appbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}
.appbar-title { font-size: 19px; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.appbar-actions { display: flex; gap: 8px; align-items: center; }

/* ── Main ────────────────────────────────────────────────── */
.main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
}
.main-full {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  padding: 24px 20px calc(var(--safe-bottom) + 24px);
  justify-content: center;
}

/* ── Tab bar ─────────────────────────────────────────────── */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 50;
  display: flex;
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.tab {
  flex: 1;
  border: none;
  background: none;
  color: var(--text-faint);
  height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  transition: color .15s;
}
.tab-icon { font-size: 21px; line-height: 1; filter: grayscale(.4) opacity(.85); }
.tab-label { font-size: 11px; font-weight: 600; }
.tab.active { color: var(--accent); }
.tab.active .tab-icon { filter: none; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card, .card + .section, .section + .card { margin-top: 14px; }
.section { margin-top: 20px; }
.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-faint);
  margin: 0 0 10px 4px;
}

/* Summary card */
.summary {
  background: linear-gradient(135deg, var(--accent) -20%, #6b3df0 120%);
  color: #fff;
  border: none;
}
.summary .sum-label { font-size: 13px; opacity: .85; }
.summary .sum-big { font-size: 30px; font-weight: 800; letter-spacing: -.03em; margin: 2px 0 14px; }
.summary-row { display: flex; gap: 12px; }
.summary-cell { flex: 1; background: #ffffff1f; border-radius: var(--radius-sm); padding: 10px 12px; }
.summary-cell .sc-label { font-size: 11px; opacity: .85; }
.summary-cell .sc-val { font-size: 16px; font-weight: 700; margin-top: 2px; }

/* Loan card */
.loan-card {
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .1s, border-color .15s;
}
.loan-card:active { transform: scale(.985); }
.loan-card.inactive { opacity: .6; }
.loan-badge {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.loan-main { flex: 1; min-width: 0; }
.loan-name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.loan-sub { font-size: 13px; color: var(--text-dim); margin-top: 2px; }
.loan-right { text-align: right; flex-shrink: 0; }
.loan-balance { font-weight: 700; font-size: 16px; }
.loan-next { font-size: 12px; color: var(--text-faint); margin-top: 3px; }
.loan-next.soon { color: var(--warn); }
.loan-list { display: flex; flex-direction: column; gap: 12px; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px;
  background: var(--card-2); color: var(--text-dim);
}
.chip.chip-accent { background: var(--accent-soft); color: var(--accent); }
.chip.chip-warn { background: #ffb84d22; color: var(--warn); }
.chip.chip-good { background: #38e0a822; color: var(--good); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 15px; font-weight: 600;
  cursor: pointer;
  min-height: 46px;
  transition: filter .12s, background .12s, transform .08s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { filter: brightness(1.1); }
.btn-ghost { background: var(--card-2); color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding: 8px 14px; font-size: 14px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--text);
  font-size: 17px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { transform: scale(.92); }
.icon-btn.primary { background: var(--accent); color: #fff; border: none; }

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 28px; line-height: 1;
  box-shadow: 0 8px 24px #4f8cff66;
  cursor: pointer;
  z-index: 40;
  display: flex; align-items: center; justify-content: center;
}
.fab:active { transform: scale(.92); }

/* ── Forms ───────────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
.field-hint { font-size: 12px; color: var(--text-faint); margin-top: 5px; }
.input {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 13px 14px;
  font-size: 16px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder { color: var(--text-faint); }
.select { appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%239aa7b8' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-grid .field { margin-bottom: 0; }
.form-error { color: var(--danger); font-size: 14px; margin: 8px 0; min-height: 1px; }

/* segmented control */
.seg { display: flex; background: var(--card-2); border-radius: var(--radius-sm); padding: 4px; gap: 4px; }
.seg button {
  flex: 1; border: none; background: none; color: var(--text-dim);
  padding: 9px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .15s, color .15s;
}
.seg button.active { background: var(--accent); color: #fff; }

/* slider */
.slider-row { display: flex; align-items: center; gap: 12px; }
input[type=range] {
  -webkit-appearance: none; appearance: none;
  flex: 1; height: 6px; border-radius: 3px;
  background: var(--card-2);
  outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 3px solid var(--bg);
  box-shadow: 0 1px 4px #0006;
}
input[type=range]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 3px solid var(--bg);
}

/* ── Auth ────────────────────────────────────────────────── */
.auth-logo { text-align: center; margin-bottom: 22px; }
.auth-logo .logo-mark { font-size: 46px; }
.auth-logo h1 { font-size: 26px; font-weight: 800; margin: 8px 0 2px; letter-spacing: -.02em; }
.auth-logo p { color: var(--text-dim); margin: 0; font-size: 14px; }
.auth-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }

/* ── Stats / detail ──────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat {
  background: var(--card-2); border-radius: var(--radius-sm); padding: 12px 14px;
}
.stat .stat-label { font-size: 12px; color: var(--text-faint); }
.stat .stat-val { font-size: 18px; font-weight: 700; margin-top: 3px; }
.stat .stat-val.interest { color: var(--interest); }
.stat .stat-val.good { color: var(--good); }

.kv { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.kv:last-child { border-bottom: none; }
.kv .kv-k { color: var(--text-dim); }
.kv .kv-v { font-weight: 600; }

/* chart */
.chart-wrap { position: relative; height: 220px; margin-top: 4px; }
.chart-wrap.tall { height: 240px; }
.chart-legend { display: flex; gap: 16px; justify-content: center; margin-top: 10px; font-size: 13px; color: var(--text-dim); }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }

/* amortization table */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-sm); border: 1px solid var(--border); }
table.amort { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.amort th, table.amort td { padding: 9px 10px; text-align: right; white-space: nowrap; }
table.amort th { position: sticky; top: 0; background: var(--bg-elev); color: var(--text-faint); font-weight: 600; font-size: 12px; }
table.amort th:first-child, table.amort td:first-child { text-align: left; }
table.amort tbody tr:nth-child(even) { background: var(--card-2); }
table.amort td.interest { color: var(--interest); }
table.amort td.principal { color: var(--principal); }

/* payment history */
.pay-item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.pay-item:last-child { border-bottom: none; }
.pay-ic { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.pay-ic.scheduled { background: var(--accent-soft); color: var(--accent); }
.pay-ic.prepay { background: #38e0a822; color: var(--good); }
.pay-main { flex: 1; }
.pay-kind { font-weight: 600; font-size: 14px; }
.pay-date { font-size: 12px; color: var(--text-faint); }
.pay-amt { font-weight: 700; font-variant-numeric: tabular-nums; }

/* compare */
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.compare-col { background: var(--card-2); border-radius: var(--radius-sm); padding: 14px; border: 1px solid transparent; }
.compare-col.recommended { border-color: var(--good); background: #38e0a812; }
.compare-col h4 { margin: 0 0 10px; font-size: 14px; }
.compare-metric { margin-bottom: 8px; }
.compare-metric .cm-val { font-size: 19px; font-weight: 800; }
.compare-metric .cm-label { font-size: 11px; color: var(--text-faint); }
.compare-metric .cm-val.good { color: var(--good); }
.rec-badge { display: inline-flex; gap: 6px; align-items: center; background: var(--good); color: #04130d; font-weight: 700; padding: 6px 12px; border-radius: 999px; font-size: 13px; margin-top: 4px; }

.note {
  background: var(--card-2); border-left: 3px solid var(--warn);
  padding: 12px 14px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 14px; color: var(--text-dim);
}
.note.accent { border-left-color: var(--accent); }

/* portfolio order */
.order-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.order-item:last-child { border-bottom: none; }
.order-num { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 14px; }
.order-main { flex: 1; }
.order-name { font-weight: 600; }
.order-sub { font-size: 12px; color: var(--text-faint); }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: #0009;
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; transition: opacity .2s;
}
.modal-overlay.show { opacity: 1; }
.modal-sheet {
  background: var(--bg-elev);
  width: 100%; max-width: 560px;
  border-radius: 20px 20px 0 0;
  max-height: 92vh;
  display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .25s cubic-bezier(.2,.8,.2,1);
  padding-bottom: var(--safe-bottom);
}
.modal-overlay.show .modal-sheet { transform: translateY(0); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px; }
.modal-title { font-size: 19px; font-weight: 700; margin: 0; }
.modal-body { padding: 8px 16px 16px; overflow-y: auto; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }
.confirm-text { font-size: 15px; line-height: 1.5; }
@media (min-width: 560px) {
  .modal-overlay { align-items: center; }
  .modal-sheet { border-radius: 20px; max-height: 86vh; }
}

/* ── Toasts ──────────────────────────────────────────────── */
.toast-host { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px); z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast {
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--border);
  padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0; transform: translateY(10px); transition: opacity .25s, transform .25s;
  max-width: 420px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-color: var(--good); }
.toast-error { border-color: var(--danger); }

/* ── Loading / empty ─────────────────────────────────────── */
.loading { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 60px 0; color: var(--text-dim); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 56px 24px; color: var(--text-dim); }
.empty-emoji { font-size: 46px; }
.empty-title { margin: 0; font-size: 18px; color: var(--text); }
.empty-sub { margin: 0; font-size: 14px; max-width: 320px; }
.empty .btn { margin-top: 8px; }

/* misc */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--text-dim); }
.center { text-align: center; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.big-num { font-variant-numeric: tabular-nums; }
.pin-dots { display: flex; gap: 14px; justify-content: center; margin: 24px 0; }
.pin-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--text-dim); }
.pin-dot.filled { background: var(--accent); border-color: var(--accent); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; max-width: 280px; margin: 0 auto; }
.pin-key { aspect-ratio: 1; border-radius: 50%; border: 1px solid var(--border); background: var(--card); color: var(--text); font-size: 24px; font-weight: 600; cursor: pointer; }
.pin-key:active { background: var(--card-2); }
.pin-key.blank { border: none; background: none; cursor: default; }

.toggle { position: relative; display: inline-block; width: 50px; height: 30px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .track { position: absolute; inset: 0; background: var(--card-2); border: 1px solid var(--border); border-radius: 999px; transition: background .2s; }
.toggle .track::before { content: ''; position: absolute; width: 24px; height: 24px; border-radius: 50%; background: #fff; top: 2px; left: 2px; transition: transform .2s; box-shadow: 0 1px 3px #0005; }
.toggle input:checked + .track { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .track::before { transform: translateX(20px); }
