/* ══════════════════════════════════════════════
   MOBILE-FIRST ENHANCEMENTS
   Loaded after style.css
   ══════════════════════════════════════════════ */

/* ── GLOBAL TOUCH ──────────────────────────── */
* { -webkit-tap-highlight-color: rgba(0,0,0,.04); }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
select, input, textarea { font-size: 16px; } /* prevent iOS zoom */
@media (min-width: 501px) { select, input, textarea { font-size: 14px; } }

/* ── SIDEBAR IMPROVEMENTS ──────────────────── */
@media (max-width: 900px) {
    .sidebar { width: 270px; }
    .sidebar-brand { padding: 16px 14px 14px; }
    .sidebar-brand-icon { height: 70px; }
    .nav-item { padding: 11px 12px; font-size: 14px; gap: 10px; }
    .nav-group > summary { padding: 11px 12px; font-size: 14px; gap: 10px; }
    .nav-sub a { padding: 9px 12px; font-size: 13.5px; }
    .nav-label { padding: 16px 12px 6px; }
    .sidebar-overlay { -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
}

/* ── TOPBAR ────────────────────────────────── */
@media (max-width: 500px) {
    .topbar { height: 52px; padding: 0 10px; gap: 8px; }
    .topbar-title { font-size: 13px; }
    .topbar-user { font-size: 11px; max-width: 35vw; }
    .topbar-avatar { width: 26px; height: 26px; font-size: 11px; }
    .sidebar-toggle { width: 32px; height: 32px; }
}

/* ── CONTENT AREA ──────────────────────────── */
@media (max-width: 900px) {
    .content { padding: 16px 14px 36px; }
}
@media (max-width: 500px) {
    .content { padding: 12px 10px 28px; }
}

/* ── PAGE HEADER ───────────────────────────── */
@media (max-width: 600px) {
    .page-header { flex-direction: column; align-items: stretch; gap: 10px; padding-bottom: 12px; margin-bottom: 14px; }
    .page-header-left h1 { font-size: 17px; }
    .page-header-left p { font-size: 11.5px; }
    .page-header .btn, .page-header a.btn { width: 100%; justify-content: center; font-size: 13px; }
    .brand-heading img { width: 34px; height: 34px; }
}

/* ── CARDS ──────────────────────────────────── */
@media (max-width: 500px) {
    .card { padding: 12px; border-radius: 10px; }
}

/* ── STAT GRID ─────────────────────────────── */
@media (max-width: 900px) {
    .stat-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .stat-card { padding: 14px 10px; }
    .stat-number { font-size: 24px; }
}
@media (max-width: 500px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 6px; }
    .stat-card { padding: 12px 8px; border-radius: 10px; }
    .stat-card::before { height: 2px; }
    .stat-number { font-size: 20px; }
    .stat-label { font-size: 9.5px; letter-spacing: .4px; }
}

/* ── GRID LAYOUTS ──────────────────────────── */
@media (max-width: 900px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .row { gap: 12px; }
    .col-4, .col-6, .col-8 { grid-column: span 12; }
}

/* ── FORMS ──────────────────────────────────── */
@media (max-width: 600px) {
    .form-row { grid-template-columns: 1fr; gap: 10px; }
    .form-group { margin-bottom: 12px; }
    label { font-size: 12px; margin-bottom: 4px; }
    input[type="text"], input[type="email"], input[type="password"], input[type="date"], select, textarea {
        padding: 10px 12px;
        border-radius: 10px;
    }
    textarea { min-height: 65px; }
}

/* ── BUTTONS ───────────────────────────────── */
@media (max-width: 500px) {
    .btn, button[type="submit"], button[type="button"] {
        min-height: 38px;
        padding: 8px 14px;
        font-size: 13px;
        line-height: 1.2;
        white-space: normal;
    }
    .btn-sm { min-height: 32px; padding: 6px 10px; font-size: 11.5px; }
    .btn-lg { padding: 10px 20px; font-size: 14px; }
}

/* ── FILTER BAR ────────────────────────────── */
@media (max-width: 600px) {
    .filter-bar {
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 4px;
        gap: 5px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .filter-bar::-webkit-scrollbar { display: none; }
    .filter-bar a { white-space: nowrap; padding: 6px 12px; font-size: 12px; }
}

/* ── SEARCH FORMS ──────────────────────────── */
@media (max-width: 600px) {
    form[style*="display:flex"][style*="flex-wrap"] {
        flex-direction: column;
    }
    form[style*="display:flex"][style*="flex-wrap"] input[style*="min-width:200px"] {
        min-width: 0 !important;
        width: 100%;
    }
    form[style*="display:flex"][style*="flex-wrap"] select[style*="width:120px"],
    form[style*="display:flex"][style*="flex-wrap"] select[style*="width:150px"] {
        width: 100% !important;
    }
}

/* ── TABLE ─────────────────────────────────── */
@media (max-width: 900px) {
    .table-wrap { margin: 0 -4px; padding: 0 4px; -webkit-overflow-scrolling: touch; }
    .table { min-width: 580px; font-size: 12.5px; }
    .table th { padding: 8px 10px; font-size: 10px; }
    .table td { padding: 9px 10px; }
}

/* ── MOBILE LEAD CARDS (replaces table <600px) ── */
.m-lead-cards { display: none; }

@media (max-width: 600px) {
    .m-lead-cards { display: block; }
    .m-lead-cards + .table-wrap,
    .m-lead-cards ~ .table-wrap { display: none; }

    .m-lc {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 12px;
        padding: 12px;
        margin-bottom: 8px;
        display: block;
        text-decoration: none;
        color: var(--ink);
        transition: box-shadow .15s;
        position: relative;
    }
    .m-lc:active { box-shadow: 0 1px 4px rgba(0,0,0,.08); }
    .m-lc:hover { text-decoration: none; color: var(--ink); }
    .m-lc-top { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
    .m-lc-avatar {
        width: 38px; height: 38px; border-radius: 50%;
        background: linear-gradient(135deg, #0ea5e9, #6366f1);
        color: #fff; display: flex; align-items: center; justify-content: center;
        font-size: 14px; font-weight: 800; flex-shrink: 0;
    }
    .m-lc-info { flex: 1; min-width: 0; }
    .m-lc-name { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .m-lc-sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .m-lc-badges { flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
    .m-lc-row { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 6px; }
    .m-lc-chip {
        display: inline-flex; align-items: center; gap: 2px;
        padding: 2px 7px; border-radius: 999px; font-size: 10.5px; font-weight: 600;
        background: var(--bg); color: var(--muted); border: 1px solid var(--border);
    }
    .m-lc-chip.green { background: #ecfdf5; color: #059669; border-color: #a7f3d0; }
    .m-lc-chip.red { background: #fef2f2; color: #dc2626; border-color: #fecaca; }
    .m-lc-chip.blue { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
    .m-lc-chip.yellow { background: #fefce8; color: #a16207; border-color: #fde68a; }
    .m-lc-sno { position: absolute; top: 10px; right: 12px; font-size: 10px; color: #cbd5e1; font-weight: 700; }
    .m-lc-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }
    .m-lc-footer span { font-size: 10.5px; color: var(--muted); }
}

/* ── ALERTS ────────────────────────────────── */
@media (max-width: 500px) {
    .alert { padding: 10px 12px; font-size: 12.5px; border-radius: 8px; }
}

/* ── BADGES ────────────────────────────────── */
@media (max-width: 500px) {
    .badge { font-size: 10px; padding: 2px 6px; }
    .badge::before { font-size: 5px; }
}

/* ── QUICK CARDS ───────────────────────────── */
@media (max-width: 500px) {
    .quick-card { padding: 12px; }
    .quick-card-icon { font-size: 20px; margin-bottom: 6px; }
    .quick-card h3 { font-size: 13px; }
    .quick-card p { font-size: 11px; }
}

/* ── STATUS / BAR GRIDS ────────────────────── */
@media (max-width: 500px) {
    .status-grid { grid-template-columns: 1fr; gap: 6px; }
    .status-grid div { padding: 8px 10px; font-size: 12px; }
    .status-grid strong { font-size: 16px; }
    .mini-stack { grid-template-columns: 1fr; }
    .bar-meta { font-size: 12px; }
}

/* ── PAGINATION ────────────────────────────── */
@media (max-width: 500px) {
    div[style*="justify-content:center"][style*="gap:6px"] {
        flex-wrap: wrap;
    }
    div[style*="justify-content:center"][style*="gap:6px"] .btn-sm {
        min-width: 32px;
        padding: 5px 8px;
    }
}

/* ── INFO BOX ──────────────────────────────── */
@media (max-width: 500px) {
    .info-box { padding: 10px 12px; font-size: 12px; border-radius: 8px; }
    .info-box code { font-size: 11px; }
}

/* ── TYPOGRAPHY ─────────────────────────────── */
@media (max-width: 500px) {
    h1 { font-size: 17px; }
    h2 { font-size: 14px; }
    h3 { font-size: 13px; }
    .section-header h1, .section-header h2 { font-size: 16px; }
}

/* ── SAFE AREAS (notch phones) ─────────────── */
@supports (padding: env(safe-area-inset-bottom)) {
    .sidebar { padding-bottom: env(safe-area-inset-bottom); }
    .content { padding-bottom: calc(28px + env(safe-area-inset-bottom)); }
}

/* ── PWA STANDALONE MODE ───────────────────── */
@media all and (display-mode: standalone) {
    body { padding-top: env(safe-area-inset-top, 0); }
    .topbar {
        padding-top: env(safe-area-inset-top, 0);
        height: calc(52px + env(safe-area-inset-top, 0));
    }
    .sidebar { padding-top: env(safe-area-inset-top, 0); }
    .content { padding-bottom: calc(36px + env(safe-area-inset-bottom, 0)); }
    .notif-bell { bottom: calc(24px + env(safe-area-inset-bottom, 0)); }
    .notif-panel { bottom: calc(80px + env(safe-area-inset-bottom, 0)); }
    #pwaInstallBanner { display: none !important; }
}

/* ── REDUCED MOTION ────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
    html { scroll-behavior: auto; }
}

/* ── TOUCH-ONLY DEVICES ────────────────────── */
@media (hover: none) and (pointer: coarse) {
    .table tbody tr:hover { background: transparent; }
    .btn:hover, button:hover { opacity: 1; }
    .btn:active, button:active { opacity: .85; transform: scale(.97); }
    .quick-card:hover { transform: none; box-shadow: var(--shadow); }
    .quick-card:active { transform: scale(.98); }
    .nav-item:hover { background: none; }
    .nav-item:active { background: rgba(255,255,255,.06); }
}
