/* ============================================================
   EMANTOURS CRM — MAIN CSS (Design System)
   Variables, Reset, Typography, Layout, Sidebar, Header
   ============================================================ */

/* ==========================================
   CSS VARIABLES (Design Tokens)
   ========================================== */
:root {
  /* Primary Blues */
  --blue-50:  #eff6ff;
  --blue-100: #dbeafe;
  --blue-200: #bfdbfe;
  --blue-300: #93c5fd;
  --blue-400: #60a5fa;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;
  --blue-800: #1e40af;
  --blue-900: #1e3a8a;
  --blue-950: #172554;

  /* Sidebar Colors */
  --sidebar-bg:          #0d1b2e;
  --sidebar-bg-2:        #1a2d4a;
  --sidebar-hover:       rgba(255,255,255,0.07);
  --sidebar-active-bg:   rgba(37,99,235,0.4);
  --sidebar-active-bd:   rgba(96,165,250,0.3);
  --sidebar-text:        #8da4c0;
  --sidebar-text-active: #ffffff;
  --sidebar-label:       #4a6580;

  /* Backgrounds */
  --bg-app:    #eef2fb;
  --bg-card:   #ffffff;
  --bg-header: #ffffff;
  --bg-input:  #f8fafc;
  --bg-hover:  #f1f5f9;

  /* Text */
  --text-primary:   #0d1b2e;
  --text-secondary: #475569;
  --text-muted:     #94a3b8;
  --text-white:     #ffffff;

  /* Status Colors */
  --success:        #10b981;
  --success-light:  #d1fae5;
  --success-text:   #065f46;
  --warning:        #f59e0b;
  --warning-light:  #fef3c7;
  --warning-text:   #78350f;
  --danger:         #ef4444;
  --danger-light:   #fee2e2;
  --danger-text:    #7f1d1d;
  --info:           #3b82f6;
  --info-light:     #dbeafe;
  --info-text:      #1e3a8a;

  /* Gradients */
  --gradient-primary:  linear-gradient(135deg, #1d4ed8 0%, #0ea5e9 100%);
  --gradient-sidebar:  linear-gradient(180deg, #0d1b2e 0%, #0a1628 100%);
  --gradient-card:     linear-gradient(145deg, #ffffff 0%, #f8fafc 100%);
  --gradient-success:  linear-gradient(135deg, #059669 0%, #10b981 100%);
  --gradient-warning:  linear-gradient(135deg, #d97706 0%, #f59e0b 100%);
  --gradient-danger:   linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
  --gradient-info:     linear-gradient(135deg, #1d4ed8 0%, #3b82f6 100%);
  --gradient-glass:    linear-gradient(135deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0.05) 100%);

  /* Shadows */
  --shadow-xs:   0 1px 2px rgba(0,0,0,0.05);
  --shadow-sm:   0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md:   0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);
  --shadow-lg:   0 10px 15px rgba(0,0,0,0.08), 0 4px 6px rgba(0,0,0,0.05);
  --shadow-xl:   0 20px 25px rgba(0,0,0,0.1), 0 8px 10px rgba(0,0,0,0.06);
  --shadow-blue: 0 4px 20px rgba(37,99,235,0.3);
  --shadow-glow: 0 0 40px rgba(59,130,246,0.12);

  /* Border Radius */
  --radius-xs:   4px;
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   14px;
  --radius-xl:   20px;
  --radius-2xl:  28px;
  --radius-full: 9999px;

  /* Spacing */
  --sp-1: 4px;   --sp-2: 8px;   --sp-3: 12px;  --sp-4: 16px;
  --sp-5: 20px;  --sp-6: 24px;  --sp-7: 28px;  --sp-8: 32px;
  --sp-10: 40px; --sp-12: 48px; --sp-16: 64px;

  /* Typography */
  --font:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --fs-xs:     11px;  --fs-sm: 12px;  --fs-base: 13px; --fs-md: 14px;
  --fs-lg:     15px;  --fs-xl: 17px;  --fs-2xl: 20px;  --fs-3xl: 26px;
  --fs-4xl:    32px;

  /* Layout */
  --sidebar-w:   260px;
  --sidebar-col: 68px;
  --header-h:    62px;

  /* Transitions */
  --t-fast:   120ms ease;
  --t-normal: 220ms ease;
  --t-slow:   380ms ease;
}

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

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

body {
  font-family: var(--font);
  font-size: var(--fs-base);
  color: var(--text-primary);
  background: var(--bg-app);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

a { text-decoration: none; color: inherit; }

button {
  cursor: pointer;
  font-family: var(--font);
  border: none;
  outline: none;
  background: none;
}

input, textarea, select {
  font-family: var(--font);
  outline: none;
  border: none;
}

img { max-width: 100%; height: auto; display: block; }
ul, ol { list-style: none; }

/* Custom scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--blue-200); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--blue-400); }

/* ==========================================
   LAYOUT
   ========================================== */
.app-wrapper {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-app);
}

/* ==========================================
   SIDEBAR
   ========================================== */
.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--gradient-sidebar);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--t-normal);
  overflow: hidden;
  position: relative;
  z-index: 200;
  box-shadow: 4px 0 20px rgba(0,0,0,0.2);
}

.sidebar.collapsed { width: var(--sidebar-col); }

/* Header */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4);
  min-height: var(--header-h);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  overflow: hidden;
}

.brand-icon {
  width: 38px;
  height: 38px;
  background: var(--gradient-primary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  box-shadow: var(--shadow-blue);
}

.brand-text {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity var(--t-normal), width var(--t-normal);
}

.brand-name {
  font-size: var(--fs-xl);
  font-weight: 800;
  color: var(--text-white);
  white-space: nowrap;
  letter-spacing: -0.5px;
}

.brand-sub {
  font-size: var(--fs-xs);
  color: var(--sidebar-label);
  white-space: nowrap;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.sidebar-toggle {
  color: var(--sidebar-text);
  padding: var(--sp-2);
  border-radius: var(--radius-sm);
  transition: all var(--t-fast);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-toggle:hover {
  color: var(--text-white);
  background: var(--sidebar-hover);
}

/* Navigation */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-4) 0;
}

.nav-section { margin-bottom: var(--sp-5); }

.nav-label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--sidebar-label);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  padding: 0 var(--sp-4);
  margin-bottom: var(--sp-2);
  white-space: nowrap;
  transition: opacity var(--t-normal);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 10px var(--sp-4);
  margin: 2px var(--sp-3);
  border-radius: var(--radius-md);
  color: var(--sidebar-text);
  font-size: var(--fs-sm);
  font-weight: 500;
  transition: all var(--t-fast);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  border: 1px solid transparent;
}

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

.nav-item.active {
  color: var(--text-white);
  background: var(--sidebar-active-bg);
  border-color: var(--sidebar-active-bd);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--blue-400);
  border-radius: 0 2px 2px 0;
}

.nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 20px;
  color: inherit;
}

.nav-text { overflow: hidden; text-overflow: ellipsis; transition: opacity var(--t-normal); }

.nav-badge {
  margin-left: auto;
  background: var(--blue-600);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: var(--radius-full);
  min-width: 20px;
  text-align: center;
  transition: opacity var(--t-normal);
}

/* Collapsed state */
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed .user-details { opacity: 0; width: 0; pointer-events: none; }

.sidebar.collapsed .nav-item { justify-content: center; padding: 10px; margin: 2px 8px; }
.sidebar.collapsed .sidebar-toggle { transform: rotate(180deg); }

/* Footer */
.sidebar-footer {
  padding: var(--sp-4);
  border-top: 1px solid rgba(255,255,255,0.06);
}

.user-info {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  overflow: hidden;
}

.user-avatar {
  width: 34px;
  height: 34px;
  background: var(--gradient-primary);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--text-white);
  flex-shrink: 0;
  letter-spacing: 0.5px;
}

.user-details { display: flex; flex-direction: column; overflow: hidden; transition: opacity var(--t-normal); }
.user-name { font-size: var(--fs-sm); font-weight: 600; color: var(--text-white); white-space: nowrap; }
.user-role { font-size: var(--fs-xs); color: var(--sidebar-text); white-space: nowrap; }

/* ==========================================
   MAIN CONTENT
   ========================================== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ==========================================
   HEADER
   ========================================== */
.app-header {
  height: var(--header-h);
  background: var(--bg-header);
  border-bottom: 1px solid rgba(0,0,0,0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-6);
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  z-index: 50;
  position: relative;
}

.header-left { display: flex; align-items: center; gap: var(--sp-4); }

.menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  padding: var(--sp-2);
  border-radius: var(--radius-sm);
  transition: all var(--t-fast);
}

.menu-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

.breadcrumb { display: flex; align-items: center; gap: var(--sp-3); }

.breadcrumb-icon { font-size: 20px; }

#currentModule {
  font-size: var(--fs-2xl);
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.header-right { display: flex; align-items: center; gap: var(--sp-4); }

.header-date { font-size: var(--fs-sm); color: var(--text-muted); font-weight: 500; }

.header-badge {
  background: var(--gradient-primary);
  color: #fff;
  font-size: var(--fs-xs);
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* ==========================================
   CONTENT AREA
   ========================================== */
.content-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-6);
  background: var(--bg-app);
}

/* ==========================================
   LOADING
   ========================================== */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 300px;
  gap: var(--sp-4);
  color: var(--text-muted);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--blue-100);
  border-top-color: var(--blue-600);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ==========================================
   MOBILE OVERLAY
   ========================================== */
.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 150;
  backdrop-filter: blur(2px);
}

.mobile-overlay.active { display: block; }

/* ==========================================
   TOASTS
   ========================================== */
.toast-container {
  position: fixed;
  bottom: var(--sp-6);
  right: var(--sp-6);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  pointer-events: none;
}

.toast {
  pointer-events: all;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-radius: var(--radius-lg);
  background: var(--text-primary);
  color: #fff;
  font-size: var(--fs-sm);
  font-weight: 500;
  box-shadow: var(--shadow-xl);
  animation: toastIn 0.3s ease forwards;
  max-width: 380px;
  min-width: 280px;
  border-left: 4px solid transparent;
}

.toast.toast-success { background: #065f46; border-color: var(--success); }
.toast.toast-error   { background: #7f1d1d; border-color: var(--danger); }
.toast.toast-warning { background: #78350f; border-color: var(--warning); }
.toast.toast-info    { background: #1e3a8a; border-color: var(--info); }
.toast.hiding        { animation: toastOut 0.3s ease forwards; }

.toast-icon { font-size: 16px; flex-shrink: 0; }
.toast-msg  { flex: 1; line-height: 1.4; }
.toast-close { cursor: pointer; opacity: 0.7; font-size: 16px; padding: 2px 4px; }
.toast-close:hover { opacity: 1; }

/* ==========================================
   CONFIRM DIALOG
   ========================================== */
.confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 9998;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.confirm-overlay.active { display: flex; }

.confirm-dialog {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: var(--sp-8);
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow-xl);
  text-align: center;
  animation: fadeInScale 0.25s ease forwards;
}

.confirm-icon { font-size: 48px; margin-bottom: var(--sp-4); }
.confirm-title { font-size: var(--fs-xl); font-weight: 700; margin-bottom: var(--sp-2); }
.confirm-message { font-size: var(--fs-md); color: var(--text-secondary); margin-bottom: var(--sp-6); }
.confirm-actions { display: flex; gap: var(--sp-3); justify-content: center; }

/* ==========================================
   ANIMATIONS
   ========================================== */
@keyframes fadeIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }
@keyframes slideInRight { from { opacity:0; transform:translateX(16px); } to { opacity:1; transform:translateX(0); } }
@keyframes fadeInScale { from { opacity:0; transform:scale(0.95); } to { opacity:1; transform:scale(1); } }
@keyframes spin { to { transform:rotate(360deg); } }
@keyframes toastIn { from { opacity:0; transform:translateX(100%); } to { opacity:1; transform:translateX(0); } }
@keyframes toastOut { from { opacity:1; transform:translateX(0); } to { opacity:0; transform:translateX(100%); } }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.6; } }
@keyframes shimmer { to { background-position: 200% center; } }

.animate-fade  { animation: fadeIn 0.25s ease forwards; }
.animate-slide { animation: slideInRight 0.25s ease forwards; }

/* ==========================================
   RESPONSIVE
   ========================================== */
@media (max-width: 1024px) {
  .sidebar {
    position: fixed;
    left: calc(-1 * var(--sidebar-w));
    top: 0;
    transition: left var(--t-normal);
  }
  .sidebar.mobile-open { left: 0; }
  .sidebar.collapsed { width: var(--sidebar-w); }
  .sidebar.collapsed .nav-label, .sidebar.collapsed .nav-text,
  .sidebar.collapsed .brand-text, .sidebar.collapsed .nav-badge,
  .sidebar.collapsed .user-details { opacity: 1; width: auto; pointer-events: auto; }
  .sidebar.collapsed .nav-item { justify-content: flex-start; padding: 10px var(--sp-4); margin: 2px var(--sp-3); }
  .sidebar.collapsed .sidebar-toggle { transform: none; }
  .menu-btn { display: flex; }
  .main-content { width: 100%; }
}

@media (max-width: 768px) {
  .content-area { padding: var(--sp-4); }
  .app-header { padding: 0 var(--sp-4); }
  #currentModule { font-size: var(--fs-xl); }
  .header-date { display: none; }
}

@media (max-width: 480px) {
  .content-area { padding: var(--sp-3); }
}

/* Print styles */
@media print {
  .sidebar, .app-header, .no-print { display: none !important; }
  .main-content { width: 100% !important; }
  .content-area { padding: 0 !important; overflow: visible !important; }
  body { background: #fff !important; }
  .print-only { display: block !important; }
}

.print-only { display: none; }

/* Hide number input spinners globally */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type=number] {
  -moz-appearance: textfield;
}

