:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #e2e4e9;
  --text: #16181d;
  --muted: #6b7080;
  --accent: #e5484d;
  --accent-soft: #fdecec;
  --ok: #2f9e6e;
  --ok-soft: #e4f5ec;
  --warn: #c98a16;
  --warn-soft: #fbf1dc;
  --info: #3b6fd9;
  --info-soft: #e6eefc;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --border: #2a2f39;
    --text: #e9ebf0;
    --muted: #9399a8;
    --accent: #ff6369;
    --accent-soft: #3a1d20;
    --ok: #4cc38a;
    --ok-soft: #16302a;
    --warn: #f0b440;
    --warn-soft: #3a2e14;
    --info: #6f9bf2;
    --info-soft: #1b2741;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

button, input, select { font: inherit; color: inherit; }

.ltr { direction: ltr; unicode-bidi: embed; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- Buttons & inputs ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-ok { color: var(--ok); }
.btn-info { color: var(--info); }
.btn-danger { color: var(--accent); }

.input {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 12px;
  min-width: 0;
}
.input:focus, .btn:focus-visible { outline: 2px solid var(--info); outline-offset: 1px; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 12px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 24px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.login-card .input { width: 100%; }
.login-card .btn-primary { width: 100%; margin-top: 22px; padding: 10px; }
.error { color: var(--accent); font-size: 14px; margin-top: 14px; min-height: 1em; }

.logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: .5px;
}
.logo-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 15px;
}

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner, .container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
}
.topbar-inner {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 13px; min-width: 0; }
.topbar-user span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.container { padding-top: 24px; padding-bottom: 48px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.panel-head h2 { margin: 0; font-size: 16px; }
.panel-body { padding: 20px; }

/* ---------- Stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.stat { padding: 16px 18px; }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-value { font-size: 28px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--muted); }
.stat.approved .stat-value { color: var(--accent); }
.stat.pending .stat-value { color: var(--warn); }
.stat.whitelisted .stat-value { color: var(--ok); }

/* ---------- Usage ---------- */
.section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 8px;
}

/* ---------- Threshold ---------- */
.threshold { margin-bottom: 20px; }
.mode-switch {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
}
.mode-switch button {
  border: 0;
  background: transparent;
  padding: 6px 14px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--muted);
}
.mode-switch button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.threshold-row {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field .input { width: 130px; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.hint { font-size: 13px; color: var(--muted); margin: 14px 0 0; }
.hint strong { color: var(--text); }

/* ---------- Tabs & filters ---------- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  border: 0;
  background: transparent;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
}
.tab:hover { background: var(--surface-2); }
.tab.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.tab .count {
  display: inline-block;
  min-width: 22px;
  padding: 0 6px;
  margin-inline-start: 6px;
  border-radius: 99px;
  background: var(--border);
  font-size: 12px;
  text-align: center;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 99px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 13px;
}
.chip.active { background: var(--text); border-color: var(--text); color: var(--bg); }
.toolbar .search { flex: 1; min-width: 180px; }

.add-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.add-form .input:nth-child(2) { flex: 1; min-width: 160px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 20px; text-align: start; border-bottom: 1px solid var(--border); }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td.num { font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; }
td.actions .btn { margin-inline-end: 4px; }

.user-link { color: var(--text); text-decoration: none; font-weight: 500; }
.user-link:hover { text-decoration: underline; }

.badge {
  display: inline-block;
  font-size: 12px;
  padding: 2px 9px;
  border-radius: 99px;
  font-weight: 500;
}
.p-instagram { background: #fde8f1; color: #c1357a; }
.p-facebook  { background: var(--info-soft); color: var(--info); }
.p-tiktok    { background: var(--surface-2); color: var(--text); }
.p-x         { background: var(--surface-2); color: var(--text); }
@media (prefers-color-scheme: dark) {
  .p-instagram { background: #3a1a2b; color: #f07ab4; }
}

.progress { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.progress-bar { flex: 1; height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; background: var(--warn); border-radius: 99px; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 20;
  max-width: calc(100% - 32px);
}
.toast.error { background: var(--accent); color: #fff; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  th, td { padding: 10px 12px; }
  .panel-head, .panel-body, .toolbar, .add-form { padding-left: 14px; padding-right: 14px; }
  .col-date { display: none; }
}
