/* ===== Fix: X button overlap (all screens) ===== */
#page-mapa .detail-header {
    padding-right: 44px !important;
}

/* Fix: Detail header — WO inside date badge (all screens) */
#page-mapa .detail-fecha-badge .wo-in-badge {
    display: block;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.5px;
}
#page-mapa .detail-fecha-badge .date-in-badge {
    display: block;
    font-size: 11px;
    font-weight: 600;
}
#page-mapa .detail-header h3 {
    display: none !important;
}

/* ===== Mobile fixes (≤600px) ===== */
@media (max-width: 600px), (max-height: 500px) and (orientation: landscape) {

    /* Fix: Global — sidebar overlay mode for all modules on mobile */
    .app-container {
        margin-left: 0 !important;
        width: 100% !important;
    }
    /* Fix: NC panel full width on mobile (overrides styles.min.css 500px) */
    #page-mapa .nc-mapa-panel.open {
        width: 100% !important;
        min-width: 100% !important;
    }
    .page-section {
        margin-left: 0 !important;
        padding-left: 2px !important;
        padding-right: 2px !important;
        width: 100% !important;
    }

    /* Fix: Footer buttons — icon only on mobile, Save is biggest */
    #page-mapa .detail-footer {
        padding: 8px 14px;
        gap: 6px;
    }
    #page-mapa .btn-onmyway,
    #page-mapa .btn-navigate,
    #page-mapa .btn-reschedule-footer,
    #page-mapa .btn-save {
        font-size: 0 !important;
        padding: 10px 14px !important;
        min-width: 44px;
        justify-content: center;
    }
    #page-mapa .btn-onmyway i,
    #page-mapa .btn-navigate i,
    #page-mapa .btn-reschedule-footer i,
    #page-mapa .btn-save i {
        font-size: 18px !important;
    }
    #page-mapa .btn-save {
        flex: 1 !important;
    }

    /* Fix: Route panel — full width, above sidebar */
    #page-mapa .route-panel.open {
        left: 0 !important;
        right: 0 !important;
        margin-left: 0 !important;
        width: 100vw !important;
        min-width: 100vw !important;
        position: fixed !important;
        top: 0; bottom: 0;
        z-index: 1050;
    }

    /* Fix: Hide route-header minimize/close buttons on mobile — moved to route-controls */
    #page-mapa .route-header .route-close {
        display: none !important;
    }

    /* Fix: Route load row — Load Route + icon buttons on same line */
    #page-mapa .route-controls .route-load-row {
        display: flex;
        gap: 6px;
        align-items: stretch;
    }
    #page-mapa .route-controls .route-load-row .route-load-btn {
        flex: 1;
    }
    #page-mapa .route-controls .route-mobile-icon-btn {
        width: 44px;
        min-width: 44px;
        border: 1px solid #e2e8f0;
        border-radius: 8px;
        font-size: 16px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
    }
    #page-mapa .route-controls .route-icon-min {
        background: #f1f5f9;
        color: #475569;
    }
    #page-mapa .route-controls .route-icon-close {
        background: #fef2f2;
        color: #dc2626;
        border-color: #fecaca;
    }

        /* Fix: KPI toggle visible on mobile */
    #page-inventory .inv-kpi-toggle {
        display: block !important;
        text-align: center;
        padding: 6px;
        font-size: 12px;
        font-weight: 600;
        color: #3b82f6;
        cursor: pointer;
        background: #eff6ff;
        border-radius: 8px;
        margin-bottom: 8px;
        user-select: none;
    }
    #page-inventory .inv-kpis {
        display: none !important;
    }
    #page-inventory .inv-kpis.kpi-visible {
        display: grid !important;
    }

    /* Fix: Inventory header compact */
    #page-inventory {
        padding: 10px 8px !important;
    }
    #page-inventory .inv-header {
        gap: 6px;
        margin-bottom: 8px;
    }
    #page-inventory .inv-header h1 {
        font-size: 16px !important;
    }
    #page-inventory .inv-controls {
        gap: 4px;
        width: 100%;
    }
    #page-inventory .inv-select {
        padding: 5px 6px;
        font-size: 11px;
        min-width: 80px;
        flex: 1;
    }
    #page-inventory .inv-search {
        padding: 5px 8px;
        font-size: 11px;
        min-width: 0;
        flex: 2;
    }
    #page-inventory .inv-btn {
        padding: 5px 8px;
        font-size: 11px;
    }
    #page-inventory .inv-btn-export {
        display: none;
    }
    #page-inventory .inv-kpis {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 6px;
        margin-bottom: 8px;
    }
    #page-inventory .inv-kpi {
        padding: 8px 10px;
    }
    #page-inventory .inv-kpi-label {
        font-size: 9px;
    }
    #page-inventory .inv-kpi-value {
        font-size: 16px;
    }

    /* Fix: Sidebar scroll in landscape */
    .sidebar {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    .sidebar-nav {
        overflow-y: auto;
        flex: 1;
        min-height: 0;
    }

    /* Fix: Detail header — adjust badge on mobile */
    #page-mapa .detail-fecha-badge {
        display: flex !important;
        flex-direction: column;
        align-items: center;
        padding: 6px 16px !important;
        line-height: 1.2;
    }

    /* Shared toggle button style */
    .mobile-toggle-btn {
        display: block !important;
        text-align: center;
        padding: 6px;
        font-size: 12px;
        font-weight: 600;
        color: #3b82f6;
        cursor: pointer;
        background: #eff6ff;
        border-radius: 8px;
        margin-bottom: 8px;
        user-select: none;
        -webkit-user-select: none;
    }

    /* Fix: Estimates compact */
    #page-estimates .est-header h1 {
        font-size: 16px !important;
    }
    #page-estimates .est-controls {
        gap: 4px;
        width: 100%;
    }
    #page-estimates .est-select,
    #page-estimates .est-date,
    #page-estimates .est-controls > span:not(#estLiveIndicator),
    #page-estimates .est-controls .est-btn-reset,
    #page-estimates #estLiveIndicator {
        display: none !important;
    }
    #page-estimates .est-select.kpi-visible,
    #page-estimates .est-date.kpi-visible,
    #page-estimates .est-controls > span.kpi-visible,
    #page-estimates .est-controls .est-btn-reset.kpi-visible {
        display: inline-flex !important;
    }
    #page-estimates .est-summary {
        display: none !important;
    }
    #page-estimates .est-summary.kpi-visible {
        display: flex !important;
    }
    #page-estimates .est-search {
        flex: 1;
        font-size: 12px;
        padding: 6px 10px;
        min-width: 0;
    }
    #page-estimates .est-controls > button[onclick*="estRefreshData"] {
        font-size: 11px !important;
        padding: 6px 10px !important;
    }
    #page-estimates .est-drafts {
        display: none !important;
    }
    #page-estimates .est-drafts.kpi-visible {
        display: block !important;
    }

    /* Fix: Returns compact */
    #page-returns .ret-header h1 {
        font-size: 16px !important;
    }
    #page-returns .ret-controls {
        gap: 4px;
        width: 100%;
        display: flex !important;
        align-items: center;
        flex-wrap: wrap;
    }
    #page-returns .ret-select,
    #page-returns .ret-date,
    #page-returns .ret-controls > span,
    #page-returns .ret-btn-reset,
    #page-returns .ret-btn-export {
        display: none !important;
    }
    #page-returns .ret-select.kpi-visible,
    #page-returns .ret-date.kpi-visible,
    #page-returns .ret-controls > span.kpi-visible,
    #page-returns .ret-btn-reset.kpi-visible,
    #page-returns .ret-btn-export.kpi-visible {
        display: inline-flex !important;
    }
    #page-returns .ret-summary {
        display: none !important;
    }
    #page-returns .ret-summary.kpi-visible {
        display: flex !important;
    }
    #page-returns .ret-search {
        flex: 1;
        font-size: 12px;
        padding: 6px 10px;
        min-width: 0;
    }
    #page-returns .ret-btn-new {
        font-size: 11px !important;
        padding: 6px 10px !important;
        white-space: nowrap;
    }

    /* Fix: Parts Tracking compact */
    #page-parts-track .pt-header h1 {
        font-size: 16px !important;
    }
    #page-parts-track .pt-tabs {
        gap: 2px;
    }
    #page-parts-track .pt-tab {
        font-size: 11px;
        padding: 6px 8px;
    }

    /* Fix: Parts Tracking deliver form toggle */
    #page-parts-track .deliver-form {
        display: none !important;
    }
    #page-parts-track .deliver-form.kpi-visible {
        display: block !important;
    }

    /* Fix: Parts Track — 5-rule scroll pattern */
    #page-parts-track.active {
        display: flex !important;
        flex-direction: column;
        height: calc(100vh - 60px) !important;
        overflow: hidden !important;
        min-height: 0;
        box-sizing: border-box;
        padding: 0 !important;
    }
    #page-parts-track .pt-container {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
        padding: 8px 2px !important;
        overflow: hidden;
    }
    #page-parts-track .pt-header { flex-shrink: 0; padding: 0 8px; }
    #page-parts-track .pt-tabs { flex-shrink: 0; }
    #page-parts-track .pt-panel.active {
        display: flex !important;
        flex-direction: column;
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }
    #page-parts-track .pt-table-wrap {
        flex: 1 1 0;
        min-height: 0;
        overflow-y: auto !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Fix: Tech Inventory filters + KPIs — hidden by default with toggle */
    #ptTechFilters { display: none !important; }
    #ptTechFilters.kpi-visible { display: flex !important; }
    #ptTechKpis { display: none !important; }
    #ptTechKpis.kpi-visible { display: flex !important; }

    /* Fix: Transaction Log filters — hidden by default with toggle */
    #ptLogFilters { display: none !important; }
    #ptLogFilters.kpi-visible { display: flex !important; }

    /* Fix: Search field wider on mobile */
    #page-mapa .top-bar {
        flex-wrap: wrap;
        padding: 6px 8px;
    }
    #page-mapa .top-bar .logo,
    #page-mapa .top-bar .separator,
    #page-mapa .top-bar .stats { display: none; }
    #page-mapa .top-bar .search-wrapper {
        flex: 1 1 auto;
        min-width: 0;
        max-width: none;
        order: 2;
    }
    #page-mapa .top-bar .search-input {
        width: 100%;
    }
    #page-mapa .top-bar .mapa-menu-btn { order: 1; }
    #page-mapa .top-bar > div[style*="flex:1"] { display: none; }
    #page-mapa .top-bar .user-bar { order: 3; }

    /* Fix: Settings scroll on mobile */
    #page-settings {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        height: calc(100vh - 60px) !important;
        max-height: none !important;
        padding-bottom: 120px !important;
        -ms-overflow-style: auto;
    }
    #page-settings.active {
        overflow-y: auto !important;
    }
    #page-settings .stg-table {
        font-size: 11px;
    }
    #page-settings .stg-input {
        width: 55px;
        font-size: 11px;
    }
}

/* ===== iOS zoom prevention ===== */
input, select, textarea {
    font-size: 16px !important;
}

/* ===== Search selection color feedback ===== */
.search-input.has-selection {
    background: #fef3c7 !important;
    border-color: #f59e0b !important;
}

/* === AI SMS MODULE === */
#page-ai-sms.active { display:flex !important; flex-direction:column; height:100%; padding:0 !important; }
.aisms-wrapper { display:flex; flex:1; min-height:0; background:#f8fafc; }
@media (max-width: 768px) {
    .aisms-list-panel { width:100%; display:flex; flex-direction:column; min-height:0; height:100%; background:#fff; }
    .aisms-detail-panel { position:fixed; top:0; left:0; right:0; bottom:0; z-index:1000; background:#fff; display:none; flex-direction:column; }
}
@media (max-width: 600px) {
    #page-ai-sms.active { height:calc(100vh - 60px) !important; }
    .aisms-list-body { overflow-y:auto !important; -webkit-overflow-scrolling:touch; min-height:0 !important; }
}
.aisms-header { padding:16px 16px 10px; border-bottom:1px solid #e2e8f0; background:#fff; flex-shrink:0; }
.aisms-title-row { display:flex; align-items:center; justify-content:space-between; margin-bottom:10px; }
.aisms-title-row h1 { font-size:17px; font-weight:700; color:#1e293b; margin:0; display:flex; align-items:center; gap:8px; }
.aisms-count { background:#3b82f6; color:#fff; border-radius:50px; font-size:11px; font-weight:700; padding:2px 9px; }
.aisms-refresh-btn { background:#f1f5f9; border:1px solid #e2e8f0; border-radius:8px; padding:6px 12px; cursor:pointer; color:#64748b; font-size:12px; font-weight:600; display:flex; align-items:center; gap:5px; }
.aisms-filters { display:flex; gap:5px; flex-wrap:wrap; overflow-x:auto; padding-bottom:2px; }
.aisms-chip { background:#f1f5f9; border:1px solid #e2e8f0; border-radius:50px; padding:4px 10px; font-size:11px; font-weight:600; cursor:pointer; color:#64748b; white-space:nowrap; }
.aisms-chip.active { background:#3b82f6; color:#fff; border-color:#3b82f6; }
.aisms-list-body { flex:1; overflow-y:auto; min-height:0; padding:10px; display:flex; flex-direction:column; gap:7px; -webkit-overflow-scrolling:touch; }
.aisms-empty { display:flex; flex-direction:column; align-items:center; justify-content:center; gap:10px; padding:60px 20px; color:#94a3b8; font-size:14px; text-align:center; width:100%; }
.aisms-card { background:#fff; border:1px solid #e2e8f0; border-radius:12px; padding:12px 14px; cursor:pointer; }
.aisms-card.aisms-selected { border-color:#3b82f6; background:#eff6ff; }
.aisms-card-top { display:flex; align-items:center; justify-content:space-between; margin-bottom:5px; gap:8px; }
.aisms-card-name { font-weight:700; color:#1e293b; font-size:13px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.aisms-card-date { font-size:11px; color:#94a3b8; white-space:nowrap; flex-shrink:0; }
.aisms-card-mid { display:flex; align-items:center; gap:5px; margin-bottom:5px; flex-wrap:wrap; }
.aisms-card-phone { font-size:11px; color:#64748b; }
.aisms-badge { font-size:10px; font-weight:700; padding:2px 7px; border-radius:50px; display:inline-block; }
.aisms-src-angi { background:#fff3e0; color:#e65100; }
.aisms-src-thumbtack { background:#e0f2fe; color:#0277bd; }
.aisms-src-direct { background:#e2e8f0; color:#475569; }
.aisms-st-active { background:#dbeafe; color:#1d4ed8; }
.aisms-st-qualified { background:#dcfce7; color:#15803d; }
.aisms-st-escalated { background:#fee2e2; color:#b91c1c; }
.aisms-st-no_response { background:#f1f5f9; color:#475569; }
.aisms-st-warranty_redirect { background:#ffedd5; color:#c2410c; }
.aisms-st-unmatched { background:#e2e8f0; color:#64748b; }
.aisms-st-closed { background:#f8fafc; color:#94a3b8; border:1px solid #e2e8f0; }
.aisms-card-preview { font-size:11px; color:#94a3b8; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.aisms-placeholder { display:flex; flex-direction:column; align-items:center; justify-content:center; height:100%; gap:12px; color:#94a3b8; font-size:14px; }
.aisms-detail-header { display:flex; align-items:center; gap:10px; padding:14px 16px; border-bottom:1px solid #e2e8f0; background:#f8fafc; flex-shrink:0; }
.aisms-back-btn { background:none; border:none; font-size:20px; cursor:pointer; color:#64748b; padding:4px 8px; border-radius:8px; line-height:1; }
.aisms-detail-title { flex:1; font-weight:700; font-size:15px; color:#1e293b; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.aisms-detail-body { flex:1; overflow-y:auto; padding:16px; display:flex; flex-direction:column; gap:12px; -webkit-overflow-scrolling:touch; }
.aisms-info-card { background:#fff; border:1px solid #e2e8f0; border-radius:12px; padding:14px; }
.aisms-info-title { font-size:11px; font-weight:700; color:#94a3b8; text-transform:uppercase; letter-spacing:0.5px; margin-bottom:10px; }
.aisms-info-row { display:flex; justify-content:space-between; align-items:flex-start; margin-bottom:5px; gap:8px; }
.aisms-info-label { font-size:12px; color:#64748b; flex-shrink:0; padding-top:1px; }
.aisms-info-value { font-size:12px; font-weight:600; color:#1e293b; text-align:right; word-break:break-word; }
.aisms-wo-link { color:#3b82f6; cursor:pointer; text-decoration:underline; font-weight:700; }
.aisms-messages-box { display:flex; flex-direction:column; gap:10px; max-height:50vh; overflow-y:auto; padding:4px 0; -webkit-overflow-scrolling:touch; }
.aisms-msg { display:flex; flex-direction:column; max-width:85%; }
.aisms-msg.aisms-assistant { align-self:flex-end; align-items:flex-end; }
.aisms-msg.aisms-customer { align-self:flex-start; align-items:flex-start; }
.aisms-bubble { padding:9px 13px; border-radius:16px; font-size:13px; line-height:1.5; word-break:break-word; }
.aisms-assistant .aisms-bubble { background:#3b82f6; color:#fff; border-bottom-right-radius:4px; }
.aisms-msg.aisms-office { align-self:flex-end; align-items:flex-end; }
.aisms-office .aisms-bubble { background:#10b981; color:#fff; border-bottom-right-radius:4px; }
.aisms-customer .aisms-bubble { background:#f1f5f9; color:#1e293b; border-bottom-left-radius:4px; }
.aisms-msg-time { font-size:10px; color:#94a3b8; margin-top:3px; padding:0 4px; }
.aisms-reply-box { display:flex; gap:8px; margin-top:12px; }
.aisms-reply-input { flex:1; border-radius:12px; border:1px solid #cbd5e1; padding:8px 12px; font-size:13px; resize:none; font-family:inherit; }
.aisms-reply-btn { background:#10b981; color:#fff; border:none; border-radius:12px; padding:8px 16px; font-weight:600; cursor:pointer; white-space:nowrap; }
.aisms-reply-btn:disabled { opacity:0.5; }
.aisms-admin-row { display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
.aisms-status-select { flex:1; min-width:140px; font-size:12px; padding:7px 10px; border:1px solid #e2e8f0; border-radius:8px; background:#fff; color:#1e293b; }
.aisms-del-btn { background:#fee2e2; color:#b91c1c; border:none; border-radius:8px; padding:7px 14px; font-size:12px; font-weight:600; cursor:pointer; }
.aisms-stg-row { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; padding:14px 16px; background:#fff; border-radius:10px; margin-bottom:8px; box-shadow:0 1px 4px rgba(0,0,0,0.06); }
.aisms-stg-info { flex:1; }
.aisms-stg-label { font-size:14px; font-weight:600; color:#334155; margin-bottom:3px; }
.aisms-stg-desc { font-size:12px; color:#94a3b8; line-height:1.5; }

/* === REVIEWS MODULE MOBILE === */
#page-reviews.active { display:flex !important; flex-direction:column; height:100vh !important; overflow:hidden !important; min-height:0; box-sizing:border-box; padding-bottom:60px !important; }
#page-reviews #rvHeader { flex-shrink:0; }
#page-reviews #rvFiltersWrap { flex-shrink:0; }
#page-reviews #rvKpis { flex-shrink:0; }
#rvTableWrap { flex:1 1 0; min-height:0; overflow-y:auto !important; overflow-x:auto !important; -webkit-overflow-scrolling:touch; }
/* Tech Payments module layout (no hide rules — those are in @media below) */
#page-tech-payments.active { display:flex !important; flex-direction:column; height:100vh !important; overflow:hidden !important; min-height:0; box-sizing:border-box; padding-bottom:60px !important; }
#page-tech-payments #tpHeader { flex-shrink:0; }
#page-tech-payments #tpFiltersWrap { flex-shrink:0; }
#page-tech-payments #tpKpis { flex-shrink:0; }
#tpContent { flex:1 1 0; min-height:0; overflow-y:auto !important; overflow-x:auto !important; -webkit-overflow-scrolling:touch; }
/* Parts Track read-only mode for techs — hide all action buttons/columns */
.pt-readonly .deliver-form { display: none !important; }
.pt-readonly .pt-table th:last-child,
.pt-readonly .pt-table td:last-child { display: none !important; }
.pt-readonly button[onclick*="ptExport"] { display: none !important; }

/* Employees table horizontal scroll */
.emp-table-wrap { overflow-x:auto !important; -webkit-overflow-scrolling:touch; }
.emp-table { min-width:520px; }
.emp-time-cell .emp-clear-btn { display:inline-block; margin-left:4px; color:#ef4444; cursor:pointer; font-size:12px; }

@media (max-width: 600px) {
    #page-reviews #rvHeader h1 { font-size:18px; }
    #page-reviews .stg-table th, #page-reviews .stg-table td { font-size:11px; padding:6px 4px; }
    .emp-table th, .emp-table td { font-size:11px; padding:5px 4px; white-space:nowrap; }
    .emp-actions { flex-wrap:wrap; gap:4px; }
    .emp-btn { font-size:11px; padding:4px 8px; }
    .emp-cc-label { font-size:10px; }

    /* Reviews — hide filters/KPIs with toggle (mobile only) */
    #rvFiltersWrap { display:none !important; }
    #rvFiltersWrap.kpi-visible { display:flex !important; }
    #rvKpis { display:none !important; }
    #rvKpis.kpi-visible { display:flex !important; }

    /* Tech Payments — hide filters/KPIs with toggle (mobile only) */
    #tpFiltersWrap { display:none !important; }
    #tpFiltersWrap.kpi-visible { display:flex !important; }
    #tpKpis { display:none !important; }
    #tpKpis.kpi-visible { display:flex !important; }

    /* Payment Records — hide filters/KPIs + scroll (mobile only) */
    #page-payment-records.active { display:flex !important; flex-direction:column; height:calc(100vh - 60px) !important; overflow:hidden !important; min-height:0; padding:0 2px !important; }
    #prFiltersWrap { display:none !important; }
    #prFiltersWrap.kpi-visible { display:flex !important; }
    #prKpis { display:none !important; }
    #prKpis.kpi-visible { display:flex !important; }
    #prContent { flex:1 1 0; min-height:0; overflow-y:auto !important; overflow-x:auto !important; -webkit-overflow-scrolling:touch; }
}