/* Mini App ko'rinishi. Ranglar Telegram mavzusidan olinadi (yorug'/qorong'i o'zi moslashadi). */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111318);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #3478f6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #3478f6);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --line: rgba(138, 143, 152, .22);       /* eski telefonlar uchun zaxira rang */
  --soft: rgba(52, 120, 246, .10);
  --danger-soft: rgba(229, 72, 77, .12);
  --ok: #2fb36b;
  --warn: #f2a33a;
  --pink: #e1306c;
  --radius: 16px;
}
@supports (color: color-mix(in srgb, red 50%, blue)) {
  :root {
    --line: color-mix(in srgb, var(--hint) 22%, transparent);
    --soft: color-mix(in srgb, var(--accent) 10%, transparent);
    --danger-soft: color-mix(in srgb, var(--danger) 12%, transparent);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding: 12px 16px calc(96px + env(safe-area-inset-bottom));
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; }
[hidden] { display: none !important; }

/* ---------- umumiy ---------- */
.loader { display: grid; place-items: center; min-height: 60vh; }
.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); } }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar { display: flex; align-items: center; gap: 10px; margin: 4px 0 14px; }
.topbar h1 { font-size: 22px; line-height: 1.2; margin: 0; flex: 1; letter-spacing: -.01em; }
.account {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px;
  background: var(--card); border-radius: 999px; font-size: 13px; font-weight: 600;
}
.account .ig {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 30% 107%, #fdf497 0%, #fd5949 45%, #d6249f 60%, #285aeb 90%);
}
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--card);
  display: grid; place-items: center; color: var(--text);
}
.icon-btn svg { width: 20px; height: 20px; }

.card { background: var(--card); border-radius: var(--radius); padding: 14px; }
.section-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint);
  margin: 20px 4px 8px; font-weight: 600;
}

/* ---------- umumiy statistika ---------- */
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.total { background: var(--card); border-radius: 14px; padding: 12px; }
.total b { display: block; font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.total span { font-size: 12px; color: var(--hint); }

/* ---------- avtomatlashtirish kartalari ---------- */
.list { display: grid; gap: 10px; }
.auto {
  display: flex; gap: 12px; padding: 12px; background: var(--card); border-radius: var(--radius);
  align-items: center; border: 0; width: 100%; text-align: left;
}
.auto.off { opacity: .55; }
.thumb {
  width: 54px; height: 72px; border-radius: 10px; flex: none; object-fit: cover;
  background: var(--line);
}
.thumb.empty { display: grid; place-items: center; color: var(--hint); font-size: 11px; }
.auto .name { font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.chip {
  font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--accent);
  font-weight: 600;
}
.funnel { font-size: 12px; color: var(--hint); font-variant-numeric: tabular-nums; }
.funnel b { color: var(--text); font-weight: 600; }

/* yoqish/o'chirish tugmasi */
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .2s;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s;
}
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(18px); }

.empty-state { text-align: center; padding: 40px 20px; }
.empty-state .big { font-size: 40px; }
.empty-state h2 { font-size: 18px; margin: 8px 0 4px; }

/* ---------- post tanlash ---------- */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; border-radius: 12px; overflow: hidden; }
.post { position: relative; aspect-ratio: 3 / 4; border: 0; padding: 0; background: var(--line); }
.post img { width: 100%; height: 100%; object-fit: cover; }
.post .badge {
  position: absolute; left: 6px; bottom: 6px; font-size: 11px; color: #fff; font-weight: 600;
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
}
.post .taken {
  position: absolute; inset: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 12px; font-weight: 600;
  display: grid; place-items: center; text-align: center; padding: 6px;
}
.post:disabled { cursor: default; }
.manual { margin-top: 14px; }

/* ---------- tahrirlagich: bloklar zanjiri ---------- */
.post-head { display: flex; gap: 12px; align-items: center; }
.post-head .thumb { width: 60px; height: 80px; }
.flow { position: relative; margin-top: 18px; }
.step { position: relative; padding-left: 44px; padding-bottom: 14px; }
.step::before {          /* bloklarni bog'lovchi chiziq */
  content: ""; position: absolute; left: 15px; top: 34px; bottom: -2px; width: 2px; background: var(--line);
}
.step:last-child::before { display: none; }
.node {
  position: absolute; left: 0; top: 2px; width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-size: 15px;
}
.node svg { width: 17px; height: 17px; }
.n-trigger { background: var(--pink); }
.n-reply { background: #8b5cf6; }
.n-dm { background: var(--accent); }
.n-follow { background: var(--warn); }
.n-link { background: var(--ok); }
.step .card { padding: 12px 14px; }
.step-title { font-weight: 600; margin: 0 0 2px; }
.step-sub { font-size: 13px; color: var(--hint); margin: 0 0 10px; }

label.field { display: block; margin-top: 10px; }
label.field > span { display: flex; justify-content: space-between; font-size: 12px; color: var(--hint); margin-bottom: 4px; }
.counter.over { color: var(--danger); font-weight: 600; }
.input, .textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px;
  padding: 10px 12px; outline: none; transition: border-color .15s;
}
.input:focus, .textarea:focus { border-color: var(--accent); }
.textarea { resize: vertical; min-height: 76px; }

.tag-input { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 5px 6px 5px 10px; border-radius: 999px;
  background: var(--soft); color: var(--accent); font-weight: 600; font-size: 14px;
}
.tag button {
  border: 0; background: transparent; color: inherit; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; padding: 0; font-size: 16px; line-height: 1;
}
.add-row { display: flex; gap: 8px; margin-top: 8px; }
.add-row .input { flex: 1; }
.btn {
  border: 0; border-radius: 12px; padding: 10px 14px; background: var(--soft); color: var(--accent);
  font-weight: 600; white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { background: var(--danger-soft); color: var(--danger); width: 100%; margin-top: 18px; }
.btn.block { width: 100%; }

.reply-list { display: grid; gap: 6px; }
.reply-item {
  display: flex; gap: 8px; align-items: center; padding: 8px 8px 8px 12px; border-radius: 12px; background: var(--bg);
}
.reply-item .grow { word-break: break-word; }
.x-btn { border: 0; background: transparent; color: var(--hint); width: 28px; height: 28px; border-radius: 50%; font-size: 18px; }

/* xabar ko'rinishi (direktda qanday chiqishi) */
.preview { margin-top: 12px; padding: 10px; border-radius: 14px; background: var(--bg); }
.preview .cap { font-size: 11px; color: var(--hint); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.bubble {
  max-width: 88%; background: var(--card); border-radius: 18px 18px 18px 6px; overflow: hidden;
  border: 1px solid var(--line);
}
.bubble .msg { padding: 10px 12px; white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.bubble .bbtn {
  border-top: 1px solid var(--line); padding: 9px; text-align: center; color: var(--link); font-weight: 600; font-size: 14px;
}

/* statistika voronkasi */
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 36px; gap: 8px; align-items: center; font-size: 13px; }
.bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar-row b { text-align: right; font-variant-numeric: tabular-nums; }

/* sozlamalar */
.admin { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.admin:last-child { border-bottom: 0; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700;
}
.id-box {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 20px; font-weight: 700; letter-spacing: .02em; font-variant-numeric: tabular-nums;
}

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 10;
  background: var(--text); color: var(--bg); padding: 12px 14px; border-radius: 12px; font-size: 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.2);
}
.error-box { color: var(--danger); background: var(--danger-soft); padding: 10px 12px; border-radius: 12px; margin-top: 10px; font-size: 14px; }

/* ---------- sayt rejimi (kompyuter brauzeri, Telegram'siz) ---------- */
html.web body { max-width: 920px; margin: 0 auto; padding: 24px 24px 48px; }
html.web .topbar h1 { font-size: 26px; }
.webback {
  border: 0; background: transparent; color: var(--link); font-weight: 600; padding: 4px 0; margin-bottom: 6px;
}
html.web .btn:hover, html.web .auto:hover, html.web .post:not(:disabled):hover { filter: brightness(.97); }
html.web .auto { cursor: pointer; }
@media (min-width: 760px) {
  html.web .list { grid-template-columns: 1fr 1fr; }
  html.web .grid { grid-template-columns: repeat(5, 1fr); }
  html.web .totals .total b { font-size: 28px; }
  html.web .flow { max-width: 680px; }
}
.login { min-height: 80vh; display: grid; place-items: center; }
.login .empty-state { max-width: 420px; width: 100%; padding: 36px 28px; }
.logo-badge {
  width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 12px; display: grid; place-items: center; color: #fff;
  background: radial-gradient(circle at 30% 107%, #fdf497 0%, #fd5949 45%, #d6249f 60%, #285aeb 90%);
}
.logo-badge svg { width: 32px; height: 32px; }
.tg-login { min-height: 48px; display: flex; justify-content: center; align-items: center; margin-top: 18px; }

/* saytda qorong'i rejim (Telegram ranglari bo'lmaganda) */
@media (prefers-color-scheme: dark) {
  html.web {
    --bg: #0f1115; --card: #1a1d23; --text: #e8eaed; --hint: #8b919c;
    --accent: #4c8dff; --accent-text: #fff; --link: #6ea2ff;
    --line: rgba(139, 145, 156, .22); --soft: rgba(76, 141, 255, .14);
  }
}
