:root {
  --primary: #5856D6;
  --primary-soft: #EBEBFB;
  --primary-text: #4A48C4;
  --tana: #34C759;   --tana-text: #1E7B34;   --tana-soft: #E3F7E8;
  --aql: #007AFF;    --aql-text: #0058BB;    --aql-soft: #E0EEFF;
  --ish: #FF9500;    --ish-text: #A85F00;    --ish-soft: #FFF0DB;
  --odamlar: #FF2D55; --odamlar-text: #C8143A; --odamlar-soft: #FFE3E9;
  --flame: #FF9500;
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --text: #000000;
  --text-2: #6C6C70;
  --text-3: #AEAEB2;
  --sep: rgba(60, 60, 67, 0.12);
  --fill: rgba(118, 118, 128, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  --radius: 16px;
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", Inter, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --primary: #6E6CF0;
  --primary-soft: #26254A;
  --primary-text: #A5A4FF;
  --tana: #30D158;   --tana-text: #4BE070;   --tana-soft: #12301B;
  --aql: #0A84FF;    --aql-text: #5AB0FF;    --aql-soft: #0C2440;
  --ish: #FF9F0A;    --ish-text: #FFB547;    --ish-soft: #3A2708;
  --odamlar: #FF375F; --odamlar-text: #FF6F8C; --odamlar-soft: #3D1019;
  --bg: #000000;
  --card: #1C1C1E;
  --text: #FFFFFF;
  --text-2: #98989F;
  --text-3: #5A5A5F;
  --sep: rgba(84, 84, 88, 0.45);
  --fill: rgba(118, 118, 128, 0.24);
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.3;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
svg { display: block; flex-shrink: 0; }

#app { min-height: 100vh; }
.screen { padding: 12px 16px calc(32px + var(--safe-bottom)); max-width: 520px; margin: 0 auto; }
.screen.enter { animation: fade .18s ease; }
.screen.with-tabs { padding-bottom: calc(96px + var(--safe-bottom)); }
.screen.with-cta { padding-bottom: calc(100px + var(--safe-bottom)); }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Tipografiya ---------- */
.large-title { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.12; margin: 0; }
.title1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.title2 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; margin: 0; }
.title3 { font-size: 20px; font-weight: 600; margin: 0; }
.headline { font-size: 17px; font-weight: 600; }
.sub { font-size: 15px; color: var(--text-2); }
.footnote { font-size: 13px; color: var(--text-2); }
.caption { font-size: 12px; color: var(--text-2); }
.overline { font-size: 13px; font-weight: 500; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.02em; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; margin: 24px 4px 8px; }
.section-head .overline { margin: 0; }
.muted { color: var(--text-2); }
.center { text-align: center; }

/* ---------- Header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 14px; }
.top .grow { min-width: 0; }
.nav { display: flex; align-items: center; justify-content: space-between; min-height: 32px; margin: 4px 0 12px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--primary); font-size: 17px; margin-left: -6px; }
.link { color: var(--primary); font-size: 17px; }

.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 15px;
  background: var(--primary-soft); color: var(--primary-text); flex-shrink: 0; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 96px; height: 96px; font-size: 34px; }
.avatar.md { width: 64px; height: 64px; font-size: 24px; }
.avatar.sm { width: 26px; height: 26px; font-size: 10px; border: 2px solid var(--card); }
.avatar[data-c="tana"] { background: var(--tana-soft); color: var(--tana-text); }
.avatar[data-c="aql"] { background: var(--aql-soft); color: var(--aql-text); }
.avatar[data-c="ish"] { background: var(--ish-soft); color: var(--ish-text); }
.avatar[data-c="odamlar"] { background: var(--odamlar-soft); color: var(--odamlar-text); }

/* ---------- Kartalar ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card, .card + .grid2, .grid2 + .card { margin-top: 12px; }
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; position: relative; width: 100%; text-align: left; }
.row + .row::before { content: ""; position: absolute; top: 0; right: 0; left: 16px; border-top: 0.5px solid var(--sep); }
.row.indent + .row.indent::before { left: 68px; }
.row .grow { flex: 1; min-width: 0; }
.row .chev { color: var(--text-3); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 > .card { margin-top: 0; }

/* ---------- Tugmalar ---------- */
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 52px; border-radius: 14px;
  background: var(--primary); color: #fff; font-size: 17px; font-weight: 600; transition: transform .1s, opacity .15s; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; }
.btn.soft { background: var(--primary-soft); color: var(--primary-text); }
.btn.ghost { background: var(--fill); color: var(--text); }
.btn.small { height: 44px; font-size: 16px; border-radius: 12px; }
.icon-btn { width: 52px; height: 52px; border-radius: 14px; background: var(--fill); display: grid; place-items: center; flex-shrink: 0; }
.cta { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent); z-index: 5; }
.cta > * { max-width: 488px; margin: 0 auto; }
.cta .hint { text-align: center; margin-bottom: 10px; }

/* ---------- Chiplar ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { height: 38px; padding: 0 16px; border-radius: 19px; background: var(--card); font-size: 15px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; box-shadow: var(--shadow); flex-shrink: 0; }
.chip.sm { height: 32px; padding: 0 12px; font-size: 14px; }
.chip.on { background: var(--primary); color: #fff; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip[data-d] { background: var(--fill); color: var(--text-2); box-shadow: none; }
.chip[data-d].on { color: var(--c-text); background: var(--c-soft); }
.chip[data-d] .dot { background: var(--c); }

.tag { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 10px; font-size: 15px; }
.tag.give { background: var(--tana-soft); color: var(--tana-text); }
.tag.need { background: var(--odamlar-soft); color: var(--odamlar-text); }
.tag .x { opacity: 0.7; display: inline-grid; }
.tag.add { border: 1px dashed var(--sep); color: var(--primary); font-weight: 600; background: none; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; font-size: 15px; font-weight: 600; }
.pill.flame { background: var(--ish-soft); color: var(--ish-text); }
.pill.ok { background: var(--tana-soft); color: var(--tana-text); }
.pill.warn { background: var(--ish-soft); color: var(--ish-text); }
.pill.plain { background: var(--fill); color: var(--text); font-weight: 500; }

/* Yo'nalish ranglari */
[data-d="tana"] { --c: var(--tana); --c-text: var(--tana-text); --c-soft: var(--tana-soft); }
[data-d="aql"] { --c: var(--aql); --c-text: var(--aql-text); --c-soft: var(--aql-soft); }
[data-d="ish"] { --c: var(--ish); --c-text: var(--ish-text); --c-soft: var(--ish-soft); }
[data-d="odamlar"] { --c: var(--odamlar); --c-text: var(--odamlar-text); --c-soft: var(--odamlar-soft); }
.c-text { color: var(--c-text); }
.ico-tile { flex-shrink: 0; width: 36px; height: 36px; border-radius: 9px; background: var(--c, var(--primary)); color: #fff; display: grid; place-items: center; }
.ico-tile.soft { background: var(--c-soft, var(--primary-soft)); color: var(--c-text, var(--primary-text)); }

/* ---------- Formalar ---------- */
.field-label { font-size: 13px; font-weight: 500; color: var(--text-2); text-transform: uppercase; margin: 20px 4px 8px; letter-spacing: 0.02em; }
.input, .textarea { width: 100%; border: 0; outline: 0; background: var(--card); border-radius: 14px; padding: 15px 16px; font-size: 17px; box-shadow: var(--shadow); }
.textarea { resize: none; min-height: 88px; line-height: 1.35; }
.input.big { font-size: 22px; font-weight: 600; min-height: 90px; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.note { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; color: var(--text-2); margin: 10px 4px; }
.note svg { margin-top: 1px; }
.inline-input { border: 0; outline: 0; background: transparent; padding: 0; font-size: 17px; width: 100%; }

.switch { position: relative; width: 51px; height: 31px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: var(--fill); transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.18); transition: transform .2s; }
.switch input:checked + span { background: var(--tana); }
.switch input:checked + span::after { transform: translateX(20px); }
.time-input { background: var(--fill); border: 0; border-radius: 8px; padding: 6px 8px; font-size: 17px; font-variant-numeric: tabular-nums; }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--fill); border-radius: 10px; padding: 2px; }
.segmented button { height: 34px; border-radius: 8px; font-size: 15px; font-weight: 500; }
.segmented button.on { background: var(--card); box-shadow: 0 2px 6px rgba(0,0,0,.1); }

/* ---------- Onboarding ---------- */
.dots { display: flex; gap: 6px; align-items: center; }
.dots i { width: 8px; height: 8px; border-radius: 4px; background: var(--fill); transition: width .2s; }
.dots i.on { background: var(--primary); }
.dots i.cur { width: 24px; background: var(--primary); }
.welcome-logo { display: flex; justify-content: center; margin: 32px 0 16px; }
.feature { display: flex; gap: 14px; align-items: flex-start; margin: 18px 0; }
.feature .ico-tile { width: 40px; height: 40px; border-radius: 10px; }
.habit-row .ico-tile { width: 40px; height: 40px; border-radius: 10px; }
.habit-row .lbl { font-size: 13px; font-weight: 600; color: var(--c-text); }

/* ---------- Bugun ---------- */
.rings-card { display: flex; gap: 16px; align-items: center; }
.legend { flex: 1; display: grid; gap: 6px; }
.legend .li { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--text-2); }
.legend .li b { margin-left: auto; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.legend .li i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.habit-card { display: flex; flex-direction: column; justify-content: space-between; min-height: 112px; gap: 10px; text-align: left; transition: transform .1s; }
.habit-card:active { transform: scale(0.97); }
.habit-card .hd { display: flex; align-items: center; justify-content: space-between; color: var(--c-text); font-weight: 600; font-size: 15px; }
.habit-card .hd span { display: inline-flex; gap: 6px; align-items: center; }
.habit-card .tx { font-weight: 600; font-size: 17px; line-height: 1.25; }
.check { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--text-3); display: grid; place-items: center; color: #fff; transition: all .15s; }
.check.on { background: var(--c, var(--primary)); border-color: var(--c, var(--primary)); }
.bar { height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 3px; background: var(--c, var(--primary)); transition: width .4s; }
.goal-card .row1 { display: flex; gap: 12px; align-items: center; }
.goal-card .num { font-size: 20px; font-weight: 700; color: var(--primary-text); font-variant-numeric: tabular-nums; }
.stepper { display: flex; gap: 8px; }
.stepper button { width: 34px; height: 34px; border-radius: 10px; background: var(--fill); display: grid; place-items: center; }

/* ---------- Tab bar ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(6px + var(--safe-bottom)); background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-top: 0.5px solid var(--sep); }
.tabbar button { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; font-weight: 500; color: var(--text-2); padding: 4px 0; }
.tabbar button.on { color: var(--primary); }

/* ---------- Hisobot ---------- */
.q-card { display: flex; gap: 12px; }
.q-num { width: 26px; height: 26px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-text); font-size: 14px; font-weight: 600; display: grid; place-items: center; flex-shrink: 0; }
.q-card .textarea { box-shadow: none; padding: 6px 0 0; min-height: 52px; border-radius: 0; background: transparent; }
.success { text-align: center; padding-top: 24px; }
.confetti { position: relative; height: 230px; display: grid; place-items: center; }
.confetti i { position: absolute; width: 8px; height: 14px; border-radius: 2px; animation: pop 0.9s cubic-bezier(.2,.8,.3,1) both; }
@keyframes pop { from { transform: translate(0,0) rotate(0) scale(.3); opacity: 0; } to { opacity: 1; } }
.week { display: flex; justify-content: space-between; margin-top: 16px; }
.week .d { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); }
.week .d .c { width: 36px; height: 36px; border-radius: 50%; border: 1.5px solid var(--sep); display: grid; place-items: center; color: #fff; }
.week .d.on .c { background: var(--primary); border-color: var(--primary); }
.week .d.today { color: var(--text); font-weight: 600; }

/* ---------- Progress ---------- */
.stat .big { font-size: 28px; font-weight: 700; margin-top: 6px; }
.stat .sub { white-space: nowrap; font-size: 14px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-head .arrows { display: flex; gap: 16px; color: var(--primary); }
.cal-head .arrows button:disabled { color: var(--text-3); }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; text-align: center; }
.cal .wd { font-size: 12px; color: var(--text-2); padding-bottom: 2px; }
.cal .day { aspect-ratio: 1.45; border-radius: 8px; display: grid; place-items: center; font-size: 14px; font-variant-numeric: tabular-nums;
  border: 1px solid var(--sep); color: var(--text-2); }
.cal .day.future { border-color: transparent; background: var(--fill); opacity: .5; }
.cal .day.l1 { background: color-mix(in srgb, var(--primary) 28%, transparent); border-color: transparent; color: var(--text); }
.cal .day.l2 { background: color-mix(in srgb, var(--primary) 50%, transparent); border-color: transparent; color: #fff; }
.cal .day.l3 { background: color-mix(in srgb, var(--primary) 75%, transparent); border-color: transparent; color: #fff; }
.cal .day.l4 { background: var(--primary); border-color: transparent; color: #fff; }
.cal .day.today { outline: 2px solid var(--text); outline-offset: -1px; font-weight: 700; }
.scale { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 12px; }
.scale i { width: 12px; height: 12px; border-radius: 3px; }
.dir-stat .hd { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.dir-stat .hd span { display: inline-flex; gap: 6px; align-items: center; color: var(--c-text); font-weight: 600; font-size: 15px; }
.dir-stat .hd b { font-size: 22px; }

/* ---------- A'zolar ---------- */
.search { display: flex; align-items: center; gap: 8px; background: var(--fill); border-radius: 11px; padding: 0 10px; height: 40px; color: var(--text-2); margin-bottom: 12px; }
.search input { border: 0; outline: 0; background: transparent; flex: 1; font-size: 17px; color: var(--text); }
.member-row .name { font-weight: 600; }
.streak { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; font-variant-numeric: tabular-nums; }
.profile-head { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 4px 0 16px; }
.offer-head { display: flex; gap: 12px; align-items: center; }
.empty { text-align: center; color: var(--text-2); padding: 32px 16px; }

/* ---------- Tadbirlar ---------- */
.event-head { display: flex; gap: 12px; align-items: flex-start; }
.datebox { width: 50px; border-radius: 12px; background: var(--fill); text-align: center; padding: 6px 0; flex-shrink: 0; }
.datebox small { display: block; font-size: 11px; font-weight: 700; color: var(--odamlar); text-transform: uppercase; }
.datebox b { font-size: 22px; }
.meta { display: grid; gap: 8px; margin: 14px 0; font-size: 15px; }
.meta div { display: flex; gap: 10px; align-items: center; }
.meta svg { color: var(--text-2); }
.faces { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.faces .stack { display: flex; }
.faces .stack .avatar + .avatar { margin-left: -8px; }
.km { color: var(--tana-text); background: var(--tana-soft); border-radius: 6px; padding: 1px 6px; font-weight: 600; font-size: 14px; }
.qr { width: 220px; height: 220px; margin: 0 auto; background: #fff; padding: 14px; border-radius: 16px; border: 1px solid var(--sep); }
.qr svg { width: 100%; height: 100%; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.12em; color: var(--text-2); }

/* ---------- Toast / loader ---------- */
.toast { position: fixed; left: 50%; top: 16px; transform: translateX(-50%); background: rgba(30,30,30,.92); color: #fff; padding: 10px 16px;
  border-radius: 12px; font-size: 15px; z-index: 50; max-width: calc(100% - 32px); animation: fade .2s ease; }
.loader { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--fill); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Odatlar (bir nechta, guruhlangan) ---------- */
.plain { display: block; width: 100%; text-align: left; }
.habit-group { padding: 12px 16px 4px; }
.habit-group + .habit-group { margin-top: 10px; }
.hg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
.hg-head span:first-child { display: inline-flex; gap: 6px; align-items: center; color: var(--c-text); font-weight: 600; font-size: 15px; }
.habit-item { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; padding: 11px 0; border-top: 0.5px solid var(--sep); }
.hg-head + .habit-item { border-top: 0; }
.habit-item .grow { flex: 1; min-width: 0; }
.habit-item .tx { font-size: 17px; font-weight: 500; line-height: 1.25; }
.habit-item .tx.done { color: var(--text-2); }
.habit-item .check { flex-shrink: 0; }
.remind { display: inline-flex; gap: 3px; align-items: center; margin-top: 2px; white-space: nowrap; }
.add-habit { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; height: 46px; border-radius: 14px;
  border: 1.5px dashed var(--sep); color: var(--primary); font-weight: 600; font-size: 16px; }
.dir-head { display: inline-flex; gap: 6px; align-items: center; color: var(--c-text); font-weight: 600; font-size: 15px; }
.add-row { color: var(--primary); font-weight: 600; gap: 10px; }
.dir-opt { text-align: left; border: 2px solid transparent; padding: 12px; }
.dir-opt.on { border-color: var(--c); background: var(--c-soft); }
.dir-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex-shrink: 0; }
.btn.danger { color: var(--odamlar-text); }
.time-input:disabled { opacity: 0.4; }

/* ---------- Maqsad ---------- */
.goal-card .num small, .stat .big small { font-size: 13px; font-weight: 600; color: var(--text-2); margin-left: 2px; }
.goal-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 12px; padding-top: 12px; border-top: 0.5px solid var(--sep); }
.goal-foot .chip { flex-shrink: 0; }
.icon-del { width: 30px; height: 30px; border-radius: 15px; display: grid; place-items: center; color: var(--text-3); flex-shrink: 0; }
.chart-legend { display: flex; gap: 14px; margin-top: 8px; }
.chart-legend span { display: inline-flex; gap: 5px; align-items: center; }
.chart-legend i { width: 12px; height: 4px; border-radius: 2px; display: inline-block; }
.chart-legend i.dash { height: 0; border-top: 2px dashed var(--text-3); background: none; border-radius: 0; }

.sheet-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 40; display: flex; align-items: flex-end; animation: fade .15s ease; }
.sheet { background: var(--bg); width: 100%; max-width: 520px; margin: 0 auto; border-radius: 20px 20px 0 0; padding: 8px 16px calc(16px + var(--safe-bottom)); }
.sheet-grip { width: 36px; height: 5px; border-radius: 3px; background: var(--fill); margin: 0 auto 12px; }
