/* Moomkin Socialbot dashboard — bitta qo'lda yozilgan CSS, framework yo'q.
   Qoida: accent = amallar, status ranglari = holatlar, hech qachon aralashmaydi. */

:root {
  --bg: #F8F7F5;
  --surface: #FFFFFF;
  --border: #E7E4E0;
  --ink: #1C1917;
  --ink-2: #78716C;
  --accent: #FF3355;
  --accent-ink: #FFFFFF;
  --accent-soft: #FFE7EC;
  --danger: #B91C1C;
  --ok: #15803D;
  /* status: text on tint */
  --st-new: #B45309;      --st-new-bg: #FEF3C7;
  --st-replied: #15803D;  --st-replied-bg: #DCFCE7;
  --st-filtered: #B91C1C; --st-filtered-bg: #FEE2E2;
  --st-skipped: #4B5563;  --st-skipped-bg: #F3F4F6;
  --st-error: #6D28D9;    --st-error-bg: #EDE9FE;
  --radius: 12px;
  --radius-s: 6px;
  --shadow: 0 1px 3px rgb(28 25 23 / 0.07);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; font-weight: 700; margin: 0 0 16px; }
h2 { font-size: 17px; font-weight: 600; margin: 0 0 12px; }
.muted { color: var(--ink-2); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ── Top strip ─────────────────────────────────────────────── */
.topstrip {
  display: flex; align-items: center; gap: 12px;
  height: 48px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; display: inline-flex; align-items: center; gap: 8px; }
.logomark { height: 1.35em; width: auto; vertical-align: -0.28em; }
.brand-lockup { display: inline-flex; align-items: center; gap: 8px; justify-content: center; }
.login-logo { height: 1.05em; width: auto; vertical-align: -0.16em; }
.page-title { color: var(--ink-2); flex: 1; }
.logout-form { margin: 0; }
.app-switch { margin: 0; }
.app-switch select {
  font: inherit; padding: 4px 8px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg); color: var(--ink);
  max-width: 220px;
}

/* ── Nav: desktop top bar / mobile bottom tabs ─────────────── */
.mainnav {
  display: flex; gap: 4px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 12px;
}
.mainnav a {
  display: flex; align-items: center; gap: 6px;
  padding: 12px 14px; min-height: 44px;
  color: var(--ink-2); font-weight: 500; text-decoration: none;
  border-bottom: 2px solid transparent; position: relative;
}
.mainnav a:hover { color: var(--ink); text-decoration: none; }
.mainnav a.active { color: var(--accent); border-bottom-color: var(--accent); }
.badge-count {
  background: var(--danger); color: #fff;
  font-size: 12px; font-weight: 600; line-height: 1;
  padding: 3px 7px; border-radius: 999px;
}
.badge-count.zero { display: none; }

.content { max-width: 1040px; margin: 0 auto; padding: 24px 16px 96px; }

@media (max-width: 767px) {
  .mainnav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    border-top: 1px solid var(--border); border-bottom: none;
    padding: 0; justify-content: space-around;
  }
  .mainnav a {
    flex-direction: column; gap: 2px; font-size: 11px;
    padding: 8px 4px; flex: 1; justify-content: center;
    border-bottom: none; border-top: 2px solid transparent;
  }
  .mainnav a.active { border-top-color: var(--accent); }
  .mainnav .ico { font-size: 18px; }
  .badge-count { position: absolute; top: 4px; right: 50%; transform: translateX(18px); }
  body { padding-bottom: 72px; }
}
@media (min-width: 768px) {
  .mainnav .ico { display: none; }
}

/* ── Cards / buttons ───────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 16px;
}
button, .btn-primary, .btn-ghost, .btn-danger {
  font: inherit; cursor: pointer; border-radius: var(--radius-s);
  min-height: 40px; padding: 8px 16px; border: 1px solid transparent;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { filter: brightness(0.95); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--ink); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: var(--surface); border-color: var(--st-filtered); color: var(--danger); }
.btn-sm { min-height: 32px; padding: 4px 12px; font-size: 13px; }
@media (max-width: 767px) { button, .btn-primary, .btn-ghost, .btn-danger { min-height: 44px; } }
/* Loading state (set by /static/forms.js on submit until the request settles). */
button.is-loading { pointer-events: none; opacity: 0.75; }
button.is-loading::before {
  content: ""; display: inline-block; width: 12px; height: 12px;
  margin-right: 7px; vertical-align: -1px;
  border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%; animation: btnspin 0.6s linear infinite;
}
@keyframes btnspin { to { transform: rotate(360deg); } }
/* Self-service channel connect (Kanallar) */
.connect-list { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; margin-top: 4px; }
.connect-btn { text-decoration: none; display: inline-block; }

/* ── Status badges ─────────────────────────────────────────── */
.badge {
  display: inline-block; font-size: 12px; font-weight: 600;
  padding: 4px 8px; border-radius: 999px; white-space: nowrap;
}
.badge.st-new      { color: var(--st-new);      background: var(--st-new-bg); }
.badge.st-replied  { color: var(--st-replied);  background: var(--st-replied-bg); }
.badge.st-filtered { color: var(--st-filtered); background: var(--st-filtered-bg); }
.badge.st-skipped  { color: var(--st-skipped);  background: var(--st-skipped-bg); }
.badge.st-error    { color: var(--st-error);    background: var(--st-error-bg); }

/* ── Login page ────────────────────────────────────────────── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 32px; width: min(360px, 90vw);
}
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card label { display: block; margin: 16px 0 6px; font-weight: 500; }
.login-card input {
  width: 100%; font: inherit; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-s);
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.login-card .btn-primary { width: 100%; margin-top: 16px; }
.login-error {
  color: var(--danger); background: var(--st-filtered-bg);
  padding: 8px 12px; border-radius: var(--radius-s); font-size: 14px;
}

/* ── Toast ─────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 50; padding: 10px 20px; border-radius: 999px;
  font-weight: 500; box-shadow: 0 4px 12px rgb(28 25 23 / 0.2);
}
#toast.good { background: var(--ink); color: #fff; }
#toast.bad { background: var(--danger); color: #fff; }
@media (max-width: 767px) { #toast { bottom: 84px; } }

/* ── Forms ─────────────────────────────────────────────────── */
textarea {
  width: 100%; font: inherit; line-height: 1.6;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-s);
  resize: vertical;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

/* HTMX loading holati */
.htmx-request { opacity: 0.5; transition: opacity 150ms; }

/* ── KPI kartalar ──────────────────────────────────────────── */
.kpi-grid {
  display: grid; gap: 12px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.kpi { display: flex; flex-direction: column; gap: 4px; margin-bottom: 0; color: inherit; }
a.kpi:hover { text-decoration: none; border-color: var(--accent); }
.kpi-alert { border-left: 4px solid var(--danger); }
.kpi-label { font-size: 13px; color: var(--ink-2); }
.kpi-num { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi-num.danger { color: var(--danger); }
.kpi-small { font-size: 14px; font-weight: 500; color: var(--ink-2); }
.kpi-sub { font-size: 13px; color: var(--ink-2); }
.gauge { display: block; height: 6px; background: var(--st-skipped-bg); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.gauge-fill { display: block; height: 100%; background: var(--ok); border-radius: 999px; }
.gauge-fill.amber { background: var(--st-new); }
.gauge-fill.red { background: var(--danger); }

/* ── Grafiklar ─────────────────────────────────────────────── */
.chart-pair { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
@media (max-width: 767px) { .chart-pair { grid-template-columns: 1fr; } }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; font-size: 13px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; }

/* ── Faoliyat lentasi ──────────────────────────────────────── */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.feed li:last-child { border-bottom: none; }
.feed-author { font-weight: 600; white-space: nowrap; }
.feed-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.feed-time { font-size: 12px; color: var(--ink-2); white-space: nowrap; }
@media (max-width: 767px) { .feed-time { display: none; } }

/* ── Filtr paneli ──────────────────────────────────────────── */
.filterbar {
  position: sticky; top: 48px; z-index: 10;
  background: var(--bg); padding: 8px 0 12px; margin-bottom: 8px;
}
.pills { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.pills::-webkit-scrollbar { display: none; }
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 8px 14px; border-radius: 999px; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--ink); font-size: 14px; font-weight: 500;
}
.pill small { color: var(--ink-2); font-size: 12px; }
.pill:hover { text-decoration: none; border-color: var(--accent); }
.pill.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.pill.active small { color: var(--accent); }
.filter-form { display: flex; gap: 8px; }
.filter-form input[type="search"] {
  flex: 1; font: inherit; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-s); background: var(--surface);
}
.filter-form select {
  font: inherit; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-s); background: var(--surface);
}

/* ── Izoh qatorlari ────────────────────────────────────────── */
.comment-row {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 8px;
  cursor: pointer;
  display: flex; gap: 12px; align-items: flex-start;
}
.comment-row:hover { border-color: var(--accent); }
/* Videos page: whole card toggles its detail (matches the comments UX). */
.video-card { cursor: pointer; }
.video-detail { display: none; margin-top: 10px; }
.video-card.open .video-detail { display: block; }
.video-title-text { font-weight: 600; }
.analyzing { display: none; }
.video-card.htmx-request .analyzing { display: inline; }
.video-card.htmx-request .btn-reanalyze { display: none; }
/* Admin (human) reply markers. */
.badge-admin { color: #0E7490; background: #CFFAFE; }
.reply-admin { border-left-color: #0E7490; background: #ECFEFF; }
/* Thread conversation in the comment detail. */
.held-head { display: flex; gap: 12px; align-items: flex-start; }
.badge-followup { color: #1D4ED8; background: #DBEAFE; }
/* Platform chip (which network the comment came from). */
.badge-platform { color: var(--fg-muted); background: var(--st-skipped-bg); font-weight: 500; }
.thread { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.thread-label { margin: 10px 0 2px; font-weight: 600; }
.thread-msg { padding: 8px 12px; border-radius: 10px; max-width: 92%; }
.thread-msg p { margin: 0; white-space: pre-wrap; }
.thread-who { font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 2px; }
.thread-user { background: #F3F4F6; align-self: flex-start; }
.thread-reply { background: #DCFCE7; align-self: flex-end; }
.thread-admin { background: #ECFEFF; }
.row-body { flex: 1; min-width: 0; }  /* min-width:0 → text clamp works inside flex */
.row-thumb {
  position: relative; flex-shrink: 0; display: block;
  width: 112px; height: 63px; border-radius: var(--radius-s);
  overflow: hidden; background: var(--st-skipped-bg);
}
.row-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Instagram/Facebook posts are vertical (9:16 reels, 4:5 photos): portrait box +
   contain so the whole image is shown, never cropped. YouTube stays 16:9 cover. */
.row-thumb-portrait { width: 72px; height: 128px; }
.row-thumb-portrait img { object-fit: contain; background: var(--st-skipped-bg); }
@media (max-width: 767px) { .row-thumb-portrait { width: 56px; height: 100px; } }
/* Placeholder when a platform has no derivable thumbnail (e.g. Instagram). */
.row-thumb .thumb-ph {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: var(--fg-muted); background: var(--st-skipped-bg);
}
.row-thumb .play {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 20px; text-shadow: 0 1px 4px rgb(0 0 0 / 0.7); opacity: 0.9;
}
.row-thumb:hover .play { opacity: 1; }
@media (max-width: 767px) { .row-thumb { width: 88px; height: 50px; } }
.row-line1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-author { font-weight: 600; }
.row-time { margin-left: auto; font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.row-text {
  margin: 6px 0 4px; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.row-meta { font-size: 13px; color: var(--ink-2); margin: 4px 0 0; }
.load-more { display: block; width: 100%; margin-top: 8px; }
.list-end { text-align: center; padding: 12px; }

/* ── Detal paneli ──────────────────────────────────────────── */
.detail { background: var(--bg); margin: -4px 0 8px; }
.detail-text { white-space: pre-wrap; margin-top: 0; }
.detail-label { margin: 14px 0 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.detail-label:first-child { margin-top: 0; }
.detail-note { padding: 8px 12px; background: var(--st-replied-bg); border-left: 3px solid var(--accent); border-radius: var(--radius-s); }
.detail-desc { color: var(--muted); font-size: 13px; }
.reply-quote {
  margin: 8px 0; padding: 8px 12px;
  background: var(--st-replied-bg); border-left: 3px solid var(--st-replied);
  border-radius: var(--radius-s);
}
.reply-quote p { margin: 0 0 4px; }
.reply-quote footer { font-size: 12px; }
.detail-actions { display: flex; align-items: center; gap: 16px; margin-top: 8px; }

/* ── Video kartalar ────────────────────────────────────────── */
.video-title { font-weight: 600; color: var(--ink); }
.video-title:hover { color: var(--accent); }
.video-summary { margin: 8px 0; font-size: 14px; color: var(--ink-2); }
.video-summary summary { cursor: pointer; list-style: none; }
.video-summary[open] summary { display: none; }
.video-summary p { white-space: pre-wrap; }
.held-note { color: var(--danger); }

/* ── Kutish navbati ────────────────────────────────────────── */
.queue-sub { margin-top: -8px; }
.held-card { border-left: 3px solid var(--st-filtered); }
.held-card.held-error { border-left-color: var(--st-error); }
.held-text { white-space: pre-wrap; margin: 8px 0; }
.actions { display: flex; gap: 8px; margin-top: 12px; }
.reply-open { flex-direction: column; align-items: stretch; }
.reply-open form { display: flex; flex-direction: column; gap: 6px; }
.form-actions { display: flex; gap: 8px; }
.form-error {
  color: var(--danger); background: var(--st-filtered-bg);
  padding: 8px 12px; border-radius: var(--radius-s); font-size: 14px; margin: 0 0 4px;
}
@media (max-width: 767px) {
  .form-actions { flex-direction: column; }
  .form-actions button { width: 100%; }
}
.held-stub {
  background: var(--st-replied-bg); color: var(--st-replied);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 8px;
  font-weight: 500; overflow: hidden;
  animation: stub-collapse 4s ease forwards;
}
@keyframes stub-collapse {
  0%, 70% { opacity: 1; max-height: 60px; }
  100% { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; margin-bottom: 0; }
}
.empty-emoji { font-size: 48px; margin: 0; }

/* ── Sozlamalar ────────────────────────────────────────────── */
.settings-card { max-width: 720px; }
.warn-banner {
  background: var(--st-new-bg); color: var(--st-new);
  padding: 10px 14px; border-radius: var(--radius-s);
  font-size: 14px; margin-bottom: 12px;
}
.settings-card textarea { min-height: 320px; }
.settings-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }

/* ── Bo'sh holatlar ────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 16px; color: var(--ink-2); }
.empty-state.big { font-size: 17px; }

/* DM inbox (Xabarlar) — fills the viewport; each pane scrolls on its own. */
.content-flush{max-width:none;padding:12px 16px;height:calc(100dvh - 96px);box-sizing:border-box}
.dm-wrap{display:grid;grid-template-columns:320px 1fr;gap:16px;align-items:stretch;height:100%;min-height:0}
.dm-list{display:flex;flex-direction:column;gap:8px;height:100%;min-height:0;overflow-y:auto;padding-right:4px}
.dm-conv{display:block;padding:10px 12px;border:1px solid var(--border);border-radius:10px;text-decoration:none;color:inherit;background:var(--card)}
.dm-conv,.dm-conv:hover{text-decoration:none}
.dm-conv:hover{border-color:var(--accent)}
.dm-conv.dm-active{border-color:var(--accent);box-shadow:0 0 0 1px var(--accent)}
.dm-conv-line{display:flex;align-items:center;gap:6px;flex-wrap:wrap}
.dm-preview{margin:4px 0 2px;color:var(--muted);font-size:.9em}
.dm-thread-pane{padding:16px;display:flex;flex-direction:column;height:100%;min-height:0;overflow:hidden}
.dm-head{display:flex;align-items:center;gap:8px;padding-bottom:10px;border-bottom:1px solid var(--border);margin-bottom:12px}
.dm-messages{display:flex;flex-direction:column;gap:8px;flex:1;overflow-y:auto;min-height:0}
@media (max-width:767px){
  .content-flush{height:calc(100dvh - 120px)}
  .dm-wrap{grid-template-columns:1fr;grid-template-rows:40vh 1fr}
}
.dm-msg{max-width:75%;padding:8px 12px;border-radius:12px}
.dm-msg p{margin:0;white-space:pre-wrap}
.dm-in{align-self:flex-start;background:var(--border)}
.dm-out{align-self:flex-end;background:var(--accent);color:#fff}
.dm-time{display:block;font-size:.72em;opacity:.7;margin-top:2px}
.dm-resume{display:flex;gap:10px;align-items:center;flex-wrap:wrap;margin-top:12px;padding:10px 12px;background:var(--card-alt,rgba(127,127,127,.08));border:1px solid var(--border);border-radius:8px}
.dm-resume .muted{font-size:.85em}
.dm-resume button{margin-left:auto;white-space:nowrap}
.dm-reply{display:flex;gap:8px;margin-top:12px}
.dm-reply textarea{flex:1;resize:vertical}
.dm-empty,.dm-note{margin:auto;text-align:center}
.badge.dm-st-open,.badge.dm-st-clarifying,.badge.dm-st-held,.badge.dm-st-closed{color:#fff}
.badge.dm-st-open{background:#2b7a2b}.badge.dm-st-clarifying{background:#b8860b}
.badge.dm-st-held{background:#a33}.badge.dm-st-closed{background:#555}
.dm-conv-foot{display:flex;justify-content:space-between;align-items:center;gap:8px;flex-wrap:wrap}
.dm-cost{font-size:.75em;color:var(--muted);white-space:nowrap}
.dm-cost-total{margin-left:auto;font-weight:600}
.dm-summary{margin:0 0 10px;padding:8px 12px;background:var(--card-alt,rgba(127,127,127,.08));border:1px solid var(--border);border-radius:8px}
.dm-summary>summary{cursor:pointer;font-size:.85em;color:var(--muted);font-weight:600}
.dm-summary-text{margin:8px 0 0;white-space:pre-wrap;font-size:.9em}

/* Leadlar jadvali */
.table-wrap{overflow-x:auto}
.leads-table{width:100%;border-collapse:collapse;font-size:14px}
.leads-table th,.leads-table td{text-align:left;padding:10px 12px;border-bottom:1px solid var(--border);white-space:nowrap}
.leads-table th{color:var(--muted);font-weight:600}
.leads-table tr:hover td{background:var(--card)}
.dm-who{display:block;font-size:.7em;font-weight:600;opacity:.85;margin-bottom:2px}
.dm-out .dm-who{color:#fff}
.badge.dm-st-human{background:#1e6fb8;color:#fff}

.cost-filter{display:flex;gap:16px;align-items:end;flex-wrap:wrap;margin-bottom:16px}
.cost-filter label{display:flex;flex-direction:column;gap:4px;font-size:13px;color:var(--muted,#555)}
.cost-filter input[type=date]{padding:8px;border:1px solid #ddd;border-radius:8px}
.section-h{margin:24px 0 8px;font-size:16px}

.dm-media-img{max-width:220px;max-height:260px;border-radius:10px;display:block;margin-bottom:4px}
.dm-media-label{font-style:italic;opacity:.85;margin:0 0 4px}

.dm-audio{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-bottom:4px}
.dm-audio audio{height:34px;max-width:220px}
.dm-speed{display:inline-flex;gap:4px}
.dm-speed button{font-size:11px;padding:2px 7px;border:1px solid #d0d0d7;background:#fff;border-radius:999px;cursor:pointer;color:#444;line-height:1.4}
.dm-speed button.active{background:#2563eb;border-color:#2563eb;color:#fff}
.dm-media-video{max-width:240px;max-height:280px;border-radius:10px;display:block;margin-bottom:4px}
