/* Colors come from the Telegram theme (--tg-theme-*), with fallbacks for a plain browser. */
:root {
  color-scheme: light;
  --bg: var(--tg-theme-secondary-bg-color, #f4f4f1);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #fcfcfb));
  --text: var(--tg-theme-text-color, #0b0b0b);
  --text-2: var(--tg-theme-subtitle-text-color, #52514e);
  --muted: var(--tg-theme-hint-color, #7a7872);
  --accent: var(--tg-theme-button-color, #2a78d6);
  --accent-ink: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, var(--accent));
  --danger: var(--tg-theme-destructive-text-color, #d03b3b);
  --section-title: var(--tg-theme-section-header-text-color, var(--muted));
  --border: color-mix(in srgb, var(--text) 10%, transparent);
  --fill: color-mix(in srgb, var(--text) 6%, transparent);
  --accent-soft: color-mix(in srgb, var(--accent) 14%, var(--surface));
  --income: #1d7f1d;
  /* Charts: validated categorical slots 1–2 and chrome. */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: color-mix(in srgb, var(--text) 9%, transparent);
  /* Status: always shown together with an icon and a label. */
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: var(--tg-theme-secondary-bg-color, #0d0d0d);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1a1a19));
  --text: var(--tg-theme-text-color, #ffffff);
  --text-2: var(--tg-theme-subtitle-text-color, #c3c2b7);
  --muted: var(--tg-theme-hint-color, #8f8d86);
  --accent: var(--tg-theme-button-color, #3987e5);
  --income: #3fbf3f;
  --series-1: #3987e5;
  --series-2: #d95926;
}

* { box-sizing: border-box; }
html { -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 var(--font);
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { font-size: 16px; } /* no iOS zoom on focus */
a { color: var(--link); text-decoration: none; }
.tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.xs { font-size: 12px; }
.bold { font-weight: 600; }
.income { color: var(--income); }
.danger { color: var(--danger); }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(12px + var(--tg-content-safe-area-inset-top, 0px)) 16px
    calc(88px + var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
}

/* ---------- blocks ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.card.flush { padding: 0; overflow: hidden; }
.section-title {
  margin: 20px 4px 8px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--section-title);
}
.section-title .link { text-transform: none; letter-spacing: 0; font-weight: 500; }
h1.page { font-size: 22px; margin: 4px 4px 14px; }
.hero { font-size: 34px; font-weight: 700; line-height: 1.1; margin: 4px 0; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile .label { color: var(--muted); font-size: 13px; }
.tile .value { font-size: 20px; font-weight: 600; margin-top: 2px; }

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  width: 100%;
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
}
.list-item + .list-item { border-top: 1px solid var(--border); }
.list-item:active { background: var(--fill); }
.icon-bubble {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--fill);
  font-size: 19px;
}
.date-header { padding: 14px 4px 6px; font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
}
.btn:disabled { opacity: 0.5; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--link); padding: 0 8px; min-height: 36px; font-weight: 500; }
.btn.danger { background: transparent; color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 8px; }

.segmented {
  display: flex;
  background: var(--fill);
  border-radius: 10px;
  padding: 2px;
}
.segmented button {
  flex: 1;
  border: 0;
  background: none;
  padding: 7px 4px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-2);
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 2px 4px; }
.input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  outline: none;
}
.input:focus { border-color: var(--accent); }
.input.amount { font-size: 24px; font-weight: 600; }
.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.cat-chip {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px; border-radius: 10px; border: 1px solid transparent;
  background: var(--fill); font-size: 11px; line-height: 1.15; text-align: center; cursor: pointer;
}
.cat-chip .emoji { font-size: 20px; }
.cat-chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }

.month-switch { display: flex; align-items: center; justify-content: space-between; margin: 0 0 12px; }
.month-switch .title { font-weight: 600; font-size: 17px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--fill);
  display: grid; place-items: center; cursor: pointer; font-size: 18px; color: var(--text-2); padding: 0; line-height: 0;
}
.icon-btn:disabled { opacity: 0.35; }

/* ---------- progress & status ---------- */
.progress { height: 8px; border-radius: 4px; background: var(--fill); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 4px; background: var(--good); }
.progress.warn > i { background: var(--warning); }
.progress.over > i { background: var(--critical); }
.status { font-size: 12px; font-weight: 600; white-space: nowrap; }
.status.warn { color: #b07800; }
.status.over { color: var(--critical); }
:root[data-theme="dark"] .status.warn { color: var(--warning); }
.banner {
  display: flex; gap: 10px; align-items: center;
  padding: 12px 14px; border-radius: var(--radius); background: var(--accent-soft);
}

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
}
.tabbar ul { list-style: none; margin: 0 auto; padding: 0; max-width: 640px; display: grid; grid-template-columns: repeat(5, 1fr); }
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 7px 0 6px; font-size: 11px; font-weight: 500; color: var(--muted);
}
.tabbar a[aria-current="page"] { color: var(--accent); }
.tabbar svg { width: 23px; height: 23px; }
.tabbar .primary span.circle {
  margin-top: -18px; width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
  box-shadow: 0 3px 10px rgba(0,0,0,.18);
}

/* ---------- sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.4);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease-out;
}
.sheet {
  width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(16px + var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
  animation: rise .2s ease-out;
}
.sheet .grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 10px; }
.sheet h2 { font-size: 18px; margin: 0 0 14px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(30px); opacity: .6; } }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom, 0px)); z-index: 60;
  transform: translateX(-50%); max-width: calc(100% - 32px);
  background: color-mix(in srgb, var(--text) 88%, transparent); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: 14px;
  animation: fade .2s;
}

.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty .emoji { font-size: 34px; display: block; margin-bottom: 6px; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%; margin: 30px auto;
  border: 3px solid var(--fill); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { height: 64px; border-radius: var(--radius); background: var(--fill); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }
.error-box { padding: 12px 14px; border-radius: 12px; background: color-mix(in srgb, var(--critical) 12%, var(--surface)); color: var(--danger); }

/* ---------- scan ---------- */
.scan-actions { display: grid; gap: 10px; }
.scan-big {
  display: flex; align-items: center; gap: 14px; padding: 18px 16px;
  border-radius: var(--radius); border: 0; background: var(--surface); text-align: left; cursor: pointer; width: 100%;
}
.scan-big .emoji { font-size: 30px; }
.thumbs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.thumbs figure { position: relative; margin: 0; flex: none; }
.thumbs img { width: 84px; height: 112px; object-fit: cover; border-radius: 10px; display: block; }
.thumbs button {
  position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 14px; line-height: 1; cursor: pointer;
}
.item-row { display: flex; gap: 10px; align-items: center; padding: 9px 0; }
.item-row + .item-row { border-top: 1px solid var(--border); }
.item-row select {
  max-width: 44%; border: 0; background: var(--fill); border-radius: 8px; padding: 5px 6px; font-size: 13px;
}
.group-head { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 0 2px; font-weight: 600; }

/* ---------- charts ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--text-2); margin: 0 0 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,.14); padding: 8px 10px; font-size: 13px; white-space: nowrap;
}
.hbar { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 9px 0; }
.hbar + .hbar { border-top: 1px solid var(--border); }
.hbar .track { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--fill); }
.hbar .track i { display: block; height: 100%; border-radius: 3px; background: var(--series-1); min-width: 3px; }

/* ---------- invest ---------- */
.quotes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.quote .label { font-size: 12px; color: var(--muted); }
.quote .value { font-weight: 600; font-size: 16px; }
.up { color: var(--income); }
.down { color: var(--critical); }
.bullets { margin: 0; padding: 0; list-style: none; }
.bullets li { padding: 10px 0; display: flex; gap: 10px; }
.bullets li + li { border-top: 1px solid var(--border); }
.bullets .dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-top: 8px; }
.ticker { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 6px; background: var(--fill); color: var(--text-2); margin: 4px 4px 0 0; }
.mood { font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 20px; background: var(--fill); }
details summary { cursor: pointer; color: var(--link); font-size: 14px; list-style: none; }
details summary::-webkit-details-marker { display: none; }
.hbar > :nth-child(2), .hbar > :nth-child(5) { text-align: right; }
.link { color: var(--link); }
.tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.section-title .mood { text-transform: none; letter-spacing: 0; font-weight: 500; }
.mover { display: flex; align-items: baseline; gap: 6px; font-size: 13px; }
.mover .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mover .chg { white-space: nowrap; }
.cat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cat-chip { min-width: 0; hyphens: auto; -webkit-hyphens: auto; overflow-wrap: anywhere; }
