:root {
  --brand-50: #eef4ff;
  --brand-100: #dbe7ff;
  --brand-500: #4f7cff;
  --brand-600: #3b63e6;
  --brand-700: #2f4dbd;
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-700: #334155;
  --slate-900: #0f172a;
  --emerald-500: #10b981;
  --emerald-600: #059669;
  --amber-500: #f59e0b;
  --rose-500: #f43f5e;
  --rose-600: #e11d48;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
}

html[lang="ar"] {
  font-family: 'Cairo', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html[lang="en"] {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
  height: 100%;
  font-family: inherit;
  background: var(--slate-50);
  color: var(--slate-900);
  line-height: 1.55;
}

a {
  color: var(--brand-600);
  text-decoration: none;
}

a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
}

input, select, textarea {
  font-family: inherit;
}

/* Numbers stay LTR for proper digit grouping */
.num, .kpi-value, .summary-total, .price-num,
table td:not(:first-child) {
  unicode-bidi: plaintext;
}

/* ============= AUTH PAGES ============= */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: linear-gradient(135deg, var(--slate-50), var(--brand-50));
  position: relative;
}

.auth-lang-switcher {
  position: absolute;
  top: 16px;
  inset-inline-end: 16px;
  z-index: 10;
}

.auth-card {
  background: white;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(16,24,40,0.08);
  padding: 32px;
  width: 100%;
  max-width: 420px;
}

.auth-logo {
  width: 48px; height: 48px;
  background: var(--brand-500);
  color: white;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 22px;
  margin: 0 auto 12px;
}

.auth-title {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}

.auth-subtitle {
  text-align: center;
  color: var(--slate-500);
  font-size: 14px;
  margin-bottom: 24px;
}

.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--slate-700);
  text-align: start;
}

.form-input, .form-select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--slate-200);
  border-radius: 8px;
  font-size: 14px;
  transition: all 0.15s;
  background: white;
  text-align: start;
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--brand-100);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--brand-500);
  color: white;
  width: 100%;
}

.btn-primary:hover { background: var(--brand-600); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary {
  background: var(--slate-100);
  color: var(--slate-700);
}

.btn-secondary:hover { background: var(--slate-200); }

.btn-ghost {
  background: transparent;
  color: var(--slate-500);
}

.btn-ghost:hover { background: var(--slate-100); }

.alert {
  padding: 12px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
  text-align: start;
}

.alert-error {
  background: #fef2f2;
  color: var(--rose-600);
  border: 1px solid #fecaca;
}

.alert-success {
  background: #f0fdf4;
  color: var(--emerald-600);
  border: 1px solid #bbf7d0;
}

.alert-warning {
  background: #fffbeb;
  color: #b45309;
  border: 1px solid #fcd34d;
}

.text-center { text-align: center; }
.text-start { text-align: start; }
.text-end { text-align: end; }
.text-sm { font-size: 14px; }
.text-xs { font-size: 12px; }
.text-muted { color: var(--slate-500); }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }

/* ============= APP LAYOUT ============= */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 256px;
  background: white;
  border-inline-end: 1px solid var(--slate-200);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--slate-100);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo {
  width: 36px; height: 36px;
  background: var(--brand-500);
  color: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-name {
  font-weight: 700;
  font-size: 15px;
}

.sidebar-tagline {
  font-size: 11px;
  color: var(--slate-500);
}

.sidebar-nav {
  flex: 1;
  padding: 12px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--slate-700);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}

.nav-item:hover {
  background: var(--slate-100);
  text-decoration: none;
}

.nav-item.active {
  background: var(--brand-50);
  color: var(--brand-700);
}

.nav-item-icon {
  flex-shrink: 0;
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--slate-100);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
}

.user-avatar {
  width: 32px; height: 32px;
  background: var(--slate-200);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--slate-700);
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

.user-email {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.signout-btn {
  width: 100%;
  text-align: start;
  padding: 8px 12px;
  border-radius: 8px;
  background: transparent;
  color: var(--slate-500);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}

.signout-btn:hover {
  background: #fef2f2;
  color: var(--rose-600);
}

.main {
  flex: 1;
  min-width: 0;
  padding: 24px 32px;
  overflow-x: hidden;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.page-title {
  font-size: 26px;
  font-weight: 700;
}

.page-subtitle {
  color: var(--slate-500);
  font-size: 14px;
  margin-top: 4px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}

.badge-warning {
  background: #fffbeb;
  color: #b45309;
}

/* ============= LANG SWITCHER ============= */
.lang-switcher {
  display: inline-flex;
  background: var(--slate-100);
  border-radius: 8px;
  padding: 2px;
  gap: 0;
  font-size: 12px;
  font-weight: 600;
}

.lang-switcher button {
  padding: 5px 12px;
  border-radius: 6px;
  background: transparent;
  color: var(--slate-500);
  transition: all 0.15s;
  font-family: inherit;
}

.lang-switcher button.active {
  background: white;
  color: var(--slate-900);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

#lang-switcher {
  display: flex;
  justify-content: center;
  padding: 4px 0;
}

/* ============= FILTERS ============= */
.filters {
  background: white;
  border-radius: 12px;
  padding: 14px;
  border: 1px solid var(--slate-100);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(16,24,40,0.04);
}

.filters-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--slate-500);
}

.filter-divider {
  width: 1px;
  height: 24px;
  background: var(--slate-200);
  margin: 0 4px;
}

.chip {
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  background: var(--slate-100);
  color: var(--slate-700);
  transition: all 0.15s;
  white-space: nowrap;
}

.chip:hover {
  background: var(--slate-200);
}

.chip.active {
  background: var(--brand-500);
  color: white;
}

.chip.platform-chip.active {
  background: var(--slate-900);
  color: white;
}

/* ============= KPI CARDS ============= */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: white;
  border-radius: 16px;
  padding: 18px;
  border: 1px solid var(--slate-100);
  box-shadow: 0 1px 2px rgba(16,24,40,0.04);
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  text-align: start;
}

.kpi-label {
  font-size: 13px;
  color: var(--slate-500);
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--slate-900);
  line-height: 1.15;
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}

.kpi-hint {
  font-size: 11px;
  color: var(--slate-400);
  margin-top: 6px;
}

.kpi-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.kpi-icon.brand { background: var(--brand-50); color: var(--brand-600); }
.kpi-icon.emerald { background: #d1fae5; color: var(--emerald-600); }
.kpi-icon.amber { background: #fef3c7; color: #d97706; }
.kpi-icon.rose { background: #ffe4e6; color: var(--rose-600); }
.kpi-icon.violet { background: #ede9fe; color: #7c3aed; }
.kpi-icon.slate { background: var(--slate-100); color: var(--slate-700); }

.delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 5px;
  unicode-bidi: plaintext;
}
.delta.up { background: #d1fae5; color: var(--emerald-600); }
.delta.down { background: #fee2e2; color: var(--rose-600); }
.delta.flat { background: var(--slate-100); color: var(--slate-500); }

/* ============= CHART CARDS ============= */
.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

@media (max-width: 1024px) {
  .charts-grid { grid-template-columns: 1fr; }
}

.card {
  background: white;
  border-radius: 16px;
  border: 1px solid var(--slate-100);
  box-shadow: 0 1px 2px rgba(16,24,40,0.04);
  overflow: hidden;
}

.card-header {
  padding: 18px;
  border-bottom: 1px solid var(--slate-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  font-weight: 600;
  font-size: 15px;
}

.card-body {
  padding: 18px;
}

.chart-container {
  height: 280px;
  position: relative;
}

/* ============= FUNNEL ============= */
.funnel-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.funnel-row:last-child { margin-bottom: 0; }

.funnel-label {
  width: 130px;
  font-size: 13px;
  color: var(--slate-700);
  font-weight: 500;
  flex-shrink: 0;
}

.funnel-bar {
  height: 36px;
  background: var(--brand-500);
  border-radius: 8px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  color: white;
  font-weight: 600;
  font-size: 13px;
  unicode-bidi: plaintext;
  min-width: 80px;
}

.funnel-value {
  width: 80px;
  text-align: end;
  font-weight: 600;
  color: var(--slate-900);
  flex-shrink: 0;
  font-size: 13px;
  unicode-bidi: plaintext;
}

/* ============= CAMPAIGNS / DATA TABLE ============= */
.table-wrap {
  overflow-x: auto;
}

.campaigns-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.campaigns-table thead {
  background: var(--slate-50);
}

.campaigns-table th {
  text-align: start;
  padding: 12px 16px;
  font-weight: 500;
  color: var(--slate-500);
  font-size: 13px;
  white-space: nowrap;
}

.campaigns-table td {
  padding: 14px 16px;
  border-top: 1px solid var(--slate-100);
  text-align: start;
}

.campaigns-table tr:hover td {
  background: var(--slate-50);
}

.platform-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.platform-badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.roas {
  font-weight: 600;
  unicode-bidi: plaintext;
}

.roas.high { color: var(--emerald-600); }
.roas.mid { color: #d97706; }
.roas.low { color: var(--rose-600); }

/* ============= CONNECTIONS PAGE ============= */
.connection-list {
  list-style: none;
}

.connection-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--slate-100);
}

.connection-item:last-child { border-bottom: none; }

.connection-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  flex-shrink: 0;
}

.add-form {
  display: grid;
  grid-template-columns: 1fr 1.5fr 1.5fr auto;
  gap: 10px;
}

@media (max-width: 768px) {
  .add-form { grid-template-columns: 1fr; }
}

.empty-state {
  padding: 48px 16px;
  text-align: center;
  color: var(--slate-400);
  font-size: 14px;
}

/* ============= LOADING ============= */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--slate-200);
  border-top-color: var(--brand-500);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 60px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

/* ============= PRICING PAGE ============= */
.pricing-hero {
  text-align: center;
  padding: 32px 16px 16px;
  background: linear-gradient(135deg, var(--brand-50), #ffffff);
  border-radius: 16px;
  border: 1px solid #e0e7ff;
  margin-bottom: 24px;
}

.price-display {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  margin: 16px 0;
  unicode-bidi: plaintext;
}
.price-num { font-size: 56px; font-weight: 800; color: var(--brand-500); line-height: 1; }
.price-suffix { font-size: 18px; color: var(--slate-500); }

.platform-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.platform-option {
  background: white;
  border: 2px solid var(--slate-200);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 12px;
  user-select: none;
}

.platform-option:hover {
  border-color: var(--slate-300);
  background: var(--slate-50);
}

.platform-option.selected {
  border-color: var(--brand-500);
  background: var(--brand-50);
}

.platform-option .check {
  width: 22px;
  height: 22px;
  border: 2px solid var(--slate-300);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
  font-size: 13px;
}

.platform-option.selected .check {
  background: var(--brand-500);
  border-color: var(--brand-500);
}

.platform-option .platform-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}

.platform-option .platform-info { flex: 1; min-width: 0; }
.platform-option .platform-name { font-weight: 600; font-size: 14px; }
.platform-option .platform-price { font-size: 12px; color: var(--slate-500); unicode-bidi: plaintext; }

.summary-bar {
  background: white;
  border-radius: 12px;
  padding: 18px;
  border: 1px solid var(--slate-200);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.summary-info { display: flex; flex-direction: column; }

.summary-total {
  font-size: 32px;
  font-weight: 700;
  color: var(--slate-900);
  line-height: 1;
  unicode-bidi: plaintext;
}

.summary-label { font-size: 13px; color: var(--slate-500); }

.features-card {
  background: white;
  border-radius: 12px;
  border: 1px solid var(--slate-200);
  padding: 20px;
  margin-top: 20px;
}

.features-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.features-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--slate-700);
}

.features-list li::before {
  content: "✓";
  color: var(--emerald-600);
  font-weight: 700;
  flex-shrink: 0;
}

.status-badge {
  display: inline-flex;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  margin-inline-start: 6px;
}
.status-trial { background: #fef3c7; color: #b45309; }
.status-active { background: #d1fae5; color: var(--emerald-600); }
.status-cancelled { background: #fee2e2; color: var(--rose-600); }

/* ============= ADMIN ============= */
.admin-badge {
  display: inline-block;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: white;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  margin-inline-start: 6px;
}

.danger-btn {
  background: transparent;
  color: var(--rose-600);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  border: 1px solid #fca5a5;
  cursor: pointer;
  font-family: inherit;
}
.danger-btn:hover { background: #fef2f2; }

.sub-status {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.sub-status.trial { background: #fef3c7; color: #b45309; }
.sub-status.active { background: #d1fae5; color: var(--emerald-600); }
.sub-status.cancelled, .sub-status.past_due { background: #fee2e2; color: var(--rose-600); }

.platform-pill {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-inline-end: 3px;
}

/* ============= MOBILE ============= */
@media (max-width: 768px) {
  .sidebar {
    width: 64px;
  }
  .sidebar-name, .sidebar-tagline,
  .nav-item span:not(.nav-item-icon),
  .user-email,
  .signout-btn span:last-child,
  #lang-switcher { display: none; }
  .main { padding: 16px; }
  .page-title { font-size: 22px; }
  .kpi-value { font-size: 22px; }
  .price-num { font-size: 44px; }
}
