/* Ranglar: dataviz ma'lumotnoma palitrasi (yorug'/qorong'i alohida tekshirilgan) */
:root {
  color-scheme: light;
  --page: #f2f2ef;
  --card: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-soft: #86b6ef;
  --accent-track: #cde2fb;
  --btn: #2a78d6;
  --btn-text: #ffffff;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300;
  --other: #b5b3ab;
  --good: #0ca30c;
  --warn: #fab219;
  --crit: #d03b3b;
  --crit-wash: rgba(208, 59, 59, 0.08);
  --warn-wash: rgba(250, 178, 25, 0.10);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --card: #1a1a19; --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --ring: rgba(255, 255, 255, 0.10);
    --accent: #3987e5; --accent-soft: #256abf; --accent-track: #1d3250;
    --btn: #3987e5;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300;
    --other: #6b6a65;
    --crit-wash: rgba(208, 59, 59, 0.16); --warn-wash: rgba(250, 178, 25, 0.12);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --card: #1a1a19; --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --ring: rgba(255, 255, 255, 0.10);
  --accent: #3987e5; --accent-soft: #256abf; --accent-track: #1d3250;
  --btn: #3987e5;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300;
  --other: #6b6a65;
  --crit-wash: rgba(208, 59, 59, 0.16); --warn-wash: rgba(250, 178, 25, 0.12);
}
/* Telegram ichida: fon va matn ranglari Telegram mavzusidan olinadi */
:root.tg {
  --page: var(--tg-theme-secondary-bg-color, var(--page));
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--card)));
  --ink: var(--tg-theme-text-color, var(--ink));
  --muted: var(--tg-theme-hint-color, var(--muted));
  --ink-2: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, var(--ink-2)));
  --btn: var(--tg-theme-button-color, var(--btn));
  --btn-text: var(--tg-theme-button-text-color, var(--btn-text));
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 18px; margin: 0; }
h4 { font-size: 15px; margin: 0 0 10px; }

.wrap { max-width: 560px; margin: 0 auto; padding: 12px 16px 96px; }
.card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
}
.eyebrow { font-size: 13px; color: var(--muted); }
.hint { color: var(--muted); }
.small { font-size: 13px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row-between h2 { margin-bottom: 8px; }
#content { transition: opacity .15s; }
#content.loading { opacity: .55; }

/* Yuqori panel */
.top { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--card); border-radius: 12px; padding: 3px; }
.seg button {
  border: 0; background: transparent; padding: 8px 0; border-radius: 9px; font-weight: 500; color: var(--ink-2); cursor: pointer;
}
.seg button[aria-selected="true"] { background: var(--btn); color: var(--btn-text); }
.nav { display: flex; align-items: center; justify-content: space-between; }
.nav-label { font-weight: 600; }
.icon-btn {
  border: 0; background: var(--card); width: 36px; height: 36px; border-radius: 10px; font-size: 20px; line-height: 1; cursor: pointer;
}
.icon-btn:disabled { opacity: .35; cursor: default; }

/* Asosiy raqam */
.hero { text-align: left; }
.hero-value { font-size: 44px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; margin: 4px 0; }
.hero-value .unit { font-size: 18px; font-weight: 500; color: var(--muted); letter-spacing: 0; }

/* Limit chizig'i */
.meter { height: 8px; border-radius: 4px; background: var(--accent-track); overflow: hidden; margin: 8px 0 6px; }
.meter.big { height: 12px; border-radius: 6px; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; }
.meter.warn i { background: var(--warn); }
.meter.over i { background: var(--crit); }
.meter.none { background: var(--grid); }
.status { font-size: 13px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.status.warn::before { background: var(--warn); }
.status.over::before { background: var(--crit); }
.status.none::before { display: none; }
.status.over { color: var(--ink); font-weight: 600; }

/* KPI */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.kpi { background: var(--card); border-radius: 16px; padding: 12px 14px; min-width: 0; }
.kpi .v { font-size: 20px; font-weight: 650; margin-top: 2px; overflow-wrap: anywhere; }
.kpi .v small { font-size: 12px; font-weight: 500; color: var(--muted); }
.kpi .d { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; align-items: center; gap: 5px; }
.kpi .d .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* Ulush (100% to'plamli chiziq) */
.share-bar { display: flex; gap: 2px; height: 24px; margin-bottom: 14px; }
.share-bar span { display: block; height: 100%; min-width: 3px; cursor: pointer; }
.share-bar span:first-child { border-radius: 4px 0 0 4px; }
.share-bar span:last-child { border-radius: 0 4px 4px 0; }
.share-bar span:only-child { border-radius: 4px; }
.share-bar span.active { filter: brightness(1.15); }
.legend { display: grid; gap: 8px; }
.legend-row { display: grid; grid-template-columns: 12px 1fr auto auto; align-items: center; gap: 8px; font-size: 14px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; }
.legend-row .pct { color: var(--muted); font-size: 13px; min-width: 36px; text-align: right; font-variant-numeric: tabular-nums; }
.legend-row .amt { font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 8px 0; }

/* Toifalar ro'yxati */
.cat-list { display: grid; gap: 4px; }
.cat-row { padding: 10px 10px; margin: 0 -10px; border-radius: 12px; }
.cat-row.over { background: var(--crit-wash); }
.cat-row.warn { background: var(--warn-wash); }
.cat-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.cat-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cat-sub { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.cat-row .meter { margin: 6px 0 4px; }

/* Ustunli diagramma */
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .tick { font-size: 11px; fill: var(--muted); }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--axis); stroke-width: 1; }
.chart .ref { stroke: var(--ink-2); stroke-width: 1; opacity: .55; }
.chart .ref-label { font-size: 11px; fill: var(--ink-2); }
.chart .bar { fill: var(--accent-soft); }
.chart .bar.today { fill: var(--accent); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + .bar, .chart .bar.active { filter: brightness(1.12); }

/* Xarajatlar ro'yxati */
.tx-list { display: grid; }
.tx { display: grid; grid-template-columns: 36px 1fr auto 28px; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--grid); }
.tx:first-child { border-top: 0; }
.tx .em { width: 36px; height: 36px; border-radius: 10px; background: var(--page); display: grid; place-items: center; font-size: 18px; }
.tx .t1 { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .t2 { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx .del { border: 0; background: transparent; color: var(--muted); width: 28px; height: 28px; border-radius: 8px; cursor: pointer; }
.tx-day { font-size: 12px; color: var(--muted); padding: 10px 0 2px; font-weight: 600; }
.tx-day:first-child { padding-top: 0; }

/* Tugmalar */
.link-btn { border: 0; background: transparent; color: var(--btn); font-weight: 500; cursor: pointer; padding: 4px 0; margin-bottom: 8px; }
.primary {
  width: 100%; border: 0; border-radius: 12px; padding: 14px; margin-top: 14px;
  background: var(--btn); color: var(--btn-text); font-weight: 600; font-size: 16px; cursor: pointer;
}
.primary:disabled { opacity: .5; }
.fab {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom));
  border: 0; border-radius: 14px; padding: 14px 22px; background: var(--btn); color: var(--btn-text);
  font-weight: 600; font-size: 16px; box-shadow: 0 6px 20px rgba(0, 0, 0, .18); cursor: pointer;
  width: min(528px, calc(100% - 32px));
}

/* Pastdan chiqadigan oyna */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .4); }
.sheet-body {
  position: relative; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--card); border-radius: 20px 20px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-head .icon-btn { background: var(--page); font-size: 16px; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--grid); background: var(--page); border-radius: 10px; padding: 8px 12px; cursor: pointer; font-size: 14px;
}
.chip[aria-pressed="true"] { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }
.input, .amount-field {
  width: 100%; border: 1px solid var(--grid); background: var(--page); color: var(--ink);
  border-radius: 12px; padding: 12px; font: inherit;
}
.input.date { width: auto; flex: 1; min-width: 140px; padding: 7px 10px; }
.amount-field { display: flex; align-items: center; gap: 8px; }
.amount-field input { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink); font: inherit; outline: none; }
#add-amount { font-size: 26px; font-weight: 650; }
.amount-field span { color: var(--muted); }
.form-error { color: var(--crit); font-size: 13px; min-height: 18px; margin-top: 8px; }

.manage-list { display: grid; gap: 10px; margin: 8px 0 18px; }
.m-row { display: grid; grid-template-columns: 1fr 120px 32px; gap: 8px; align-items: center; }
.m-row .m-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-row input { width: 100%; border: 1px solid var(--grid); background: var(--page); color: var(--ink); border-radius: 10px; padding: 8px; font: inherit; text-align: right; }
.m-row .del { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 16px; }
.new-cat { border-top: 1px solid var(--grid); padding-top: 14px; display: grid; gap: 10px; }
.new-cat .primary { margin-top: 0; }

.tooltip {
  position: fixed; z-index: 30; pointer-events: none; background: var(--ink); color: var(--card);
  padding: 8px 10px; border-radius: 10px; font-size: 13px; line-height: 1.3; max-width: 220px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .2); white-space: pre-line;
}
.tooltip b { display: block; font-size: 15px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 40;
  background: var(--ink); color: var(--card); padding: 10px 16px; border-radius: 12px; font-size: 14px;
}
.error { background: var(--crit-wash); color: var(--ink); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
