/* TgBrowser — "Galereya" dizayni. O'z brendi: indigo → binafsha. */

:root {
  --brand-1: #6366f1;
  --brand-2: #a855f7;
  --brand: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  --brand-soft: rgba(124, 92, 246, 0.12);

  --bg: #f6f5fb;
  --surface: #ffffff;
  --surface-2: #efedf7;
  --text: #16142b;
  --muted: #7a7894;
  --line: rgba(22, 20, 43, 0.08);
  --danger: #ef4461;
  --ok: #10b981;
  --shadow: 0 8px 28px rgba(40, 30, 90, 0.10);
  --shadow-lg: 0 18px 50px rgba(40, 30, 90, 0.22);

  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 12px;
}

:root[data-theme="dark"] {
  --bg: #0e0d17;
  --surface: #181627;
  --surface-2: #221f35;
  --text: #f1effb;
  --muted: #9794b3;
  --line: rgba(255, 255, 255, 0.08);
  --brand-soft: rgba(139, 110, 255, 0.18);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 "Manrope", -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }

/* `clip` — `hidden`dan farqli, scroll konteyner yaratmaydi:
   yonga surilish bo'lmaydi, vertikal scroll esa sahifada qoladi. */
#app { max-width: 640px; overflow-x: clip; margin: 0 auto; padding: 0 16px calc(110px + env(safe-area-inset-bottom)); }

/* ── Topbar ─────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 0 10px;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.acc-pill {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  padding: 5px 12px 5px 5px; border-radius: 999px;
  background: var(--surface); box-shadow: var(--shadow);
}
.acc-ava {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 13px;
  background: var(--brand);
}
.acc-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.chev { width: 18px; height: 18px; color: var(--muted); }
.plan-badge {
  padding: 7px 14px; border-radius: 999px; font-weight: 800; font-size: 12px; letter-spacing: .06em;
  color: #fff; background: var(--brand); box-shadow: 0 6px 18px rgba(124, 92, 246, .35);
}

/* ── Views ──────────────────────────────────────────────────────────── */
.view { display: none; animation: fadeUp .28s ease both; }
.view.active { display: block; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.page-head { display: flex; align-items: center; justify-content: space-between; margin: 8px 0 4px; }
.page-head h2 { margin: 0; font-size: 24px; font-weight: 800; }
.hint { color: var(--muted); margin: 4px 0 14px; font-size: 14px; }
.section-title { margin: 18px 2px 10px; font-size: 13px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }

/* ── Search ─────────────────────────────────────────────────────────── */
.search {
  display: flex; align-items: center; gap: 10px;
  padding: 0 8px 0 16px; height: 50px; border-radius: 999px;
  background: var(--surface); box-shadow: var(--shadow); margin: 4px 0 6px;
}
.search svg { color: var(--muted); flex: none; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; height: 100%; }
.search input::-webkit-search-cancel-button { display: none; }
.search-go { padding: 9px 16px; border-radius: 999px; color: #fff; font-weight: 700; background: var(--brand); }

/* ── Segmented control ──────────────────────────────────────────────── */
/* Barcha bo'limlar bir qatorga teng sig'adi — yonga surish shart emas. */
.segments {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  gap: 2px; padding: 4px; margin: 12px 0; border-radius: 999px; background: var(--surface-2);
}
.seg {
  min-width: 0; padding: 9px 3px; border-radius: 999px; text-align: center;
  font-weight: 700; font-size: 12px; letter-spacing: -.1px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .2s, color .2s;
}
.seg.active { background: var(--surface); color: var(--text); box-shadow: 0 2px 10px rgba(0,0,0,.08); }

/* ── Avatars ────────────────────────────────────────────────────────── */
.ava {
  position: relative; border-radius: 50%; overflow: hidden; flex: none;
  display: grid; place-items: center; color: #fff; font-weight: 800;
  background: var(--brand);
}
.ava img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ava.g1 { background: linear-gradient(135deg, #f97316, #ec4899); }
.ava.g2 { background: linear-gradient(135deg, #06b6d4, #6366f1); }
.ava.g3 { background: linear-gradient(135deg, #10b981, #06b6d4); }
.ava.g4 { background: linear-gradient(135deg, #eab308, #f97316); }

/* ── Chat cards ─────────────────────────────────────────────────────── */
/* minmax(0,1fr) bo'lmasa uzun nomli karta grid ustunini kengaytirib,
   butun sahifani yonga suriladigan qilib qo'yadi. */
.cards { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.card {
  display: flex; align-items: center; gap: 12px; width: 100%; min-width: 0; text-align: left;
  padding: 12px; border-radius: var(--r-md); background: var(--surface); box-shadow: var(--shadow);
  animation: pop .3s ease both;
}
.card .ava { width: 50px; height: 50px; font-size: 18px; }
.card-main { flex: 1; min-width: 0; }
.card-title { min-width: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 6px; }
.card-sub { min-width: 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; color: var(--muted); font-size: 12px; }
.badge-count { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 11px; background: var(--brand); }
.kind-tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-1); }
@keyframes pop { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: none; } }

/* ── Hero (umumiy rejim, bo'sh holatlar) ───────────────────────────── */
.hero {
  position: relative; overflow: hidden; margin: 14px 0; padding: 22px;
  border-radius: var(--r-lg); color: #fff; background: var(--brand); box-shadow: var(--shadow-lg);
}
.hero::after { content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%; background: rgba(255,255,255,.14); }
.hero h3 { margin: 0 0 6px; font-size: 20px; font-weight: 800; }
.hero p { margin: 0 0 16px; opacity: .92; }
.hero .btn-light { background: #fff; color: #4c3bd6; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .big { font-size: 44px; margin-bottom: 8px; }

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 50px; padding: 0 22px; border-radius: 999px; font-weight: 800;
  color: #fff; background: var(--brand); box-shadow: 0 10px 24px rgba(124, 92, 246, .35);
  transition: transform .12s;
}
.btn:active { transform: scale(.97); }
.btn.block { width: 100%; }
.btn.ghost { background: var(--surface-2); color: var(--text); box-shadow: none; }
.btn.danger { background: var(--danger); box-shadow: none; }
.btn[disabled] { opacity: .6; pointer-events: none; }
.chip-btn { padding: 8px 14px; border-radius: 999px; font-weight: 700; font-size: 13px; color: var(--brand-1); background: var(--brand-soft); }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); box-shadow: var(--shadow); flex: none; }
.icon-btn.on { color: #fff; background: var(--brand); }
.icon-btn.danger { color: var(--danger); }

/* ── Chat head ──────────────────────────────────────────────────────── */
.chat-head { display: flex; align-items: center; gap: 12px; margin: 4px 0 8px; }
.chat-head-ava .ava { width: 44px; height: 44px; font-size: 16px; }
.chat-head-text { flex: 1; min-width: 0; }
.list { grid-template-columns: minmax(0, 1fr); }
.chat-title { font-weight: 800; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub { color: var(--muted); font-size: 13px; }

/* ── Stories ────────────────────────────────────────────────────────── */
.stories { display: flex; gap: 12px; overflow-x: auto; scrollbar-width: none; margin: 8px -16px 4px; padding: 4px 16px; }
.stories::-webkit-scrollbar { display: none; }
.story { flex: none; width: 70px; text-align: center; font-size: 11px; color: var(--muted); }
.story-ring { width: 68px; height: 68px; border-radius: 50%; padding: 3px; background: var(--brand); margin-bottom: 4px; }
.story-ring.seen { background: var(--surface-2); }
.story-ring > div { width: 100%; height: 100%; border-radius: 50%; overflow: hidden; border: 3px solid var(--bg); background: var(--surface-2); }
.story-ring img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ── Media grid ─────────────────────────────────────────────────────── */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; border-radius: var(--r-md); overflow: hidden; }
.tile {
  position: relative; aspect-ratio: 1 / 1; overflow: hidden; background: var(--surface-2);
  animation: pop .3s ease both;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .3s; }
.tile:active img { transform: scale(1.05); }
.tile-badge {
  position: absolute; right: 6px; bottom: 6px; max-width: calc(100% - 12px); padding: 2px 7px; border-radius: 8px;
  font-size: 11px; font-weight: 800; color: #fff; background: rgba(0, 0, 0, .55); backdrop-filter: blur(6px);
}
.tile-icon { position: absolute; inset: 0 0 26px; display: grid; place-items: center; color: var(--muted); }
.tile-icon svg { width: 30px; height: 30px; }
.tile-file { position: absolute; left: 8px; right: 8px; bottom: 32px; text-align: center; font-size: 11px; font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile.sent::after { content: "✓"; position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 800; color: #fff; background: var(--ok); }
.sentinel { height: 40px; }

/* ── Skeleton ───────────────────────────────────────────────────────── */
.sk { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.sk-card { height: 74px; border-radius: var(--r-md); }
.sk-tile { aspect-ratio: 1 / 1; }

/* ── Dock ───────────────────────────────────────────────────────────── */
.dock {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  display: flex; gap: 4px; padding: 6px; border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 86%, transparent); backdrop-filter: blur(16px);
  box-shadow: var(--shadow-lg);
}
.dock-btn { display: flex; align-items: center; gap: 6px; height: 46px; padding: 0 16px; border-radius: 999px; color: var(--muted); font-weight: 700; font-size: 13px; transition: all .2s; }
.dock-btn span { display: none; }
.dock-btn.active { color: #fff; background: var(--brand); }
.dock-btn.active span { display: inline; }

/* ── Sheet ──────────────────────────────────────────────────────────── */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(8, 6, 20, .5); animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; max-width: 640px; margin: 0 auto;
  max-height: 88vh; overflow-y: auto; border-radius: 26px 26px 0 0; background: var(--surface);
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform .3s cubic-bezier(.2, .8, .2, 1);
}
.sheet.open { transform: none; }
.sheet-handle { width: 42px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 14px; }
.preview { position: relative; border-radius: var(--r-md); overflow: hidden; background: var(--surface-2); aspect-ratio: 4 / 3; margin-bottom: 14px; }
.preview img { width: 100%; height: 100%; object-fit: contain; display: block; }
.meta-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.meta-chip { padding: 5px 11px; border-radius: 999px; background: var(--surface-2); font-size: 12px; font-weight: 700; color: var(--muted); }
.caption { color: var(--muted); font-size: 14px; margin: 0 0 16px; white-space: pre-wrap; max-height: 120px; overflow: auto; }
.sheet h3 { margin: 0 0 12px; font-size: 19px; font-weight: 800; }
.list { display: grid; gap: 8px; margin-bottom: 14px; }
.list-item { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 10px; border-radius: var(--r-sm); background: var(--surface-2); text-align: left; width: 100%; }
.list-item.active { outline: 2px solid var(--brand-1); }
.list-item .ava { width: 40px; height: 40px; font-size: 15px; }

/* Progress halqasi */
.ring { position: relative; width: 22px; height: 22px; }
.ring svg { width: 22px; height: 22px; transform: rotate(-90deg); }
.ring circle { stroke: rgba(255,255,255,.35); stroke-width: 3; fill: none; }
.ring circle.fg { stroke: #fff; stroke-dasharray: 57; stroke-dashoffset: 57; transition: stroke-dashoffset .3s; }

/* ── Plans ──────────────────────────────────────────────────────────── */
.plan-now { padding: 20px; border-radius: var(--r-lg); color: #fff; background: var(--brand); box-shadow: var(--shadow-lg); margin: 8px 0 18px; }
.plan-now .label { opacity: .85; font-size: 13px; font-weight: 700; }
.plan-now .name { font-size: 28px; font-weight: 800; margin: 2px 0 12px; }
.meter { height: 8px; border-radius: 4px; background: rgba(255,255,255,.25); overflow: hidden; }
.meter > div { height: 100%; background: #fff; border-radius: 4px; transition: width .4s; }
.meter-label { display: flex; justify-content: space-between; font-size: 12px; margin-top: 6px; opacity: .9; }
.balance-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-radius: var(--r-lg); background: var(--surface);
  box-shadow: var(--shadow); margin-bottom: 14px;
}
.balance-card .label { color: var(--muted); font-size: 13px; font-weight: 700; }
.balance-card .amount { font-size: 22px; font-weight: 800; }
.balance-card .amount small { font-size: 13px; color: var(--muted); font-weight: 700; }
.balance-card .btn { height: 42px; padding: 0 18px; }

.plan-card { padding: 18px; border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow); margin-bottom: 12px; border: 2px solid transparent; }
.plan-card.current { border-color: var(--brand-1); }
.plan-card-top { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.plan-card-name { font-size: 20px; font-weight: 800; }
.plan-price { font-weight: 800; font-size: 18px; background: var(--brand); -webkit-background-clip: text; background-clip: text; color: transparent; }
.plan-price small { font-size: 12px; color: var(--muted); -webkit-text-fill-color: var(--muted); }
.features { list-style: none; padding: 0; margin: 0 0 14px; display: grid; gap: 6px; font-size: 14px; }
.features li::before { content: "✦"; margin-right: 8px; color: var(--brand-2); }

/* ── Toast ──────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 60;
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 16px; font-weight: 700; font-size: 14px;
  color: #fff; background: #1f1b36; box-shadow: var(--shadow-lg); animation: fadeUp .25s ease;
}
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
