:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #26334d;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --secondary: #f97316;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
}

body[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --primary: #0b5ed7;
  --primary-hover: #0a4eb8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Cairo', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }
code, pre, [dir="ltr"].mono { font-family: 'JetBrains Mono', monospace; }

.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.stack-md { display: flex; flex-direction: column; gap: 14px; }

.toast-root {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 92vw;
}
.toast {
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 700;
  color: #fff;
  box-shadow: 0 10px 28px rgba(0,0,0,.35);
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }
.toast.warning { background: var(--warning); color: #111827; }

/* Login */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at top right, rgba(59,130,246,.18), transparent 45%),
              radial-gradient(circle at bottom left, rgba(249,115,22,.12), transparent 45%), var(--bg);
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0,0,0,.3);
}
.brand-badge {
  width: 58px;
  height: 58px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: grid;
  place-items: center;
  margin: 0 auto 14px;
  font-size: 26px;
}
.login-card h1 { margin: 0; text-align: center; font-size: 22px; font-weight: 800; }
.subtitle { margin: 4px 0 20px; text-align: center; color: var(--text-muted); font-size: 13px; }
.advanced-api summary { cursor: pointer; font-size: 12px; color: var(--text-muted); }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.logo-pill {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: grid; place-items: center; font-size: 18px;
}
.topbar-title { font-weight: 800; font-size: 16px; }
.topbar-sub { font-size: 11.5px; color: var(--text-muted); }
.topbar-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.container { max-width: 1360px; margin: 0 auto; padding: 20px; }

/* Cards & KPIs */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  border-top: 3px solid var(--primary);
}
.kpi-card.kpi-success { border-top-color: var(--success); }
.kpi-card.kpi-warning { border-top-color: var(--warning); }
.kpi-card.kpi-danger { border-top-color: var(--danger); }
.kpi-card.kpi-info { border-top-color: var(--secondary); }
.kpi-label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
.kpi-value { font-size: 26px; font-weight: 800; margin: 4px 0; }
.kpi-foot { font-size: 11.5px; color: var(--text-muted); }

/* Toolbar */
.toolbar {
  padding: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.search-wrap { flex: 1 1 280px; }
.search-wrap input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
}
.filter-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill, .chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.pill.active, .chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Table */
.table-card { overflow: hidden; }
.table-responsive { overflow-x: auto; }
.tenants-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.tenants-table th, .tenants-table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  vertical-align: middle;
}
.tenants-table th { background: var(--surface-2); color: var(--text-muted); font-weight: 700; font-size: 12px; }
.tenants-table tr:hover td { background: rgba(59,130,246,.05); }

.store-cell { display: flex; align-items: center; gap: 10px; }
.store-avatar {
  width: 38px; height: 38px; border-radius: 10px; object-fit: cover;
  background: var(--surface-2); display: grid; place-items: center; font-weight: 800; color: #fff; flex-shrink: 0;
}
.swatches { display: flex; align-items: center; gap: 5px; }
.dot { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(255,255,255,.25); display: inline-block; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700;
}
.badge-ok { background: rgba(16,185,129,.16); color: #34d399; }
.badge-warn { background: rgba(245,158,11,.18); color: #fbbf24; }
.badge-bad { background: rgba(239,68,68,.16); color: #f87171; }
body[data-theme="light"] .badge-ok { color: #047857; }
body[data-theme="light"] .badge-warn { color: #b45309; }
body[data-theme="light"] .badge-bad { color: #b91c1c; }

.actions-row { display: flex; flex-wrap: wrap; gap: 5px; }

/* Mobile cards */
.mobile-cards { display: none; flex-direction: column; gap: 12px; }
@media (max-width: 960px) {
  .table-card { display: none; }
  .mobile-cards { display: flex; }
}
.m-card { padding: 14px; display: flex; flex-direction: column; gap: 10px; }

/* Form fields & buttons */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12.5px; font-weight: 700; color: var(--text-muted); }
.field small { font-size: 11px; color: var(--text-muted); }
.field input, .field select, .field textarea {
  padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-family: inherit; font-size: 13.5px; width: 100%;
}
.input-with-btn { display: flex; gap: 6px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.span-2 { grid-column: span 2; }
@media (max-width: 720px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
}

.btn {
  border: 1px solid transparent; border-radius: 10px; padding: 9px 14px;
  font-family: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn-lg { padding: 12px 18px; font-size: 15px; width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-outline { background: transparent; border-color: rgba(239,68,68,.45); color: var(--danger); }
.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font-family: inherit;
}

.alert { padding: 10px 12px; border-radius: 10px; font-size: 12.5px; font-weight: 600; }
.alert-error { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.4); color: #f87171; }
body[data-theme="light"] .alert-error { color: #b91c1c; }

/* Modals */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(2,6,23,.72); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 16px;
}
.modal {
  width: 100%; max-height: 92vh; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; display: flex; flex-direction: column;
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
}
.modal-sm { max-width: 460px; }
.modal-lg { max-width: 780px; }
.modal-xl { max-width: 960px; }
.modal-header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-tabs {
  display: flex; gap: 6px; padding: 10px 18px;
  border-bottom: 1px solid var(--border); background: var(--surface-2); overflow-x: auto;
}
.tab-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-muted);
  padding: 7px 14px; border-radius: 10px; font-family: inherit; font-weight: 700; cursor: pointer; font-size: 12.5px;
}
.tab-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.modal-body { padding: 18px; overflow-y: auto; max-height: 68vh; }
.modal-footer {
  padding: 12px 18px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}
.tab-pane { display: none; }
.tab-pane.active { display: block; }
.sub-box {
  margin-top: 16px; padding: 14px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.sub-box h3 { margin: 0 0 10px; font-size: 14px; }
.preset-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.preset-themes { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; font-size: 12.5px; font-weight: 700; }

/* Theme Workspace & Live Preview */
.theme-workspace { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; }
@media (max-width: 820px) { .theme-workspace { grid-template-columns: 1fr; } }
.theme-inputs h4, .theme-previews h4 { margin: 0 0 8px; font-size: 13px; color: var(--text-muted); }
.color-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); gap: 8px; }
.color-item {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 7px 9px; display: flex; flex-direction: column; gap: 4px;
}
.color-item span { font-size: 11px; color: var(--text-muted); }
.color-item-row { display: flex; align-items: center; gap: 6px; }
.color-item input[type="color"] { width: 28px; height: 28px; border: none; padding: 0; background: none; cursor: pointer; }
.color-item input[type="text"] {
  border: none; background: transparent; color: var(--text);
  font-family: 'JetBrains Mono', monospace; font-size: 11.5px; width: 100%; padding: 0;
}

.live-preview-box { border-radius: 14px; overflow: hidden; border: 1px solid var(--border); }
.lp-header { padding: 10px 14px; color: #fff; font-weight: 800; font-size: 13.5px; display: flex; justify-content: space-between; align-items: center; }
.lp-badge { padding: 2px 8px; border-radius: 999px; font-size: 10.5px; color: #fff; }
.lp-body { padding: 12px; }
.lp-surface { padding: 12px; border-radius: 12px; border: 1px solid transparent; }
.lp-title { font-weight: 800; font-size: 13.5px; }
.lp-sub { font-size: 11.5px; margin: 3px 0 10px; }
.lp-actions { display: flex; justify-content: space-between; align-items: center; }
.lp-btn { padding: 4px 12px; border-radius: 8px; color: #fff; font-size: 11.5px; font-weight: 700; }
.lp-status { padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; color: #fff; }

.logo-upload-row { display: flex; align-items: center; gap: 8px; }
.logo-thumb { width: 38px; height: 38px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border); }
.upload-btn { white-space: nowrap; }

.empty-state { padding: 36px; text-align: center; color: var(--text-muted); }
.cmd-box {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.json-pre {
  background: #020617; color: #e2e8f0; border: 1px solid var(--border);
  border-radius: 12px; padding: 14px; font-size: 12px; overflow: auto; max-height: 360px; margin: 0;
}
.user-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border);
}
.cred-row {
  padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.hint { margin: 0; font-size: 12.5px; color: var(--text-muted); }
