/* ====================================================
   CRM PREMIUM DESIGN SYSTEM & VARIABLES (Arabic RTL)
   ==================================================== */
:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-hover: #f1f5f9;
  --surface-glass: rgba(255, 255, 255, 0.85);
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --border-focus: #0f766e;
  
  /* Harmonious Color Palette */
  --primary: #0f766e;
  --primary-hover: #0d9488;
  --primary-soft: #f0fdfa;
  
  --success: #10b981;
  --success-hover: #059669;
  --success-soft: #ecfdf5;
  
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-soft: #fef2f2;
  
  --warning: #f59e0b;
  --warning-soft: #fffbeb;
  
  --info: #0ea5e9;
  --info-soft: #f0f9ff;
  
  /* Layout Metrics */
  --sidebar-width: 260px;
  --radius: 16px;
  --radius-sm: 10px;
  
  /* Premium Shadows & Glows */
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.04);
  --shadow: 0 10px 30px -5px rgba(13, 148, 136, 0.05), 0 8px 20px -6px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 20px 40px -10px rgba(15, 23, 42, 0.1), 0 0 0 1px rgba(15, 23, 42, 0.05);
  --glow-primary: 0 0 0 4px rgba(13, 148, 136, 0.15);
  --glow-danger: 0 0 0 4px rgba(239, 68, 68, 0.15);
  
  /* Transitions */
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== GENERAL BASE & RESET ===== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Cairo', system-ui, -apple-system, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button, input, select, textarea {
  font-family: inherit;
  transition: var(--transition);
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: var(--transition);
}
a:hover {
  color: var(--primary-hover);
}

/* ===== CORE ADMIN LAYOUT ===== */
.admin-wrapper {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* Sidebar Styling */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  z-index: 100;
  transition: var(--transition);
}

.sidebar-header {
  padding: 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary), #0d9488);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.3rem;
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.2);
}

.logo-wrap h2 {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}

.logo-badge {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--primary);
  background-color: var(--primary-soft);
  padding: 2px 6px;
  border-radius: 4px;
}

.close-sidebar-btn {
  display: none;
  font-size: 1.2rem;
  color: var(--muted);
  padding: 4px 8px;
}

.sidebar-nav {
  flex: 1;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 700;
  font-size: 0.95rem;
  text-align: right;
  width: 100%;
}

.nav-item:hover {
  background-color: var(--bg);
  color: var(--text);
}

.nav-item.active {
  background-color: var(--primary-soft);
  color: var(--primary);
}

.nav-icon {
  font-size: 1.15rem;
}

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

.footer-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  font-size: 0.75rem;
  color: var(--muted);
}

.version-lbl {
  background-color: var(--border);
  color: var(--text);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
}

/* Main Layout Area */
.main-layout {
  flex: 1;
  margin-right: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg);
  transition: var(--transition);
}

/* Top Navbar */
.top-navbar {
  background-color: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 18px 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 90;
}

.top-nav-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.menu-toggle-btn {
  display: none;
  font-size: 1.5rem;
  color: var(--text);
  padding: 4px;
}

.page-title-wrap h1 {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}

.page-title-wrap p {
  font-size: 0.8rem;
  color: var(--muted);
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--success);
  display: inline-block;
  box-shadow: 0 0 8px var(--success);
}

.connection-status.connected .status-dot {
  background-color: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.connection-status.disconnected .status-dot {
  background-color: var(--danger);
  box-shadow: 0 0 8px var(--danger);
  animation: pulseGlow 1.2s infinite;
}

@keyframes pulseGlow {
  50% { opacity: 0.5; }
}

/* Content Container */
.content-container {
  flex: 1;
  padding: 30px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* ===== TAB SYSTEM ===== */
.tab-content {
  display: none;
  animation: slideUp 0.38s cubic-bezier(0.16, 1, 0.3, 1);
}

.tab-content.active {
  display: block;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== STATS CARDS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  position: relative;
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: rgba(99, 102, 241, 0.25);
}

.stat-icon-wrap {
  width: 54px;
  height: 54px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.bg-primary-soft { background-color: var(--primary-soft); color: var(--primary); }
.bg-success-soft { background-color: var(--success-soft); color: var(--success); }
.bg-warning-soft { background-color: var(--warning-soft); color: var(--warning); }

.stat-icon {
  font-size: 1.5rem;
}

.stat-info {
  flex: 1;
}

.stat-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  display: block;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}

.stat-indicator {
  position: absolute;
  top: 14px;
  left: 14px;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
}

.stat-indicator.positive {
  background-color: var(--success-soft);
  color: var(--success);
}

/* ===== CARDS & GRID ===== */
.card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.card.glass {
  background-color: var(--surface-glass);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.card-head {
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
}

.card-head h3 {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 2px;
}

.muted {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
}

.mt-24 { margin-top: 24px; }
.mt-20 { margin-top: 20px; }
.mt-16 { margin-top: 16px; }
.w-full { width: 100%; }

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 24px;
}

.flex-col-card {
  display: flex;
  flex-direction: column;
}

.quick-actions-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
}

.quick-intro {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 8px;
}

/* Dynamic distributions styling */
.dist-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.dist-group h4 {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
}

.dist-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.dist-pill {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 20px;
  background-color: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
}

.dist-pill.primary {
  background-color: var(--primary-soft);
  color: var(--primary);
  border-color: rgba(99, 102, 241, 0.15);
}

.placeholder-dist {
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

/* ===== RECENT TABLES ===== */
.table-card {
  padding: 24px 0 0 0;
  overflow: hidden;
}

.flex-row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px 14px 24px;
}

.btn-link {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
}
.btn-link:hover {
  color: var(--primary-hover);
  transform: translateX(-4px);
}

.recent-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.recent-table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  font-size: 0.85rem;
}

.recent-table th {
  background-color: var(--bg);
  padding: 14px 20px;
  color: var(--muted);
  font-weight: 700;
  border-bottom: 1px solid var(--border);
}

.recent-table td {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}

.recent-table tbody tr:hover {
  background-color: var(--bg);
}

.recent-table tbody tr:last-child td {
  border-bottom: none;
}

.loading-td {
  text-align: center;
  color: var(--muted);
  padding: 30px !important;
  font-style: italic;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 30px;
  line-height: 1;
}

.status-badge.new { background-color: var(--info-soft); color: var(--info); }
.status-badge.active { background-color: var(--success-soft); color: var(--success); }
.status-badge.inactive { background-color: var(--danger-soft); color: var(--danger); }

/* ===== STICKY ADVANCED FILTER CARD ===== */
.search-sticky-card {
  position: sticky;
  top: 85px; /* right below top-navbar */
  z-index: 80;
  background-color: var(--surface-glass);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.search-bar-row {
  width: 100%;
}

.search-input-wrap {
  position: relative;
  width: 100%;
}

.search-input-wrap input {
  width: 100%;
  padding: 14px 44px 14px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  box-shadow: var(--shadow-sm);
}

.search-input-wrap input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--glow-primary);
}

.search-input-icon {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.15rem;
  color: var(--muted);
}

.filters-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  align-items: flex-end;
  width: 100%;
}

.filter-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-item label {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--muted);
}

.filter-select {
  padding: 12px 14px;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 700;
  outline: none;
}

.filter-select:focus {
  border-color: var(--primary);
  box-shadow: var(--glow-primary);
}

.btn-reset {
  padding: 10px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background-color: var(--surface);
  height: 48px;
  width: 100%;
  white-space: nowrap;
}

.btn-reset:hover {
  background-color: var(--surface-hover);
  color: var(--text);
}

.search-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  border-top: 1px dashed var(--border);
  padding-top: 10px;
}

/* ===== CONTACT CARDS GRID ===== */
.contacts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

.contact-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: var(--transition);
  position: relative;
}

.contact-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: rgba(99, 102, 241, 0.2);
}

.contact-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.contact-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.05rem;
  flex-shrink: 0;
}

.contact-title h4 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}

.contact-date {
  font-size: 0.7rem;
  color: var(--muted);
}

.contact-card-actions {
  display: flex;
  gap: 6px;
}

.btn-card-action {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-card-action:hover {
  background-color: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary);
}

.btn-card-action.danger:hover {
  background-color: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger);
}

.contact-details {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.detail-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  border-bottom: 1px dashed var(--border);
  padding-bottom: 6px;
}

.detail-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.detail-label {
  color: var(--muted);
  font-weight: 700;
}

.detail-val-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 75%;
  justify-content: flex-end;
}

.detail-value {
  font-weight: 700;
  color: var(--text);
}

.detail-value.mono {
  font-family: monospace;
  font-size: 0.85rem;
  direction: ltr;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
  display: inline-block;
}

/* Copy button */
.copy-btn {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 800;
  background-color: var(--primary-soft);
  color: var(--primary);
}

.copy-btn:hover {
  background-color: var(--primary);
  color: white;
}

.copy-btn.copied {
  background-color: var(--success-soft);
  color: var(--success);
}

.contact-notes {
  background-color: var(--bg);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--text);
  max-height: 80px;
  overflow-y: auto;
  border-right: 3px solid var(--primary);
}

/* ===== PAGINATION ===== */
.pagination-container {
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.page-size-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 700;
}

.page-select-inline {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  background-color: var(--surface);
  outline: none;
}

.pagination-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-page {
  padding: 8px 16px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
}

.btn-page:hover:not(:disabled) {
  background-color: var(--surface-hover);
  border-color: var(--muted);
}

.btn-page:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-num-lbl {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
}

/* ===== FORMS & FIELDS ===== */
.max-width-form {
  max-width: 650px;
  margin: 0 auto;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-full {
  grid-column: 1 / -1;
}

.field label {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--text);
}

.field input, .field select, .field textarea {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  resize: vertical;
}

.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary);
  box-shadow: var(--glow-primary);
}

.form-select {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}

.label-description {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: -4px;
}

.error-msg {
  color: var(--danger);
  font-size: 0.75rem;
  font-weight: 700;
  min-height: 1.2em;
}

.border-top {
  border-top: 1px solid var(--border);
  padding-top: 18px;
}

.form-actions {
  display: flex;
  gap: 10px;
}

/* ===== BUTTONS ===== */
.btn-primary, .btn-ghost, .btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  font-weight: 800;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
}

.btn-primary {
  background-color: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.15);
}
.btn-primary:hover:not(:disabled) {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.25);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-ghost {
  background-color: var(--border);
  color: var(--text);
}
.btn-ghost:hover {
  background-color: #cbd5e1;
}

.btn-danger {
  background-color: var(--danger);
  color: white;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.15);
}
.btn-danger:hover {
  background-color: var(--danger-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(239, 68, 68, 0.25);
}

/* ===== SIDEBAR BACKDROP FOR MOBILE ===== */
.sidebar-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 95;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.sidebar-backdrop.active {
  opacity: 1;
  visibility: visible;
}

/* ===== MODALS & OVERLAYS ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 550px;
  box-shadow: var(--shadow-lg);
  padding: 24px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.modal-card.modal-sm {
  max-width: 420px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 2px;
}

.modal-header.header-danger h3 {
  color: var(--danger);
}

.modal-close-btn {
  font-size: 1.2rem;
  color: var(--muted);
  padding: 4px 8px;
}
.modal-close-btn:hover {
  color: var(--text);
}

.modal-body {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text);
}

.alert-delete-msg {
  background-color: var(--danger-soft);
  border-right: 4px solid var(--danger);
  padding: 12px;
  border-radius: var(--radius-sm);
  color: #991b1b;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 10px;
}

/* Animations */
.animate-scaleIn {
  transform: scale(0.95);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.active .animate-scaleIn {
  transform: scale(1);
}

/* ===== EMPTY & LOADING STATE ===== */
.empty, .loading {
  background-color: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 50px 20px;
  text-align: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
}

.empty-icon {
  font-size: 3rem;
  opacity: 0.6;
}

.empty p {
  font-weight: 700;
  font-size: 0.95rem;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ===== TOAST NOTIFICATIONS ===== */
.toast-wrap {
  position: fixed;
  top: 24px;
  left: 24px;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-right: 5px solid var(--primary);
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
  font-weight: 700;
  min-width: 280px;
  animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transition: var(--transition);
}

.toast.success {
  border-right-color: var(--success);
  background-color: var(--success-soft);
  color: #065f46;
}

.toast.error {
  border-right-color: var(--danger);
  background-color: var(--danger-soft);
  color: #991b1b;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(-24px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

/* ===== RESPONSIVE DESIGN & MOBILE OPTIMIZATIONS ===== */

/* Base responsiveness safeguards */
html, body {
  max-width: 100vw;
  overflow-x: hidden;
}

/* --- Breakpoint: Medium screens (Tablets/Small Laptops < 1024px) --- */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 240px;
  }
  
  .content-container {
    padding: 24px 20px;
  }
  
  .top-navbar {
    padding: 16px 20px;
  }
}

/* --- Breakpoint: Small screens (Tablets/Phones < 900px) --- */
@media (max-width: 900px) {
  /* Mobile App Bottom Navigation Bar */
  .sidebar {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 70px;
    flex-direction: row;
    transform: none;
    visibility: visible;
    border-left: none;
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
    z-index: 999;
    background-color: var(--surface-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }
  
  .sidebar-header, .sidebar-footer {
    display: none !important;
  }
  
  .sidebar-nav {
    flex-direction: row;
    justify-content: space-around;
    padding: 0;
    align-items: center;
    width: 100%;
    height: 100%;
  }
  
  .nav-item {
    flex-direction: column;
    padding: 6px 4px;
    gap: 4px;
    justify-content: center;
    border-radius: 12px;
    height: 100%;
    text-align: center;
  }
  
  .nav-item span:not(.nav-icon) {
    font-size: 0.65rem;
    font-weight: 800;
  }
  
  .nav-icon {
    font-size: 1.3rem;
  }

  .close-sidebar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--surface-hover);
    color: var(--text);
  }
  .close-sidebar-btn:hover {
    background-color: var(--border);
  }

  .menu-toggle-btn {
    display: none; /* Hide hamburger, bottom nav takes over */
  }
  
  .mobile-logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--danger-soft);
    color: var(--danger);
    font-size: 1.1rem;
    border: 1px solid rgba(239, 68, 68, 0.2);
  }
  
  .hide-mobile {
    display: none;
  }
  
  .top-navbar {
    padding: 12px 16px;
    position: sticky;
    top: 0;
    box-shadow: var(--shadow-sm);
  }
  
  .top-nav-left {
    display: flex;
    align-items: center;
    flex-direction: row-reverse;
    gap: 12px;
  }
  
  .main-layout {
    margin-right: 0; /* Occupy full width */
    padding-bottom: 70px; /* Space for bottom nav */
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    box-sizing: border-box;
  }
  
  .content-container {
    padding: 20px 16px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
  }

  .search-sticky-card {
    top: 75px;
    padding: 16px;
  }
  
  .filters-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
}

/* --- Breakpoint: Touch-friendly Stacking & Grid collapse (Tablets & Phones < 768px) --- */
@media (max-width: 768px) {
  /* Mobile App feel: Compact Grid for Stats (1 Hero + 2 Secondary) */
  .stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
  }
  
  .stat-card {
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
    position: relative;
  }
  
  .stat-card:first-child {
    grid-column: span 2;
    flex-direction: row;
    text-align: right;
    padding: 20px 16px;
  }
  
  .stat-icon-wrap {
    width: 42px;
    height: 42px;
  }
  
  .stat-icon {
    font-size: 1.2rem;
  }
  
  .stat-value {
    font-size: 1.15rem;
  }
  
  .stat-label {
    font-size: 0.75rem;
    line-height: 1.3;
  }
  
  .stat-indicator {
    position: static;
    display: inline-block;
    margin-top: 4px;
    font-size: 0.6rem;
  }
  
  .stat-card:first-child .stat-indicator {
    position: absolute;
    top: 16px;
    left: 16px;
    margin-top: 0;
  }
  
  /* Dashboard layout grids collapse to one column */
  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  
  /* Card spacing and sizing tweaks */
  .card {
    padding: 20px;
  }
  
  .card-head {
    margin-bottom: 16px;
    padding-bottom: 12px;
  }

  /* ----------------------------------------------------
     RESPONSIVE RECENT TABLE-TO-CARDS TRANSFORMATION
     ---------------------------------------------------- */
  .recent-table-wrap {
    overflow-x: visible; /* Cards don't need horizontal scroll */
  }
  
  .recent-table thead {
    display: none; /* Hide header rows */
  }
  
  .recent-table, 
  .recent-table tbody, 
  .recent-table tr, 
  .recent-table td {
    display: block;
    width: 100%;
  }
  
  .recent-table tr {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    padding: 16px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
  }
  
  .recent-table tr:hover {
    border-color: rgba(99, 102, 241, 0.2);
    background-color: var(--surface);
  }
  
  .recent-table tr::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 4px;
    height: 100%;
    background-color: var(--primary);
  }
  
  .recent-table tr:last-child {
    margin-bottom: 0;
  }
  
  .recent-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px dashed var(--border);
    white-space: normal;
    font-size: 0.9rem;
    text-align: left;
    word-break: break-word; /* Prevent long emails from expanding the table */
    min-width: 0;
    gap: 8px;
  }
  
  .recent-table td:last-child {
    border-bottom: none;
  }
  
  /* Generate Arabic descriptive headers before cells dynamically */
  .recent-table td::before {
    content: attr(data-label);
    font-weight: 800;
    color: var(--muted);
    margin-left: 16px;
    text-align: right;
    flex-shrink: 0;
    font-size: 0.8rem;
  }
  
  .recent-table td strong {
    text-align: left;
    color: var(--text);
  }
  
  .recent-table td .detail-val-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: flex-end;
    width: auto;
    max-width: 70%;
  }
  
  .recent-table td .status-badge {
    margin: 0;
  }
}

/* --- Breakpoint: Ultra-mobile Optimization (Phones < 500px) --- */
@media (max-width: 500px) {
  /* Compression of sticky filters header to protect vertical space */
  .search-sticky-card {
    top: 70px;
    padding: 12px;
    gap: 12px;
    border-radius: var(--radius-sm);
  }
  
  .search-input-wrap input {
    padding: 12px 40px 12px 16px;
    font-size: 0.9rem;
  }
  
  .search-input-icon {
    right: 14px;
  }
  
  /* Vertical single-column stack on filter items to avoid squishing */
  .filters-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  
  .filter-select, .btn-reset {
    height: 46px;
    font-size: 0.85rem;
  }

  .search-status-bar {
    font-size: 0.7rem;
    padding-top: 8px;
  }

  /* Main headings & text scaling */
  .page-title-wrap h1 {
    font-size: 1.15rem;
  }
  
  .page-title-wrap p {
    font-size: 0.75rem;
  }
  
  .connection-status {
    padding: 4px 10px;
    font-size: 0.7rem;
  }
  
  /* Actions buttons stacking */
  .form-actions {
    flex-direction: column;
    gap: 10px;
  }
  
  .form-actions button {
    width: 100%;
  }
  
  .modal-actions {
    flex-direction: column;
    width: 100%;
    gap: 10px;
  }
  
  .modal-actions button {
    width: 100%;
    margin-right: 0 !important;
  }

  .pagination-container {
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding-top: 16px;
  }
  
  .pagination-nav {
    width: 100%;
    justify-content: space-between;
  }

  .btn-page {
    flex: 1;
    text-align: center;
  }

  /* Contact cards grid tweaks */
  .contacts-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .contact-card {
    padding: 16px;
    gap: 12px;
  }

  .avatar {
    width: 38px;
    height: 38px;
    font-size: 0.95rem;
  }
  
  .contact-title h4 {
    font-size: 0.9rem;
  }
}

/* --- Breakpoint: Micro-screens (Tiny Phones < 320px) --- */
@media (max-width: 320px) {
  .content-container {
    padding: 16px 8px;
  }

  .recent-table tr {
    padding: 12px 10px;
  }

  .recent-table td {
    font-size: 0.8rem;
  }

  .copy-btn {
    padding: 1px 4px;
    font-size: 0.6rem;
  }
}

/* --- LOGIN PAGE STYLES --- */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
  background: radial-gradient(circle at top right, #0d9488 0%, #0f766e 40%, #093d39 100%);
  padding: 20px;
  box-sizing: border-box;
  animation: fadeIn 0.5s ease-out;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius);
  padding: 40px 32px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  box-sizing: border-box;
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary), #0d9488);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.8rem;
  box-shadow: 0 8px 24px rgba(13, 148, 136, 0.3);
  margin: 0 auto 16px auto;
}

.login-header h2 {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 6px;
}

.login-header p {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 500;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.login-card form .field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.login-card form label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}

.login-card form input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  box-sizing: border-box;
}

.login-card form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--glow-primary);
}

.btn-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-weight: 700;
  font-size: 0.9rem;
  background-color: var(--danger-soft);
  border: 1px solid rgba(239, 68, 68, 0.15);
  transition: var(--transition);
  box-sizing: border-box;
}

.btn-logout:hover {
  background-color: var(--danger);
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}

/* --- LOGIN INPUT WITH ICONS & ALERT --- */
.input-with-icon {
  position: relative;
  width: 100%;
}

.input-with-icon .input-icon {
  position: absolute;
  top: 50%;
  right: 14px;
  transform: translateY(-50%);
  font-size: 1.1rem;
  color: var(--muted);
  pointer-events: none;
}

.input-with-icon input {
  padding-right: 44px !important;
  padding-left: 16px !important;
}

.login-alert {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 24px;
  font-size: 0.82rem;
  line-height: 1.5;
  box-sizing: border-box;
  text-align: right;
}

.info-alert {
  background-color: var(--primary-soft);
  border: 1px solid rgba(13, 148, 136, 0.15);
  color: var(--primary);
}

.info-alert span {
  font-size: 1.2rem;
  flex-shrink: 0;
}

.info-alert p {
  margin: 0;
  font-weight: 500;
}
