:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #1c1f24;
  --muted: #6b7280;
  --border: #e2e5ea;
  --accent: #2f6fde;
  --expense: #d9534f;
  --income: #1f9d61;
  --savings: #7b5cd6;
  --warn: #c77d0a;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 6%);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418;
    --surface: #1b1e24;
    --surface-2: #252932;
    --text: #e8eaed;
    --muted: #9aa1ac;
    --border: #2d323b;
    --accent: #6c9cf0;
    --expense: #f07a76;
    --income: #4cc58b;
    --savings: #a68cf0;
    --warn: #e6a33e;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; }

.top {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.top-row, .tabs, main {
  max-width: 720px;
  margin: 0 auto;
  padding-inline: 16px;
}

.top-row { display: flex; align-items: center; gap: 8px; padding-top: 8px; }
.month-label {
  flex: 1;
  text-align: left;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.not-current {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--warn) 20%, var(--surface));
  color: var(--warn);
}
.brand { font-weight: 600; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; }

.month-switch { display: flex; align-items: center; gap: 8px; }
.month-name { flex: 1; text-align: center; font-size: 17px; }
.month-pick { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
input[type='month'] {
  font: inherit;
  color: inherit;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  max-width: 11em;
}

.icon {
  width: 34px; height: 34px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  cursor: pointer;
}
.icon:hover { background: var(--surface-2); }
.icon.busy { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 4px 6px; }
.link:disabled { color: var(--muted); cursor: default; }

.tabs { display: flex; gap: 4px; }
.tab {
  flex: 1;
  border: 0;
  background: none;
  padding: 10px 4px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.tab[aria-selected='true'] { color: var(--text); border-bottom-color: var(--accent); }
.count {
  display: inline-block;
  margin-left: 6px;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

main { padding-block: 14px 96px; }

.banner { padding: 8px 12px; margin-bottom: 12px; border-radius: 8px; background: var(--surface-2); color: var(--muted); font-size: 14px; }
.banner.error { background: color-mix(in srgb, var(--expense) 14%, var(--surface)); color: var(--text); }

.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.stat, .hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums; }
.summary.hero { display: block; }
.hero-value { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; margin: 2px 0 6px; }


.section { margin-bottom: 20px; }
.section h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 8px; }

.cards { display: flex; flex-direction: column; gap: 8px; }

.card {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
  text-align: left;
  width: 100%;
}
.card.type-expense { border-left-color: var(--expense); }
.card.type-income { border-left-color: var(--income); }
.card.type-savings { border-left-color: var(--savings); }
.card-main { min-width: 0; flex: 1; }
.card-amount { text-align: right; white-space: nowrap; font-weight: 600; font-variant-numeric: tabular-nums; }
.title { font-weight: 500; overflow-wrap: anywhere; }
.meta, .sub { font-size: 12px; color: var(--muted); font-weight: 400; }
.muted { color: var(--muted); }
.negative { color: var(--expense); }
.approx { color: var(--warn); margin-right: 2px; font-weight: 600; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  margin-bottom: 2px;
  color: var(--surface);
}
.badge.type-expense { background: var(--expense); }
.badge.type-income { background: var(--income); }
.badge.type-savings { background: var(--savings); }

.card.plan { flex-direction: column; gap: 8px; }
.plan-head { display: flex; justify-content: space-between; gap: 12px; }
.status { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--surface-2); color: var(--muted); margin-top: 2px; }
.status.tone-over { background: color-mix(in srgb, var(--expense) 18%, var(--surface)); color: var(--expense); }
.status.tone-done { background: color-mix(in srgb, var(--income) 18%, var(--surface)); color: var(--income); }
.status.tone-progress { background: color-mix(in srgb, var(--accent) 15%, var(--surface)); color: var(--accent); }
.card.tone-planned { border-style: dashed; border-left-style: solid; background: transparent; box-shadow: none; }

.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar { height: 100%; background: var(--accent); border-radius: 3px; }
.tone-over .bar { background: var(--expense); }
.tone-done .bar { background: var(--income); }
.progress-meta { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-top: 4px; }

.linked { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; padding-left: 10px; border-left: 2px solid var(--surface-2); }
.card.compact { padding: 6px 10px; border-left-width: 1px; box-shadow: none; background: var(--surface-2); border-color: transparent; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.chip { font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--surface-2); color: var(--muted); font-variant-numeric: tabular-nums; }

.month-card { cursor: pointer; font: inherit; color: inherit; }
.month-card:hover { border-color: var(--accent); }
.month-card.selected { outline: 2px solid var(--accent); outline-offset: -1px; }

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

@media (max-width: 420px) {
  .summary { gap: 6px; }
  .stat { padding: 8px; }
  .stat-value { font-size: 13px; }
}

/* ——— 006: недели, сводка плана, кнопка ввода, листы, формы ——— */

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 8px; display: flex; align-items: center; }

.weekly { display: flex; flex-direction: column; gap: 8px; }
.week-now, .week-list, .plan-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}
.week-now { border-left: 4px solid var(--accent); }
.week-now.over { border-left-color: var(--expense); }
.week-left { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; margin: 2px 0 8px; }
.week-now.over .week-left { color: var(--expense); }
.today-line { margin-top: 8px; font-size: 13px; }
.today-line.bad { color: var(--expense); }
.week-list { display: flex; flex-direction: column; gap: 6px; padding-block: 10px; }
.week-row { font-size: 14px; font-variant-numeric: tabular-nums; }
.week-row + .week-row { border-top: 1px solid var(--border); padding-top: 6px; }
.week-top { display: flex; justify-content: space-between; gap: 8px; }
.week-row .week-dates { font-weight: 500; }
.week-row.over .week-left-small { color: var(--expense); }
.week-row.ok .week-left-small { color: var(--income); }
.month-line { padding: 0 4px; }

.progress.tone-over .bar { background: var(--expense); }
.progress.tone-done .bar { background: var(--income); }

.plan-summary { display: grid; grid-template-columns: 1fr auto auto; gap: 6px 0; margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.summary-head, .summary-row { display: contents; }
.summary-head span { font-size: 12px; color: var(--muted); text-align: right; }
.summary-row span:not(.summary-label), .summary-head span + span { text-align: right; white-space: nowrap; padding-left: 16px; }
.summary-label { color: var(--muted); }
.summary-row.balance span { font-weight: 700; border-top: 1px solid var(--border); padding-top: 6px; }
.summary-row.balance .summary-label { color: var(--text); }
.plan-summary > .meta { grid-column: 1 / -1; }

.fab {
  position: fixed;
  right: max(16px, calc(50vw - 360px + 16px));
  bottom: calc(16px + env(safe-area-inset-bottom));
  border: 0;
  border-radius: 24px;
  padding: 12px 20px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 14px rgb(0 0 0 / 25%);
  cursor: pointer;
}
.fab[hidden] { display: none; }

.primary, .secondary {
  border-radius: 10px;
  padding: 11px 16px;
  font-weight: 600;
  cursor: pointer;
}
.primary { border: 0; background: var(--accent); color: #fff; width: 100%; }
.primary:disabled { opacity: .6; cursor: progress; }
.secondary { border: 1px solid var(--accent); background: none; color: var(--accent); }

.sheet {
  border: 0;
  padding: 0;
  margin: auto auto 0;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  border-radius: 16px 16px 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 -4px 24px rgb(0 0 0 / 20%);
}
.sheet::backdrop { background: rgb(0 0 0 / 40%); }
@media (min-width: 640px) {
  .sheet { margin: auto; border-radius: 16px; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 4px; }
.sheet-head h2 { font-size: 17px; margin: 0; }

.form { display: flex; flex-direction: column; gap: 12px; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field[hidden] { display: none; }
.field-label { font-size: 12px; color: var(--muted); }
.field input, .field select {
  font: inherit;
  font-size: 16px;
  color: inherit;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  width: 100%;
  min-width: 0;
}
.field.invalid input, .field.invalid select { border-color: var(--expense); }
.field-error, .form-error { color: var(--expense); font-size: 12px; }
.field-error:empty, .form-error:empty { display: none; }
.amount-row { display: flex; gap: 8px; }
.amount-row input { flex: 1; }
.amount-row select { width: 6em; flex: none; }

.segmented { display: flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 3px; }
.seg { flex: 1; border: 0; background: none; padding: 7px 4px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 500; }
.seg[aria-checked='true'] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(76px + env(safe-area-inset-bottom));
  background: var(--text);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  display: flex;
  gap: 10px;
  align-items: center;
  max-width: calc(100vw - 32px);
  z-index: 10;
}
.toast .link { color: var(--accent); font-weight: 600; }
.empty .secondary { margin-top: 4px; }

/* Вход (спека 007) */
.login { max-width: 360px; margin: 48px auto 0; text-align: center; display: flex; flex-direction: column; gap: 12px; }
.login h1 { font-size: 22px; margin: 0; }
.login p { margin: 0 0 8px; }
.login .banner { text-align: left; margin: 0; }
.login-button { display: block; text-decoration: none; box-sizing: border-box; }
.account { display: flex; align-items: center; justify-content: space-between; gap: 8px; overflow-wrap: anywhere; }

[hidden] { display: none !important; }
