@font-face {
  font-family: 'Vazirmatn';
  src: url('../fonts/Vazirmatn-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1c1f24;
  --muted: #6b7280;
  --border: #e3e6ea;
  --primary: #1f5eff;
  --primary-ink: #ffffff;
  --danger: #d93636;
  --warn: #b7791f;
  --ok: #178a4c;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 2px 8px rgb(0 0 0 / 4%);
  --radius: 14px;
  --c-bale: #1db38b;
  --c-eitaa: #ef7f1a;
  --c-telegram: #229ed9;
  --c-whatsapp: #1faa53;
  --nav-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #20242c;
    --text: #e8eaee;
    --muted: #9aa3af;
    --border: #2a2f38;
    --primary: #5b8cff;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --surface: #181b21; --surface-2: #20242c; --text: #e8eaee; --muted: #9aa3af; --border: #2a2f38; --primary: #5b8cff; --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Vazirmatn', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.7;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--primary); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 17px; margin: 0; flex: 1; font-weight: 700; }
.topbar .back { border: 0; background: none; font-size: 22px; padding: 0 4px; cursor: pointer; }

main { max-width: 720px; margin: 0 auto; padding: 12px 16px 24px; }

.nav {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 12px;
}
.nav a svg { width: 24px; height: 24px; }
.nav a.active { color: var(--primary); font-weight: 600; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px;
}
.card h2 { font-size: 15px; margin: 0 0 10px; }
.card h3 { font-size: 14px; margin: 12px 0 6px; }

label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type="text"], input[type="password"], input[type="number"], input[type="search"], input[type="tel"], textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 140px; line-height: 1.8; }
.ltr { direction: ltr; text-align: left; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer; font-weight: 500; text-decoration: none; color: var(--text);
  min-height: 40px;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; min-height: 32px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.wa { background: var(--c-whatsapp); border-color: var(--c-whatsapp); color: #fff; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.hidden { display: none !important; }

.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap;
}
.chip.sent { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.chip.failed { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.chip.pending, .chip.retry, .chip.queued, .chip.scheduled, .chip.sending { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.chip.partial { color: var(--warn); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot.bale { background: var(--c-bale); } .dot.eitaa { background: var(--c-eitaa); }
.dot.telegram { background: var(--c-telegram); } .dot.whatsapp { background: var(--c-whatsapp); }

.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 0 0 10px; padding-bottom: 2px; scrollbar-width: none; }
.tabs button {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 5px 12px;
  cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
}
.tabs button.active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.tabs button .mark { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.counter { font-size: 12px; color: var(--muted); text-align: left; direction: ltr; }
.counter.over { color: var(--danger); font-weight: 700; }
.counter.near { color: var(--warn); }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-bottom: 8px; }
.media-item { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.media-item img, .media-item video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-item .doc { display: flex; align-items: center; justify-content: center; height: 100%; padding: 6px; font-size: 11px; text-align: center; word-break: break-all; }
.media-item .x, .media-item .mv {
  position: absolute; top: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0;
  background: rgb(0 0 0 / 60%); color: #fff; cursor: pointer; font-size: 14px; line-height: 26px; padding: 0;
}
.media-item .x { inset-inline-start: 4px; }
.media-item .mv { inset-inline-end: 4px; }
.media-item .size { position: absolute; bottom: 4px; inset-inline-start: 4px; font-size: 10px; background: rgb(0 0 0 / 60%); color: #fff; border-radius: 6px; padding: 0 5px; direction: ltr; }
.media-item.uploading { display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--muted); }
.drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 14px; text-align: center; cursor: pointer; color: var(--muted); }

.checklist { display: grid; gap: 6px; }
.check {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); cursor: pointer;
}
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.check .sub { color: var(--muted); font-size: 12px; direction: ltr; }
.sig-toggle { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.switch input { width: 18px; height: 18px; accent-color: var(--primary); margin: 0; }
label.field > span.group-title { color: var(--text); margin-top: 4px; }
.sig-input { min-height: 72px; }
/* ردیف‌های ورودی + دکمه: ورودی جای باقی‌مانده را بگیرد و دکمه‌ها کنارش بمانند */
.row > input:not([type="checkbox"]):not([type="radio"]) { flex: 1 1 180px; width: auto; min-width: 0; }
.group-title { align-items: center; gap: 6px; font-weight: 600; font-size: 13px; margin: 10px 0 4px; }

.warnings { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.warnings li { padding: 8px 10px; border-radius: 10px; font-size: 13px; }
.warnings li.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.warnings li.warn { background: color-mix(in srgb, var(--warn) 12%, transparent); color: var(--warn); }

.preview { border-radius: 12px; padding: 10px; background: var(--surface-2); }
.bubble {
  max-width: 92%; background: var(--surface); border-radius: 12px; padding: 6px; box-shadow: var(--shadow);
  border: 1px solid var(--border); white-space: pre-wrap; word-wrap: break-word; overflow: hidden;
}
.bubble .pm { display: grid; gap: 2px; grid-template-columns: repeat(2, 1fr); margin: -6px -6px 6px; }
.bubble .pm.one { grid-template-columns: 1fr; }
.bubble .pm img, .bubble .pm video { width: 100%; max-height: 260px; object-fit: cover; display: block; }
.bubble .pm .doc { padding: 10px; background: var(--surface-2); font-size: 12px; }
.bubble .txt { padding: 0 4px; }
.bubble .txt .sig { color: var(--muted); }
.bubble + .bubble { margin-top: 6px; }
.preview.telegram { background: color-mix(in srgb, var(--c-telegram) 10%, var(--surface-2)); }
.preview.bale { background: color-mix(in srgb, var(--c-bale) 10%, var(--surface-2)); }
.preview.eitaa { background: color-mix(in srgb, var(--c-eitaa) 10%, var(--surface-2)); }
.preview.whatsapp { background: color-mix(in srgb, var(--c-whatsapp) 10%, var(--surface-2)); }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--surface-2); padding: 7px 14px; cursor: pointer; }
.seg button.active { background: var(--primary); color: var(--primary-ink); }

.post-item { display: block; color: inherit; text-decoration: none; }
.post-item .body { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; margin: 4px 0 8px; }
.post-item .thumbs { display: flex; gap: 4px; margin-bottom: 6px; }
.post-item .thumbs img, .post-item .thumbs .t { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-size: 10px; }

.delivery { border-top: 1px solid var(--border); padding: 10px 0; }
.delivery:first-of-type { border-top: 0; }
.delivery .err { color: var(--danger); font-size: 13px; margin-top: 4px; word-break: break-word; }
.delivery details { font-size: 12px; color: var(--muted); margin-top: 4px; }
.delivery details li { margin: 2px 0; }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filters .full { grid-column: 1 / -1; }

.toast {
  position: fixed; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); inset-inline: 16px; z-index: 50;
  margin: 0 auto; max-width: 480px; padding: 10px 14px; border-radius: 12px; background: #222; color: #fff;
  box-shadow: 0 4px 16px rgb(0 0 0 / 25%); font-size: 14px; animation: rise .2s ease-out;
}
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } }

body.no-nav { padding-bottom: 0; padding-inline-start: 0; }
.login { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.login .card { width: 100%; max-width: 380px; }
.brand { text-align: center; margin-bottom: 14px; }
.brand img { width: 72px; height: 72px; border-radius: 18px; }
.brand h1 { margin: 6px 0 0; font-size: 20px; }

.qr { display: flex; justify-content: center; padding: 12px; background: #fff; border-radius: 12px; }
.qr img { width: 100%; max-width: 280px; image-rendering: pixelated; }
.status-line { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.status-line .dot { width: 10px; height: 10px; }
.dot.on { background: var(--ok); } .dot.off { background: var(--danger); } .dot.wait { background: var(--warn); }

/* تقویم شمسی */
.dp-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 45%); z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.dp { background: var(--surface); width: 100%; max-width: 420px; border-radius: 18px 18px 0 0; padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); }
.dp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-weight: 700; }
.dp-head button { border: 0; background: var(--surface-2); border-radius: 8px; width: 36px; height: 36px; cursor: pointer; font-size: 18px; }
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.dp-grid .wd { font-size: 12px; color: var(--muted); }
.dp-grid button { border: 0; background: none; height: 40px; border-radius: 10px; cursor: pointer; }
.dp-grid button.today { outline: 1px solid var(--primary); }
.dp-grid button.sel { background: var(--primary); color: var(--primary-ink); }
.dp-grid button:disabled { opacity: .3; }
.dp-time { display: flex; gap: 8px; align-items: center; margin-top: 10px; direction: ltr; justify-content: center; }
.dp-time select { width: auto; }

.empty { text-align: center; color: var(--muted); padding: 32px 0; }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 900px) {
  body { padding-bottom: 0; padding-top: 0; }
  .nav { top: 0; bottom: auto; inset-inline: 0 auto; width: 88px; height: 100vh; grid-template-columns: 1fr; grid-auto-rows: 72px; align-content: start; padding-top: 20px; border-top: 0; border-inline-end: 1px solid var(--border); }
  /* منو سمت راست (شروع خط در RTL) و محتوا وسطِ فضای باقی‌مانده */
  body { padding-inline-start: 88px; }
  .topbar h1 { max-width: 720px; margin: 0 auto; }
  .toast { bottom: 24px; }
}

/* کد اتصال ربات ورود خبر */
.pair { margin-top: 12px; padding: 12px; border-radius: 12px; background: var(--surface-2); border: 1px dashed var(--border); display: grid; gap: 8px; justify-items: center; text-align: center; }
.pair-code { font-size: 30px; font-weight: 800; letter-spacing: 6px; font-variant-numeric: tabular-nums; }
.err { color: var(--danger); font-size: 13px; }
.chip.bot { color: var(--c-telegram); border-color: color-mix(in srgb, var(--c-telegram) 40%, transparent); }
