/* =========================================================
   Family Budget — premium dark UI.
   No frameworks, no CDN fonts. System type stack used as a feature.
   ========================================================= */

:root {
  /* surface */
  --bg:        #0b0b10;
  --bg-soft:   #0f0f15;
  --surface:   #15151d;
  --surface-2: #1c1c26;
  --surface-3: #232330;
  --hairline:  rgba(255, 255, 255, 0.06);
  --hairline-2: rgba(255, 255, 255, 0.10);

  /* text — все проходят WCAG AA на --surface */
  --text:      #f2f2f5;
  --text-2:    #b4b4c5;   /* было #a3a3b3 — поднял для AA */
  --text-3:    #8a8a99;   /* было #6c6c7d — поднял для AA */

  /* brand + semantic. Кнопочный градиент тёмнее, чтобы белый текст на нём
     проходил AA. Светлый --brand-2 оставлен для свечений и ringов. */
  --brand:       #8b5cf6;
  --brand-2:     #a78bfa;
  --brand-deep:  #6d28d9;
  --brand-on:    #ffffff;
  --brand-glow:  rgba(139, 92, 246, 0.32);
  --income:      #4ade80;
  --expense:     #f87171;
  --warn:        #fbbf24;
  --info:        #60a5fa;
  --info-deep:   #1e3a8a;

  /* spacing scale */
  --gap-xs: 6px;
  --gap-sm: 10px;
  --gap-md: 14px;
  --gap-lg: 20px;
  --gap-xl: 28px;
  --gap-section: 28px;
  --label-sm-size: 11px;
  --label-sm-tracking: 0.08em;

  /* radii / motion */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --shadow-1: 0 1px 0 rgba(255,255,255,0.04) inset, 0 1px 2px rgba(0,0,0,0.4);
  --shadow-2: 0 10px 40px -10px rgba(0,0,0,0.6), 0 1px 0 rgba(255,255,255,0.05) inset;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  --safe-bottom: env(safe-area-inset-bottom, 0);
  --safe-top:    env(safe-area-inset-top, 0);
}

/* prefers-reduced-motion: убираем анимации/transitions/hover-фильтры */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  button:hover,
  .nav-add:hover,
  .ana-top-item:hover {
    filter: none !important;
    transform: none !important;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
html { color-scheme: dark; }

body {
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "Inter", "Segoe UI Variable", "Segoe UI", "Helvetica Neue", Arial,
    "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  letter-spacing: -0.005em;
  font-feature-settings: "ss01", "cv11";
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  background-image:
    radial-gradient(1100px 600px at 80% -10%, rgba(183, 148, 244, 0.10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(96, 165, 250, 0.08), transparent 60%);
  background-attachment: fixed;
}

[hidden] { display: none !important; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.02em; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 13px; font-weight: 600; color: var(--text-2);
     text-transform: uppercase; letter-spacing: 0.08em; }

/* Однородный «section label», заменяет h3 внутри dashboard */
.h-section {
  font-size: var(--label-sm-size);
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: var(--label-sm-tracking);
  margin: 0;
}
.muted { color: var(--text-2); }
.dim   { color: var(--text-3); }

button {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  font: inherit;
  cursor: pointer;
  transition: background .18s var(--ease), transform .15s var(--ease), border-color .18s var(--ease);
}
button:hover  { background: var(--surface-3); border-color: var(--hairline-2); }
button:active { transform: translateY(1px); }
button.primary {
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand-deep) 100%);
  border-color: transparent;
  color: var(--brand-on);
  font-weight: 600;
  letter-spacing: -0.005em;
  box-shadow:
    0 6px 20px -8px var(--brand-glow),
    inset 0 1px 0 rgba(255,255,255,0.18);
  padding: 12px 16px;
}
button.primary:hover { filter: brightness(1.06); }
button.primary:active { filter: brightness(0.96); }
button.ghost  { background: transparent; border-color: transparent; color: var(--text-2); }
button.ghost:hover { color: var(--text); background: var(--surface-2); }

input, select, textarea {
  width: 100%;
  min-height: 44px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  font: inherit;
  outline: none;
  transition: border-color .18s var(--ease), background .18s var(--ease);
}
input:focus, select:focus, textarea:focus,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: var(--brand);
  background: var(--surface-2);
  box-shadow: 0 0 0 4px var(--brand-glow);
}
input::placeholder { color: var(--text-3); }

/* Visible keyboard focus for buttons */
button:focus-visible {
  outline: 2px solid var(--brand-2);
  outline-offset: 2px;
}

/* Screen-reader-only utility */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* =========================================================
   LOGIN
   ========================================================= */
#login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: calc(20px + var(--safe-top)) 20px calc(20px + var(--safe-bottom));
}
.login-card {
  width: min(380px, 100%);
  background: linear-gradient(160deg, var(--surface) 0%, var(--bg-soft) 100%);
  border: 1px solid var(--hairline);
  border-radius: var(--r-xl);
  padding: 28px;
  box-shadow: var(--shadow-2);
  position: relative;
  overflow: hidden;
}
.login-card::before {
  content: "";
  position: absolute; inset: -1px;
  background: linear-gradient(135deg, var(--brand-glow), transparent 40%);
  border-radius: var(--r-xl);
  pointer-events: none;
  z-index: 0;
}
.login-card > * { position: relative; z-index: 1; }
.login-mark {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--brand-2), var(--brand-deep));
  display: grid; place-items: center;
  font-size: 22px; color: var(--brand-on); font-weight: 700;
  margin-bottom: 16px;
  box-shadow: 0 10px 30px -10px var(--brand-glow);
}
.login-card h1 { font-size: 24px; }
.login-card .sub { color: var(--text-2); margin-top: 4px; font-size: 14px; }
.login-card form { display: grid; gap: 12px; margin-top: 20px; }
.error { color: var(--expense); font-size: 13px; }

/* =========================================================
   APP shell
   ========================================================= */
#app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  padding-bottom: calc(94px + var(--safe-bottom));
}
/* На узких экранах bottom-nav становится 2x2 — нужно больше места снизу */
@media (max-width: 460px) {
  #app { padding-bottom: calc(140px + var(--safe-bottom)); }
}

.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  color: var(--text-2);
  padding: 0;
}
.icon-btn:hover { color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; stroke: currentColor; }
.icon-btn[disabled] { opacity: 0.35; cursor: not-allowed; }
/* На мобильнике стрелки переключения периода — ≥44px (Apple HIG / WCAG 2.5.5) */
@media (max-width: 460px) {
  .period-nav .icon-btn { width: 44px; height: 44px; }
  .period-nav .icon-btn svg { width: 20px; height: 20px; }
}

main.tab { padding: calc(18px + var(--safe-top)) 18px 0; max-width: 720px; margin: 0 auto; width: 100%; }
/* На дашборде и в анализе шапка sticky — убираем верхний padding табы,
   воздух кладём внутри самой sticky-шапки (включая safe-area для island/notch). */
#tab-dash, #tab-analysis { padding-top: 0; }

/* =========================================================
   DASHBOARD
   ========================================================= */
.range-segment {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  padding: 4px;
  border-radius: 999px;
  margin-bottom: 14px;
}

/* Custom date range picker */
.period-custom {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  align-items: center;
  gap: 10px;
  margin: -8px 0 22px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
}
.period-custom input[type="date"] {
  background: var(--surface-3);
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  color-scheme: dark;
  min-width: 0;
  width: 100%;
}
.period-custom input[type="date"]:focus {
  outline: 2px solid var(--brand-2);
  outline-offset: 1px;
  border-color: transparent;
}
.period-custom .apply-period {
  padding: 8px 14px;
  font-size: 13px;
}
.period-custom .apply-period[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.4);
  box-shadow: none;
}
.period-custom-field { display: contents; }
.period-custom-field input[type="date"] { width: 100%; }
@media (max-width: 460px) {
  .period-custom {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .period-custom .dim { display: none; }
  .period-custom .apply-period { grid-column: 1 / -1; }
}

.period-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 22px;
}
.period-nav .period-name {
  text-align: center;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  min-width: 160px;
}
.range-segment button {
  background: transparent;
  border: none;
  padding: 8px 4px;
  min-height: 36px;
  border-radius: 999px;
  color: var(--text-2);
  font-size: clamp(11px, 3.4vw, 13px);
  font-weight: 500;
  white-space: nowrap;
}
.range-segment button.active {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: var(--shadow-1);
}

.hero {
  display: grid;
  gap: 14px;
  margin-bottom: 22px;
  background:
    radial-gradient(120% 140% at 0% 0%, rgba(139, 92, 246, 0.18), transparent 55%),
    radial-gradient(140% 140% at 100% 100%, rgba(96, 165, 250, 0.12), transparent 55%),
    var(--surface);
  border: 1px solid var(--hairline-2);
  border-radius: var(--r-xl);
  padding: 20px 22px 18px;
  box-shadow: var(--shadow-2);
}
.hero .hero-lbl-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.hero .hero-lbl {
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
}

.hero-amount {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
  margin-top: -4px;
}
.hero-amount .num {
  font-size: clamp(40px, 11vw, 56px);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
  background: linear-gradient(180deg, #ffffff 0%, #cdcdda 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.hero-amount .cur {
  font-size: clamp(22px, 5.5vw, 32px);
  color: var(--text-2);
  font-weight: 500;
  margin-left: 6px;
  letter-spacing: -0.01em;
  align-self: center;
  line-height: 1;
}

.delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  font-variant-numeric: tabular-nums;
}
.delta.up   { color: var(--expense); }
.delta.down { color: var(--income); }
.delta.flat { color: var(--text-2); }
.delta svg { width: 10px; height: 10px; stroke: currentColor; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 14px;
  display: grid;
  gap: 6px;
  min-width: 0;
  position: relative;
  overflow: hidden;
}
.kpi.lg { grid-column: 1 / -1; }
.kpi .lbl {
  color: var(--text-3);
  font-size: var(--label-sm-size);
  text-transform: uppercase;
  letter-spacing: var(--label-sm-tracking);
}
.kpi .val {
  font-size: clamp(14px, 4.4vw, 19px);
  font-weight: 600;
  letter-spacing: -0.02em;
  font-feature-settings: "tnum"; font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi.income  .val { color: var(--income); }
.kpi.expense .val { color: var(--expense); }
.kpi.net.positive .val { color: var(--income); }
.kpi.net.negative .val { color: var(--expense); }

.pace {
  display: flex; gap: 6px 18px; flex-wrap: wrap;
  font-size: 13px; color: var(--text-2);
  margin-top: 4px;
  min-height: 22px;        /* стабилизирует высоту hero между периодами */
}
.pace .pace-item {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
}
.pace b { color: var(--text); font-weight: 600;
          font-variant-numeric: tabular-nums; }

/* Sparkline area for periods */
.spark-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 18px 18px 14px;
  margin-top: 22px;
}
.spark-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 14px; gap: 12px;
}
.spark-head .ttl { font-weight: 600; font-size: 15px; }
.spark-head .sub { color: var(--text-3); font-size: 12px; }
.spark-toggle {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--hairline);
}
.spark-toggle button {
  background: transparent; border: none; color: var(--text-2);
  padding: 5px 11px; font-size: 12px; border-radius: 999px;
}
.spark-toggle button.active { background: var(--surface-3); color: var(--text); }

.spark { display: grid; gap: 10px; }
.spark-row {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.spark-row .lbl  { color: var(--text-2); font-variant-numeric: tabular-nums; }
.spark-row .val-col {
  display: grid; gap: 2px; justify-items: end;
}
.spark-row .val  { font-weight: 600; font-variant-numeric: tabular-nums; }
.spark-row .delta {
  font-size: 11px;
  padding: 1px 6px;
}

/* Split track: current на верхнем, prev — узкая дорожка под ним
   с другим цветом. Видны оба значения независимо от того, кто больше. */
.spark-row .stack {
  display: grid; gap: 4px;
}
.spark-row .track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.spark-row .track.prev { height: 4px; opacity: 0.7; }
.spark-row .fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand-2), var(--brand));
  border-radius: 999px;
  transition: width .8s var(--ease);
}
.spark-row .fill.prev {
  background: var(--text-3);
}
.spark-legend {
  display: flex; gap: 14px; font-size: 11px; color: var(--text-3);
  margin-top: 4px;
  text-transform: uppercase; letter-spacing: var(--label-sm-tracking);
}
.spark-legend i {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 999px; margin-right: 6px; vertical-align: -1px;
}
.spark-legend .now  i { background: var(--brand); }
.spark-legend .past i { background: var(--text-3); }

/* Categories list */
.section { margin-top: 26px; }
.section .head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 12px;
}
.section .head a {
  color: var(--text-2); font-size: 12px; cursor: pointer;
}

.cat-list { display: grid; gap: 4px; }
.cat-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .12s var(--ease);
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.cat-item:hover  { background: var(--surface-2); border-color: var(--hairline-2); }
.cat-item:active { transform: scale(0.995); }
.cat-item:focus-visible {
  outline: 2px solid var(--brand-2);
  outline-offset: 2px;
}
.cat-item .dot {
  width: 12px; height: 12px;
  border-radius: 4px;
  justify-self: center;
  background: var(--brand);
}
.cat-item .name { font-size: 14px; font-weight: 500;
                  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-item .meta { color: var(--text-3); font-size: 12px;
                  display: flex; gap: 8px; align-items: center; }
.cat-item .num {
  font-weight: 600; font-variant-numeric: tabular-nums;
  font-size: 14px; text-align: right;
}
.cat-item .delta {
  font-size: 11px;
  padding: 2px 6px;
}

/* Users row */
.user-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px; align-items: center;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
}
.user-row .avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: #16121d;
}
.user-row .num { font-variant-numeric: tabular-nums; font-weight: 600; }

/* =========================================================
   MODAL
   ========================================================= */
.modal-scrim {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
  z-index: 20;
  display: flex; align-items: flex-end;
  animation: fade .2s var(--ease);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { transform: translateY(40px); } to { transform: translateY(0); } }

.sheet {
  width: 100%;
  max-width: 540px;
  max-height: 92dvh;
  overflow-y: auto;
  margin: 0 auto;
  background: var(--surface);
  border-top-left-radius: var(--r-xl);
  border-top-right-radius: var(--r-xl);
  border-top: 1px solid var(--hairline);
  padding: 18px 18px calc(20px + var(--safe-bottom));
  animation: slide-up .25s var(--ease);
  -webkit-overflow-scrolling: touch;
}
.sheet .grabber {
  width: 38px; height: 5px;
  background: rgba(255,255,255,0.18);
  border-radius: 999px;
  margin: 0 auto 14px;
}
.sheet h2 { font-size: 17px; margin-bottom: 12px; }
.sheet-sm { max-width: 420px; }

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.form-actions .ghost     { flex: 1; }
.form-actions .primary   { flex: 2; }
.form-actions .danger-ghost {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: var(--expense);
  font-weight: 500;
}
.form-actions .danger-ghost:hover {
  background: rgba(248, 113, 113, 0.08);
  border-color: rgba(248, 113, 113, 0.55);
}
.primary.danger {
  background: linear-gradient(180deg, #ef4444 0%, #b91c1c 100%);
  box-shadow:
    0 6px 20px -8px rgba(239, 68, 68, 0.45),
    inset 0 1px 0 rgba(255,255,255,0.18);
}

/* Category suggestions popover */
.cat-input-wrap { position: relative; }
.cat-suggest {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  z-index: 5;
  margin: 0; padding: 4px;
  list-style: none;
  background: var(--surface-2);
  border: 1px solid var(--hairline-2);
  border-radius: var(--r-md);
  max-height: 220px;
  overflow-y: auto;
  box-shadow: var(--shadow-2);
}
.cat-suggest li {
  padding: 10px 12px;
  border-radius: var(--r-sm);
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
  display: flex; align-items: center; gap: 8px;
  min-height: 40px;
}
.cat-suggest li mark {
  background: transparent;
  color: var(--brand-2);
  font-weight: 600;
  padding: 0;
}
.cat-suggest li:hover,
.cat-suggest li[aria-selected="true"] {
  background: var(--surface-3);
}

.kind-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
  margin-bottom: 16px;
}
.kind-toggle button {
  border: none;
  background: transparent;
  border-radius: 999px;
  padding: 9px 0;
  font-size: 12px;
  color: var(--text-2);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.kind-toggle button.active {
  background: var(--surface-3);
  color: var(--text);
}
.kind-toggle button[data-kind="expense"].active { color: var(--expense); }
.kind-toggle button[data-kind="income"].active  { color: var(--income); }

.amount-row {
  display: flex;
  align-items: baseline;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.amount-row input {
  border: none; background: transparent;
  font-size: 38px; font-weight: 700;
  padding: 0; text-align: right;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}
.amount-row input:focus { box-shadow: none; background: transparent; }
.amount-row .cur {
  font-size: 28px; color: var(--text-2); margin-left: 8px; font-weight: 500;
  align-self: center;
}

.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label { color: var(--text-2); font-size: 12px;
               text-transform: uppercase; letter-spacing: .06em; font-weight: 500; }

.chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 4px;
}
.chip {
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  color: var(--text);
  padding: 8px 14px;
  min-height: 36px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease);
}
.chip:hover { background: var(--surface-3); }
.chip.active {
  background: rgba(139, 92, 246, 0.15);
  border-color: var(--brand);
  color: var(--brand-2);
}

.quick-dates { display: flex; gap: 6px; margin-top: 4px; }
.quick-dates button {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  padding: 8px;
  font-size: 13px;
  color: var(--text-2);
  border-radius: var(--r-sm);
}
.quick-dates button:hover { color: var(--text); }

.flash {
  background: var(--surface-2);
  color: var(--income);
  padding: 10px 14px 10px 16px;
  border-radius: var(--r-sm);
  border-left: 3px solid var(--income);
  font-weight: 500;
  font-size: 14px;
  margin-top: 10px;
}
.flash.error { color: var(--expense); border-left-color: var(--expense); }

/* Undo toast — bottom of viewport */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(82px + var(--safe-bottom) + 80px);
  transform: translateX(-50%);
  z-index: 30;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 14px;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--hairline-2);
  border-radius: 999px;
  padding: 10px 8px 10px 18px;
  font-size: 14px;
  box-shadow: var(--shadow-2);
  animation: slide-up .22s var(--ease);
}
.toast button {
  background: var(--brand-deep);
  color: var(--brand-on);
  border: none;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
}
.toast .progress {
  position: absolute;
  inset: auto 12px 4px;
  height: 2px;
  background: var(--brand);
  border-radius: 999px;
  transform-origin: left;
  animation: shrink 5s linear forwards;
}
@keyframes shrink { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* =========================================================
   CATEGORY SHEET
   ========================================================= */
.cat-sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.cat-sheet-title-wrap {
  display: flex; align-items: center; gap: 12px;
  min-width: 0;
}
.cat-sheet-dot {
  width: 14px; height: 14px;
  border-radius: 4px;
  background: var(--brand);
  flex-shrink: 0;
}
.cat-sheet-head h2 {
  font-size: 17px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cat-sheet-meta {
  display: grid; gap: 6px;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  margin-bottom: 14px;
}
.cat-sheet-num {
  display: flex; align-items: baseline; gap: 6px;
  font-feature-settings: "tnum"; font-variant-numeric: tabular-nums;
  font-size: 28px; font-weight: 700; letter-spacing: -0.03em;
  line-height: 1;
}
.cat-sheet-num .cur { font-size: 16px; color: var(--text-3); font-weight: 500; }
.cat-sheet-sub {
  color: var(--text-2);
  font-size: 13px;
  display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline;
}
.cat-sheet-sub .dot-sep { color: var(--text-3); }
.cat-sheet-list { gap: 4px; }
.cat-sheet-list .tx-item {
  grid-template-columns: 1fr auto;
  padding: 10px 14px;
}
.cat-sheet-list .tx-item .meta-col .name { font-size: 13px; }
.cat-sheet-list .tx-item .meta-col .sub  { font-size: 12px; }
.cat-sheet-list .tx-item .amt { font-size: 14px; }
.cat-sheet-list .tx-day {
  padding: 14px 4px 2px;
}

/* =========================================================
   HISTORY
   ========================================================= */
.filter-bar { display: flex; gap: 8px; margin-bottom: 14px; }
.filter-bar select { width: auto; flex: 1; }
.tx-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.tx-day {
  color: var(--text-3);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 18px 4px 4px;
}
.tx-item {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease);
}
.tx-item:hover { background: var(--surface-2); border-color: var(--hairline-2); }
.tx-item:focus-visible {
  outline: 2px solid var(--brand-2);
  outline-offset: 2px;
}
.tx-item .avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700; color: #16121d;
}
.tx-item .meta-col { display: grid; gap: 2px; min-width: 0; }
.tx-item .name {
  font-size: 14px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tx-item .sub {
  color: var(--text-3); font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tx-item .amt {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
}
.tx-item.expense .amt { color: var(--expense); }
.tx-item.income  .amt { color: var(--income); }
#history-more { width: 100%; margin-top: 14px; }

/* =========================================================
   BOTTOM NAV
   ========================================================= */
.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(12px + var(--safe-bottom));
  width: min(520px, calc(100% - 24px));
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1.15fr;
  column-gap: 4px;
  background: rgba(28,28,38,0.85);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--hairline);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-2);
  padding: 6px;
  z-index: 11;
}
.bottom-nav button {
  background: transparent;
  border: none;
  border-radius: calc(var(--r-xl) - 8px);
  padding: 10px 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bottom-nav button svg { width: 18px; height: 18px; stroke: currentColor; flex: 0 0 auto; }
.bottom-nav button.active {
  background: var(--surface-3);
  color: var(--text);
}
/* Кнопка-action «Добавить» — фиолетовая, выделяется среди табов */
.bottom-nav .nav-add {
  background: linear-gradient(135deg, var(--brand-2), var(--brand-deep));
  color: var(--brand-on);
  font-weight: 600;
  margin-left: 6px;            /* визуальный отрыв от обычных табов */
  box-shadow:
    0 8px 22px -10px var(--brand-glow),
    inset 0 1px 0 rgba(255,255,255,0.18);
  transition: transform .15s var(--ease), filter .15s var(--ease);
}
.bottom-nav .nav-add:hover  { filter: brightness(1.06); }
.bottom-nav .nav-add:active { transform: scale(0.97); }
.bottom-nav .nav-add svg { stroke-width: 2.4; }
@media (max-width: 460px) {
  .bottom-nav { grid-template-columns: 1fr 1fr; }
  .bottom-nav button { font-size: 13px; }
}

/* =========================================================
   EMPTY / LOADING
   ========================================================= */
.empty {
  padding: 32px 22px 28px;
  text-align: center;
  color: var(--text-2);
  font-size: 14px;
  background: var(--surface);
  border: 1px dashed var(--hairline-2);
  border-radius: var(--r-lg);
  display: grid;
  gap: 8px;
  justify-items: center;
}
.empty .empty-art {
  width: 56px; height: 56px;
  display: grid; place-items: center;
  color: var(--text-3);
  margin-bottom: 4px;
}
.empty .empty-art svg { display: block; }
.empty .empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.empty .empty-sub {
  font-size: 13px;
  color: var(--text-3);
  max-width: 260px;
  line-height: 1.45;
}
.empty .cta {
  margin-top: 6px;
  color: var(--brand-on);
  font-weight: 600;
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand-deep) 100%);
  border: none;
  padding: 9px 16px; border-radius: 999px;
  font-size: 13px;
  box-shadow:
    0 6px 18px -8px var(--brand-glow),
    inset 0 1px 0 rgba(255,255,255,0.18);
}
.empty .cta:hover { filter: brightness(1.06); }
.skeleton {
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r-sm);
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* Inline-skeleton поверх текста — пока данные грузятся, цифры и заголовки
   не выглядят как «—» на голой поверхности. */
.skel-text {
  display: inline-block;
  position: relative;
  color: transparent !important;
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
  user-select: none;
  min-width: 64px;
}
.skel-text * { visibility: hidden; }
.skel-block {
  display: block;
  width: 100%;
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r-md);
}
@media (prefers-reduced-motion: reduce) {
  .skel-text, .skel-block { animation: none; }
  .skel-block { background: var(--surface-2); }
}

/* =========================================================
   Datalist styling fallback (browsers can't fully style native datalist —
   we only ensure the input matches the rest)
   ========================================================= */

/* Fade-in for tab content */
main.tab > * { animation: fade .25s var(--ease); }


/* =========================================================
   ANALYSIS TAB
   ========================================================= */
#tab-analysis {
  padding: 18px 22px calc(110px + var(--safe-bottom));
  display: grid;
  gap: var(--gap-section);
  /* На десктопе — на всю ширину окна, max-width у main.tab переопределяем */
  max-width: none;
}
@media (max-width: 460px) {
  #tab-analysis { padding-bottom: calc(150px + var(--safe-bottom)); }
}

/* На широких экранах раскладываем все секции одинаковой шириной.
   Заголовок и подзаголовок остаются full-row, остальные карточки —
   обычные ячейки grid'а. */
@media (min-width: 900px) {
  #tab-analysis {
    grid-template-columns: 1fr 1fr;
    column-gap: 20px;
    row-gap: 22px;
    padding: 28px 32px calc(96px + var(--safe-bottom));
  }
  #tab-analysis > .ana-head,
  #tab-analysis > .ana-hero {
    grid-column: 1 / -1;
  }
}

@media (min-width: 1400px) {
  #tab-analysis {
    grid-template-columns: 1fr 1fr 1fr;
    padding-inline: 48px;
  }
  #tab-analysis > .ana-head,
  #tab-analysis > .ana-hero {
    grid-column: 1 / -1;
  }
}

/* Длинные списки (топ-категорий, год-к-году, самые крупные расходы) —
   фиксированная высота карточки + внутренняя прокрутка содержимого.
   Шапка не залипает (по запросу пользователя). */
.ana-card.scrollable {
  max-height: clamp(360px, 70vh, 720px);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  padding: 0;
}
.ana-card.scrollable .ana-card-head {
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--hairline);
  margin: 0;
}
.ana-card.scrollable .ana-scroll-body {
  overflow-y: auto;
  padding: 14px 18px 18px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}
.ana-card.scrollable .ana-scroll-body::-webkit-scrollbar { width: 6px; }
.ana-card.scrollable .ana-scroll-body::-webkit-scrollbar-thumb {
  background: var(--surface-3); border-radius: 3px;
}

/* YoY year switcher — компактная панель в шапке карточки */
.yoy-picker {
  display: inline-flex; align-items: center; gap: 6px;
  font-variant-numeric: tabular-nums;
}
.yoy-picker .yoy-label {
  font-size: 13px; font-weight: 500; color: var(--text);
  padding: 0 6px;
  white-space: nowrap;
}
.yoy-picker .icon-btn {
  width: 36px; height: 36px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); border-color: var(--hairline);
}
@media (max-width: 460px) {
  .yoy-picker .icon-btn { width: 40px; height: 40px; }
}
.yoy-picker .icon-btn[disabled] {
  opacity: 0.4; cursor: not-allowed;
  background: transparent; border-color: var(--hairline);
}
.yoy-picker .icon-btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; }

/* Tooltip графика — теперь всегда виден как info-блок под чартом */
.ana-chart-tooltip {
  /* hidden-атрибут больше не используем — JS заполняет всегда */
}
.ana-h1 {
  font-size: 22px;
  letter-spacing: -0.02em;
  margin: 0;
  font-weight: 600;
}
.ana-sub { color: var(--text-3); margin: 4px 0 0; font-size: 13px; }

/* ana-head: фиксированная вертикальная сетка, чтобы блоки не «прыгали»
   при переключении периодов. range-segment → title+sub → стрелки переключения.
   Sticky-позиция — чтобы стрелки/picker всегда были на виду. */
.ana-head {
  display: grid;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 10;
  margin-bottom: 20px;
  /* safe-top — высота island/notch на iPhone PWA, иначе кнопки лезут под него */
  padding: calc(16px + var(--safe-top)) 0 14px;
  background: rgba(11, 11, 16, 0.86);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-bottom: 1px solid var(--hairline);
}
/* На широких экранах внутри грида Анализа ana-head sticky тоже работает */
@media (min-width: 900px) {
  .ana-head {
    /* sticky уже задан, тут не пере-объявляем */
    padding-top: 14px;
  }
}
.ana-head .period-picker { margin: 0; }
.ana-head .period-picker .range-segment {
  margin-bottom: 0;
}
.ana-head .period-picker .period-custom {
  margin: 0;
}
.ana-head .ana-title-block {
  /* Период виден в стрелках period-nav — большой title здесь дублирует.
     h1 и sub оставляем в DOM (sr-only), чтобы aria-labelledby и
     screen-reader-озвучка работали. */
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}
.ana-head .ana-period-nav {
  margin: 0;
  justify-content: center;
}
@media (min-width: 760px) {
  .ana-head .ana-h1 { font-size: 24px; }
}

/* Hero — крупный блок «жизненной» статистики */
.ana-hero {
  background:
    radial-gradient(120% 140% at 0% 0%, rgba(139, 92, 246, 0.22), transparent 55%),
    radial-gradient(140% 140% at 100% 100%, rgba(96, 165, 250, 0.16), transparent 55%),
    var(--surface);
  border: 1px solid var(--hairline-2);
  border-radius: var(--r-xl);
  padding: 22px 22px 18px;
  display: grid;
  gap: 16px;
  box-shadow: var(--shadow-2);
}
/* Главная строка: расходы за период — крупно, доход и остаток мельче рядом */
.ana-hero-headline {
  display: grid;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}
.ana-hero-headline .hero-lbl {
  font-size: 11px; color: var(--text-3);
  letter-spacing: 0.08em; text-transform: uppercase;
  font-weight: 600;
}
.ana-hero-headline .hero-amount {
  display: flex; align-items: baseline; gap: 6px;
}
.ana-hero-headline .hero-amount .num {
  font-size: clamp(32px, 7vw, 44px);
  font-weight: 700; letter-spacing: -0.03em;
}
.ana-hero-headline .hero-amount .cur {
  font-size: clamp(20px, 4vw, 26px); color: var(--text-2);
  font-weight: 500;
}
.ana-hero-headline .hero-meta {
  display: flex; flex-wrap: wrap; gap: 10px;
  font-size: 14px; color: var(--text-2);
  align-items: baseline;
}
.ana-hero-headline .hero-meta b {
  color: var(--text); font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.ana-hero-headline .hero-meta b.up   { color: var(--expense); }
.ana-hero-headline .hero-meta b.down { color: var(--income); }
.ana-hero-headline .hero-meta b.flat { color: var(--text-2); }
.ana-hero-headline .hero-meta .sep   { color: var(--text-3); }
.ana-hero-kpis {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding-top: 6px;
}
@media (min-width: 540px) {
  .ana-hero-kpis { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1100px) {
  .ana-hero-kpis { grid-template-columns: repeat(6, 1fr); }
}

/* Trend-блок внутри hero (после kpis) */
.ana-hero-trend {
  margin-top: 4px;
  padding-top: 14px;
  border-top: 1px solid var(--hairline);
  display: grid;
  gap: 6px;
}
.ana-hero-trend-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px;
}
.ana-hero-trend-head .muted { font-size: 12px; }
.ana-hero-trend .ana-trend-line {
  margin: 0; line-height: 1.55; color: var(--text);
}
.ana-hero-trend .ana-trend-line b { font-weight: 600; }
.ana-kpi .sub { font-size: 11px; color: var(--text-3); }
.ana-kpi .val.up   { color: var(--expense); }
.ana-kpi .val.down { color: var(--income); }
.ana-kpi {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 10px 12px;
  display: grid; gap: 4px;
}
.ana-kpi .lbl { font-size: 11px; color: var(--text-3);
  letter-spacing: 0.06em; text-transform: uppercase; }
.ana-kpi .val { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Generic card */
.ana-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: 18px;
  display: grid;
  gap: 14px;
  box-shadow: var(--shadow-1);
}
.ana-card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
}
.ana-card-head .muted { font-size: 12px; }

.ana-trend-line { margin: 0; line-height: 1.55; color: var(--text); }
.ana-trend-line b { font-weight: 600; }

.ana-pill {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 500;
  border: 1px solid currentColor;
  margin-left: 4px;
  background: rgba(255, 255, 255, 0.02);
}
.ana-pill.up   { color: var(--expense); }
.ana-pill.down { color: var(--income); }
.ana-pill.flat { color: var(--text-2); }

/* Monthly chart */
.ana-chart-wrap { display: grid; gap: 10px; }
.ana-chart-scroll {
  overflow-x: auto;
  margin: 0 -6px;
  padding: 0 6px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}
.ana-chart-scroll::-webkit-scrollbar { height: 6px; }
.ana-chart-scroll::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }
.ana-chart {
  display: block;
  height: 220px;
  width: 100%;
  font: 11px var(--font-numeric, inherit);
  font-variant-numeric: tabular-nums;
}
@media (max-width: 460px) {
  .ana-chart { height: 280px; }
}
.ana-chart .grid     { stroke: var(--hairline); stroke-width: 1; }
.ana-chart .grid.axis { stroke: var(--hairline-2); stroke-width: 1; }
.ana-chart .grid-lbl { fill: var(--text-3); font-size: 11px; }
.ana-chart .x-lbl    { fill: var(--text-3); font-size: 11px; }
.ana-chart .ana-bar {
  fill: var(--brand);
  transition: fill .15s var(--ease);
}
.ana-chart .ana-bar.active {
  fill: var(--brand-2);
}
.ana-chart .ana-inc {
  fill: var(--income);
}
.ana-chart .ana-inc-path {
  fill: none; stroke: var(--income); stroke-width: 1.4; opacity: 0.85;
  stroke-linejoin: round; stroke-linecap: round;
}
.ana-chart .ana-hit { fill: transparent; cursor: pointer; }
.ana-chart .avg-line { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.55; }
.ana-chart .avg-lbl  { fill: var(--text-3); font-size: 11px; }

.ana-chart-legend {
  display: flex; gap: 16px; flex-wrap: wrap;
  font-size: 12px; color: var(--text-2);
}
.ana-chart-legend i {
  display: inline-block; width: 10px; height: 10px; margin-right: 6px;
  vertical-align: -1px;
  border-radius: 2px;
}
.ana-chart-legend .now i  { background: var(--brand); }
.ana-chart-legend .past i { background: var(--income); border-radius: 50%; }
.ana-chart-legend .avgline i { background: transparent; border-top: 2px dashed var(--text-3); height: 0; width: 14px; border-radius: 0; }

.ana-chart-tooltip {
  background: var(--surface-2);
  border: 1px solid var(--hairline-2);
  border-radius: var(--r-md);
  padding: 10px 12px;
  display: grid; gap: 6px;
  font-size: 13px;
}
.ana-chart-tooltip .t-title {
  font-weight: 600; font-size: 14px; letter-spacing: -0.01em;
}
.ana-chart-tooltip .t-row {
  display: flex; align-items: baseline; gap: 8px;
  font-variant-numeric: tabular-nums;
}
.ana-chart-tooltip .t-row span:first-child { color: var(--text-2); flex: 1; }
.ana-chart-tooltip .t-row b { font-weight: 600; }
.ana-chart-tooltip .t-row .up   { color: var(--expense); font-weight: 500; }
.ana-chart-tooltip .t-row .down { color: var(--income); font-weight: 500; }
.ana-chart-tooltip .t-row .flat { color: var(--text-3); font-weight: 500; }
/* Согласованная семантика: .up = плохо (красный), .down = хорошо (зелёный) */
.ana-chart-tooltip .net.up   b { color: var(--expense); }
.ana-chart-tooltip .net.down b { color: var(--income); }

/* Top categories — горизонтальные бары */
.ana-bars { display: grid; gap: 14px; }
.ana-bar-row { display: grid; gap: 6px; }
.ana-bar-head {
  display: grid; grid-template-columns: auto 1fr auto;
  align-items: baseline; gap: 10px;
}
.ana-bar-head .dot {
  width: 10px; height: 10px; border-radius: 50%; align-self: center;
}
.ana-bar-head .name { font-weight: 500; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ana-bar-head .amt {
  font-weight: 600; font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.ana-bar-track {
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
}
.ana-bar-fill { height: 100%; border-radius: 3px;
  transition: width .25s var(--ease);
  background: var(--brand);
}
.ana-bar-meta {
  display: flex; gap: 10px; font-size: 12px;
  color: var(--text-2); flex-wrap: wrap;
}
.ana-bar-meta b { color: var(--text); font-weight: 600; }
.ana-bar-meta .dim { color: var(--text-3); }

/* Year-over-year */
.ana-yoy { display: grid; gap: 12px; }
.ana-yoy-legend {
  margin: 0 0 -4px;
  font-size: 12px;
  color: var(--text-3);
}
.ana-yoy-totals {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: var(--r-md);
  align-items: center;
}
.ana-yoy-totals > div { display: grid; gap: 2px; }
.ana-yoy-totals .dim {
  font-size: 11px; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.ana-yoy-totals b {
  font-size: 16px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.ana-yoy-totals .d { justify-self: end; }
.ana-yoy-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--hairline);
}
.ana-yoy-row:last-child { border-bottom: 0; }
.ana-yoy-name {
  font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.ana-yoy-vals {
  display: grid; gap: 2px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.ana-yoy-vals .cur { font-weight: 600; }
.ana-yoy-vals .dim { color: var(--text-3); font-size: 11px; }
.ana-yoy-d { min-width: 60px; text-align: right; }

/* Top transactions */
.ana-top-list {
  list-style: none; padding: 0; margin: 0;
  display: grid; gap: 6px;
}
.ana-top-item {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .15s var(--ease);
}
.ana-top-item:hover { background: var(--surface-3); border-color: var(--hairline-2); }
.ana-top-item:active { transform: scale(0.99); }
.ana-top-item .rank {
  font-weight: 700; color: var(--text-3);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.ana-top-item .meta-col { display: grid; gap: 2px; min-width: 0; }
.ana-top-item .name {
  font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ana-top-item .sub {
  color: var(--text-3); font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ana-top-item .amt {
  color: var(--expense); font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Weekday breakdown */
.ana-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  align-items: end;
  min-height: 160px;
}
.ana-week-col {
  display: grid;
  grid-template-rows: 1fr auto auto;
  gap: 6px;
  text-align: center;
  min-height: 140px;
}
.ana-week-bar-wrap {
  display: flex; align-items: end; justify-content: center;
  height: 100%; min-height: 80px;
}
.ana-week-bar {
  width: 70%;
  max-width: 28px;
  background: linear-gradient(180deg, var(--brand-2), var(--brand-deep));
  border-radius: 6px 6px 2px 2px;
  transition: height .35s var(--ease);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.04) inset, 0 8px 16px -8px var(--brand-glow);
}
.ana-week-col.weekend .ana-week-bar {
  background: linear-gradient(180deg, var(--info), var(--info-deep));
  box-shadow: 0 0 0 1px rgba(255,255,255,0.04) inset, 0 8px 16px -8px rgba(96, 165, 250, 0.4);
}
.ana-week-val {
  font-size: 11px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.ana-week-name {
  font-size: 12px;
  color: var(--text-3);
  font-weight: 500;
}
.ana-week-summary {
  margin: 0; font-size: 13px; color: var(--text);
  line-height: 1.55;
}
.ana-week-summary b { font-weight: 600; }

.ana-empty {
  padding: 20px 12px;
  text-align: center;
  color: var(--text-2);
  background: var(--surface-2);
  border-radius: var(--r-md);
  margin: 0;
  font-size: 13px;
}

/* Узкие экраны */
@media (max-width: 380px) {
  .ana-hero-kpis { grid-template-columns: 1fr 1fr; }
  .ana-hero-kpis .ana-kpi:last-child { grid-column: span 2; }
  .ana-yoy-totals { grid-template-columns: 1fr 1fr; }
  .ana-yoy-totals .d { grid-column: span 2; justify-self: start; }
}
