:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #14211f;
  --muted: #5d6f6b;
  --line: #dde5e3;
  --primary: #0f766e;
  --primary-2: #115e59;
  --on-primary: #ffffff;
  --accent: #d97706;
  --danger: #c2410c;
  --danger-bg: #fdece4;
  --ok: #15803d;
  --ok-bg: #e4f5ea;
  --warn-bg: #fff4dc;
  --shadow: 0 1px 2px rgba(15, 40, 36, .06), 0 6px 18px rgba(15, 40, 36, .06);
  --radius: 16px;
  --nav-h: 64px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0c1413;
  --surface: #131e1c;
  --surface-2: #1b2926;
  --text: #e6f0ee;
  --muted: #8ba39e;
  --line: #243633;
  --primary: #2dd4bf;
  --primary-2: #5eead4;
  --on-primary: #062321;
  --accent: #fbbf24;
  --danger: #fb923c;
  --danger-bg: #36200f;
  --ok: #4ade80;
  --ok-bg: #12301d;
  --warn-bg: #33270b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1413;
    --surface: #131e1c;
    --surface-2: #1b2926;
    --text: #e6f0ee;
    --muted: #8ba39e;
    --line: #243633;
    --primary: #2dd4bf;
    --primary-2: #5eead4;
    --on-primary: #062321;
    --accent: #fbbf24;
    --danger: #fb923c;
    --danger-bg: #36200f;
    --ok: #4ade80;
    --ok-bg: #12301d;
    --warn-bg: #33270b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* ---------- Kirish ekrani ---------- */
.login {
  min-height: 100dvh;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 15% 10%, rgba(251, 191, 36, .28), transparent 38%),
    radial-gradient(circle at 90% 85%, rgba(45, 212, 191, .30), transparent 42%),
    linear-gradient(160deg, #0b4f4a 0%, #0f766e 55%, #115e59 100%);
  position: relative; overflow: hidden;
}
.login::before {
  content: ""; position: absolute; inset: 0; opacity: .10; pointer-events: none;
  background-image:
    conic-gradient(from 45deg at 50% 50%, #fff 0 25%, transparent 0 50%, #fff 0 75%, transparent 0);
  background-size: 46px 46px;
  mask-image: linear-gradient(180deg, #000, transparent 70%);
  -webkit-mask-image: linear-gradient(180deg, #000, transparent 70%);
}
.login-brand { position: relative; text-align: center; color: #fff; margin-bottom: 22px; }
.login-logo {
  width: 78px; height: 78px; margin: 0 auto 12px; border-radius: 24px;
  background: rgba(255, 255, 255, .16); border: 1px solid rgba(255, 255, 255, .35);
  display: grid; place-items: center; backdrop-filter: blur(6px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}
.login-brand h1 { margin: 0; font-size: 28px; letter-spacing: .14em; font-weight: 800; }
.login-brand p { margin: 4px 0 0; opacity: .85; font-size: 14px; }
.login-card {
  position: relative; width: 100%; max-width: 380px;
  background: var(--surface); border-radius: 24px; padding: 22px 20px 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .30);
}
.login-card h2 { margin: 0 0 14px; font-size: 18px; }
.login-foot { position: relative; margin-top: 18px; color: rgba(255, 255, 255, .75); font-size: 12.5px; text-align: center; max-width: 340px; }

/* ---------- Umumiy shakllar ---------- */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 5px 2px; font-weight: 600; }
.input, input[type=text], input[type=password], input[type=date], input[type=month], input[type=search], textarea, select {
  width: 100%; min-height: 48px; padding: 11px 14px; border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--surface-2); outline: none; transition: border-color .15s, box-shadow .15s, background .15s;
  appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 21px, calc(100% - 14px) 21px; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
textarea { resize: vertical; min-height: 140px; line-height: 1.5; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent); }
.pw { position: relative; }
.pw input { padding-right: 52px; }
.pw button { position: absolute; right: 4px; top: 4px; width: 44px; height: 44px; border: 0; background: transparent; color: var(--muted); border-radius: 10px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.err { background: var(--danger-bg); color: var(--danger); padding: 10px 12px; border-radius: 12px; font-size: 14px; margin-bottom: 12px; }
.err:empty { display: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 14px; border: 0; font-weight: 700;
  background: var(--primary); color: var(--on-primary); transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--danger-bg); color: var(--danger); }
.btn.small { min-height: 38px; padding: 0 12px; border-radius: 11px; font-size: 14px; }
.btn.accent { background: var(--accent); color: #1c1203; }

/* ---------- Ilova qobig'i ---------- */
.shell { display: flex; flex-direction: column; height: 100dvh; max-width: 720px; margin: 0 auto; background: var(--bg); }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--primary); color: var(--on-primary); position: relative; z-index: 2;
}
:root[data-theme="dark"] .topbar { background: #0f2b28; color: var(--text); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .topbar { background: #0f2b28; color: var(--text); } }
.topbar h1 { margin: 0; font-size: 19px; flex: 1; font-weight: 800; letter-spacing: .02em; }
.topbar .back { background: transparent; border: 0; color: inherit; width: 40px; height: 40px; margin-left: -10px; border-radius: 12px; display: grid; place-items: center; }
.chip { font-size: 12px; font-weight: 700; padding: 5px 10px; border-radius: 99px; background: rgba(255, 255, 255, .18); white-space: nowrap; }
.chip.off { background: var(--warn-bg); color: #8a5a00; }
:root[data-theme="dark"] .chip.off { color: var(--accent); }
.chip.sync { background: rgba(255, 255, 255, .28); }
.view { flex: 1; overflow-y: auto; padding: 14px 14px calc(var(--nav-h) + 90px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 720px; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -6px 20px rgba(15, 40, 36, .06);
}
.nav button { border: 0; background: transparent; padding: 8px 2px 7px; height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 11.5px; font-weight: 600; position: relative; }
.nav button svg { width: 24px; height: 24px; }
.nav button.on { color: var(--primary); }
.nav button.on::before { content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 4px 4px; background: var(--primary); }
.nav .dot { position: absolute; top: 9px; margin-left: 18px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }

.fab {
  position: fixed; right: max(16px, calc(50% - 344px)); bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 20px; border: 0; background: var(--accent); color: #1c1203;
  box-shadow: 0 10px 24px rgba(217, 119, 6, .38); display: grid; place-items: center; z-index: 4;
}
.fab svg { width: 28px; height: 28px; }

/* ---------- Kartalar va ro'yxatlar ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 13px 14px; box-shadow: var(--shadow); min-width: 0; }
.stat small { display: block; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.stat b { display: block; font-size: 20px; margin-top: 2px; overflow-wrap: anywhere; }
.stat em { font-style: normal; font-size: 12px; color: var(--muted); font-weight: 600; }
.stat.debt b { color: var(--danger); }
.stat.good b { color: var(--ok); }
.hero {
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: var(--on-primary);
  border-radius: 20px; padding: 18px; margin-bottom: 12px; box-shadow: var(--shadow);
}
:root[data-theme="dark"] .hero { background: linear-gradient(135deg, #0f3d38, #0b2c29); color: var(--text); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .hero { background: linear-gradient(135deg, #0f3d38, #0b2c29); color: var(--text); } }
.hero small { opacity: .85; font-weight: 600; }
.hero b { display: block; font-size: 30px; margin: 2px 0 8px; letter-spacing: -.01em; }
.hero .sub { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13.5px; opacity: .92; }
.section-t { font-size: 13px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 16px 4px 8px; display: flex; justify-content: space-between; align-items: baseline; }
.section-t span:last-child { text-transform: none; letter-spacing: 0; font-weight: 700; }
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 0; background: transparent; width: 100%; text-align: left; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .ic { width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2); color: var(--primary); display: grid; place-items: center; flex: none; }
.item .ic svg { width: 21px; height: 21px; }
.item .ic.exp { color: var(--accent); }
.item .mid { flex: 1; min-width: 0; }
.item .mid b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.item .mid small { color: var(--muted); font-size: 13px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .rt { text-align: right; flex: none; }
.item .rt b { display: block; font-weight: 800; }
.badge { display: inline-block; font-size: 11.5px; font-weight: 800; padding: 2px 8px; border-radius: 99px; }
.badge.debt { background: var(--danger-bg); color: var(--danger); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: #8a5a00; }
:root[data-theme="dark"] .badge.warn { color: var(--accent); }
.dayhead { display: flex; justify-content: space-between; padding: 8px 14px; background: var(--surface-2); font-size: 13px; font-weight: 700; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 38px 20px; }
.empty svg { width: 54px; height: 54px; opacity: .45; margin-bottom: 8px; }
.empty b { display: block; color: var(--text); margin-bottom: 4px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); padding: 4px; border-radius: 14px; margin-bottom: 12px; gap: 4px; }
.seg button { border: 0; background: transparent; padding: 10px 6px; border-radius: 11px; font-weight: 700; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
.search { margin-bottom: 12px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--muted); }
.kv b { text-align: right; overflow-wrap: anywhere; }
.menu .item .ic { background: color-mix(in srgb, var(--primary) 12%, transparent); }
.note-card { padding: 13px 14px; border-bottom: 1px solid var(--line); width: 100%; border-left: 0; border-right: 0; border-top: 0; background: transparent; text-align: left; display: block; }
.note-card:last-child { border-bottom: 0; }
.note-card b { display: block; }
.note-card p { margin: 3px 0 4px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.note-card small { color: var(--muted); font-size: 12px; }
.user-card .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.user-card .acts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.dev { font-size: 13px; color: var(--muted); padding: 6px 0; display: flex; justify-content: space-between; gap: 8px; }

/* ---------- Modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(5, 18, 16, .55); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; background: var(--surface); border-radius: 24px 24px 0 0; padding: 8px 18px calc(18px + env(safe-area-inset-bottom)); animation: up .2s ease-out; }
.sheet .grab { width: 40px; height: 4px; background: var(--line); border-radius: 4px; margin: 4px auto 12px; }
.sheet h3 { margin: 0 0 14px; font-size: 19px; }
.sheet .actions { display: flex; gap: 10px; margin-top: 8px; }
.sheet .actions .btn { flex: 1; }
.calc { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; display: flex; justify-content: space-between; font-weight: 700; }
.calc b.d { color: var(--danger); }
@media (min-width: 640px) { .overlay { align-items: center; } .sheet { border-radius: 24px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: #0f2b28; color: #fff; padding: 11px 16px; border-radius: 14px; font-size: 14.5px; font-weight: 600; opacity: 0; pointer-events: none; transition: .2s; z-index: 40; max-width: 90vw; text-align: center; box-shadow: 0 10px 30px rgba(0, 0, 0, .3); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.spin { width: 18px; height: 18px; border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: rot .7s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }
.splash { height: 100dvh; display: grid; place-items: center; color: var(--muted); }
.note-hint { font-size: 13px; color: var(--muted); margin: 0 4px 12px; }
