/* ==========================================
   MATES EDUCATION ERP — DESIGN SYSTEM
   Color Theme: Teal/Turquoise from Logo
   ========================================== */

:root {
  --primary: #2ABFBF;
  --primary-dark: #1A8C8C;
  --primary-light: #4DD9D9;
  --primary-glow: rgba(42, 191, 191, 0.4);
  --primary-subtle: rgba(42, 191, 191, 0.08);

  --bg-dark: #060B18;
  --bg-body: #0A0F1A;
  --bg-surface: #0F1629;
  --bg-card: rgba(15, 22, 41, 0.7);
  --bg-card-hover: rgba(42, 191, 191, 0.06);
  --bg-input: rgba(255, 255, 255, 0.04);

  --border: rgba(42, 191, 191, 0.12);
  --border-hover: rgba(42, 191, 191, 0.3);

  --text-primary: #F1F5F9;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;

  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --info: #3B82F6;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 20px var(--primary-glow);

  --sidebar-width: 260px;
  --topbar-height: 72px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg-body);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  min-height: 100vh;
  position: relative;
}

/* === ANIMATED BACKGROUND === */
.animated-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.bg-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.15;
  animation: orbFloat 20s ease-in-out infinite;
}
.bg-orb-1 { width: 600px; height: 600px; background: var(--primary); top: -200px; left: -100px; animation-delay: 0s; }
.bg-orb-2 { width: 500px; height: 500px; background: #7c3aed; bottom: -150px; right: -100px; animation-delay: -7s; }
.bg-orb-3 { width: 400px; height: 400px; background: var(--primary-dark); top: 50%; left: 50%; animation-delay: -14s; }

.bg-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(42,191,191,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42,191,191,0.03) 1px, transparent 1px);
  background-size: 60px 60px;
}

/* === SIDEBAR === */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  position: fixed;
  left: 0; top: 0;
  background: rgba(10, 15, 26, 0.85);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: var(--transition);
}

.sidebar-header {
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(42, 191, 191, 0.06), rgba(255, 255, 255, 0.03), rgba(42, 191, 191, 0.04));
}

.sidebar-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 50%, rgba(255, 255, 255, 0.06), transparent 70%);
  animation: sidebarHeaderGlow 4s ease-in-out infinite;
}

.sidebar-header::after {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 200%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.04), transparent);
  animation: sidebarShimmer 6s ease-in-out infinite;
}

@keyframes sidebarHeaderGlow {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

@keyframes sidebarShimmer {
  0% { transform: translateX(-50%); }
  100% { transform: translateX(50%); }
}

.sidebar-logo {
  height: 42px;
  width: auto;
  filter: drop-shadow(0 0 12px var(--primary-glow));
  position: relative;
  z-index: 1;
  animation: logoFloat 4s ease-in-out infinite;
}

@keyframes logoFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}


.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
  transition: var(--transition);
  position: relative;
}

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

.nav-item.active {
  background: linear-gradient(135deg, rgba(42,191,191,0.12), rgba(42,191,191,0.05));
  color: var(--primary);
  box-shadow: inset 0 0 0 1px rgba(42,191,191,0.2);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 24px;
  background: var(--primary);
  border-radius: 0 4px 4px 0;
  box-shadow: 0 0 12px var(--primary-glow);
}

.nav-icon { display: flex; align-items: center; flex-shrink: 0; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.sidebar-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--success);
  font-weight: 500;
}

.badge-dot {
  width: 8px; height: 8px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

/* === MAIN CONTENT === */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

/* === TOPBAR === */
.topbar {
  height: var(--topbar-height);
  padding: 0 32px;
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(10, 15, 26, 0.6);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 8px;
}

.topbar-title {
  font-size: 20px;
  font-weight: 700;
  flex: 1;
}

.topbar-actions { display: flex; align-items: center; gap: 16px; }

.topbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--bg-card);
  padding: 8px 16px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
}

.status-indicator {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}
.status-indicator.online { background: var(--success); box-shadow: 0 0 8px rgba(16,185,129,0.5); }

/* === PAGE CONTAINER === */
.page-container {
  padding: 32px;
  animation: fadeIn 0.4s ease;
}

/* === CARDS & PANELS === */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  transition: var(--transition);
}

.card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-glow);
}

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

.card-title {
  font-size: 18px;
  font-weight: 700;
}

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

.stat-card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  opacity: 0;
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-hover);
  box-shadow: var(--shadow-glow);
}

.stat-card:hover::before { opacity: 1; }

.stat-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  background: var(--primary-subtle);
  color: var(--primary);
}

.stat-value {
  font-size: 32px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--text-primary), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
  font-weight: 500;
}

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-weight: 600;
  font-size: 14px;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  box-shadow: 0 4px 16px rgba(42,191,191,0.25);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(42,191,191,0.4);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  border-color: var(--border-hover);
  background: var(--bg-card-hover);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
}
.btn-danger:hover {
  background: rgba(239, 68, 68, 0.25);
}

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* === FORM ELEMENTS === */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group {
  position: relative;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  transition: var(--transition);
  outline: none;
  box-sizing: border-box;
  max-width: 100%;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(42,191,191,0.15);
}

.form-input::placeholder, .form-textarea::placeholder {
  color: var(--text-muted);
}

.form-textarea {
  min-height: 120px;
  resize: vertical;
}

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%2394A3B8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  padding-right: 40px;
}

/* === CUSTOM DROPDOWN === */
.custom-select {
  position: relative;
  width: 100%;
  box-sizing: border-box;
}

.custom-select-trigger {
  width: 100%;
  padding: 12px 40px 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: var(--transition);
  box-sizing: border-box;
  min-height: 44px;
}

.custom-select-trigger:hover {
  border-color: rgba(42,191,191,0.4);
}

.custom-select.open .custom-select-trigger {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(42,191,191,0.15);
}

.custom-select-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-select-arrow {
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.custom-select.open .custom-select-arrow {
  transform: rotate(180deg);
}

.custom-select-dropdown {
  display: none;
  position: fixed;
  width: auto;
  background: #1a2332;
  border: 1px solid rgba(42,191,191,0.3);
  border-radius: var(--radius-md);
  box-shadow: 0 16px 48px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.06) inset;
  z-index: 999999;
  max-height: 220px;
  overflow-y: auto;
  box-sizing: border-box;
  animation: customSelectOpen 0.15s ease;
}

@keyframes customSelectOpen {
  0% { opacity: 0; transform: translateY(-6px); }
  100% { opacity: 1; transform: translateY(0); }
}

.custom-select.open .custom-select-dropdown {
  display: block;
}

.custom-select-option {
  padding: 10px 16px;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.custom-select-option:hover {
  background: rgba(42,191,191,0.08);
  color: var(--text-primary);
}

.custom-select-option.selected {
  background: rgba(42,191,191,0.12);
  color: var(--primary);
  font-weight: 600;
}

.custom-select-option.selected::before {
  content: '✓ ';
  font-weight: 700;
}

/* === TABLE === */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  padding: 14px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: rgba(42,191,191,0.04);
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 14px 16px;
  font-size: 14px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  color: var(--text-secondary);
}

.data-table tr:hover td {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.data-table .email-cell {
  color: var(--primary);
  font-weight: 500;
}

/* === BADGES === */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
}

.badge-success { background: rgba(16,185,129,0.12); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.12); color: var(--warning); }
.badge-danger { background: rgba(239,68,68,0.12); color: var(--danger); }
.badge-info { background: rgba(59,130,246,0.12); color: var(--info); }
.badge-primary { background: var(--primary-subtle); color: var(--primary); }

/* === SEARCH BAR === */
.search-bar {
  position: relative;
  max-width: 400px;
}

.search-bar .form-input {
  padding-left: 44px;
}

.search-bar svg {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

/* === CSV UPLOADER === */
.csv-dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 48px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  background: var(--bg-input);
}

.csv-dropzone:hover, .csv-dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-subtle);
  box-shadow: var(--shadow-glow);
}

.csv-dropzone-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  color: var(--primary);
  opacity: 0.6;
}

.csv-dropzone-text {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.csv-dropzone-sub {
  font-size: 13px;
  color: var(--text-muted);
}

/* === TOAST NOTIFICATIONS === */
.toast-container {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.toast {
  padding: 14px 24px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 320px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  animation: toastSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  border: 1px solid;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3), 0 0 0 1px rgba(255,255,255,0.05) inset;
}

.toast-success { background: rgba(16,185,129,0.12); color: var(--success); border-color: rgba(16,185,129,0.2); }
.toast-error { background: rgba(239,68,68,0.12); color: var(--danger); border-color: rgba(239,68,68,0.2); }
.toast-warning { background: rgba(245,158,11,0.12); color: var(--warning); border-color: rgba(245,158,11,0.2); }
.toast-info { background: rgba(59,130,246,0.12); color: var(--info); border-color: rgba(59,130,246,0.2); }

/* === MODAL === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.modal-content {
  width: 90%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 32px;
  animation: scaleIn 0.3s ease;
}

/* === TABS === */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.tab {
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
  font-family: var(--font);
}

.tab:hover { color: var(--text-secondary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* === CHECKBOX === */
.checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.checkbox-wrapper input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* === EMPTY STATE === */
.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-muted);
}

.empty-state svg { margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 { color: var(--text-secondary); margin-bottom: 8px; }
.empty-state p { font-size: 14px; }

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

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(6,11,24,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-lg);
  z-index: 10;
}

/* === PROGRESS BAR === */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-input);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-dark), var(--primary));
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

/* === EMAIL EDITOR === */
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  flex-wrap: wrap;
}

.editor-toolbar button {
  padding: 6px 10px;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  transition: var(--transition);
}

.editor-toolbar button:hover {
  background: var(--bg-card-hover);
  border-color: var(--border);
  color: var(--primary);
}

.editor-area {
  min-height: 300px;
  padding: 20px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.7;
  outline: none;
}

.editor-area:focus {
  border-color: var(--primary);
}

/* === TEMPLATE CARDS === */
.templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.template-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: var(--transition);
  cursor: pointer;
}

.template-card:hover {
  transform: translateY(-4px);
  border-color: var(--primary);
  box-shadow: var(--shadow-glow);
}

.template-preview {
  height: 160px;
  overflow: hidden;
  position: relative;
  background: #fff;
}

.template-preview iframe {
  width: 200%;
  height: 200%;
  transform: scale(0.5);
  transform-origin: top left;
  border: none;
  pointer-events: none;
}

.template-info {
  padding: 16px;
}

.template-name {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 4px;
}

.template-category {
  font-size: 12px;
  color: var(--primary);
}

/* === DASHBOARD ENTRY ANIMATION === */
.app-transition-in {
  animation: appFadeIn 0.5s ease;
}

@keyframes appFadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

/* Sidebar mobile overlay backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 99;
}

/* === RESPONSIVE — TABLET (max-width: 1024px) === */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar.open ~ .sidebar-backdrop { display: block; }
  .main-content { margin-left: 0; }
  .menu-toggle { display: flex; }
  .page-container { padding: 20px; }

  /* Dashboard panels: stack vertically */
  .dashboard-panels { grid-template-columns: 1fr !important; }

  /* Stats: 2x2 grid on tablet */
  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  /* Compose: stack email form and preview */
  .compose-grid {
    grid-template-columns: 1fr !important;
  }

  /* Templates grid: 2 columns */
  .templates-grid { grid-template-columns: repeat(2, 1fr); }

  /* Tables: allow horizontal scroll only within table wrapper */
  .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Prevent horizontal scroll on body */
  body, html, #app { overflow-x: hidden; max-width: 100vw; }

  /* Modal smaller */
  .modal-content { width: 90%; max-width: 560px; }

  /* Select/dropdown constrain to parent */
  .form-select, select { max-width: 100%; width: 100%; box-sizing: border-box; }

  /* Fix action buttons wrapping */
  .template-info div[style*="display:flex"] { flex-wrap: wrap; gap: 6px; }
}

/* === RESPONSIVE — MOBILE (max-width: 640px) === */
@media (max-width: 640px) {
  /* Stats: 2 column on mobile */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 22px; }
  .stat-icon { width: 36px; height: 36px; margin-bottom: 10px; }

  .page-container { padding: 12px; }
  .topbar { padding: 0 12px; }
  .topbar-title { font-size: 15px; }

  /* Dashboard panels stack */
  .dashboard-panels { grid-template-columns: 1fr !important; gap: 14px !important; }

  /* Templates: single column on mobile */
  .templates-grid { grid-template-columns: 1fr !important; gap: 14px; }
  .template-card { font-size: 13px; }
  .template-preview { height: 120px; }
  .template-info { padding: 12px; }
  .template-name { font-size: 14px; }

  /* Cards compact */
  .card { padding: 14px; }
  .card-header { margin-bottom: 12px; padding-bottom: 10px; }
  .card-title { font-size: 15px; }

  /* ALL buttons smaller on mobile */
  .btn { font-size: 13px; padding: 10px 14px; }
  .btn-sm { font-size: 11px; padding: 6px 10px; }
  .btn-lg { padding: 12px 18px; font-size: 13px; }
  div[style*="display:flex"][style*="gap"] { flex-wrap: wrap; }

  /* Modal compact on mobile */
  .modal-content {
    width: 92%;
    padding: 18px;
    max-height: 85vh;
    margin: auto;
  }
  .modal-content h3 { font-size: 17px !important; }

  /* Editor compact */
  .editor-area { min-height: 160px; padding: 12px; font-size: 13px; }

  /* Search bar full width */
  .search-bar { max-width: 100%; }

  /* Sidebar full-width on mobile */
  .sidebar { width: 280px; }

  /* Compose mode tabs */
  .tabs { flex-wrap: wrap; }

  /* Form groups compact */
  .form-group { margin-bottom: 12px; }
  .form-label { font-size: 11px; }
  .form-input, .form-select, .form-textarea {
    font-size: 13px;
    padding: 10px 12px;
  }

  /* SELECT DROPDOWN — constrain to parent width */
  .form-select, select {
    max-width: 100% !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  /* Bulk contacts list compact */
  #bulk-contacts-list { max-height: 150px; }

  /* Dashboard hero compact */
  .dashboard-hero h2 { font-size: 20px !important; }
  .dashboard-hero p { font-size: 13px !important; }

  /* Page headings — stack title & buttons vertically */
  .animate-fade-up > div[style*="justify-content:space-between"] {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px !important;
  }
  /* Make header buttons row wrap and smaller */
  .animate-fade-up > div > div[style*="display:flex"] {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  /* ===== TABLES → CARD LAYOUT ON MOBILE ===== */
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td {
    display: block;
    width: 100%;
  }
  .data-table tr {
    padding: 14px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
    position: relative;
  }
  .data-table td {
    padding: 4px 0;
    border-bottom: none;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .data-table td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    min-width: 80px;
    letter-spacing: 0.3px;
  }
  .data-table td:first-child { padding-top: 0; }
  .data-table td:last-child { padding-bottom: 0; }

  /* Email cell wrapping */
  .email-cell { word-break: break-all; }

  /* History activity stats */
  .activity-stats-grid { grid-template-columns: 1fr !important; gap: 10px !important; }

  /* Email quota grid */
  div[style*="grid-template-columns: repeat(4"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  /* Detail grid (email/campaign modals) — single column on mobile */
  .detail-grid { grid-template-columns: 1fr !important; }
  .detail-grid div[style*="grid-column"] { grid-column: auto !important; }
  .modal-content { overflow-x: hidden; word-break: break-word; }
  .modal-content p { word-break: break-word !important; overflow-wrap: break-word !important; }

  /* Confirm dialog compact */
  .confirm-card { padding: 24px 18px 20px; max-width: 320px; }
  .confirm-title { font-size: 17px; }
  .confirm-message { font-size: 13px; margin-bottom: 20px; }
  .confirm-icon-wrap { width: 52px; height: 52px; margin-bottom: 16px; }
  .confirm-icon { font-size: 24px; }
  .confirm-btn { padding: 10px 16px; font-size: 13px; }
}

/* === RESPONSIVE — SMALL MOBILE (max-width: 400px) === */
@media (max-width: 400px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-card { padding: 10px; }
  .stat-value { font-size: 18px; }
  .stat-label { font-size: 11px; }
  .stat-icon { width: 30px; height: 30px; margin-bottom: 8px; }
  .stat-icon svg { width: 16px; height: 16px; }
  .page-container { padding: 8px; }
  .topbar-title { font-size: 13px; }
  .topbar-status { display: none; }
  .templates-grid { grid-template-columns: 1fr !important; }
  .btn { font-size: 12px; padding: 8px 12px; }
  .btn-sm { font-size: 11px; padding: 5px 8px; }
}

/* === GLOBAL NO HORIZONTAL SCROLL === */
html, body { overflow-x: hidden; }
#app { width: 100%; max-width: 100vw; overflow-x: hidden; }


/* === SIDEBAR MODULE BUTTONS === */
.nav-module-btn {
  position: relative;
}

.nav-module-btn .nav-chevron {
  margin-left: auto;
  transition: transform 0.3s ease;
  opacity: 0.5;
  flex-shrink: 0;
}

.nav-module-btn.active .nav-chevron {
  opacity: 1;
}

/* === SIDEBAR SUB-MENU === */
.nav-submenu {
  padding-left: 12px;
  overflow: hidden;
}

.nav-submenu .nav-sub {
  padding: 10px 12px 10px 20px;
  font-size: 13px;
  margin-bottom: 2px;
  border-radius: var(--radius-md);
  position: relative;
}

.nav-submenu .nav-sub::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.4;
  transition: all 0.2s ease;
}

.nav-submenu .nav-sub.active::before {
  background: var(--primary);
  opacity: 1;
  box-shadow: 0 0 8px var(--primary-glow);
}

.nav-submenu .nav-sub .nav-icon {
  width: 28px;
  height: 28px;
}

.nav-submenu .nav-sub .nav-icon svg {
  width: 14px;
  height: 14px;
}

/* Old section labels (keep for backwards compat) */
.nav-section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 16px 16px 8px;
  opacity: 0.7;
}

.nav-section-label svg {
  opacity: 0.5;
}

/* === SIDEBAR USER INFO === */
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(42, 191, 191, 0.04), rgba(255, 255, 255, 0.02), rgba(42, 191, 191, 0.03));
}

.sidebar-footer::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 30% 50%, rgba(255, 255, 255, 0.05), transparent 70%);
  animation: sidebarHeaderGlow 5s ease-in-out infinite;
}

.sidebar-footer::after {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 200%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.03), transparent);
  animation: sidebarShimmer 8s ease-in-out infinite;
}

.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.sidebar-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  flex-shrink: 0;
  box-shadow: 0 0 12px rgba(42, 191, 191, 0.2);
}

.sidebar-user-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-email {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-logout-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(239, 68, 68, 0.15);
  background: rgba(239, 68, 68, 0.06);
  color: var(--danger);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--transition);
  position: relative;
  z-index: 1;
}

.sidebar-logout-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.15);
}

/* === ACTIVITY STATS GRID === */
.activity-stats-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.activity-stats-grid .stat-card {
  padding: 16px;
}

@media (max-width: 1024px) {
  .activity-stats-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 640px) {
  .activity-stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Active range button */
.activity-range.active {
  background: var(--primary) !important;
  color: #fff !important;
  border-color: var(--primary) !important;
}

/* Badge info variant */
.badge-info {
  background: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
  border: 1px solid rgba(59, 130, 246, 0.2);
}

/* Toast slide-in animation */
@keyframes toastSlideIn {
  0% { opacity: 0; transform: translateY(-20px) scale(0.95); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* === PREMIUM CONFIRM DIALOG === */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.confirm-overlay.confirm-visible {
  opacity: 1;
}

.confirm-card {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 36px 32px 28px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  position: relative;
  overflow: hidden;
  transform: scale(0.9) translateY(20px);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow:
    0 24px 80px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.05) inset,
    0 0 60px rgba(59, 130, 246, 0.08);
}

.confirm-visible .confirm-card {
  transform: scale(1) translateY(0);
}

.confirm-glow {
  position: absolute;
  top: -60px;
  left: 50%;
  transform: translateX(-50%);
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: rgba(59, 130, 246, 0.15);
  filter: blur(60px);
  pointer-events: none;
  animation: confirmGlowPulse 3s ease-in-out infinite;
}

@keyframes confirmGlowPulse {
  0%, 100% { opacity: 0.5; transform: translateX(-50%) scale(1); }
  50% { opacity: 0.8; transform: translateX(-50%) scale(1.1); }
}

.confirm-icon-wrap {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  border: 2px solid;
  position: relative;
  z-index: 1;
  animation: confirmIconPop 0.4s cubic-bezier(0.16, 1, 0.3, 1) 0.1s both;
}

@keyframes confirmIconPop {
  0% { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.confirm-icon {
  font-size: 28px;
}

.confirm-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 8px;
  position: relative;
  z-index: 1;
}

.confirm-message {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 28px;
  position: relative;
  z-index: 1;
}

.confirm-actions {
  display: flex;
  gap: 12px;
  position: relative;
  z-index: 1;
}

.confirm-btn {
  flex: 1;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  letter-spacing: 0.3px;
}

.confirm-btn-cancel {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.confirm-btn-cancel:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.confirm-btn-ok {
  color: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.confirm-btn-ok:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
}
