/* NasiyaCRM mini app — Telegram mavzusiga moslashadigan dizayn */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f3f5f2);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --ink: var(--tg-theme-text-color, #16201b);
  --muted: var(--tg-theme-hint-color, #6b7770);
  --line: color-mix(in srgb, var(--ink) 11%, transparent);
  --line-strong: color-mix(in srgb, var(--ink) 22%, transparent);
  --soft: color-mix(in srgb, var(--ink) 5%, transparent);

  --money: #0e7a55;
  --money-ink: #ffffff;
  --money-soft: color-mix(in srgb, var(--money) 12%, transparent);
  --late: #c2412d;
  --late-soft: color-mix(in srgb, var(--late) 11%, transparent);
  --due: #b7791f;
  --due-soft: color-mix(in srgb, var(--due) 14%, transparent);
  --inv: #a8661a;
  --mgr: #4f55c9;
  --link: var(--tg-theme-link-color, #0e7a55);

  --r-lg: 18px;
  --r-md: 12px;
  --r-sm: 8px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: 'Onest', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-tg]) {
    --bg: #0f1513;
    --surface: #18201d;
    --ink: #e7eeea;
    --muted: #8d9a93;
  }
}
:root[data-scheme="dark"] {
  --money: #3cc48e;
  --money-ink: #04140d;
  --late: #f07a63;
  --due: #e0a84a;
  --inv: #e3a457;
  --mgr: #9196ff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-scheme="light"]) {
    --money: #3cc48e;
    --money-ink: #04140d;
    --late: #f07a63;
    --due: #e0a84a;
    --inv: #e3a457;
    --mgr: #9196ff;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  overflow-x: hidden;
  font-feature-settings: 'tnum' 1;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); text-decoration: none; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--money); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.late { color: var(--late); }
.ok { color: var(--money); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.strong { font-weight: 600; }

/* ---------- Ekran tuzilishi ---------- */
#app { max-width: 720px; margin: 0 auto; padding: 0 16px calc(var(--nav-h) + var(--safe-b) + 24px); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 0 14px; }
.topbar h1 { font-size: 22px; line-height: 1.2; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.chip-rate {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 11px; font-size: 12.5px; color: var(--muted); white-space: nowrap;
}
.chip-rate b { color: var(--ink); font-weight: 600; }

.section { margin-top: 22px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 2px 10px; }
.section-head h2 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: -0.005em; }
.section-head .link { font-size: 14px; color: var(--link); background: none; border: 0; padding: 0; }

.panel { background: var(--surface); border-radius: var(--r-lg); padding: 16px; }
.panel + .panel { margin-top: 10px; }
.list { background: var(--surface); border-radius: var(--r-lg); overflow: hidden; }
.list > * + * { border-top: 1px solid var(--line); }

/* ---------- Kun daftari (bosh sahifa) ---------- */
.daybook { background: var(--surface); border-radius: var(--r-lg); padding: 18px 16px 8px; }
.daybook-date { font-size: 13px; color: var(--muted); }
.daybook-title { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin: 2px 0 10px; line-height: 1.15; }
.lrow { display: flex; align-items: baseline; padding: 9px 0; gap: 8px; width: 100%; background: none; border: 0; text-align: left; }
.lrow + .lrow { border-top: 1px solid var(--line); }
.lrow .label { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 0 1 auto; }
.lrow .val { flex: none; white-space: nowrap; }
.lrow .lead { flex: 1; border-bottom: 1.5px dotted var(--line-strong); transform: translateY(-4px); min-width: 16px; }
.lrow .val { text-align: right; font-weight: 600; }
.lrow .val small { display: block; font-weight: 500; color: var(--muted); font-size: 12.5px; }
.lrow .count { font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.dot.late { background: var(--late); }
.dot.due { background: var(--due); }
.dot.soon { background: transparent; border: 1.5px solid var(--muted); }
.dot.got { background: var(--money); }

.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.action {
  background: var(--surface); border: 0; border-radius: var(--r-md); padding: 12px 8px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 13px; font-weight: 550;
}
.action svg { width: 22px; height: 22px; }
.action.primary { background: var(--money); color: var(--money-ink); }

/* ---------- To'lov treki (shartnomaning "imzo" elementi) ---------- */
.pips { display: flex; gap: 3px; align-items: center; }
.pips i { flex: 1; max-width: 16px; min-width: 3px; height: 6px; border-radius: 2px; background: var(--line); }
.pips.big { gap: 4px; }
.pips.big i { height: 12px; max-width: 26px; border-radius: 3px; }
.pips i.p-paid { background: var(--money); }
.pips i.p-partial { background: linear-gradient(90deg, var(--money) 50%, var(--line) 50%); }
.pips i.p-overdue { background: var(--late); }
.pips i.p-today { background: var(--due); }
.pips i.p-upcoming { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line-strong); }

/* ---------- Shartnoma qatori ---------- */
.crow { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 13px 16px 12px; }
.crow:active { background: var(--soft); }
.crow .top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.crow .name { font-weight: 600; font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crow .amt { font-weight: 650; white-space: nowrap; }
.crow .item { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.crow .pips { margin: 9px 0 7px; }
.crow .meta { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; color: var(--muted); }
.crow .meta .late { font-weight: 600; }
.crow .meta .due { color: var(--due); font-weight: 600; }
.flag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }

/* ---------- Qidiruv va filtrlar ---------- */
.searchbar { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 0 8px; }
.search {
  display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: var(--r-md);
  padding: 0 12px; border: 1px solid var(--line);
}
.search svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search input { flex: 1; border: 0; background: none; padding: 11px 0; outline: none; min-width: 0; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px;
  font-size: 13.5px; white-space: nowrap; color: var(--ink);
}
.chip .c { color: var(--muted); margin-left: 4px; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip.on .c { color: inherit; opacity: 0.7; }

/* ---------- Tugmalar ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: var(--r-md);
  padding: 13px 16px; font-weight: 600; font-size: 15px; background: var(--soft); color: var(--ink);
}
.btn svg { width: 18px; height: 18px; }
.btn.block { width: 100%; }
.btn.primary { background: var(--money); color: var(--money-ink); }
.btn.danger { background: var(--late-soft); color: var(--late); }
.btn.ghost { background: none; color: var(--link); padding: 10px 8px; }
.btn.sm { padding: 8px 12px; font-size: 13.5px; border-radius: var(--r-sm); }
.btn:disabled { opacity: 0.5; }
.btn-row { display: flex; gap: 8px; }
.btn-row > * { flex: 1; }

/* ---------- Pastki navigatsiya ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
.nav-in { max-width: 720px; margin: 0 auto; display: grid; grid-template-columns: repeat(var(--n, 5), 1fr); height: var(--nav-h); }
.nav button { background: none; border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11.5px; color: var(--muted); }
.nav button svg { width: 23px; height: 23px; }
.nav button.on { color: var(--money); font-weight: 600; }

/* ---------- Bottom sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-bg { position: absolute; inset: 0; background: rgba(5, 10, 8, 0.45); animation: fade .18s ease; }
.sheet {
  position: relative; width: 100%; max-width: 720px; max-height: 92vh; overflow-y: auto; background: var(--bg);
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(20px + var(--safe-b)); animation: up .22s cubic-bezier(.2,.8,.2,1);
  overscroll-behavior: contain;
}
.sheet.full { min-height: 92vh; }
.sheet-grip { width: 38px; height: 4px; border-radius: 4px; background: var(--line-strong); margin: 2px auto 10px; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sheet-head h3 { margin: 0; font-size: 19px; font-weight: 700; line-height: 1.25; }
.sheet-head .sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.x { width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--soft); display: grid; place-items: center; flex: none; }
.x svg { width: 16px; height: 16px; }
@keyframes up { from { transform: translateY(40px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- Forma ---------- */
.form { display: flex; flex-direction: column; gap: 12px; }
.group { background: var(--surface); border-radius: var(--r-lg); padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.group-title { font-size: 14px; font-weight: 650; margin: 4px 2px -4px; color: var(--muted); }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line-strong); background: var(--surface); border-radius: var(--r-sm);
  padding: 11px 12px; font-size: 16px; outline: none; -webkit-appearance: none; appearance: none; min-width: 0; min-height: 46px;
}
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
.input:focus { border-color: var(--money); }
.input.big { font-size: 22px; font-weight: 650; padding: 12px; }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.row2 > *, .row3 > * { min-width: 0; }
.seg { display: flex; background: var(--soft); border-radius: var(--r-sm); padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 6px; padding: 8px 6px; font-size: 13.5px; color: var(--muted); font-weight: 550; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.quick button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 11px; font-size: 13px; }
.quick button.on { border-color: var(--money); color: var(--money); font-weight: 600; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch input { width: 44px; height: 26px; appearance: none; -webkit-appearance: none; background: var(--line-strong); border-radius: 999px; position: relative; flex: none; transition: background .15s; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked { background: var(--money); }
.switch input:checked::after { transform: translateX(18px); }
.err { color: var(--late); font-size: 13.5px; }

/* ---------- Hisob-kitob ko'rinishi ---------- */
.preview { background: var(--surface); border-radius: var(--r-lg); padding: 14px 16px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; align-items: baseline; }
.kv + .kv { border-top: 1px solid var(--line); }
.kv .k { color: var(--muted); font-size: 14px; }
.kv .v { font-weight: 600; text-align: right; }
.kv .v.inv { color: var(--inv); }
.kv .v.mgr { color: var(--mgr); }
.split { display: flex; height: 8px; border-radius: 4px; overflow: hidden; margin: 10px 0 4px; background: var(--line); }
.split span { display: block; height: 100%; }
.split .s-tani { background: var(--muted); opacity: .55; }
.split .s-inv { background: var(--inv); }
.split .s-mgr { background: var(--mgr); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: 0; }

/* ---------- Shartnoma tafsiloti ---------- */
.hero-debt { background: var(--surface); border-radius: var(--r-lg); padding: 16px; }
.hero-debt .k { font-size: 13.5px; color: var(--muted); }
.hero-debt .big { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; margin: 2px 0 12px; }
.hero-debt .pips { margin-bottom: 8px; }
.hero-debt .foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; font-size: 13px; color: var(--muted); }
.hero-debt .foot span { white-space: nowrap; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 999px; font-size: 12.5px; background: var(--soft); color: var(--muted); }
.badge.good { background: var(--money-soft); color: var(--money); }
.badge.bad { background: var(--late-soft); color: var(--late); }
.badge.warn { background: var(--due-soft); color: var(--due); }
.badge svg { width: 13px; height: 13px; }
.sched { list-style: none; margin: 0; padding: 0; }
.sched li { display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; padding: 10px 14px; align-items: center; }
.sched .n { width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; font-size: 12px; font-weight: 600; background: var(--soft); color: var(--muted); }
.sched .paid .n { background: var(--money); color: var(--money-ink); }
.sched .overdue .n { background: var(--late); color: #fff; }
.sched .today .n { background: var(--due); color: #fff; }
.sched .partial .n { background: var(--money-soft); color: var(--money); }
.sched .d { font-size: 14px; }
.sched .s { font-size: 12.5px; color: var(--muted); }
.sched .overdue .s { color: var(--late); }
.sched .a { text-align: right; font-weight: 600; }
.prow { display: flex; justify-content: space-between; gap: 12px; padding: 11px 14px; align-items: center; width: 100%; background: none; border: 0; text-align: left; }
.prow .t { font-weight: 600; }
.prow .s { font-size: 12.5px; color: var(--muted); }
.prow.void .t { text-decoration: line-through; color: var(--muted); }
.date-head { font-size: 13px; color: var(--muted); margin: 16px 4px 6px; display: flex; justify-content: space-between; }

/* ---------- Hisobot ---------- */
.bars { display: flex; flex-direction: column; }
.bar-row { display: block; width: 100%; padding: 10px 14px; background: none; border: 0; text-align: left; }
.bar-row .top { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.bar-row .share-line { display: flex; align-items: baseline; gap: 8px; font-size: 13px; margin-top: 4px; color: var(--inv); }
.bar-row .share-line .lead { flex: 1; border-bottom: 1.5px dotted var(--line-strong); transform: translateY(-4px); min-width: 16px; }
.bar-row .share-line .num { font-weight: 600; white-space: nowrap; }
.cur-month { background: color-mix(in srgb, var(--inv) 7%, transparent); }
.bar-row .share-line.late { color: var(--late); }
.bar-track { height: 8px; background: var(--soft); border-radius: 4px; margin-top: 7px; overflow: hidden; display: flex; }
.bar-track span { display: block; height: 100%; }
.bar-track .b-inv { background: var(--inv); }
.bar-track .b-mgr { background: var(--mgr); }
.bar-items { padding: 0 14px 10px; font-size: 13px; }
.bar-items div { display: flex; justify-content: space-between; padding: 4px 0; color: var(--muted); }

/* ---------- Kirish ekrani ---------- */
.auth { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; max-width: 420px; margin: 0 auto; padding: 32px 20px; gap: 18px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { display: grid; grid-template-columns: repeat(4, 7px); gap: 3px; }
.brand-mark i { height: 16px; border-radius: 2px; background: var(--money); }
.brand-mark i:nth-child(3) { background: var(--due); }
.brand-mark i:nth-child(4) { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line-strong); }
.brand b { font-size: 22px; letter-spacing: -0.02em; }
.auth h2 { font-size: 24px; margin: 6px 0 0; letter-spacing: -0.015em; line-height: 1.2; }
.auth p { margin: 0; color: var(--muted); }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 28px 1fr; gap: 10px; padding: 8px 0; }
.steps li::before { content: counter(s); width: 24px; height: 24px; border-radius: 50%; background: var(--money-soft); color: var(--money); font-weight: 700; font-size: 13px; display: grid; place-items: center; }

/* ---------- Imzo ---------- */
.sign-pad { background: #fff; border-radius: var(--r-md); border: 1.5px dashed var(--line-strong); position: relative; touch-action: none; }
.sign-pad canvas { display: block; width: 100%; height: 190px; }
.sign-pad .ph { position: absolute; left: 0; right: 0; bottom: 40px; text-align: center; color: #9aa59f; font-size: 13px; pointer-events: none; border-top: 1px solid #e3e7e4; margin: 0 24px; padding-top: 6px; }
.sig-prev { background: #fff; border: 1px solid var(--line); border-radius: var(--r-md); min-height: 70px; display: flex; align-items: center; justify-content: center; padding: 6px; }
.sig-prev img { max-height: 80px; max-width: 100%; display: block; }
.terms { font-size: 14px; line-height: 1.55; background: var(--surface); border-radius: var(--r-md); padding: 12px 14px; }

/* ---------- Bildirishnoma ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 14px); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 12px; font-size: 14px; z-index: 100;
  opacity: 0; transition: all .2s; pointer-events: none; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--late); color: #fff; }

.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }
.loader { display: grid; place-items: center; min-height: 70vh; }
.loader .pips { width: 120px; }
.loader .pips i { animation: pulse 1.2s infinite ease-in-out; background: var(--money); }
.loader .pips i:nth-child(2) { animation-delay: .15s; }
.loader .pips i:nth-child(3) { animation-delay: .3s; }
.loader .pips i:nth-child(4) { animation-delay: .45s; }
@keyframes pulse { 0%, 100% { opacity: .2; } 50% { opacity: 1; } }

.dir-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; width: 100%; background: none; border: 0; text-align: left; }
.dir-row .ic { font-size: 22px; width: 32px; text-align: center; }
.dir-row .body { flex: 1; min-width: 0; }
.dir-row .t { font-weight: 600; }
.dir-row .s { font-size: 12.5px; color: var(--muted); }
.dir-row .r { text-align: right; font-size: 13px; flex: none; }
.dir-row .r small, .kv .v small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; }

.banner { background: var(--due-soft); color: var(--ink); border-radius: var(--r-md); padding: 12px 14px; font-size: 14px; display: flex; gap: 10px; align-items: center; justify-content: space-between; }

@media (min-width: 640px) {
  .actions { grid-template-columns: repeat(3, minmax(0, 160px)); }
}

/* ---------- Qo'lda grafik ---------- */
.plan-rows { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; margin-top: 10px; }
.plan-row { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 6px; align-items: center; }
.plan-row .input { padding: 8px 10px; min-height: 40px; font-size: 15px; }
.note-box { background: var(--due-soft); border-radius: var(--r-md); padding: 10px 12px; font-size: 14px; margin-top: 10px; }
