:root {
  --bg: #0b0f1a;
  --bg2: #111726;
  --card: #161d2e;
  --card2: #1b2338;
  --border: #26304a;
  --text: #e7ecf5;
  --muted: #8b96ad;
  --primary: #3b82f6;
  --primary2: #2563eb;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 12px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'IBM Plex Sans Arabic', 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  line-height: 1.6;
}
hidden, .hidden { display: none !important; }

/* Auth */
.auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 20% 10%, #1b2a4d 0%, var(--bg) 55%);
  padding: 20px;
}
.auth-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 18px;
  padding: 32px; width: 100%; max-width: 400px; box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
.auth-card input {
  width: 100%; margin-top: 14px; padding: 12px 14px; border-radius: 10px;
  background: var(--bg2); border: 1px solid var(--border); color: var(--text); font-size: 15px;
}
.auth-card input:focus { outline: none; border-color: var(--primary); }
.auth-sub { color: var(--muted); margin-top: 10px; font-size: 14px; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; background: var(--bg2); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { font-size: 32px; }
.brand h1 { font-size: 18px; font-weight: 800; }
.brand p { font-size: 12px; color: var(--muted); }
.side-brand { padding: 20px; border-bottom: 1px solid var(--border); }
.nav { padding: 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 10px;
  color: var(--muted); text-decoration: none; font-size: 14.5px; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item span { font-size: 17px; }
.nav-item:hover { background: var(--card); color: var(--text); }
.nav-item.active { background: var(--primary2); color: #fff; }
.side-footer { padding: 14px; border-top: 1px solid var(--border); }

.main { flex: 1; min-width: 0; padding: 24px 28px; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.topbar h2 { font-size: 22px; font-weight: 800; }
.sync-indicator { font-size: 13px; color: var(--muted); background: var(--card); padding: 6px 12px; border-radius: 20px; }

/* Cards & grids */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 720px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } .sidebar { display: none; } }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px;
}
.card h3 { font-size: 15px; font-weight: 700; margin-bottom: 12px; color: var(--muted); }
.card h3 .count { color: var(--text); background: var(--card2); padding: 1px 9px; border-radius: 20px; font-size: 13px; margin-inline-start: 8px; }

.stat-card { display: flex; flex-direction: column; gap: 6px; }
.stat-card .stat-label { color: var(--muted); font-size: 13px; }
.stat-card .stat-value { font-size: 30px; font-weight: 800; }
.stat-card .stat-delta { font-size: 12.5px; }
.stat-card .stat-delta.pos { color: var(--green); }
.stat-card .stat-delta.neg { color: var(--red); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card2); color: var(--text); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all .15s; font-family: inherit;
}
.btn:hover { filter: brightness(1.1); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary2); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; margin-top: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Forms */
input, textarea, select {
  width: 100%; padding: 10px 12px; border-radius: 9px; background: var(--bg2);
  border: 1px solid var(--border); color: var(--text); font-size: 14px; font-family: inherit;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); }
textarea { resize: vertical; min-height: 90px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.field { margin-bottom: 14px; }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: right; color: var(--muted); font-size: 12.5px; font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); }
td { padding: 12px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--card2); }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-ok { background: rgba(34,197,94,.15); color: var(--green); }
.badge-fail { background: rgba(239,68,68,.15); color: var(--red); }
.badge-warn { background: rgba(245,158,11,.15); color: var(--amber); }
.badge-info { background: rgba(59,130,246,.15); color: var(--primary); }

/* Account avatar */
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--card2); border: 1px solid var(--border); }
.handle-cell { display: flex; align-items: center; gap: 10px; }
.handle-cell .h-name { font-weight: 600; }
.handle-cell .h-handle { color: var(--muted); font-size: 12.5px; direction: ltr; text-align: right; }

/* Post preview */
.post-preview {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 16px;
  white-space: pre-wrap; font-size: 15px; min-height: 70px;
}
.char-count { font-size: 12.5px; color: var(--muted); text-align: left; direction: ltr; }
.char-count.over { color: var(--red); }

/* AI output */
.ai-output {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 16px;
  white-space: pre-wrap; font-size: 14.5px; min-height: 80px;
}

/* Toast */
.toast-container { position: fixed; bottom: 20px; left: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 9999; }
.toast {
  background: var(--card2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 18px; font-size: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.4);
  animation: slidein .25s ease; max-width: 360px;
}
.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }
@keyframes slidein { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.error-msg { color: var(--red); font-size: 13.5px; margin-top: 12px; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.actions-cell { display: flex; gap: 8px; flex-wrap: wrap; }
.section-title { font-size: 16px; font-weight: 700; margin: 22px 0 12px; }

/* Progress bar */
.progress { height: 8px; background: var(--bg2); border-radius: 20px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); border-radius: 20px; transition: width .3s; }

/* Toggle */
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.toggle-row:last-child { border-bottom: none; }
.switch { position: relative; width: 46px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--border); border-radius: 26px; cursor: pointer; transition: .2s; }
.slider:before { content: ''; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider:before { transform: translateX(20px); }
