/* Учёт личных финансов — стили интерфейса */

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --text: #1c2430;
  --muted: #687385;
  --primary: #2f6fed;
  --primary-hover: #1f5bd6;
  --primary-soft: #e8f0fe;
  --danger: #d4380d;
  --danger-soft: #fdecea;
  --success: #1a8a4a;
  --success-soft: #e6f6ec;
  --warning: #9a6700;
  --warning-soft: #fff6dd;
  --info-soft: #eef4ff;
  --neg: #c62828;
  --pos: #1a8a4a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --focus: 0 0 0 3px rgba(47, 111, 237, 0.25);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --surface: #171d26;
    --surface-2: #1d2430;
    --border: #2a3342;
    --text: #e6eaf0;
    --muted: #96a0b1;
    --primary: #5b8ff9;
    --primary-hover: #7aa5ff;
    --primary-soft: #1e2b45;
    --danger: #ff7a59;
    --danger-soft: #3a1f1a;
    --success: #4cc985;
    --success-soft: #16301f;
    --warning: #f0c35b;
    --warning-soft: #3a2f12;
    --info-soft: #1b2638;
    --neg: #ff6b6b;
    --pos: #4cc985;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.6rem; margin: 0; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 0.5rem; }

code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; }

.container { width: 100%; max-width: 1240px; margin: 0 auto; padding: 0 16px; }
.main { padding-top: 20px; padding-bottom: 32px; min-height: calc(100vh - 120px); }

/* ---------------------------------------------------------------- шапка и меню */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner { display: flex; align-items: center; gap: 16px; min-height: 56px; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); white-space: nowrap; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--primary); color: #fff; margin-right: 4px; font-size: 0.95rem;
}
.nav { display: flex; align-items: center; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a {
  color: var(--muted); padding: 6px 10px; border-radius: 8px; font-weight: 500; white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { color: var(--primary); background: var(--primary-soft); }
.nav-user { margin-left: auto; color: var(--muted); font-size: 0.9rem; padding: 0 6px; }
.nav-logout { margin: 0; }
.nav-toggle {
  display: none; margin-left: auto; background: none; border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 1.2rem; padding: 4px 10px; cursor: pointer;
}

@media (max-width: 1100px) {
  .nav-toggle { display: block; }
  .nav { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; padding-bottom: 12px; }
  .nav.open { display: flex; }
  .nav-user { margin-left: 0; padding: 6px 10px; }
  .nav-logout .btn { width: 100%; }
}

.footer { color: var(--muted); font-size: 0.8rem; padding-bottom: 24px; text-align: center; }

/* ---------------------------------------------------------------- карточки и заголовки */

.page-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-bottom: 16px;
}
.actions, .actions-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions-row { margin-bottom: 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.narrow { max-width: 680px; }
.narrow-left { max-width: 760px; }
.auth-card { max-width: 420px; margin: 32px auto; }
.auth-card h1 { margin-bottom: 16px; }

.stat-card { display: flex; flex-wrap: wrap; gap: 24px; }
.stat { min-width: 160px; }
.stat-label { color: var(--muted); font-size: 0.85rem; }
.stat-value { font-size: 1.4rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.account-balance { font-size: 1.3rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.error-card { text-align: center; max-width: 560px; margin: 40px auto; }
.error-code { font-size: 3rem; font-weight: 700; color: var(--muted); line-height: 1; margin-bottom: 8px; }
.lead { font-size: 1.05rem; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.empty { color: var(--muted); padding: 8px 0; margin: 0; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- уведомления */

.alert {
  border-radius: 8px; padding: 10px 14px; margin-bottom: 14px;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  border: 1px solid transparent;
}
.alert-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 25%, transparent); }
.alert-info { background: var(--info-soft); color: var(--text); border-color: var(--border); }
.alert-close { background: none; border: 0; color: inherit; font-size: 1.2rem; line-height: 1; cursor: pointer; opacity: 0.7; padding: 0 2px; }
.alert-close:hover { opacity: 1; }

.temp-password { border-color: var(--warning); background: var(--warning-soft); }
.secret code {
  display: inline-block; font-size: 1.4rem; letter-spacing: 0.08em; padding: 8px 14px;
  background: var(--surface); border: 1px dashed var(--warning); border-radius: 8px; user-select: all;
}

/* ---------------------------------------------------------------- кнопки */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
  cursor: pointer; white-space: nowrap; line-height: 1.2;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-danger { color: var(--danger); }
.btn-ghost.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 4px 9px; font-size: 0.85rem; }
.btn-block { width: 100%; }
.inline-form { display: inline; margin: 0; }

/* ---------------------------------------------------------------- таблицы */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th, .table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table thead th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.02em; white-space: nowrap; background: var(--surface-2); }
.table tfoot th { border-bottom: 0; border-top: 2px solid var(--border); }
.table tbody tr:hover { background: var(--surface-2); }
.table-compact th, .table-compact td { padding: 6px 10px; }
.table .r, .r { text-align: right; }
.table td.comment { max-width: 240px; color: var(--muted); }
.actions-col { white-space: nowrap; text-align: right; }
.row-closed td { color: var(--muted); }
.row-selected td { background: var(--primary-soft); }

.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg, .amt-expense { color: var(--neg); }
.amt-income { color: var(--pos); }
.arrow { color: var(--muted); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap;
}
.badge-income { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-expense { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge-transfer { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge-open { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-closed { background: var(--surface-2); color: var(--muted); }
.badge-admin { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge-auto { background: var(--warning-soft); color: var(--warning); border-color: transparent; }

.pager { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.year-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.year-current { font-size: 1.2rem; padding: 0 6px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------------------------------------------------------------- формы */

.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .field > .label { font-weight: 500; font-size: 0.9rem; }
.req { color: var(--danger); }
.hint { color: var(--muted); font-size: 0.8rem; }
.field-error { color: var(--danger); font-size: 0.85rem; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="month"], select, textarea {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; min-height: 38px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
input:disabled, select:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.input-num { text-align: right; font-variant-numeric: tabular-nums; }

.field-check { justify-content: flex-end; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 400; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); }

.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 6px; }

.grid-2, .grid-3 { display: grid; gap: 0 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 640px) {
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}

.inline-fields { display: flex; flex-wrap: wrap; gap: 0 14px; align-items: flex-end; }
.inline-fields .field { flex: 1 1 200px; }
.inline-fields .field-check { flex: 0 1 auto; }
.inline-fields .form-actions { margin-bottom: 14px; }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 12px; align-items: end; margin-bottom: 8px; }
.filters .field { margin-bottom: 10px; }
.filters-actions { display: flex; gap: 8px; margin-bottom: 10px; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 8px 16px; font-weight: 500; color: var(--muted); border-right: 1px solid var(--border); }
.seg:last-child span { border-right: 0; }
.seg input:focus-visible + span { box-shadow: inset var(--focus); }
.seg input:checked + span { background: var(--primary-soft); color: var(--primary); }
.seg-income input:checked + span { background: var(--success-soft); color: var(--success); }
.seg-expense input:checked + span { background: var(--danger-soft); color: var(--danger); }

@media (max-width: 640px) {
  .card { padding: 14px; }
  h1 { font-size: 1.35rem; }
  .page-head .actions { width: 100%; }
  .stat-card { gap: 12px; }
  .stat { min-width: 45%; }
}


/* История пополнений: шкала выполнения плана */
.progress-cell { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.replenish-progress {
  flex: 1; height: 10px; border: 0; border-radius: 999px; overflow: hidden;
  background: var(--border); appearance: none; -webkit-appearance: none;
}
.replenish-progress::-webkit-progress-bar { background: var(--border); border-radius: 999px; }
.replenish-progress::-webkit-progress-value { background: var(--primary); border-radius: 999px; }
.replenish-progress::-moz-progress-bar { background: var(--primary); border-radius: 999px; }
.replenish-progress.is-done::-webkit-progress-value { background: var(--success, #2e9d5b); }
.replenish-progress.is-done::-moz-progress-bar { background: var(--success, #2e9d5b); }
.progress-pct { min-width: 3.5em; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* Пользователь в шапке — ссылка на профиль */
.nav-user { color: inherit; text-decoration: none; }
a.nav-user:hover { text-decoration: underline; }
a.nav-user.active { font-weight: 600; }

/* Импорт выписки */
.import-table td { vertical-align: top; }
.main.main-wide { max-width: 1680px; }
.import-table input[type=text], .import-table select { width: 100%; min-width: 120px; }
.import-table td, .import-table th { padding-left: 6px; padding-right: 6px; }
.import-desc { min-width: 180px; max-width: 280px; }
.row-error td { background: color-mix(in srgb, var(--danger) 8%, transparent); }
textarea.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.plan-change { margin-top: 2px; font-style: italic; }
.total-row td { border-top: 2px solid var(--border); }

/* Главная: сводный баланс и ближайшие траты рядом; на узком экране — друг под другом */
.grid-halves { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.grid-halves > .card { margin-bottom: 0; min-width: 0; }
.grid-halves + .card { margin-top: 16px; }
@media (max-width: 900px) { .grid-halves { grid-template-columns: 1fr; } }
.badge-warn { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

/* Прогноз */
.forecast-table .row-current td { background: var(--primary-soft); }
.forecast-table .row-no-income td { opacity: 0.6; }
