/* Ranglar Telegram mavzusidan olinadi (yorug'/qorong'i), bo'lmasa shu qiymatlar */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f3f7);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #16181d);
  --muted: var(--tg-theme-hint-color, #7d8592);
  --accent: var(--tg-theme-button-color, #2f80ed);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--muted) 22%, transparent);
  --debt: #e5484d;
  --in: #f59e0b;
  --pay: #22a06b;
  --adv: #22a06b;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) { --bg: #0f1115; --card: #1a1d23; --text: #eef0f3; --muted: #8a919c; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); min-height: 100vh; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); }

header { padding: 14px 16px 4px; }
#top-title { font-weight: 700; font-size: 20px; }
#top-sub { color: var(--muted); font-size: 13px; }
main { padding: 8px 12px 16px; max-width: 720px; margin: 0 auto; }

.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin: 10px 0; }
.card h3 { margin: 0 0 10px; font-size: 15px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card h3 small { color: var(--muted); font-weight: 400; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Asosiy qarz kartasi */
.hero { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #7c3aed));
  color: #fff; padding: 18px; }
.hero .label { opacity: .85; font-size: 13px; }
.hero .big { font-size: 30px; font-weight: 800; letter-spacing: -.5px; margin: 2px 0 12px; }
.hero .row { display: flex; gap: 10px; }
.hero .pill { flex: 1; background: rgba(255,255,255,.16); border-radius: 12px; padding: 8px 10px; }
.hero .pill b { display: block; font-size: 16px; }
.hero .pill span { font-size: 12px; opacity: .85; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.act { background: var(--card); border-radius: var(--radius); padding: 14px; display: flex; align-items: center; gap: 10px; font-weight: 600; }
.act .ico { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; }
.act.in .ico { background: color-mix(in srgb, var(--in) 18%, transparent); }
.act.pay .ico { background: color-mix(in srgb, var(--pay) 18%, transparent); }

/* Ro'yxat qatorlari */
.list { margin: 0 -16px; }
.item { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-top: 1px solid var(--line); width: 100%; text-align: left; }
.item:first-child { border-top: 0; }
.item .avatar { width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 700; color: #fff; font-size: 15px; }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .right { text-align: right; }
.item .bar { height: 4px; border-radius: 2px; background: var(--line); margin-top: 6px; overflow: hidden; }
.item .bar i { display: block; height: 100%; background: var(--debt); border-radius: 2px; }
.debt { color: var(--debt); font-weight: 700; }
.adv { color: var(--adv); font-weight: 700; }
.zero { color: var(--muted); font-weight: 600; }
.c-in { color: var(--in); }
.c-pay { color: var(--pay); }

.search { width: 100%; padding: 11px 14px; border-radius: 12px; border: 0; background: var(--card); outline: none; margin: 6px 0; }

/* Oy almashtirgich */
.month-nav { display: flex; align-items: center; justify-content: space-between; background: var(--card);
  border-radius: var(--radius); padding: 6px; margin: 10px 0; }
.month-nav button { width: 40px; height: 36px; border-radius: 10px; font-size: 18px; }
.month-nav button:disabled { opacity: .25; }
.month-nav b { font-size: 15px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 12px 14px; }
.stat span { color: var(--muted); font-size: 12px; display: block; }
.stat b { font-size: 17px; }

/* Oldi-berdi lentasi */
.tl-row { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.tl-row:first-child { border-top: 0; }
.tl-ico { width: 34px; height: 34px; border-radius: 10px; flex: none; display: grid; place-items: center; font-size: 17px; }
.tl-ico.in { background: color-mix(in srgb, var(--in) 18%, transparent); }
.tl-ico.pay { background: color-mix(in srgb, var(--pay) 18%, transparent); }
.tl-main { flex: 1; min-width: 0; }
.tl-main .note { color: var(--muted); font-size: 13px; font-style: italic; }
.badge { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 20px; margin-top: 4px; }
.badge.ok { background: color-mix(in srgb, var(--pay) 16%, transparent); color: var(--pay); }
.badge.wrong { background: color-mix(in srgb, var(--debt) 16%, transparent); color: var(--debt); }
.badge.wait, .badge.recheck { background: var(--line); color: var(--muted); }
.balance-line { display: flex; justify-content: space-between; padding: 8px 0; font-size: 14px; }

/* Tugmalar */
.btn { display: block; width: 100%; padding: 13px; border-radius: 12px; background: var(--accent); color: var(--accent-text);
  font-weight: 600; text-align: center; }
.btn.ghost { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.btn.danger { background: color-mix(in srgb, var(--debt) 14%, transparent); color: var(--debt); }
.btn.ok { background: color-mix(in srgb, var(--pay) 16%, transparent); color: var(--pay); }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row .btn { padding: 10px; font-size: 14px; }

.alert { border: 1px solid color-mix(in srgb, var(--debt) 40%, transparent); background: color-mix(in srgb, var(--debt) 7%, var(--card)); }

/* Grafik */
.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 10px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* Pastki tablar */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 5; }
#tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 0; }
#tabs button .i { font-size: 21px; line-height: 1; filter: grayscale(1); opacity: .7; }
#tabs button.on { color: var(--accent); font-weight: 600; }
#tabs button.on .i { filter: none; opacity: 1; }
#tabs .fab { flex: none; width: 56px; height: 56px; margin-top: -24px; border-radius: 50%; background: var(--accent);
  color: var(--accent-text); font-size: 28px; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 45%, transparent); justify-content: center; }

/* Pastdan chiqadigan oyna (kirim/to'lov) */
#sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 9; }
#sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--card); border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto; max-width: 720px; margin: 0 auto;
  animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
#sheet .grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 12px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.seg button { padding: 9px; border-radius: 10px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); outline: none; }
.field input:focus, .field select:focus { border-color: var(--accent); }
.field .amount { font-size: 22px; font-weight: 700; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chips button { padding: 6px 11px; border-radius: 20px; background: var(--bg); font-size: 13px; }
.chips button.on { background: var(--accent); color: var(--accent-text); }
.preview { background: var(--bg); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.preview div { display: flex; justify-content: space-between; padding: 2px 0; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 20;
  background: rgba(20,20,24,.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; text-align: center; }

.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.empty .big { font-size: 40px; }
.loading { display: grid; place-items: center; padding: 60px 0; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.back { color: var(--accent); font-weight: 600; padding: 4px 0; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px 4px; }
table.t td { padding: 8px 4px; border-top: 1px solid var(--line); }
table.t td.r, table.t th.r { text-align: right; }
