/* ShareBot dashboard — RTL, light/dark */
:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef0f4;
  --border: #e3e6ec;
  --border-strong: #cfd4dd;
  --text: #14161a;
  --text-2: #4b5160;
  --text-3: #7b8191;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --accent-text: #ffffff;
  --good: #12805c;
  --good-soft: #e3f5ed;
  --warn: #a15c00;
  --warn-soft: #fdf1dc;
  --bad: #c62f2f;
  --bad-soft: #fde8e8;
  --info: #5b4bc4;
  --info-soft: #eeebfc;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #eceef2;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.16);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar: #0f1623;
  --sidebar-text: #c9d1e1;
  --sidebar-muted: #7f8aa3;
  --sidebar-active: #1c2638;
  --font: -apple-system, BlinkMacSystemFont, 'SF Arabic', 'Segoe UI', 'Noto Sans Arabic', Tahoma, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0b0f17;
  --surface: #121826;
  --surface-2: #161d2c;
  --surface-3: #1c2435;
  --border: #232c3f;
  --border-strong: #303b52;
  --text: #eef1f6;
  --text-2: #b6bdcc;
  --text-3: #808aa0;
  --accent: #4c8dff;
  --accent-soft: #17264a;
  --good: #34c08a;
  --good-soft: #0f2a21;
  --warn: #e7a83a;
  --warn-soft: #2d2210;
  --bad: #f06a6a;
  --bad-soft: #321616;
  --info: #9d90f2;
  --info-soft: #221d43;
  --series-1: #3987e5;
  --series-2: #d95926;
  --grid: #1f2838;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
  --sidebar: #090d14;
  --sidebar-active: #172033;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
.mono { font-family: var(--mono); font-size: 12px; direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--text-3); }
.hidden { display: none !important; }

/* ───────── layout ───────── */
.user-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; padding-top: 10px; border-top: 1px solid rgba(255, 255, 255, 0.06); font-size: 12.5px; }
.user-name { color: var(--sidebar-muted); direction: ltr; unicode-bidi: isolate; }
.logout-btn { all: unset; cursor: pointer; color: #f38b8b; font-size: 12.5px; }
.logout-btn:hover { text-decoration: underline; }
.danger-zone { border-color: color-mix(in srgb, var(--bad) 35%, var(--border)); }
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 12px;
  gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, #25d366, #1f6feb);
  display: grid; place-items: center; color: #fff; font-weight: 800;
}
.brand-name { font-weight: 700; font-size: 16px; color: #fff; }
.brand-sub { font-size: 11px; color: var(--sidebar-muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-section { font-size: 11px; color: var(--sidebar-muted); padding: 14px 12px 4px; letter-spacing: 0.02em; }
.nav button {
  all: unset;
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 9px; cursor: pointer;
  color: var(--sidebar-text); font-size: 14px;
}
.nav button:hover { background: rgba(255, 255, 255, 0.05); }
.nav button.active { background: var(--sidebar-active); color: #fff; }
.nav button.active svg { color: #4c8dff; }
.nav svg { width: 18px; height: 18px; flex: none; opacity: 0.9; }
.nav .badge { margin-inline-start: auto; }
.sidebar-foot { margin-top: auto; padding: 12px; border-top: 1px solid rgba(255, 255, 255, 0.06); }
.conn { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.conn-sub { font-size: 11px; color: var(--sidebar-muted); margin-top: 2px; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 28px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 700; }
.topbar .sub { color: var(--text-3); font-size: 13px; }
.topbar .spacer { flex: 1; }
.content { padding: 24px 28px 48px; max-width: 1320px; width: 100%; }

/* ───────── primitives ───────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-h { display: flex; align-items: center; gap: 10px; padding: 16px 18px 0; }
.card-h h2, .card-h h3 { margin: 0; font-size: 15px; font-weight: 650; }
.card-h .spacer { flex: 1; }
.card-b { padding: 16px 18px 18px; }
.card-sub { color: var(--text-3); font-size: 13px; margin-top: 2px; }
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.between { justify-content: space-between; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--border-strong); background: var(--surface);
  cursor: pointer; font-weight: 550; font-size: 13.5px; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, transform 0.05s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn.icon { width: 36px; padding: 0; }
.btn.sm.icon { width: 30px; }
.btn.loading { pointer-events: none; opacity: 0.7; }
.btn.loading::before {
  content: ''; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: 9px;
  background: var(--surface); outline: none; transition: border-color 0.12s, box-shadow 0.12s;
}
.textarea { height: auto; min-height: 110px; padding: 10px 12px; resize: vertical; line-height: 1.7; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.ltr { direction: ltr; text-align: left; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; font-size: 13px; }
.field .hint { font-size: 12px; color: var(--text-3); }
.fields { display: grid; gap: 16px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--surface-3); color: var(--text-2);
}
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.count { background: #e5484d; color: #fff; min-width: 20px; justify-content: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.dot.good { background: #25c27a; box-shadow: 0 0 0 3px rgba(37, 194, 122, 0.18); }
.dot.warn { background: #e7a83a; box-shadow: 0 0 0 3px rgba(231, 168, 58, 0.2); }
.dot.bad { background: #f06a6a; box-shadow: 0 0 0 3px rgba(240, 106, 106, 0.2); }
.dot.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

/* switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  width: 40px; height: 22px; border-radius: 999px; background: var(--border-strong);
  position: relative; transition: background 0.15s; flex: none;
}
.switch .track::after {
  content: ''; position: absolute; top: 3px; inset-inline-start: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.switch input:checked + .track { background: var(--good); }
.switch input:checked + .track::after { transform: translateX(-18px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--accent-soft); }

/* segmented */
.seg { display: inline-flex; background: var(--surface-3); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button {
  all: unset; cursor: pointer; padding: 6px 14px; border-radius: 8px; font-size: 13px; font-weight: 550; color: var(--text-2);
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  all: unset; cursor: pointer; padding: 10px 14px; font-weight: 550; color: var(--text-3);
  border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; gap: 6px; align-items: center;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }

/* ───────── stats ───────── */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.stat { padding: 16px 18px; }
.stat-label { font-size: 12.5px; color: var(--text-3); display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 28px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat-foot { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* status banner */
.banner {
  display: flex; gap: 14px; align-items: center; padding: 14px 18px;
  border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface);
}
.banner.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.banner.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.banner.info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.banner .t { font-weight: 650; }
.banner .d { font-size: 13px; color: var(--text-2); }

.next-pub { display: flex; align-items: center; gap: 16px; }
.next-pub .big { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; direction: ltr; }
.ring { width: 54px; height: 54px; flex: none; }

/* ───────── chart ───────── */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 220px; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-text { fill: var(--text-3); font-size: 11px; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover { fill: color-mix(in srgb, var(--text) 5%, transparent); }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 6px; vertical-align: -1px; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 9px;
  box-shadow: var(--shadow-lg); padding: 8px 10px; font-size: 12.5px; min-width: 130px;
  transform: translate(50%, -100%);
}
.tooltip .tt-h { font-weight: 650; margin-bottom: 4px; }
.tooltip .tt-r { display: flex; justify-content: space-between; gap: 12px; color: var(--text-2); }
.tooltip .tt-r b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ───────── activity / logs ───────── */
.feed { display: flex; flex-direction: column; max-height: 420px; overflow: auto; }
.feed-item { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.feed-item:last-child { border-bottom: 0; }
.feed-time { color: var(--text-3); font-size: 11.5px; min-width: 52px; font-variant-numeric: tabular-nums; direction: ltr; text-align: end; padding-top: 1px; }
.feed-msg { flex: 1; word-break: break-word; }
.log-view {
  background: #0a0e15; color: #cfd6e4; border-radius: var(--radius); padding: 12px 14px;
  font-family: var(--mono); font-size: 12.5px; height: calc(100vh - 230px); min-height: 360px; overflow: auto;
}
.log-line { display: flex; gap: 10px; padding: 2px 0; white-space: pre-wrap; word-break: break-word; }
.log-line .lt { color: #6b7690; flex: none; direction: ltr; }
.log-line .ls { color: #7aa2f7; flex: none; min-width: 78px; direction: ltr; }
.log-line .lm { flex: 1; font-family: var(--font); font-size: 13px; }
.log-line.warn .lm { color: #e7c07a; }
.log-line.error .lm { color: #f38b8b; }
.log-line.debug .lm { color: #7f8aa3; }

/* ───────── review cards ───────── */
.review-list { display: flex; flex-direction: column; gap: 16px; }
.review { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); }
.review > div { padding: 16px 18px; }
.review .orig { border-inline-end: 1px solid var(--border); background: var(--surface-2); border-start-start-radius: var(--radius); border-end-start-radius: var(--radius); }
.review .orig-text { white-space: pre-wrap; color: var(--text-2); font-size: 13.5px; max-height: 260px; overflow: auto; }
.review .head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.review .head .id { font-weight: 700; }
.review .textarea { min-height: 170px; }
.review .actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.media-thumb { max-width: 100%; max-height: 220px; border-radius: 10px; margin-bottom: 10px; border: 1px solid var(--border); display: block; }

/* ───────── tables ───────── */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: start; font-weight: 600; color: var(--text-3); font-size: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table .clip { max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .expand td { background: var(--surface-2); }
.pre { white-space: pre-wrap; font-size: 13px; }
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 12px 0 0; }

/* channels */
.ch-list { display: flex; flex-direction: column; }
.ch { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.ch:last-child { border-bottom: 0; }
.ch-avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; }
.ch-main { flex: 1; min-width: 0; }
.ch-name { font-weight: 600; display: flex; gap: 8px; align-items: center; }
.ch-name input { height: 30px; }
.ch-jid { color: var(--text-3); }
.ch.off { opacity: 0.55; }
.add-box { display: grid; grid-template-columns: 1fr 180px auto; gap: 8px; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; border: 1px solid var(--border-strong); border-radius: 9px; min-height: 42px; background: var(--surface); }
.chips:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-3); border-radius: 7px; padding: 3px 8px; font-size: 13px; }
.chip button { all: unset; cursor: pointer; color: var(--text-3); font-size: 15px; line-height: 1; }
.chips input { border: 0; outline: 0; background: transparent; flex: 1; min-width: 120px; height: 28px; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.preset { all: unset; cursor: pointer; font-size: 12.5px; padding: 4px 10px; border-radius: 999px; border: 1px dashed var(--border-strong); color: var(--text-2); }
.preset:hover { border-style: solid; border-color: var(--accent); color: var(--accent); }
.rules { margin: 0; padding-inline-start: 18px; color: var(--text-2); font-size: 13px; }
.rules li { margin: 3px 0; }
.result-box { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; min-height: 120px; }
.range { width: 100%; accent-color: var(--accent); }
.summary { padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--text); font-size: 13.5px; }

/* empty states */
.empty { text-align: center; padding: 48px 20px; color: var(--text-3); }
.empty svg { width: 44px; height: 44px; opacity: 0.5; margin-bottom: 8px; }
.empty .t { font-weight: 650; color: var(--text-2); font-size: 15px; }

/* QR */
.qr-card { display: flex; gap: 24px; align-items: center; }
.qr-card img { width: 220px; height: 220px; background: #fff; padding: 10px; border-radius: 12px; border: 1px solid var(--border); }
.qr-card ol { margin: 8px 0 0; padding-inline-start: 18px; color: var(--text-2); }

/* toasts & modal */
.toasts { position: fixed; bottom: 20px; left: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  min-width: 260px; max-width: 420px; padding: 12px 14px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  display: flex; gap: 10px; align-items: flex-start; animation: toast-in 0.2s ease-out;
  border-inline-start: 4px solid var(--accent);
}
.toast.good { border-inline-start-color: var(--good); }
.toast.bad { border-inline-start-color: var(--bad); }
.toast.warn { border-inline-start-color: var(--warn); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
.modal-bg { position: fixed; inset: 0; background: rgba(5, 8, 14, 0.55); display: grid; place-items: center; z-index: 90; animation: fade 0.15s; }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(480px, 92vw); padding: 22px; }
.modal h3 { margin: 0 0 6px; font-size: 17px; }
.modal p { margin: 0 0 18px; color: var(--text-2); }

.skeleton { background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; height: 16px; }
@keyframes sk { to { background-position: -200% 0; } }

@media (max-width: 1100px) {
  .g-main, .g-2, .g-3 { grid-template-columns: 1fr; }
  .review { grid-template-columns: 1fr; }
  .review .orig { border-inline-end: 0; border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; overflow-x: auto; padding: 10px; }
  .brand, .nav-section, .sidebar-foot { display: none; }
  .nav { flex-direction: row; }
  .content { padding: 16px; }
  .add-box { grid-template-columns: 1fr; }
}

.auto-switch { padding: 4px 10px 4px 12px; border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface); font-size: 13px; font-weight: 600; height: 32px; }
.auto-switch:has(input:checked) { border-color: color-mix(in srgb, var(--good) 50%, transparent); background: var(--good-soft); color: var(--good); }
.auto-switch.loading { opacity: .6; pointer-events: none; }
.ch-name em.badge { font-style: normal; }
