/* ── Self-hosted Persian font ─────────────────────────────────────────────
 * Single variable woff2 (108 KB) covers weights 100..900. Self-hosted to
 * avoid the slow/unreliable cdn.fontcdn.ir which was taking 3-6 s to
 * resolve over Iran network. Files live under /fonts/ on the same origin.
 * `font-display: swap` lets the page render in fallback fonts immediately
 * and swap when the Vazirmatn file lands. */
@font-face {
  font-family: "Vazirmatn";
  src: url("/fonts/Vazirmatn-Variable.woff2") format("woff2-variations"),
       url("/fonts/Vazirmatn-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ─────────────────────────────────────────────────────────────────────────
 * Postomatic — design system
 *
 * Two surfaces share these tokens:
 *   • the public landing page (web/landing.html)
 *   • the app SPA           (web/app.html  + web/app.js)
 *
 * Tokens are intentionally tight (one accent, one success, one warn,
 * one danger) so any user-supplied brand colour stands out.
 * ──────────────────────────────────────────────────────────────────────── */

:root {
  /* base palette */
  --bg:           #0a0f1f;
  --bg-2:         #0e1530;
  --surface:      rgba(255,255,255,0.045);
  --surface-2:    rgba(255,255,255,0.07);
  --surface-3:    rgba(255,255,255,0.10);
  --line:         rgba(255,255,255,0.10);
  --line-2:       rgba(255,255,255,0.16);
  --fg:           #e8eef9;
  --fg-2:         #c2cce0;
  --muted:        #8b97b1;
  --muted-2:      #6b7794;

  /* accent + status */
  --primary:      #7c5cff;
  --primary-2:    #22d3ee;
  --primary-soft: rgba(124,92,255,0.16);
  --primary-deep: rgba(124,92,255,0.32);
  --success:      #10b981;
  --warn:         #f59e0b;
  --danger:       #ef4444;
  --info:         #38bdf8;

  /* radii / spacing scale (4-px rhythm) */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-pill: 999px;

  /* type scale */
  --t-xs: 11px;
  --t-sm: 13px;
  --t-md: 15px;
  --t-lg: 18px;
  --t-xl: 22px;
  --t-2xl: 28px;
  --t-3xl: 38px;
  --t-4xl: 52px;

  /* elevation */
  --sh-1: 0 2px 8px rgba(0,0,0,0.18);
  --sh-2: 0 8px 28px rgba(0,0,0,0.32);
  --sh-3: 0 24px 64px rgba(0,0,0,0.45);
  --sh-glow: 0 0 0 1px rgba(124,92,255,0.32), 0 12px 40px rgba(124,92,255,0.18);

  /* motion */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --d-fast: 120ms;
  --d-med:  220ms;
  --d-slow: 420ms;

  /* Layout heights — used by sticky elements so brand-tabs / sub-nav
   * can pin themselves under the topbar without overlap. */
  --topbar-h: 56px;
  --bottombar-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Reset + base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { direction: rtl; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(124,92,255,0.18) 0%, transparent 60%),
    radial-gradient(900px 600px at 10% 110%, rgba(34,211,238,0.10) 0%, transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, "Vazirmatn", "Segoe UI", Tahoma, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  line-height: 1.6;
  /* Smooth momentum scrolling. Note: NO `overscroll-behavior: none`
   * here — that combined with the horizontal clip below was breaking
   * vertical scroll on iOS Safari. Sticky topbar handles the rubber-
   * band behavior fine on its own. */
  -webkit-overflow-scrolling: touch;
}
/* Hard horizontal clamp on the document, not the body, so the body
 * still scrolls vertically. `overflow-x: clip` is the right primitive
 * here: it clips overflow without establishing a new scroll container,
 * which is what `overflow-x: hidden` was doing (and what was making
 * the page un-scrollable on phones). */
html { overflow-x: clip; }
/* Flex/grid descendants default to `min-width: auto`, which means a
 * single long string can blow the entire flex line wider than its
 * container. Force them to honor their parent width — the cure for
 * "h1 with long Persian title overflowing the card" and similar bugs. */
.brand-head, .list-item, .topbar, .row, .field, .card, main, .layout {
  min-width: 0;
}
.brand-head > *, .list-item > *, .topbar > *, .row > *, .field > * {
  min-width: 0;
}
/* Long URLs / brand names break onto the next line instead of escaping
 * their container. */
.h1, .h2, .h3, .meta, .muted, .muted-2, .label, .help, .bubble, p {
  word-break: break-word;
  overflow-wrap: anywhere;
}
/* Native-feeling taps everywhere: kill the ugly grey square on iOS,
 * keep keyboard focus visible for accessibility. */
a, button, [role="button"], .list-item, .tab, .step .num, .chip {
  -webkit-tap-highlight-color: transparent;
}
a, button, [role="button"], .list-item, .tab {
  touch-action: manipulation; /* removes the 300ms tap delay on legacy WebViews */
}
a       { color: var(--primary); text-decoration: none; }
a:hover { color: var(--fg); }
button  { font-family: inherit; }
img     { max-width: 100%; display: block; }
/* Anchor links and hash routing land at top — leave room for sticky topbar. */
html { scroll-padding-top: calc(var(--topbar-h) + 8px); }

/* ── Typography ───────────────────────────────────────────────────────── */
.h1 { font-size: var(--t-2xl); font-weight: 800; letter-spacing: -0.4px; margin: 0 0 12px; }
.h2 { font-size: var(--t-lg); font-weight: 700; margin: 0 0 8px; }
.h3 { font-size: var(--t-md); font-weight: 700; margin: 0 0 6px; }
.muted { color: var(--muted); font-size: var(--t-sm); }
.muted-2 { color: var(--muted-2); font-size: var(--t-xs); }
.lead { font-size: var(--t-md); color: var(--fg-2); }
.sep { height: 1px; background: var(--line); margin: 12px 0; }

/* ── Icons ────────────────────────────────────────────────────────────── */
/* All icons inherit currentColor and live inline with text. The default
 * size is 18px so they sit comfortably in buttons / nav rows. */
.ic    { width: 18px; height: 18px; flex-shrink: 0; vertical-align: -3px; display: inline-block; }
.ic-sm { width: 14px; height: 14px; flex-shrink: 0; vertical-align: -2px; display: inline-block; }
.ic-lg { width: 22px; height: 22px; flex-shrink: 0; vertical-align: -4px; display: inline-block; }
.ic-xl { width: 28px; height: 28px; flex-shrink: 0; display: inline-block; }
.ic-2xl{ width: 40px; height: 40px; flex-shrink: 0; display: inline-block; }

.btn .ic, .btn .ic-sm { stroke-width: 2; }
button:disabled .ic { opacity: 0.6; }

/* ── Logo ─────────────────────────────────────────────────────────────── */
.brand { font-weight: 800; font-size: var(--t-lg); letter-spacing: -0.5px;
  display: inline-flex; align-items: center; gap: 8px; }
.brand .dot { width: 12px; height: 12px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 0 14px rgba(124,92,255,0.5); }

/* ── App shell (auth'd SPA) ───────────────────────────────────────────── */
.app { display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; min-height: var(--topbar-h);
  background: rgba(10, 15, 31, 0.78); backdrop-filter: blur(14px); z-index: 6;
  /* iOS notch */
  padding-top: max(10px, env(safe-area-inset-top));
}
.topbar .right { display: flex; gap: 8px; align-items: center; min-width: 0; }
.topbar .brand { min-width: 0; flex-shrink: 1; }
.tag { font-size: var(--t-xs); padding: 3px 8px; border-radius: var(--r-pill);
  background: var(--primary-soft); color: #cbb8ff; }
/* Phone number / role tag: hide on small screens — keep just brand + logout. */
@media (max-width: 560px) {
  .topbar { padding-inline: 12px; }
  .topbar .topbar-phone { display: none; }
}

/* Layout: sidebar visible only on real desktop (≥1024px). On mobile +
 * tablet the bottom nav rules — fewer chrome pixels, every primary
 * action thumb-reachable. */
.layout { display: grid; grid-template-columns: 1fr; flex: 1; }
@media (min-width: 1024px) {
  .layout { grid-template-columns: 220px 1fr; }
}
@media (min-width: 1024px) and (max-width: 1280px) {
  .layout { grid-template-columns: 200px 1fr; }
}

.sidebar { display: none; }
@media (min-width: 1024px) {
  .sidebar { display: flex; flex-direction: column; gap: 4px;
    padding: 14px 12px; border-left: 1px solid var(--line);
    position: sticky; top: var(--topbar-h); align-self: flex-start;
    max-height: calc(100vh - var(--topbar-h));
    overflow-y: auto; }
}
.sidebar a { display: flex; gap: 10px; align-items: center; padding: 12px 14px;
  min-height: 44px;
  border-radius: var(--r-md); color: var(--muted); font-size: var(--t-sm);
  transition: background var(--d-fast), color var(--d-fast); }
.sidebar a:hover  { background: var(--surface); color: var(--fg); }
.sidebar a.active { background: var(--primary-soft); color: #fff; }

/* Bottom nav: shown for everything below desktop (mobile + tablet). */
.bottombar { display: none; }
@media (max-width: 1023px) {
  .bottombar {
    display: flex; justify-content: space-around; align-items: stretch;
    position: fixed; bottom: 0; left: 0; right: 0;
    padding: 6px 6px calc(6px + var(--safe-bottom));
    border-top: 1px solid var(--line);
    background: rgba(10, 15, 31, 0.95); backdrop-filter: blur(12px);
    z-index: 5;
    /* Subtle elevation away from content */
    box-shadow: 0 -4px 20px rgba(0,0,0,0.25);
  }
}
.bottombar a {
  flex: 1 1 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 8px 4px; min-height: 56px;
  color: var(--muted); font-size: 10px; text-align: center;
  border-radius: var(--r-md);
  transition: color var(--d-fast), background var(--d-fast), transform var(--d-fast);
}
.bottombar a:active { transform: scale(0.96); }
.bottombar a.active {
  color: #fff;
  background: var(--primary-soft);
}
.bottombar a > svg { width: 22px; height: 22px; }

main {
  /* `--main-pad-x` exposes the current horizontal padding so sticky
   * sub-bars (brand tabs, wizard actions) can use a matching negative
   * margin and stretch edge-to-edge without overflowing. */
  --main-pad-x: 24px;
  padding: 22px var(--main-pad-x);
  max-width: 980px; width: 100%; margin: 0 auto;
  flex: 1;
}
@media (max-width: 1023px) {
  /* Bottom nav (~64px + safe-area) needs space below; otherwise the
   * last list item or sticky CTA is hidden under it. */
  main {
    --main-pad-x: 14px;
    padding: 16px var(--main-pad-x) calc(var(--bottombar-h) + var(--safe-bottom) + 16px);
  }
}
@media (max-width: 560px) {
  main { --main-pad-x: 12px; }
}

/* ── Cards ────────────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 18px; box-shadow: var(--sh-2); }
.card.glass { background: rgba(255,255,255,0.05); backdrop-filter: blur(14px); }
.card.gradient {
  background: linear-gradient(135deg, rgba(124,92,255,0.18), rgba(34,211,238,0.08));
  border-color: rgba(124,92,255,0.35);
}
.card + .card { margin-top: 12px; }
/* Tappable card variant (clickable list of brands, channels, etc.). */
a.card, .card.tappable {
  cursor: pointer;
  transition: transform var(--d-fast), border-color var(--d-fast), background var(--d-fast);
}
a.card:hover, .card.tappable:hover { border-color: var(--line-2); }
a.card:active, .card.tappable:active { transform: scale(0.985); }
@media (max-width: 760px) {
  .card { padding: 14px; border-radius: var(--r-md); }
}

/* ── Forms ────────────────────────────────────────────────────────────── */
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 200px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.label { font-size: var(--t-sm); color: var(--muted); }
.help  { font-size: var(--t-xs); color: var(--muted-2); margin-top: 2px; }
.input, .textarea, .select {
  width: 100%; padding: 12px 14px; border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface-2); color: var(--fg);
  /* 16px on mobile prevents iOS Safari from auto-zooming on focus.
   * Down-sizes to var(--t-sm) on desktop where it's not needed. */
  font-size: 16px; font-family: inherit; outline: none;
  min-height: 44px;
  transition: border-color var(--d-fast), background var(--d-fast), box-shadow var(--d-fast);
}
@media (min-width: 1024px) {
  .input, .textarea, .select { font-size: var(--t-sm); }
}
.input:hover, .textarea:hover, .select:hover { border-color: var(--line-2); }
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--primary); background: rgba(124,92,255,0.06);
  box-shadow: 0 0 0 3px rgba(124,92,255,0.18);
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.7; }
.select { appearance: none; background-image:
  linear-gradient(45deg, transparent 50%, var(--muted) 50%),
  linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: left 14px center, left 9px center;
  background-size: 5px 5px; background-repeat: no-repeat; padding-left: 28px; }

.input.invalid, .textarea.invalid { border-color: var(--danger); }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn { display: inline-flex; gap: 8px; align-items: center; justify-content: center;
  padding: 11px 18px; border-radius: var(--r-md); border: 0; cursor: pointer;
  font-weight: 600; font-size: var(--t-sm); font-family: inherit;
  min-height: 44px;        /* HIG-compliant tap target */
  background: linear-gradient(135deg, var(--primary), #6048d6);
  color: #fff; transition: transform var(--d-fast), box-shadow var(--d-fast), opacity var(--d-fast), filter var(--d-fast);
  box-shadow: 0 6px 18px rgba(124,92,255,0.32);
  -webkit-tap-highlight-color: transparent;
}
.btn:hover    { box-shadow: 0 10px 24px rgba(124,92,255,0.42); }
.btn:active   { transform: scale(0.97); filter: brightness(0.95); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; transform: none; }
.btn.ghost    { background: var(--surface-2); color: var(--fg); box-shadow: none; border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--surface-3); }
.btn.outline  { background: transparent; color: var(--fg); border: 1px solid var(--line-2); box-shadow: none; }
.btn.danger   { background: linear-gradient(135deg, var(--danger), #b91c1c); box-shadow: 0 6px 18px rgba(239,68,68,0.32); }
.btn.success  { background: linear-gradient(135deg, var(--success), #059669); box-shadow: 0 6px 18px rgba(16,185,129,0.32); }
.btn.lg       { padding: 14px 26px; font-size: var(--t-md); border-radius: var(--r-lg); min-height: 52px; }
.btn.sm       { padding: 8px 12px; font-size: var(--t-xs); border-radius: var(--r-sm); min-height: 36px; }
.btn.icon     { padding: 0; width: 44px; height: 44px; }
.btn.full     { width: 100%; }

/* ── Lists / chips ────────────────────────────────────────────────────── */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 14px;
  min-height: 56px;                 /* comfortable tap row on mobile */
  border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--line);
  transition: border-color var(--d-fast), background var(--d-fast), transform var(--d-fast);
}
.list-item.tappable { cursor: pointer; }
.list-item.tappable:hover  { border-color: var(--line-2); background: var(--surface-3); }
.list-item.tappable:active { transform: scale(0.99); }
.list-item .meta { font-size: var(--t-xs); color: var(--muted); margin-top: 2px; }
@media (max-width: 560px) {
  /* On phones the right-side action chunk needs to wrap below the
   * primary text rather than getting truncated next to it. */
  .list-item { flex-wrap: wrap; }
  .list-item > * { min-width: 0; }
}

.chip { padding: 3px 10px; border-radius: var(--r-pill); font-size: var(--t-xs); font-weight: 600; }
.chip.draft     { background: rgba(148,163,184,.15); color: #cbd5e1; }
.chip.approved  { background: rgba(99,102,241,.15);  color: #c7d2fe; }
.chip.scheduled { background: rgba(245,158,11,.15);  color: #fcd34d; }
.chip.posted    { background: rgba(16,185,129,.15);  color: #6ee7b7; }
.chip.failed    { background: rgba(239,68,68,.15);   color: #fca5a5; }
.chip.admin     { background: rgba(124,92,255,.18);  color: #cbb8ff; }

/* ── Progress bar (file uploads, async work) ──────────────────────────── */
.progress {
  width: 100%; height: 8px; border-radius: var(--r-pill);
  background: var(--surface-2); overflow: hidden; border: 1px solid var(--line);
}
.progress > .bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  transition: width var(--d-fast) linear;
}
.progress-row { display: flex; align-items: center; gap: 12px; font-size: var(--t-xs); color: var(--muted); }
.progress-row .progress { flex: 1; }

/* ── Step indicator (used in onboarding wizards) ──────────────────────── */
.steps { display: flex; gap: 8px; align-items: center; margin: 0 0 24px; flex-wrap: wrap; }
.step { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 100px; }
.step .num { width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--line);
  display: grid; place-items: center; font-size: var(--t-xs); color: var(--muted);
  transition: all var(--d-med) var(--ease); flex-shrink: 0; }
.step .lbl { font-size: var(--t-xs); color: var(--muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.step.active .num { background: var(--primary); border-color: var(--primary);
  color: #fff; box-shadow: 0 0 0 4px var(--primary-soft); }
.step.active .lbl { color: var(--fg); font-weight: 600; }
.step.done .num   { background: var(--success); border-color: var(--success); color: #fff; }
.step.done .lbl   { color: var(--fg-2); }
.step .bar { flex: 1; height: 2px; background: var(--line); border-radius: 1px;
  margin: 0 4px; transition: background var(--d-med); }
.step.done .bar  { background: var(--success); }
@media (max-width: 760px) {
  .step .lbl { display: none; }
  .step      { min-width: auto; flex: 0 0 auto; }
  .steps     { gap: 4px; justify-content: center; }
}

.wizard-card { padding: 28px; }
.wizard-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 22px; }
@media (max-width: 1023px) {
  .wizard-card { padding: 18px 16px; }
  /* Sticky action bar — Back / Next stay glued to the bottom of the
   * viewport so the user never has to scroll to advance. Sits above
   * the bottom nav (variable + safe-area accounted for). */
  .wizard-actions {
    position: sticky;
    bottom: calc(var(--bottombar-h) + var(--safe-bottom));
    margin: 16px calc(var(--main-pad-x) * -1) 0;
    padding: 12px var(--main-pad-x);
    background: linear-gradient(180deg, transparent 0%, rgba(10,15,31,0.92) 30%, rgba(10,15,31,0.96) 100%);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
    z-index: 4;
  }
  .wizard-actions > .btn,
  .wizard-actions > a.btn { flex: 1; }
}

/* ── Brand-detail tabs ───────────────────────────────────────────────── */
.brand-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  flex-wrap: wrap; gap: 12px; margin-bottom: 12px;
}
/* The brand-info block must shrink instead of overflowing — that's
 * what was clipping the title in the screenshot. */
.brand-head > div:first-child {
  min-width: 0; flex: 1 1 0;
}
.brand-head > div:first-child .muted-2 {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
@media (max-width: 560px) {
  /* On phones, put the back link on top in compact form, then the big
   * brand title — keeps the title legible and the back action
   * thumb-reachable in the top-left corner of <main>. */
  .brand-head {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: 8px;
  }
  .brand-head > a.btn { align-self: flex-start; }
  .brand-head > div:first-child .h1 { font-size: var(--t-xl); }
}
.brand-tabs {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
  /* Sticky directly under the topbar so the user can switch tabs
   * without scrolling back up. The negative margin pulls the bar to
   * the edges of <main> — `--main-pad-x` is set per-breakpoint by
   * <main> so this always matches exactly, no overflow. */
  position: sticky;
  top: var(--topbar-h);
  z-index: 4;
  background: rgba(10, 15, 31, 0.92);
  backdrop-filter: blur(12px);
  margin-inline: calc(var(--main-pad-x) * -1);
  padding-inline: var(--main-pad-x);
}
.brand-tabs .tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 12px 16px;
  min-height: 44px;
  /* Reset user-agent button styling so <button class="tab"> looks the
   * same as <a class="tab">. Without these, browsers gave buttons a
   * grey border + white background — the "old form-control" look. */
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-family: inherit; font-size: var(--t-sm); color: var(--muted);
  text-decoration: none;
  transition: color var(--d-fast), border-color var(--d-fast);
  margin-bottom: -1px;
  white-space: nowrap;
}
.brand-tabs .tab:hover  { color: var(--fg); }
.brand-tabs .tab:active { transform: scale(0.97); }
.brand-tabs .tab.active {
  color: var(--fg); font-weight: 600;
  border-bottom-color: var(--primary);
}
/* Phones/tablets: scrolly horizontal pills with momentum + snap so the
 * active tab always settles centred. */
@media (max-width: 1023px) {
  .brand-tabs {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }
  .brand-tabs::-webkit-scrollbar { display: none; }
  .brand-tabs .tab { scroll-snap-align: center; padding: 12px 14px; }
}
@media (max-width: 560px) {
  .brand-tabs .tab { font-size: var(--t-xs); padding: 12px 12px; gap: 4px; }
}

/* ── Sub-tabs (segmented control) ─────────────────────────────────────────
 * Pill-shaped switcher used inside cards (post-creator Auto/URL/Free,
 * settings sub-screens, etc). Different from .brand-tabs: not sticky, not
 * a top-level nav — it's a local control rendered inline. Active segment
 * gets a filled gradient pill; inactive segments are quiet on a glassy
 * track. */
.sub-tabs {
  display: inline-flex;
  align-items: stretch;
  gap: 4px;
  padding: 4px;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  width: 100%;
  max-width: 560px;
}
.sub-tabs .tab {
  flex: 1 1 0;
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 9px 12px;
  min-height: 40px;
  background: transparent;
  border: 0;
  border-radius: var(--r-pill);
  color: var(--muted);
  font-family: inherit;
  font-size: var(--t-sm);
  font-weight: 500;
  cursor: pointer;
  transition: color var(--d-fast) var(--ease),
              background var(--d-fast) var(--ease),
              box-shadow var(--d-med) var(--ease),
              transform var(--d-fast) var(--ease);
  white-space: nowrap;
}
.sub-tabs .tab:hover  { color: var(--fg); background: var(--surface-2); }
.sub-tabs .tab:active { transform: scale(0.97); }
.sub-tabs .tab.active {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: var(--sh-glow);
  font-weight: 600;
}
.sub-tabs .tab.active:hover { color: #fff; }
/* Phone: tighten so 3 segments still fit on narrow screens */
@media (max-width: 560px) {
  .sub-tabs .tab { font-size: var(--t-xs); padding: 9px 6px; gap: 4px; }
}

/* ── Login screen (centered card) ─────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 400px; padding: 28px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--sh-3);
  backdrop-filter: blur(14px); }
.login-card h1 { margin: 0 0 6px; font-size: var(--t-xl); }
.login-card p  { margin: 0 0 18px; color: var(--muted); font-size: var(--t-sm); }
.dev-otp { margin-top: 12px; padding: 10px; border-radius: var(--r-md);
  background: rgba(245,158,11,.12); color: #fcd34d; font-size: var(--t-xs);
  text-align: center; border: 1px solid rgba(245,158,11,.24); }

/* ── Chat ─────────────────────────────────────────────────────────────── */
.chat-thread {
  display: flex; flex-direction: column; gap: 10px;
  max-height: 60vh; overflow: auto; padding: 10px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
@media (max-width: 1023px) {
  /* On mobile/tablet the chat takes the whole content area; the input
   * row lives below in a sticky position so the user always sees both
   * the latest reply and the keyboard launcher. */
  .chat-thread {
    max-height: calc(100vh - var(--topbar-h) - var(--bottombar-h) - var(--safe-bottom) - 200px);
    min-height: 280px;
  }
}
.bubble { padding: 11px 14px; border-radius: var(--r-lg); max-width: 80%;
  line-height: 1.7; font-size: var(--t-sm); white-space: pre-wrap;
  border: 1px solid var(--line); }
.bubble.user      { align-self: flex-start;
  background: linear-gradient(135deg, var(--primary-soft), rgba(34,211,238,.06));
  border-color: rgba(124,92,255,0.3); }
.bubble.assistant { align-self: flex-end;
  background: var(--surface-2); }
@media (max-width: 560px) {
  .bubble { max-width: 92%; font-size: var(--t-md); }
}

/* ── Modal ────────────────────────────────────────────────────────────── */
/* The modal has to behave like a sheet on mobile (full width, slides
 * from the bottom) and a centered card on desktop. The two key fixes
 * over the v1 styling:
 *   • max-height + overflow-y so a long body (e.g. an LLM report) scrolls
 *     inside the card instead of pushing the close button off-screen
 *   • position-relative + absolute close button so the title can wrap
 *     freely without colliding with the float'd ×
 *   • mobile media-query that lets the modal occupy the full-width
 *     bottom of the viewport for thumb-reachable controls. */
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 16px;
  animation: fade-in var(--d-med) var(--ease);
  overflow-y: auto;
}
.modal {
  position: relative;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-xl);
  padding: 24px 22px;
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: var(--sh-3);
  animation: slide-up var(--d-med) var(--ease);
  /* Tone down the scrollbar so it doesn't fight the dark theme. */
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
}
.modal::-webkit-scrollbar         { width: 8px; }
.modal::-webkit-scrollbar-thumb   { background: var(--line-2); border-radius: 4px; }
.modal::-webkit-scrollbar-track   { background: transparent; }

.modal h3 {
  margin: 0 0 12px;
  font-size: var(--t-md);
  /* Reserve space on the LEFT for the absolute-positioned close button
   * (RTL reads right-to-left, so the icon belongs in the top-left). */
  padding-left: 32px;
  line-height: 1.5;
}
.modal .close {
  position: absolute;
  top: 14px; left: 14px;
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  border-radius: var(--r-pill);
  font-size: var(--t-xl); line-height: 1;
  color: var(--muted);
  transition: background var(--d-fast), color var(--d-fast);
  user-select: none;
}
.modal .close:hover { background: var(--surface-2); color: var(--fg); }

.modal ul { padding-inline-start: 18px; margin: 6px 0 12px; }
.modal ul li { margin: 4px 0; line-height: 1.7; }
.modal p     { line-height: 1.8; }

@media (max-width: 560px) {
  .modal-bg { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    max-height: 92vh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  }
  .modal .close { top: 10px; left: 10px; }
}

/* ── Toast ────────────────────────────────────────────────────────────── */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--surface-3); border: 1px solid var(--line);
  padding: 10px 18px; border-radius: var(--r-md); font-size: var(--t-sm);
  box-shadow: var(--sh-2); z-index: 100; animation: toast-in var(--d-med) var(--ease);
  backdrop-filter: blur(12px); }
.toast.error   { background: rgba(239,68,68,.20);  color: #fecaca; border-color: rgba(239,68,68,.4); }
.toast.success { background: rgba(16,185,129,.20); color: #a7f3d0; border-color: rgba(16,185,129,.4); }

/* ── Animations ───────────────────────────────────────────────────────── */
@keyframes fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slide-in-rtl { from { opacity: 0; transform: translateX(-12px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes spin { to { transform: rotate(360deg); } }

.fade-in  { animation: fade-in  var(--d-med) var(--ease); }
.slide-up { animation: slide-up var(--d-med) var(--ease); }
.spinner  { width: 18px; height: 18px; border: 2px solid var(--line);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 700ms linear infinite; display: inline-block; }

/* Subtle native-app feel: every direct child of <main> slides in when
 * the route changes. Keeps the page lively without being distracting. */
main > * { animation: slide-in-rtl var(--d-med) var(--ease); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* Mobile typography — slightly smaller h1/h2 so titles don't dominate
 * the viewport; main reading copy stays at 16px for readability. */
@media (max-width: 560px) {
  .h1 { font-size: var(--t-xl); }
  .h2 { font-size: var(--t-md); }
}

/* Sticky bottom CTA — anywhere we want a single primary action glued
 * to the viewport bottom (e.g. "ساخت پست" inside calendar). */
.sticky-cta {
  position: sticky;
  bottom: calc(var(--bottombar-h) + var(--safe-bottom));
  margin: 14px calc(var(--main-pad-x) * -1) 0;
  padding: 12px var(--main-pad-x);
  background: linear-gradient(180deg, transparent 0%, rgba(10,15,31,0.92) 40%, rgba(10,15,31,0.96) 100%);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  z-index: 4;
}
@media (min-width: 1024px) {
  .sticky-cta {
    position: static; background: none; backdrop-filter: none; border: 0;
    padding: 0; margin: 14px 0 0;
  }
}

/* ── Utility ──────────────────────────────────────────────────────────── */
.text-center { text-align: center; }
.flex        { display: flex; }
.flex-col    { display: flex; flex-direction: column; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }
