/* ── Global box model ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { overflow-x: hidden; }

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --brand:       #6366f1;
  --brand-dark:  #4f46e5;
  --brand-light: #e0e7ff;
  --sidebar-w:   260px;
}

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track  { background: #f1f5f9; }
::-webkit-scrollbar-thumb  { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Glassmorphism card ────────────────────────────────────── */
.glass-card {
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.6);
  box-shadow: 0 8px 32px rgba(99,102,241,0.08);
}

/* ── Stat cards ────────────────────────────────────────────── */
.stat-card {
  background: #fff;
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 2px 16px rgba(0,0,0,0.06);
  border: 1px solid #f1f5f9;
  transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(99,102,241,0.12); }
.stat-card .stat-icon {
  width: 52px; height: 52px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
}

/* ── Sidebar ───────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: linear-gradient(160deg, #1e1b4b 0%, #312e81 100%);
  position: fixed; left: 0; top: 0; z-index: 40;
  transition: transform 0.3s ease;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
#sidebar .logo-area {
  padding: 1.5rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
#sidebar .nav-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.65rem 1.25rem;
  border-radius: 10px;
  margin: 2px 0.75rem;
  color: rgba(255,255,255,0.65);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s;
  text-decoration: none;
}
#sidebar .nav-item:hover,
#sidebar .nav-item.active {
  background: rgba(255,255,255,0.12);
  color: #fff;
}
#sidebar .nav-item.active { background: rgba(99,102,241,0.35); color: #fff; }
#sidebar .nav-section {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em;
  color: rgba(255,255,255,0.3); text-transform: uppercase;
  padding: 0.75rem 1.25rem 0.25rem;
  margin-top: 0.5rem;
}

/* Sidebar overlay backdrop (mobile) */
#sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
  z-index: 39;
}
#sidebar-overlay.active { display: block; }

/* ── Main content area ─────────────────────────────────────── */
#main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  background: #f8fafc;
}

/* ── Top Nav ───────────────────────────────────────────────── */
#topnav {
  background: #fff;
  border-bottom: 1px solid #f1f5f9;
  padding: 0.875rem 1.5rem;
  position: sticky; top: 0; z-index: 30;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
  display: flex; align-items: center; justify-content: space-between;
}
#sidebar-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
  transition: background 0.2s;
}
#sidebar-toggle:hover { background: #f1f5f9; }

/* ── Page header ───────────────────────────────────────────── */
.page-header {
  padding: 1.5rem;
  border-bottom: 1px solid #f1f5f9;
  background: #fff;
  margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.35rem; font-weight: 700; color: #0f172a; }

/* ── Table ─────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.data-table thead th {
  background: #f8fafc;
  padding: 0.75rem 1rem;
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: #64748b;
  border-bottom: 1px solid #e2e8f0;
}
.data-table tbody td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  color: #334155; font-size: 0.9rem;
}
.data-table tbody tr:hover td { background: #f8fafc; }
.data-table tbody tr:last-child td { border-bottom: none; }

/* Responsive table scroll wrapper */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── Kanban board ──────────────────────────────────────────── */
.kanban-col {
  min-width: 280px; max-width: 280px;
  background: #f1f5f9;
  border-radius: 14px;
  padding: 1rem;
}
.kanban-col .col-header {
  font-size: 0.8rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; margin-bottom: 0.75rem;
  display: flex; align-items: center; justify-content: space-between;
}
.kanban-card {
  background: #fff; border-radius: 10px;
  padding: 0.85rem;
  margin-bottom: 0.6rem;
  box-shadow: 0 1px 6px rgba(0,0,0,0.06);
  cursor: grab;
  transition: box-shadow 0.2s, transform 0.1s;
  border-left: 3px solid transparent;
}
.kanban-card:hover { box-shadow: 0 4px 16px rgba(99,102,241,0.14); transform: translateY(-1px); }
.kanban-card.dragging { opacity: 0.5; transform: rotate(2deg); }
.kanban-col.drag-over { background: #e0e7ff; outline: 2px dashed #6366f1; }
.kanban-cards { min-height: 80px; }

/* ── Marketing site ────────────────────────────────────────── */
.marketing-hero {
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #4f46e5 100%);
  min-height: 100vh;
  position: relative;
  overflow: hidden;
}
.hero-badge {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  backdrop-filter: blur(8px);
}
.floating-card {
  background: rgba(255,255,255,0.95);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  animation: float 6s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-12px); }
}
.pricing-card {
  border-radius: 20px;
  padding: 2rem;
  transition: transform 0.3s, box-shadow 0.3s;
}
.pricing-card:hover { transform: translateY(-6px); box-shadow: 0 20px 50px rgba(99,102,241,0.18); }
.pricing-card.featured {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff; transform: scale(1.04);
}

/* ── Alerts ────────────────────────────────────────────────── */
.alert-success { background:#dcfce7; border:1px solid #bbf7d0; color:#15803d; border-radius:8px; padding:.75rem 1rem; }
.alert-error   { background:#fee2e2; border:1px solid #fecaca; color:#dc2626; border-radius:8px; padding:.75rem 1rem; }
.alert-info    { background:#e0f2fe; border:1px solid #bae6fd; color:#0369a1; border-radius:8px; padding:.75rem 1rem; }
.alert-warning { background:#fef9c3; border:1px solid #fef08a; color:#a16207; border-radius:8px; padding:.75rem 1rem; }

/* ── Form inputs ───────────────────────────────────────────── */
.form-input {
  width: 100%;
  padding: 0.6rem 0.875rem;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.9rem;
  color: #0f172a;
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
  -webkit-appearance: none;
}
.form-input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(99,102,241,0.12); }
.form-label { font-size: 0.85rem; font-weight: 600; color: #374151; margin-bottom: 0.35rem; display: block; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn-primary {
  background: var(--brand); color: #fff;
  padding: 0.625rem 1.25rem; border-radius: 8px;
  font-weight: 600; font-size: 0.9rem;
  border: none; cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s, transform 0.1s;
  display: inline-flex; align-items: center; gap: 0.4rem;
  text-decoration: none;
}
.btn-primary:hover { background: var(--brand-dark); box-shadow: 0 4px 12px rgba(99,102,241,0.4); transform: translateY(-1px); }
.btn-secondary {
  background: #f1f5f9; color: #374151;
  padding: 0.625rem 1.25rem; border-radius: 8px;
  font-weight: 600; font-size: 0.9rem;
  border: 1px solid #e2e8f0; cursor: pointer;
  transition: all 0.2s;
  display: inline-flex; align-items: center; gap: 0.4rem;
  text-decoration: none;
}
.btn-secondary:hover { background: #e2e8f0; }
.btn-danger {
  background: #ef4444; color: #fff;
  padding: 0.5rem 1rem; border-radius: 8px;
  font-weight: 600; font-size: 0.85rem;
  border: none; cursor: pointer; transition: all 0.2s;
}
.btn-danger:hover { background: #dc2626; }
.btn-success {
  background: #22c55e; color: #fff;
  padding: 0.5rem 1rem; border-radius: 8px;
  font-weight: 600; font-size: 0.85rem;
  border: none; cursor: pointer; transition: all 0.2s;
}

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
  padding: 1rem;
}
.modal-overlay.active { opacity: 1; pointer-events: all; }
.modal-box {
  background: #fff;
  border-radius: 16px;
  padding: 1.75rem;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95);
  transition: transform 0.2s;
  box-shadow: 0 24px 60px rgba(0,0,0,0.18);
}
.modal-overlay.active .modal-box { transform: scale(1); }

/* ── Loading spinner ───────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Priority indicators ───────────────────────────────────── */
.priority-high   { color: #ef4444; }
.priority-medium { color: #f59e0b; }
.priority-low    { color: #22c55e; }

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — Tablet  ≤ 1024px
══════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  /* 4-col stat grids → 2-col */
  #main-content div[style*="repeat(4,1fr)"],
  #main-content div[style*="repeat(4, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* 3-col plan grid → stack */
  #main-content div[style*="repeat(3,1fr)"],
  #main-content div[style*="repeat(3, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile  ≤ 768px
══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* ── Sidebar slides off-canvas ── */
  #sidebar {
    transform: translateX(-100%);
    z-index: 50;
  }
  #sidebar.open { transform: translateX(0); }

  /* ── Main takes full width ── */
  #main-content { margin-left: 0; }

  /* ── Show hamburger button ── */
  #sidebar-toggle { display: flex; align-items: center; justify-content: center; }

  /* ── Top nav padding ── */
  #topnav { padding: 0.75rem 1rem; }

  /* ── Page padding ── */
  #main-content > div[style*="padding:1.5rem"] {
    padding: 1rem !important;
  }
  .page-header { padding: 1rem; }

  /* ── Flash messages ── */
  .flash-msg { margin: 0.75rem 1rem !important; }

  /* ── All multi-col grids → 1-col ── */
  #main-content div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* 2-col forms keep side-by-side on mid mobile */
  #main-content div[style*="grid-template-columns:1fr 1fr"],
  #main-content div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* ── Tables: horizontal scroll ── */
  .data-table, table {
    min-width: 600px;
  }
  div:has(> .data-table),
  div:has(> table),
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── Kanban ── */
  .kanban-col { min-width: 240px; }

  /* ── Stat cards ── */
  .stat-card { padding: 1rem; }
  .stat-card .stat-icon { width: 42px; height: 42px; font-size: 1.2rem; }

  /* ── Modal full screen on mobile ── */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-box {
    border-radius: 20px 20px 0 0;
    max-width: 100%;
    max-height: 92vh;
    padding: 1.5rem 1.25rem;
  }

  /* ── Buttons: full width in action rows ── */
  .mobile-full { width: 100% !important; justify-content: center; }

  /* ── Hide secondary text in topnav ── */
  #topnav .user-meta { display: none; }

  /* ── Pipeline board scrolls horizontally ── */
  .kanban-board {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 1rem;
  }

  /* ── Page header flex wrap ── */
  .page-header,
  #main-content > div[style*="justify-content:space-between"] {
    flex-wrap: wrap !important;
    gap: 0.75rem !important;
  }

  /* ── Invoice/billing summary cards ── */
  #main-content div[style*="grid-template-columns:repeat(3"] {
    grid-template-columns: 1fr !important;
  }

  /* ── Leads show page: 2-col detail → 1-col ── */
  #main-content div[style*="grid-template-columns:2fr"] {
    grid-template-columns: 1fr !important;
  }
  #main-content div[style*="grid-template-columns:1.4fr"] {
    grid-template-columns: 1fr !important;
  }
  #main-content div[style*="grid-template-columns:1.5fr"] {
    grid-template-columns: 1fr !important;
  }

  /* ── Choose plan grid ── */
  #main-content div[style*="repeat(3,1fr)"],
  #main-content div[style*="repeat(3, 1fr)"] {
    grid-template-columns: 1fr !important;
  }

  /* ── Sidebar bottom plan badge: hide on mobile to save space ── */
  #sidebar .plan-badge { display: none; }

  /* ── Make page headers wrap nicely ── */
  #main-content h1[style*="font-size:1.4rem"] {
    font-size: 1.15rem !important;
  }
}

  /* ── Prevent any element from busting out of the viewport ── */
  #main-content { overflow-x: hidden; }

  /* ── Reduce card inner padding on mobile ── */
  #main-content div[style*="padding:2rem"],
  #main-content div[style*="padding: 2rem"] {
    padding: 1.25rem !important;
  }
  #main-content div[style*="padding:1.75rem"],
  #main-content div[style*="padding: 1.75rem"] {
    padding: 1.25rem !important;
  }

  /* ── Settings / narrow-max-width containers ── */
  #main-content div[style*="max-width:700px"],
  #main-content div[style*="max-width:800px"],
  #main-content div[style*="max-width:820px"],
  #main-content div[style*="max-width:900px"] {
    padding-left: 0.875rem !important;
    padding-right: 0.875rem !important;
    max-width: 100% !important;
  }

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — Small mobile  ≤ 480px
══════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  /* ── 2-col stat grids → 1-col ── */
  #main-content div[style*="repeat(2,1fr)"],
  #main-content div[style*="repeat(2, 1fr)"] {
    grid-template-columns: 1fr !important;
  }

  /* ── Top nav: compress ── */
  #topnav { padding: 0.625rem 0.875rem; gap: 0.5rem; }

  /* ── Buttons: smaller text ── */
  .btn-primary, .btn-secondary { font-size: 0.82rem; padding: 0.5rem 0.875rem; }

  /* ── Form inputs: bigger tap targets ── */
  .form-input { padding: 0.75rem 0.875rem; font-size: 0.95rem; }

  /* ── Lead/invoice action button rows ── */
  #main-content div[style*="display:flex"][style*="gap:.5rem"],
  #main-content div[style*="display:flex"][style*="gap:.75rem"] {
    flex-wrap: wrap !important;
  }

  /* ── Section padding ── */
  #main-content > div { padding-left: 0.75rem !important; padding-right: 0.75rem !important; }

  /* ── Page title ── */
  h1 { font-size: 1.1rem !important; }
}

/* ══════════════════════════════════════════════════════════════
   MOBILE BOTTOM NAV BAR
══════════════════════════════════════════════════════════════ */
#mobile-nav {
  display: none;
}
@media (max-width: 768px) {
  #mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    z-index: 35;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
    padding: 0.35rem 0 calc(0.35rem + env(safe-area-inset-bottom));
  }
  #mobile-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    padding: 0.4rem 0.25rem;
    text-decoration: none;
    color: #94a3b8;
    font-size: 0.62rem;
    font-weight: 600;
    transition: color 0.2s;
    position: relative;
  }
  #mobile-nav a.active,
  #mobile-nav a:hover { color: var(--brand); }
  #mobile-nav a i { font-size: 1.1rem; }
  #mobile-nav a .nav-badge {
    position: absolute;
    top: 2px; right: calc(50% - 20px);
    background: #ef4444;
    color: #fff;
    border-radius: 20px;
    font-size: 0.55rem;
    padding: 1px 5px;
    min-width: 14px;
    text-align: center;
    line-height: 1.4;
  }

  /* Push content above bottom nav */
  #main-content { padding-bottom: 64px; }
}
