/* ============================================================
   Otherwise — Premium SaaS Design System
   Inspired by Stripe, Vercel, Tailwind UI | Light Mode | RTL
============================================================ */

/* ===================== CSS VARIABLES ===================== */
:root {
  /* Core Backgrounds */
  --bg-app:        #f4f7fa;
  --bg-surface:    #ffffff;
  --bg-subtle:     #f1f5f9;
  --bg-input:      #f4f7fa;
  --bg-chat:       #efeae2;

  /* Text */
  --text-primary:   #0f172a;
  --text-secondary: #475569;
  --text-muted:     #94a3b8;

  /* Brand & Accents */
  --accent:         #00a884;
  --accent-hover:   #008f6f;
  --accent-glow:    rgba(0, 168, 132, 0.12);
  --accent-light:   #dcfce7;
  --bubble-out:     #dcf8c6;

  /* أسماء بديلة اتكتبت في الصفحات (inline) من غير ما تتعرّف: لازم تتعرّف هنا وإلا العنصر بيظهر من غير لون */
  --accent-green:      var(--accent);
  --accent-green-dark: var(--accent-hover);
  --accent-blue:       #3b82f6;
  --accent-red:        #ef4444;
  --accent-orange:     #f97316;
  --bg-primary:        var(--bg-subtle);
  --bg-secondary:      var(--bg-subtle);
  --bg-lighter:        var(--bg-subtle);
  --bg-card:           var(--bg-surface);
  --border-light:      var(--border);

  /* Semantic colors */
  --color-blue:     #3b82f6;
  --color-purple:   #7c3aed;
  --color-orange:   #f97316;
  --color-yellow:   #eab308;
  --color-red:      #ef4444;

  /* Borders */
  --border:         #e2e8f0;
  --border-heavy:   #cbd5e1;

  /* Shadows */
  --shadow-xs:  0 1px 2px rgba(0,0,0,0.05);
  --shadow-sm:  0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-md:  0 10px 15px -3px rgba(0,0,0,0.07), 0 4px 6px -4px rgba(0,0,0,0.05);
  --shadow-lg:  0 20px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.04);
  --shadow-accent: 0 4px 14px rgba(0, 168, 132, 0.25);

  /* Shape */
  --radius-sm:  8px;
  --radius:     12px;
  --radius-lg:  16px;
  --radius-xl:  20px;
  --radius-full: 9999px;

  /* Layout */
  --sidebar-width: 260px;
  --header-height: 64px;
  --transition:    0.18s ease;
}

/* ===================== RESET ===================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: 'Cairo', 'Inter', sans-serif;
  background-color: var(--bg-app);
  color: var(--text-primary);
  direction: rtl;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===================== SCROLLBAR ===================== */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===================== TYPOGRAPHY ===================== */
h1, h2, h3, h4 { font-weight: 700; letter-spacing: -0.01em; }

/* ===================== APP LAYOUT ===================== */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-app);
}

/* ===================== SIDEBAR ===================== */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.sidebar-slim { width: 260px; min-width: 260px; }

.sidebar-header {
  height: var(--header-height);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: var(--shadow-accent);
}

.brand-text {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.brand-text span {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}

/* ===================== SIDEBAR NAVIGATION ===================== */
.sidebar-nav {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}

.nav-item:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-glow);
  color: var(--accent);
  font-weight: 600;
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-icon svg { width: 17px; height: 17px; }
.nav-item.active .nav-icon { opacity: 1; }

/* Role Badge */
.role-badge-container {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
  margin-top: auto;
}

.role-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.role-badge-icon { font-size: 14px; flex-shrink: 0; }
.role-badge-details { display: flex; flex-direction: column; min-width: 0; }
.role-badge-name { font-size: 12px; font-weight: 700; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role-badge-subtitle { font-size: 10px; color: var(--text-muted); }

.logout-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  font-family: 'Cairo', sans-serif;
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  text-align: right;
}

.logout-btn:hover {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--color-red);
}

/* ===================== MAIN CONTENT ===================== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-app);
}

/* ===================== DASHBOARD HEADER ===================== */
.dashboard-header {
  height: var(--header-height);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  box-shadow: var(--shadow-xs);
  flex-shrink: 0;
}

.page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.page-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #15803d;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(0,168,132,0.4); }
  50%       { opacity: 0.8; box-shadow: 0 0 0 5px rgba(0,168,132,0); }
}

/* ===================== DASHBOARD BODY ===================== */
.dashboard-body {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
}

/* ===================== STATS CARDS ===================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  display: flex;
  align-items: center;
  gap: 18px;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -2px rgba(0,0,0,0.05);
  transition: transform var(--transition), box-shadow var(--transition);
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.stat-icon.green  { background: #f0fdf4; }
.stat-icon.blue   { background: #eff6ff; }
.stat-icon.purple { background: #f5f3ff; }
.stat-icon.orange { background: #fff7ed; }

.stat-info { flex: 1; }

.stat-value {
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.stat-card.green  .stat-value { color: var(--accent); }
.stat-card.blue   .stat-value { color: var(--color-blue); }
.stat-card.purple .stat-value { color: var(--color-purple); }
.stat-card.orange .stat-value { color: var(--color-orange); }

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ===================== EMPTY STATE ===================== */
.empty-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  color: var(--text-muted);
  padding: 48px;
}

.empty-icon { font-size: 64px; margin-bottom: 20px; opacity: 0.35; }
.empty-title { font-size: 20px; font-weight: 700; color: var(--text-secondary); margin-bottom: 8px; }
.empty-subtitle { font-size: 14px; max-width: 340px; line-height: 1.7; color: var(--text-muted); }

/* ===================== PAGE CARDS ===================== */
.page-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

/* ===================== BUTTONS ===================== */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-family: 'Cairo', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition);
  box-shadow: var(--shadow-accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0,168,132,0.3);
}

.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: 'Cairo', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-ghost:hover {
  background: var(--bg-subtle);
  border-color: var(--border-heavy);
  color: var(--text-primary);
}

.icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 5px 7px;
  border-radius: 6px;
  transition: background var(--transition);
  color: var(--text-secondary);
}

.icon-btn:hover { background: var(--bg-subtle); }
.icon-btn-danger:hover { background: #fef2f2; color: var(--color-red); }

/* ===================== BADGES ===================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
}

.badge-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.badge-pending { background: #fefce8; color: #a16207; border: 1px solid #fde68a; }
.badge-error   { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.badge-danger  { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.online-dot    { color: var(--accent); font-size: 10px; }

/* ===================== FORMS ===================== */
.form-group { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.form-row   { display: flex; gap: 16px; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }

.form-input {
  background: var(--bg-surface);
  border: 1px solid var(--border-heavy);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: 'Cairo', sans-serif;
  font-size: 13px;
  outline: none;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 168, 132, 0.15);
}

.form-input::placeholder { color: var(--text-muted); }
.form-textarea { resize: vertical; min-height: 80px; line-height: 1.6; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.form-hint code { background: var(--bg-subtle); padding: 1px 5px; border-radius: 4px; color: var(--accent); font-family: monospace; }

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
  padding-left: 32px;
}

.form-input.input-error {
  border-color: var(--color-red) !important;
  box-shadow: 0 0 0 3px rgba(239,68,68,0.15) !important;
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-5px); }
  60%       { transform: translateX(5px); }
}

.field-error-msg { font-size: 11px; color: var(--color-red); margin-top: 4px; display: none; }

/* ===================== TABLES ===================== */
.table-wrapper { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  padding: 11px 18px;
  text-align: right;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-app);
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
}

.data-table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: var(--bg-app); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ===================== TABLE ACTION BUTTONS (SVG icons) ===================== */
.tbl-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  color: #94a3b8;
  transition: all var(--transition);
  margin-left: 3px;
}

.tbl-action-btn svg { pointer-events: none; }

/* Toggle — green on hover */
.tbl-btn-toggle:hover {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: #15803d;
}

/* Key — blue/indigo on hover */
.tbl-btn-key:hover {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1d4ed8;
}

/* Delete — red on hover */
.tbl-btn-delete:hover {
  background: #fef2f2;
  border-color: #fecaca;
  color: #dc2626;
}

/* ===================== MODAL ===================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: all;
}

.modal-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 560px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(16px) scale(0.98);
  transition: transform 0.22s ease;
}

.modal-overlay.show .modal-box { transform: translateY(0) scale(1); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 16px; font-weight: 700; color: var(--text-primary); letter-spacing: -0.01em; }

.modal-close {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all var(--transition);
  line-height: 1;
}

.modal-close:hover { background: #fef2f2; border-color: #fecaca; color: var(--color-red); }

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-app);
}

/* ===================== SEARCH ===================== */
.search-wrapper { position: relative; }

.search-input {
  width: 100%;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 9px 16px 9px 40px;
  color: var(--text-primary);
  font-family: 'Cairo', sans-serif;
  font-size: 13px;
  outline: none;
  transition: all var(--transition);
}

.search-input:focus {
  background: var(--bg-surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,168,132,0.12);
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
}

/* ===================== MOBILE MENU BUTTON ===================== */
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition);
  flex-shrink: 0;
}

.mobile-menu-btn:hover { background: var(--bg-subtle); color: var(--text-primary); }

/* ===================== SIDEBAR BACKDROP ===================== */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.5);
  backdrop-filter: blur(3px);
  z-index: 299;
}

.sidebar-backdrop.show { display: block; }

/* ===================== PORTAL TABS ===================== */
.portal-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 22px;
  overflow-x: auto;
  flex-shrink: 0;
}

.portal-tab {
  flex: 1;
  min-width: 120px;
  padding: 8px 16px;
  background: transparent;
  border: none;
  border-radius: 7px;
  color: var(--text-secondary);
  font-family: 'Cairo', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  text-align: center;
}

.portal-tab:hover { color: var(--text-primary); background: rgba(255,255,255,0.6); }

.portal-tab.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-xs);
  border: 1px solid var(--border);
}

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ===================== CHAT LIST TABS ===================== */
.chat-list-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  background: var(--bg-surface);
}

.chat-tab {
  flex: 1;
  padding: 12px 0;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
}

.chat-tab:hover { color: var(--text-primary); }
.chat-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ===================== SETTINGS ===================== */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.settings-section { overflow: visible; }
.settings-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 16px; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.toggle-info { flex: 1; }
.toggle-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.toggle-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.toggle-divider { height: 1px; background: var(--border); margin: 2px 0; }

.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border-heavy);
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.3s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  right: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s;
  box-shadow: var(--shadow-xs);
}

.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(-20px); }

input[type=range] { width: 100%; height: 4px; accent-color: var(--accent); cursor: pointer; }

/* Quick Replies */
.quick-replies-list { display: flex; flex-direction: column; gap: 8px; }

.quick-reply-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.quick-reply-item:hover { border-color: var(--accent); }

.reply-shortcut {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-glow);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  flex-shrink: 0;
}

.reply-preview { flex: 1; font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* ===================== ANALYTICS ===================== */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.chart-card-wide { grid-column: 1 / -1; }
canvas { display: block; }

.chart-legend { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ===================== CHATBOT BUILDER ===================== */
.bot-rules-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }

.bot-rule-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: all var(--transition);
  box-shadow: var(--shadow-xs);
}

.bot-rule-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,168,132,0.08), var(--shadow-sm);
}

.bot-rule-header { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.bot-rule-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.bot-rule-title { font-size: 14px; font-weight: 700; color: var(--text-primary); }

.bot-keywords { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.keyword-tag { background: var(--accent-glow); color: var(--accent); border: 1px solid rgba(0,168,132,0.2); border-radius: var(--radius-full); padding: 2px 10px; font-size: 11px; font-weight: 700; }

.bot-reply-preview {
  background: var(--bg-subtle);
  border-right: 3px solid var(--accent);
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  border-radius: 0 8px 8px 0;
  line-height: 1.5;
  margin-bottom: 14px;
}

.bot-rule-footer { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border); padding-top: 12px; }
.bot-stat { font-size: 11px; color: var(--accent); font-weight: 600; }

/* ===================== WA-LAYOUT (3-Column WhatsApp) ===================== */
.wa-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-app);
}

/* COL 1: NAV SLIM */
.nav-slim {
  width: 68px;
  min-width: 68px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  z-index: 10;
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
}

.nav-slim-brand {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.nav-slim .sidebar-nav { padding: 8px 6px; gap: 4px; border-bottom: none; }
.nav-slim .nav-item { padding: 10px; justify-content: center; border-radius: var(--radius-sm); }
.nav-slim .nav-item span:last-child { display: none; }
.nav-slim .nav-icon { width: 22px; height: 22px; }
.nav-slim > div:last-of-type { padding: 8px 6px; }
.nav-slim > div:last-of-type button { justify-content: center; padding: 10px; }
.nav-slim > div:last-of-type button span { display: none; }
.nav-slim #roleBadgeEl { display: none !important; }

/* COL 2: CHAT LIST */
.chat-list-col {
  width: 340px;
  min-width: 280px;
  max-width: 380px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.chat-list-header {
  height: var(--header-height);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-surface);
  gap: 10px;
}

.chat-list-title { font-size: 15px; font-weight: 700; color: var(--text-primary); flex: 1; }

.chat-list-search { padding: 10px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; }

.chat-list-label {
  padding: 8px 16px 4px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex-shrink: 0;
}

.chat-list-col .contacts-list { flex: 1; overflow-y: auto; }

/* COL 3: WAMain */
.wa-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-app);
  min-width: 0;
}

/* ===================== CONTACTS ===================== */
.contacts-list { flex: 1; overflow-y: auto; }

.contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background var(--transition);
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid var(--border);
}

.contact-item:hover { background: var(--bg-app); }

.contact-item.active {
  background: var(--accent-glow);
  border-right: 3px solid var(--accent);
}

.contact-item.active .contact-name { color: var(--accent); }

.contact-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
  color: #fff;
}

.contact-info { flex: 1; min-width: 0; }
.contact-phone-sub { font-size: 11px; font-weight: 400; color: var(--text-muted); direction: ltr; unicode-bidi: embed; }
.contact-name { font-size: 14px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-preview { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.contact-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.contact-time { font-size: 11px; color: var(--text-muted); }

.badge-unread {
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.assigned-badge {
  font-size: 10px;
  font-weight: 600;
  background: #eff6ff;
  color: var(--color-blue);
  border: 1px solid #bfdbfe;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  margin-top: 4px;
  white-space: nowrap;
}

/* ===================== CHAT HEADER ===================== */
.chat-header {
  height: var(--header-height);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  box-shadow: var(--shadow-xs);
  flex-shrink: 0;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 6px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.back-label { font-size: 13px; font-weight: 600; }
.back-btn:hover { background: var(--accent-glow); color: var(--accent); border-color: var(--accent); }

.chat-contact-info { flex: 1; }
.chat-contact-name { font-size: 15px; font-weight: 700; color: var(--text-primary); letter-spacing: -0.01em; }
.chat-contact-status { font-size: 12px; color: var(--accent); display: flex; align-items: center; gap: 4px; }

/* ===================== CHAT MESSAGES ===================== */
.chat-messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background-color: var(--bg-chat);
}

.msg-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: fadeUp 0.25s ease forwards;
}

.msg-wrapper.incoming { justify-content: flex-start; }
.msg-wrapper.outgoing { justify-content: flex-end; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-bubble {
  max-width: 65%;
  padding: 9px 13px;
  border-radius: 12px;
  position: relative;
  word-wrap: break-word;
  line-height: 1.55;
  font-size: 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.msg-wrapper.incoming .msg-bubble {
  background: #ffffff;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-right-radius: 4px;
}

.msg-wrapper.outgoing .msg-bubble {
  background: var(--bubble-out);
  color: var(--text-primary);
  border: 1px solid #b6f5c8;
  border-bottom-left-radius: 4px;
}

.msg-time {
  font-size: 10px;
  color: var(--text-muted);
  display: block;
  margin-top: 4px;
  text-align: left;
}

.msg-wrapper.outgoing .msg-time { text-align: right; color: #4d7c62; }

.date-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
}

.date-separator::before, .date-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(0,0,0,0.08);
}

/* ===================== CHAT INPUT ===================== */
.chat-input-area {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.chat-form { display: flex; gap: 10px; align-items: center; }

.message-input {
  flex: 1;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 11px 20px;
  color: var(--text-primary);
  font-family: 'Cairo', sans-serif;
  font-size: 14px;
  outline: none;
  transition: all var(--transition);
}

.message-input:focus {
  background: var(--bg-surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,168,132,0.12);
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: #fff;
  font-size: 17px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
  box-shadow: var(--shadow-accent);
  opacity: 0.7;
}

.send-btn:hover { background: var(--accent-hover); transform: scale(1.06); opacity: 1; }
.send-btn:active { transform: scale(0.95); }

/* ===================== NEW MSG TOAST ===================== */
.new-msg-toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--accent);
  color: #fff;
  padding: 7px 18px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 100;
  pointer-events: none;
  box-shadow: var(--shadow-accent);
}

.new-msg-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: all; }

/* ===================== CHAT TAGS ===================== */
.chat-tags-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-app);
  min-height: 38px;
}

.customer-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  cursor: default;
  border: 1px solid transparent;
}

.customer-tag .tag-remove { cursor: pointer; opacity: 0.6; font-size: 10px; }
.customer-tag .tag-remove:hover { opacity: 1; }

.tag-interested { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.tag-purchased  { background: #eff6ff; color: var(--color-blue); border-color: #bfdbfe; }
.tag-followup   { background: #fefce8; color: #a16207; border-color: #fde68a; }
.tag-vip        { background: #f5f3ff; color: var(--color-purple); border-color: #ddd6fe; }
.tag-cancelled  { background: #fef2f2; color: var(--color-red); border-color: #fecaca; }

.add-tag-wrapper { position: relative; }
.add-tag-btn {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px dashed var(--border-heavy);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.add-tag-btn:hover { border-color: var(--accent); color: var(--accent); }

.tag-dropdown {
  position: absolute;
  top: 30px;
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-width: 180px;
  box-shadow: var(--shadow-md);
  z-index: 300;
  overflow: hidden;
  display: none;
}
.tag-dropdown.show { display: block; }

.tag-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  cursor: pointer;
  font-size: 12px;
  transition: background var(--transition);
  border-bottom: 1px solid var(--border);
}
.tag-dropdown-item:last-child { border-bottom: none; }
.tag-dropdown-item:hover { background: var(--bg-app); }
.tag-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ===================== NOTES DRAWER ===================== */
.notes-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: 300px;
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  z-index: 400;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.notes-drawer.open { transform: translateX(0); }
.notes-drawer-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.notes-drawer-title { font-size: 14px; font-weight: 700; color: var(--text-primary); display: flex; align-items: center; gap: 8px; }
.notes-close-btn { background: var(--bg-subtle); border: 1px solid var(--border); border-radius: 7px; width: 28px; height: 28px; cursor: pointer; color: var(--text-muted); font-size: 14px; display: flex; align-items: center; justify-content: center; transition: all var(--transition); }
.notes-close-btn:hover { background: #fef2f2; border-color: #fecaca; color: var(--color-red); }
.notes-body { flex: 1; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }

.notes-textarea {
  flex: 1;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text-primary);
  font-family: 'Cairo', sans-serif;
  font-size: 13px;
  resize: none;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  min-height: 200px;
  line-height: 1.6;
}
.notes-textarea:focus { border-color: var(--color-yellow); box-shadow: 0 0 0 3px rgba(234,179,8,0.12); }

.notes-hint { font-size: 11px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: #fefce8; border: 1px solid #fde68a; border-radius: 7px; }
.notes-footer { padding: 14px 18px; border-top: 1px solid var(--border); flex-shrink: 0; }

.notes-btn {
  width: 100%;
  background: #fefce8;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 10px;
  color: #a16207;
  font-family: 'Cairo', sans-serif;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
}
.notes-btn:hover { background: #fef08a; }

.notes-toggle-btn {
  width: 36px; height: 36px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.notes-toggle-btn:hover, .notes-toggle-btn.active {
  background: #fefce8;
  border-color: #fde68a;
  color: #a16207;
}

/* ===================== QUICK REPLIES POPUP ===================== */
.quick-replies-wrapper { position: relative; flex-shrink: 0; }

.quick-reply-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--color-yellow);
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}

.quick-reply-btn:hover, .quick-reply-btn.active {
  background: #fefce8;
  border-color: #fde68a;
  box-shadow: 0 0 0 3px rgba(234,179,8,0.1);
}

.quick-replies-popup {
  position: absolute;
  bottom: 58px;
  right: 0;
  width: 290px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  opacity: 0;
  transform: translateY(8px) scale(0.97);
  pointer-events: none;
  transition: all 0.18s cubic-bezier(0.4,0,0.2,1);
  z-index: 200;
}

.quick-replies-popup.show { opacity: 1; transform: translateY(0) scale(1); pointer-events: all; }

.qr-popup-header {
  padding: 10px 16px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-bottom: 1px solid var(--border);
  background: var(--bg-app);
}

.qr-popup-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid var(--border);
}

.qr-popup-item:last-child { border-bottom: none; }
.qr-popup-item:hover { background: var(--accent-glow); }

.qr-shortcut { font-size: 11px; font-weight: 700; color: var(--accent); background: var(--accent-glow); padding: 2px 8px; border-radius: var(--radius-full); flex-shrink: 0; font-family: monospace; white-space: nowrap; }
.qr-text { font-size: 12px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

/* ===================== CHAT RESOLVE BUTTON ===================== */
.btn-resolve {
  background: #f0fdf4;
  color: #15803d;
  border: 1px solid #bbf7d0;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  margin-right: auto;
}
.btn-resolve:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ===================== BROADCAST PROGRESS ===================== */
.send-progress {
  margin-top: 4px;
  padding: 16px 20px;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: none;
}

.progress-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.progress-label-text { font-size: 13px; font-weight: 700; color: var(--text-primary); }
.progress-pct { font-size: 13px; font-weight: 800; color: var(--accent); }

.progress-track { width: 100%; height: 6px; background: var(--bg-subtle); border-radius: 99px; overflow: hidden; }
.progress-fill-bar { height: 100%; background: linear-gradient(90deg, var(--accent-hover), var(--accent), #34d399); border-radius: 99px; width: 0%; transition: width 0.15s ease; }

.progress-sub-text { margin-top: 10px; font-size: 12px; color: var(--text-muted); text-align: center; }

/* ===================== TEMPLATE SELECTOR ===================== */
.template-selector {
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-top: 4px;
}

.template-option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.template-option:last-child { border-bottom: none; }
.template-option:hover { background: var(--bg-subtle); }
.template-option.selected { background: var(--accent-glow); border-right: 3px solid var(--accent); }

.template-radio { margin-top: 3px; accent-color: var(--accent); }
.template-info { flex: 1; }
.template-name { font-size: 13px; font-weight: 700; color: var(--text-primary); margin-bottom: 4px; }
.template-preview { font-size: 12px; color: var(--text-secondary); line-height: 1.5; }
.template-preview .var-placeholder { background: var(--accent-glow); color: var(--accent); padding: 1px 6px; border-radius: 4px; font-weight: 700; font-size: 11px; }

.template-vars-section { padding: 16px 20px; background: var(--bg-app); border-top: 1px solid var(--border); display: none; }
.template-vars-section.show { display: block; }
.var-field-label { font-size: 11px; font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.template-preview-box { padding: 14px 16px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; color: var(--text-secondary); line-height: 1.6; margin-top: 8px; }

/* ===================== CREDENTIALS BOX ===================== */
.creds-box { background: var(--bg-app); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; margin-top: 4px; }
/* كل سطر: الاسم، القيمة (code)، وزرار النسخ. كانت الـ classes دي من غير CSS فكل حاجة كانت بتتراص فوق بعض */
.creds-header { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--accent-light); color: var(--accent-hover); font-size: 12px; font-weight: 700; border-bottom: 1px solid var(--border); }
.creds-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.creds-row:last-child { border-bottom: none; }
.creds-label { flex: 0 0 auto; min-width: 96px; font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.creds-row code { flex: 1 1 140px; min-width: 0; direction: ltr; text-align: left; font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace; font-size: 13px; color: var(--text-primary); overflow-wrap: anywhere; user-select: all; }

/* ===================== BILLING ITEMS ===================== */
.billing-item { display: flex; justify-content: space-between; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--border); font-size: 13px; color: var(--text-secondary); }
.billing-item:last-of-type { border-bottom: none; }
.billing-item strong { color: var(--text-primary); }

/* ===================== SWEETALERT OVERRIDES ===================== */
/* نوافذ التأكيد لازم تظهر فوق أي modal (z-index بتاع الـ modal 9999)، وإلا الزرار بيتخبى وراها ومايتضغطش */
.swal2-container { z-index: 20000 !important; }
.toastify { z-index: 20001 !important; }
.swal-custom-popup { border-radius: 16px !important; font-family: 'Cairo', sans-serif !important; border: 1px solid var(--border) !important; box-shadow: var(--shadow-lg) !important; }
.swal-custom-title { font-size: 18px !important; color: var(--text-primary) !important; }
/* زرار الإلغاء رمادي فاتح: النص الأبيض الافتراضي كان بيختفي فيه */
.swal2-styled.swal2-cancel { color: var(--text-secondary) !important; border: 1px solid var(--border) !important; box-shadow: none !important; }
.swal-custom-btn { border-radius: var(--radius-sm) !important; font-family: 'Cairo', sans-serif !important; font-weight: 600 !important; padding: 10px 24px !important; }

/* ===================== TOASTIFY ===================== */
/* زرار الإغلاق (✖) الافتراضي أبيض: كان بيختفي على الإشعارات الفاتحة */
.toastify .toast-close { color: var(--text-muted); opacity: 0.8; padding-inline-start: 10px; }
.toastify .toast-close:hover { opacity: 1; color: var(--text-primary); }
.wa-toast-msg { font-family: 'Cairo', sans-serif; direction: rtl; line-height: 1.5; }
.wa-toast-phone { font-weight: 700; color: var(--accent); display: block; margin-bottom: 2px; }
.wa-toast-text { font-size: 12px; color: var(--text-muted); display: block; }

/* ===================== ANIMATIONS & UTILITIES ===================== */
.fade-in { animation: fadeUp 0.35s ease forwards; }
.text-green { color: var(--accent); }
.text-muted { color: var(--text-muted); }
.mobile-only  { display: none !important; }
.desktop-only { display: flex !important; }

@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }
@keyframes pulse-badge { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.2); } }

.skeleton {
  background: linear-gradient(90deg, var(--bg-subtle) 25%, var(--border) 50%, var(--bg-subtle) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
}

/* ===================== NAV BACKDROP ===================== */
.nav-backdrop { display: none; position: fixed; inset: 0; background: rgba(15,23,42,0.45); backdrop-filter: blur(3px); z-index: 299; }
.nav-backdrop.show { display: block; }

/* ===================== PROGRESS BAR (Table) ===================== */
.progress-bar { display: inline-block; width: 70px; height: 5px; background: var(--bg-subtle); border-radius: 99px; overflow: hidden; vertical-align: middle; margin-left: 6px; }
.progress-fill { height: 100%; border-radius: 99px; transition: width 0.8s ease; }

/* ===================== LOGIN PAGE ===================== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-app);
  background-image: radial-gradient(circle at 20% 80%, rgba(0,168,132,0.05) 0%, transparent 50%),
                    radial-gradient(circle at 80% 20%, rgba(59,130,246,0.05) 0%, transparent 50%);
}

.login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 48px;
  width: 420px;
  max-width: 95vw;
  box-shadow: var(--shadow-lg);
}

.login-logo-icon {
  width: 56px;
  height: 56px;
  background: var(--accent);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin: 0 auto 24px;
  box-shadow: var(--shadow-accent);
}

.login-title { font-size: 26px; font-weight: 800; color: var(--text-primary); text-align: center; margin-bottom: 6px; letter-spacing: -0.03em; }
.login-subtitle { font-size: 14px; color: var(--text-muted); text-align: center; margin-bottom: 32px; }
.login-form { display: flex; flex-direction: column; gap: 18px; }
.login-btn { width: 100%; }

/* ===================== SUPER ADMIN SETTINGS ===================== */

/* ===================== RESPONSIVE — 900px ===================== */
@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr !important; }
  .chart-card-wide { grid-column: 1 !important; }
  .settings-grid { grid-template-columns: 1fr !important; }
  .form-row { flex-direction: column !important; }
}

/* ===================== RESPONSIVE — 768px ===================== */
@media (max-width: 768px) {
  html, body { overflow: auto; }

  .mobile-only { display: flex !important; }
  .desktop-only { display: none !important; }

  /* App Layout */
  .app-layout { overflow: visible; height: 100vh; }

  /* Off-canvas sidebar */
  .sidebar {
    width: 82%;
    max-width: 300px;
    min-width: unset;
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    z-index: 300;
    transform: translateX(105%);
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open { transform: translateX(0); }
  .main-content { width: 100%; height: 100vh; }
  .mobile-menu-btn { display: flex; }
  .dashboard-header { padding: 0 14px; }
  /* هيدر المحادثة على الموبايل: العناصر كتير (رجوع، اسم، مؤقت، إنهاء، ملاحظات، قايمة)، فبتلف على سطرين بدل ما تطلع برا الشاشة */
  .chat-header { height: auto; min-height: var(--header-height); padding: 8px 12px; gap: 8px; flex-wrap: wrap; }
  .chat-contact-info { flex: 1 1 120px; min-width: 0; }
  .chat-contact-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #meta-timer { margin-right: 0 !important; }
  .chat-header .btn-resolve { margin-inline-start: auto; }

  .stats-grid { grid-template-columns: 1fr 1fr !important; }
  .dashboard-body { padding: 14px; }
  .msg-bubble { max-width: 88%; }

  /* WA-Layout mobile */
  .wa-layout { position: relative; }

  .nav-slim {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: 220px;
    z-index: 300;
    transform: translateX(105%);
    box-shadow: var(--shadow-lg);
  }

  .nav-slim.open { transform: translateX(0); width: 220px; }
  .nav-slim.open .nav-item { justify-content: flex-start; padding: 10px 12px; }
  .nav-slim.open .nav-item span:last-child { display: inline !important; }
  .nav-slim.open .nav-slim-brand { justify-content: flex-start; padding: 0 16px; }

  .chat-list-col { position: fixed; inset: 0; width: 100%; max-width: 100%; z-index: 10; }
  .wa-main { position: fixed; inset: 0; z-index: 11; }
  .mobile-hidden { display: none !important; }

  .dashboard-header { height: auto; padding: 12px 14px; flex-wrap: wrap; }
  .header-actions { width: 100%; margin-top: 10px; justify-content: flex-start; }

  /* Other mobile */
  .bot-rules-grid { grid-template-columns: 1fr; }
  .portal-tabs { flex-wrap: nowrap; }
  .portal-tab { font-size: 12px; padding: 8px 10px; min-width: 100px; }
  .notes-drawer { width: 260px; }
  .settings-grid { grid-template-columns: 1fr !important; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr !important; }
  .stat-value { font-size: 26px; }
  .page-title { font-size: 16px; }
  .stats-grid[style*="repeat(4"] { grid-template-columns: repeat(2, 1fr) !important; }

  /* كروت الإحصائيات 2 في الصف: من غير ضغط الـ padding والـ gap الكروت كانت بتطلع برا الشاشة وتتقص */
  .stats-grid > * { min-width: 0; }
  .stats-grid .stat-card { padding: 12px; gap: 10px; }
  .stats-grid .stat-icon { width: 36px; height: 36px; flex: 0 0 auto; border-radius: 10px; }
  .stats-grid .stat-info { min-width: 0; }
  .stats-grid .stat-value { font-size: 19px; }
  .stats-grid .stat-label { font-size: 11px; overflow-wrap: anywhere; }
}

/* ===================== RESPONSIVE TABLES — 640px =====================
   الجدول العريض بيتحوّل لكروت: كل صف كارت، وكل خانة سطر "العنوان: القيمة" (العناوين بتتحط من global.js).
   من غير كده عمود الإجراءات (أزرار الحذف والتجميد...) كان بيطلع برا الشاشة ومحدش بيوصله */
@media (max-width: 640px) {
  .table-wrapper { overflow-x: visible; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table thead { display: none; }
  .data-table tbody tr { border: 1px solid var(--border); border-radius: var(--radius); margin: 0 0 12px; padding: 6px 12px; background: var(--bg-surface); }
  .data-table td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--border); text-align: end; min-width: 0; }
  .data-table td:last-child { border-bottom: none; }
  .data-table td[data-label]::before { content: attr(data-label); flex: 0 0 auto; font-size: 11px; font-weight: 600; color: var(--text-muted); text-align: start; }
  .data-table td[colspan] { justify-content: center; text-align: center; }
  .data-table td[colspan]::before { content: none; }
  /* خلية الإجراءات: الأزرار جنب بعض وتلف على سطر جديد لو ضاقت */
  .data-table td .icon-btn, .data-table td .tbl-action-btn { flex: 0 0 auto; }
}
