/* ═══════════════════════════════════════════════════
   Lead Optimizer — Mobile App Style CSS
   Target: Android/iOS native app feel
   Base: Light theme, large touch targets
═══════════════════════════════════════════════════ */

/* ── GLOBAL OVERFLOW FIX ─────────────────────────── */
html, body { overflow-x: hidden; max-width: 100vw; }
* { box-sizing: border-box; }

/* ── MOBILE TOPBAR ───────────────────────────────── */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 58px;
  background: #1A1D2E;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  z-index: 200;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}
.mobile-menu-btn {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  background: rgba(255,255,255,0.08);
  border: none;
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  flex-shrink: 0;
}
.mobile-logo {
  flex: 1;
  font-family: 'Syne', sans-serif;
  font-size: 19px;
  font-weight: 700;
  color: #fff;
}
.mobile-logo strong { color: #818CF8; }

/* ── SIDEBAR OVERLAY ─────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
}
.sidebar-overlay.show { display: block; }

/* ════════════════════════════════════════════════════
   MOBILE BREAKPOINT ≤ 768px
════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── LIGHT BG FOR MOBILE ───────────────────────── */
  body {
    background: #F0F2F8 !important;
    color: #1A1D2E !important;
  }

  /* ── TOPBAR ON ─────────────────────────────────── */
  .mobile-topbar { display: flex; }

  /* ── LAYOUT ─────────────────────────────────────── */
  .main-content {
    margin-left: 0 !important;
    padding-top: 58px !important;
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
    background: #F0F2F8 !important;
  }
  .content-inner {
    padding: 16px 14px 32px !important;
    max-width: 100% !important;
  }

  /* ── SIDEBAR (drawer style) ──────────────────────── */
  .sidebar, .admin-sidebar {
    transform: translateX(-100%) !important;
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1) !important;
    z-index: 100 !important;
    top: 0 !important;
    width: 280px !important;
    background: #1A1D2E !important;
    box-shadow: none;
  }
  .sidebar.mobile-open, .admin-sidebar.mobile-open {
    transform: translateX(0) !important;
    box-shadow: 12px 0 48px rgba(0,0,0,0.5) !important;
  }

  /* ── SIDEBAR LOGO ──────────────────────────────── */
  .sidebar-logo {
    padding: 24px 20px 20px !important;
    border-bottom: 1px solid rgba(255,255,255,0.08) !important;
  }
  .logo-text { font-size: 20px !important; color: #fff !important; }
  .logo-mark {
    width: 40px !important; height: 40px !important;
    font-size: 18px !important;
    border-radius: 12px !important;
  }

  /* ── NAV ITEMS — large Android style ─────────────── */
  .sidebar-nav { padding: 12px 10px !important; gap: 4px !important; }
  .nav-item {
    padding: 14px 16px !important;
    font-size: 16px !important;
    font-weight: 500 !important;
    border-radius: 12px !important;
    min-height: 52px !important;
    color: rgba(255,255,255,0.75) !important;
    gap: 14px !important;
  }
  .nav-item i {
    font-size: 18px !important;
    width: 22px !important;
  }
  .nav-item.active {
    background: rgba(99,102,241,0.2) !important;
    color: #818CF8 !important;
    font-weight: 600 !important;
  }

  /* ── SIDEBAR FOOTER ─────────────────────────────── */
  .sidebar-footer {
    padding: 16px 14px !important;
    background: rgba(0,0,0,0.2) !important;
    margin: 8px !important;
    border-radius: 12px !important;
    border: none !important;
  }
  .user-avatar {
    width: 42px !important; height: 42px !important;
    font-size: 17px !important;
  }
  .user-name { font-size: 15px !important; font-weight: 700 !important; color: #fff !important; }
  .user-plan { font-size: 12px !important; }
  .logout-btn {
    width: 38px !important; height: 38px !important;
    color: rgba(255,255,255,0.5) !important;
  }

  /* ── PAGE HEADER ─────────────────────────────────── */
  .page-header, .admin-page-header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
    margin-bottom: 18px !important;
  }
  .page-title {
    font-size: 24px !important;
    font-weight: 800 !important;
    color: #1A1D2E !important;
  }
  .page-subtitle {
    font-size: 14px !important;
    color: #6B7280 !important;
    margin-top: 2px !important;
  }

  /* ── PRIMARY BUTTON — full width, large ──────────── */
  .page-header .btn-primary,
  .admin-page-header .btn-primary {
    width: 100% !important;
    justify-content: center !important;
    padding: 15px 20px !important;
    font-size: 16px !important;
    font-weight: 700 !important;
    border-radius: 14px !important;
    min-height: 52px !important;
  }

  /* ── STATS GRID — 2 columns ──────────────────────── */
  .stats-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 12px !important;
    margin-bottom: 18px !important;
    width: 100% !important;
  }
  .stat-card {
    background: #fff !important;
    border: none !important;
    border-radius: 16px !important;
    padding: 16px 14px !important;
    gap: 12px !important;
    box-shadow: 0 2px 12px rgba(0,0,0,0.07) !important;
    min-width: 0 !important;
  }
  .stat-card::before { height: 3px !important; border-radius: 16px 16px 0 0 !important; }
  .stat-icon {
    width: 42px !important; height: 42px !important;
    font-size: 17px !important;
    border-radius: 12px !important;
    flex-shrink: 0 !important;
  }
  .stat-value {
    font-size: 26px !important;
    font-weight: 800 !important;
    color: #1A1D2E !important;
    line-height: 1 !important;
  }
  .stat-label {
    font-size: 12px !important;
    font-weight: 500 !important;
    color: #6B7280 !important;
    margin-top: 3px !important;
  }

  /* ── GRIDS ───────────────────────────────────────── */
  .grid-2, .grid-3 {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }

  /* ── CARD ────────────────────────────────────────── */
  .card {
    background: #fff !important;
    border: none !important;
    border-radius: 18px !important;
    padding: 18px 16px !important;
    box-shadow: 0 2px 16px rgba(0,0,0,0.07) !important;
    width: 100% !important;
    min-width: 0 !important;
  }
  .card-header { margin-bottom: 14px !important; }
  .card-title {
    font-size: 16px !important;
    font-weight: 700 !important;
    color: #1A1D2E !important;
  }

  /* ══════════════════════════════════════════════════
     LEADS LIST — Android app card style
  ══════════════════════════════════════════════════ */
  .table-wrap { overflow-x: hidden !important; width: 100% !important; }
  .table-wrap table { display: block !important; width: 100% !important; }
  .table-wrap thead { display: none !important; }
  .table-wrap tbody { display: flex !important; flex-direction: column !important; gap: 10px !important; }

  /* Each row = full lead card */
  .table-wrap tbody tr.lead-row {
    display: block !important;
    background: #fff !important;
    border-radius: 16px !important;
    padding: 16px !important;
    box-shadow: 0 2px 12px rgba(0,0,0,0.07) !important;
    cursor: pointer !important;
    border: none !important;
    margin: 0 !important;
    transition: transform 0.15s, box-shadow 0.15s !important;
  }
  .table-wrap tbody tr.lead-row:active {
    transform: scale(0.98) !important;
    box-shadow: 0 1px 6px rgba(0,0,0,0.1) !important;
  }

  .table-wrap tbody tr.lead-row td {
    display: block !important;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
    width: 100% !important;
  }

  /* Lead name — big and bold */
  .table-wrap tbody tr.lead-row td.td-name,
  .table-wrap tbody tr.lead-row td:first-child {
    font-size: 17px !important;
    font-weight: 700 !important;
    color: #1A1D2E !important;
    margin-bottom: 6px !important;
    line-height: 1.2 !important;
  }
  .table-wrap tbody tr.lead-row td.td-name a {
    color: #1A1D2E !important;
    text-decoration: none !important;
    display: block !important;
    width: 100% !important;
  }

  /* Phone, email cells */
  .table-wrap tbody tr.lead-row td:nth-child(2) {
    font-size: 15px !important;
    color: #374151 !important;
    margin-bottom: 4px !important;
    font-weight: 500 !important;
  }
  .table-wrap tbody tr.lead-row td:nth-child(3) {
    font-size: 13px !important;
    color: #6B7280 !important;
    margin-bottom: 8px !important;
  }

  /* Source + status badges row */
  .table-wrap tbody tr.lead-row td:nth-child(4),
  .table-wrap tbody tr.lead-row td:nth-child(5) {
    display: inline-block !important;
    width: auto !important;
    margin-right: 6px !important;
    margin-bottom: 10px !important;
  }

  /* Time cell */
  .table-wrap tbody tr.lead-row td:nth-child(6) {
    font-size: 12px !important;
    color: #9CA3AF !important;
    margin-bottom: 12px !important;
  }

  /* Action buttons — large CTA row */
  .table-wrap tbody tr.lead-row td:last-child {
    display: flex !important;
    gap: 8px !important;
    margin-top: 4px !important;
    width: 100% !important;
  }
  .table-wrap tbody tr.lead-row td:last-child .btn {
    flex: 1 !important;
    justify-content: center !important;
    min-height: 44px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    border-radius: 10px !important;
  }

  /* WhatsApp button style */
  .table-wrap tbody tr.lead-row td:last-child a[href*="wa.me"] {
    background: #25D366 !important;
    color: #fff !important;
    border: none !important;
  }
  /* Call button */
  .table-wrap tbody tr.lead-row td:last-child a[href*="tel:"] {
    background: #10B981 !important;
    color: #fff !important;
    border: none !important;
  }
  /* View button */
  .table-wrap tbody tr.lead-row td:last-child a[href*="view"] {
    background: #F3F4F6 !important;
    color: #374151 !important;
    border: none !important;
  }

  /* Non-lead-row table (admin, etc) — scrollable */
  .table-wrap table:not(:has(.lead-row)) {
    display: table !important;
    min-width: 520px !important;
    overflow-x: auto !important;
  }

  /* ── FILTER BAR ────────────────────────────────── */
  .filter-bar {
    flex-direction: column !important;
    gap: 10px !important;
    width: 100% !important;
    margin-bottom: 16px !important;
  }
  .filter-bar > *, .search-input, .filter-bar select {
    width: 100% !important; min-width: 0 !important;
  }
  .search-input input,
  .filter-bar select {
    height: 50px !important;
    font-size: 16px !important;
    border-radius: 12px !important;
    padding: 12px 16px 12px 40px !important;
    background: #fff !important;
    border: 1.5px solid #E5E7EB !important;
    color: #1A1D2E !important;
    box-shadow: 0 1px 6px rgba(0,0,0,0.05) !important;
  }
  .filter-bar select { padding-left: 16px !important; }
  .search-input i { font-size: 15px !important; top: 50% !important; }

  /* ── BUTTONS ─────────────────────────────────────── */
  .btn { padding: 11px 16px !important; font-size: 14px !important; font-weight: 600 !important; }
  .btn-sm { padding: 8px 12px !important; font-size: 13px !important; }
  .btn-icon { width: 42px !important; height: 42px !important; padding: 0 !important; }

  /* ── MODAL — bottom sheet ──────────────────────── */
  .modal-overlay { align-items: flex-end !important; padding: 0 !important; }
  .modal {
    width: 100% !important; max-width: 100% !important;
    max-height: 92vh !important;
    border-radius: 24px 24px 0 0 !important;
    padding: 22px 18px 32px !important;
    animation: slideUp 0.3s ease !important;
    background: #fff !important;
  }
  .modal-lg { max-width: 100% !important; }
  @keyframes slideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }

  /* Drag handle on modal */
  .modal::before {
    content: '';
    display: block;
    width: 40px; height: 4px;
    background: #E5E7EB;
    border-radius: 10px;
    margin: -8px auto 16px;
  }
  .modal-title { font-size: 18px !important; font-weight: 700 !important; color: #1A1D2E !important; }
  .modal .grid-2 { grid-template-columns: 1fr !important; }
  .modal-close { background: #F3F4F6 !important; color: #374151 !important; border: none !important; }

  /* ── FORMS ─────────────────────────────────────── */
  .form-group { margin-bottom: 14px !important; }
  label { font-size: 14px !important; font-weight: 600 !important; color: #374151 !important; margin-bottom: 7px !important; }
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  input[type="url"],
  select, textarea {
    font-size: 16px !important;
    padding: 13px 14px !important;
    border-radius: 12px !important;
    border: 1.5px solid #E5E7EB !important;
    background: #F9FAFB !important;
    color: #1A1D2E !important;
    width: 100% !important;
    min-width: 0 !important;
    -webkit-appearance: none !important;
  }
  input:focus, select:focus, textarea:focus {
    border-color: #6366F1 !important;
    background: #fff !important;
    box-shadow: 0 0 0 3px rgba(99,102,241,0.12) !important;
  }

  /* ── ALERT ─────────────────────────────────────── */
  .alert {
    font-size: 14px !important;
    padding: 13px 16px !important;
    border-radius: 12px !important;
    margin-bottom: 14px !important;
  }

  /* ── BADGES ─────────────────────────────────────── */
  .badge { font-size: 11px !important; padding: 4px 9px !important; font-weight: 600 !important; }
  .source-badge { font-size: 12px !important; padding: 4px 10px !important; }
  .status-pill { font-size: 12px !important; padding: 4px 10px !important; }

  /* ── AUTH PAGES ─────────────────────────────────── */
  .auth-page {
    background: #F0F2F8 !important;
    align-items: flex-start !important;
    padding: 32px 18px !important;
  }
  .auth-card {
    background: #fff !important;
    border: none !important;
    border-radius: 20px !important;
    padding: 28px 22px !important;
    box-shadow: 0 4px 24px rgba(0,0,0,0.1) !important;
    max-width: 100% !important;
  }
  .auth-title { font-size: 22px !important; color: #1A1D2E !important; }
  .auth-sub { color: #6B7280 !important; }

  /* ── LEAD DETAIL ────────────────────────────────── */
  .lead-detail { grid-template-columns: 1fr !important; gap: 14px !important; }
  .lead-info-card {
    background: #fff !important;
    border: none !important;
    border-radius: 18px !important;
    box-shadow: 0 2px 16px rgba(0,0,0,0.07) !important;
  }
  .lead-name { font-size: 22px !important; font-weight: 800 !important; color: #1A1D2E !important; }
  .lead-meta-item { font-size: 15px !important; color: #374151 !important; }
  .action-btns { gap: 10px !important; }
  .action-btns .btn {
    flex: 1 !important;
    justify-content: center !important;
    min-height: 48px !important;
    font-size: 15px !important;
    font-weight: 700 !important;
    border-radius: 12px !important;
  }
  .btn-call {
    background: #10B981 !important;
    color: #fff !important;
    border: none !important;
  }
  .btn-wa {
    background: #25D366 !important;
    color: #fff !important;
    border: none !important;
  }

  /* ── TIMELINE / NOTES ───────────────────────────── */
  .timeline-content {
    background: #F9FAFB !important;
    border: 1px solid #E5E7EB !important;
    border-radius: 12px !important;
    padding: 12px 14px !important;
  }
  .timeline-text { font-size: 14px !important; color: #1A1D2E !important; }
  .timeline-time { font-size: 12px !important; color: #9CA3AF !important; }

  /* ── PLAN CARDS ──────────────────────────────────── */
  .plan-grid { grid-template-columns: 1fr !important; gap: 14px !important; }
  .plan-card {
    background: #fff !important;
    border: 1.5px solid #E5E7EB !important;
    border-radius: 18px !important;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06) !important;
  }
  .plan-name { font-size: 18px !important; color: #1A1D2E !important; }
  .plan-price { font-size: 30px !important; color: #6366F1 !important; }

  /* ── SHARE LINK BOX ──────────────────────────────── */
  .share-link-box {
    background: #F9FAFB !important;
    border: 1.5px solid #E5E7EB !important;
    border-radius: 12px !important;
    flex-direction: column !important;
    gap: 8px !important;
  }
  .share-link-box input { color: #374151 !important; font-size: 13px !important; }
  .share-link-box .btn { width: 100% !important; justify-content: center !important; }

  /* ── EMPTY STATE ─────────────────────────────────── */
  .empty-state { padding: 40px 16px !important; }
  .empty-icon {
    background: #F3F4F6 !important;
    color: #9CA3AF !important;
  }
  .empty-title { font-size: 18px !important; color: #1A1D2E !important; }
  .empty-desc { font-size: 14px !important; color: #6B7280 !important; }

  /* ── PAGINATION ──────────────────────────────────── */
  .pagination { flex-wrap: wrap !important; gap: 6px !important; }
  .page-btn {
    min-width: 40px !important; height: 40px !important;
    font-size: 14px !important;
    background: #fff !important;
    border: 1.5px solid #E5E7EB !important;
    color: #374151 !important;
    border-radius: 10px !important;
  }
  .page-btn.active {
    background: #6366F1 !important;
    border-color: #6366F1 !important;
    color: #fff !important;
  }

  /* ── SETUP STEPS ─────────────────────────────────── */
  .setup-step {
    background: #fff !important;
    border: none !important;
    border-radius: 14px !important;
    box-shadow: 0 2px 10px rgba(0,0,0,0.06) !important;
    padding: 16px !important;
  }
  .step-title { font-size: 15px !important; font-weight: 700 !important; color: #1A1D2E !important; }
  .step-desc { font-size: 13px !important; color: #6B7280 !important; line-height: 1.6 !important; }

  /* ── FORM BUILDER ────────────────────────────────── */
  .field-item {
    background: #F9FAFB !important;
    border: 1.5px solid #E5E7EB !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    padding: 12px !important;
    border-radius: 10px !important;
  }
  .field-label-edit {
    font-size: 15px !important;
    color: #1A1D2E !important;
    background: transparent !important;
  }

  /* ── ADMIN DROPDOWN → bottom sheet ──────────────── */
  .dropdown-menu {
    position: fixed !important;
    left: 12px !important; right: 12px !important;
    bottom: 16px !important; top: auto !important;
    border-radius: 18px !important;
    z-index: 500 !important;
    background: #fff !important;
    box-shadow: 0 -4px 32px rgba(0,0,0,0.15) !important;
    border: none !important;
  }
  .dropdown-menu button {
    padding: 15px 18px !important;
    font-size: 15px !important;
    color: #374151 !important;
  }

  /* ── ADMIN STATS ─────────────────────────────────── */
  .revenue-card {
    background: linear-gradient(135deg, #6366F1, #8B5CF6) !important;
    color: #fff !important;
  }
  .revenue-amount { color: #fff !important; }

  /* Settings */
  .settings-section {
    background: #fff !important;
    border: none !important;
    border-radius: 18px !important;
    box-shadow: 0 2px 12px rgba(0,0,0,0.07) !important;
  }
  .settings-section-header {
    background: #F9FAFB !important;
    color: #1A1D2E !important;
    font-size: 15px !important;
    padding: 14px 18px !important;
  }

  /* Color swatches */
  .color-swatches { gap: 10px !important; flex-wrap: wrap !important; }
  .swatch { width: 30px !important; height: 30px !important; }
}

/* ════════════════════════════════════════════════════
   VERY SMALL PHONES ≤ 380px
════════════════════════════════════════════════════ */
@media (max-width: 380px) {
  .stat-value { font-size: 22px !important; }
  .content-inner { padding: 12px 10px 28px !important; }
  .page-title { font-size: 21px !important; }
  .card { padding: 14px 12px !important; }
  .nav-item { padding: 12px 14px !important; font-size: 15px !important; }
}

/* ════════════════════════════════════════════════════
   TOUCH IMPROVEMENTS
════════════════════════════════════════════════════ */
@media (hover: none) {
  .nav-item { min-height: 52px; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; }
  .btn-icon { min-width: 44px !important; min-height: 44px !important; }
  .stat-card:hover, .kanban-card:hover, .btn-primary:hover { transform: none !important; }
  .btn:active { opacity: 0.8; transform: scale(0.98); }
  .nav-item:active { opacity: 0.7; }
}

/* ════════════════════════════════════════════════════
   TABLET 769–1024px
════════════════════════════════════════════════════ */
@media (min-width: 769px) and (max-width: 1024px) {
  :root { --sidebar-w: 210px; }
  .stats-grid { grid-template-columns: repeat(3,1fr) !important; }
  .content-inner { padding: 22px 24px !important; }
}

/* ════════════════════════════════════════════════════
   iOS SAFE AREA (notch / Dynamic Island)
════════════════════════════════════════════════════ */
@supports (padding: env(safe-area-inset-top)) {
  @media (max-width: 768px) {
    .mobile-topbar {
      padding-top: env(safe-area-inset-top);
      height: calc(58px + env(safe-area-inset-top));
    }
    .main-content {
      padding-top: calc(58px + env(safe-area-inset-top)) !important;
    }
  }
}
