/* ============================================
   L37 Trans - Mobile-First Dedicated Design
   Professional SaaS-grade mobile experience
   ============================================ */

/* === TABLET (max-width: 1024px) === */
@media (max-width: 1024px) {
    .sidebar { width: 220px; }
    .sidebar-header { margin-bottom: 30px; padding: 0 15px; }
    .sidebar-header .logo { font-size: 18px; }
    .nav-links li { padding: 10px 12px; font-size: 14px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr) !important; }
    .saas-col-left, .saas-col-right { flex: 1 1 100% !important; }
    .sticky-footer { width: calc(100% - 220px) !important; left: 220px !important; }
}

/* === MOBILE (max-width: 768px) === */
@media (max-width: 768px) {

    /* ── GLOBAL ── */
    * { -webkit-tap-highlight-color: transparent; }
    body { overflow: hidden; }

    .app-container {
        flex-direction: column;
        height: 100dvh;
    }

    /* ── TOPBAR ── */
    .topbar {
        height: 52px;
        padding: 0 16px;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 0;
        border-bottom: 1px solid var(--border-light);
    }
    .topbar .user-info {
        gap: 8px;
        font-size: 13px;
    }
    .topbar .user-info img {
        width: 30px; height: 30px;
    }
    .topbar .user-info .status-indicator {
        width: 6px; height: 6px;
    }
    .search-bar { display: none !important; }

    /* ── SIDEBAR → BOTTOM ICON TAB BAR ── */
    .sidebar {
        order: 2;
        width: 100%;
        height: 56px;
        position: fixed;
        bottom: 0;
        left: 0;
        z-index: 500;
        display: flex;
        flex-direction: row;
        align-items: stretch;
        padding: 0;
        border-right: none;
        border-top: 1px solid var(--border-light);
        border-radius: 0;
        background: rgba(255,255,255,0.97);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        box-shadow: 0 -2px 16px rgba(0,0,0,0.05);
        overflow: visible;
    }

    .sidebar-header { display: none !important; }

    .sidebar .nav-links {
        display: flex;
        flex-direction: row;
        width: 100%;
        padding: 0;
        margin: 0;
        gap: 0;
        justify-content: space-around;
        align-items: center;
        height: 100%;
    }

    /* ICON ONLY — hide all text */
    .sidebar .nav-links li {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0;
        padding: 8px 0;
        font-size: 0;        /* hide text completely */
        line-height: 0;
        border-radius: 0;
        background: transparent !important;
        color: #94a3b8;
        white-space: nowrap;
        min-width: 0;
        transition: color 0.2s;
    }

    .sidebar .nav-links li i {
        font-size: 24px;
        line-height: 1;
    }

    .sidebar .nav-links li.active {
        color: var(--accent);
        background: transparent !important;
        position: relative;
    }
    .sidebar .nav-links li.active::after {
        content: '';
        position: absolute;
        top: 0;
        left: 20%;
        width: 60%;
        height: 3px;
        background: var(--accent);
        border-radius: 0 0 6px 6px;
    }

    /* ── MAIN CONTENT ── */
    .main-content {
        order: 1;
        margin-left: 0;
        width: 100%;
        height: calc(100dvh - 52px);
        overflow: hidden;
    }

    .sections-wrapper {
        padding: 16px;
        padding-bottom: 72px; /* space for bottom tab */
        height: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* ── SECTION HEADERS ── */
    .section-title {
        font-size: 18px !important;
        margin-bottom: 14px !important;
        letter-spacing: -0.3px;
    }
    .section-header {
        flex-direction: column;
        align-items: stretch !important;
        gap: 10px;
        margin-bottom: 14px !important;
    }
    .section-header .btn {
        width: 100%;
        justify-content: center;
        padding: 11px 16px;
    }

    /* ── STAT CARDS: 2-up compact ── */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }
    .stat-card {
        padding: 12px !important;
        gap: 10px !important;
        border-left-width: 3px !important;
        border-radius: 12px !important;
        min-height: auto;
    }
    .stat-card i {
        font-size: 24px !important;
        padding: 8px !important;
        border-radius: 8px !important;
        flex-shrink: 0;
    }
    .stat-card h3 {
        font-size: 10px !important;
        margin-bottom: 2px !important;
        line-height: 1.3;
        letter-spacing: 0;
    }
    .stat-card p {
        font-size: 16px !important;
        line-height: 1.2;
    }

    /* Quick Actions — stack */
    .stat-card[style*="grid-column"] {
        grid-column: 1 / -1 !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
        padding: 14px !important;
    }
    .stat-card[style*="grid-column"] > div:first-child h3 {
        font-size: 14px !important;
    }
    .stat-card[style*="grid-column"] > div:first-child p {
        font-size: 12px !important;
    }
    .stat-card[style*="grid-column"] > div:last-child {
        display: flex;
        flex-direction: column;
        gap: 6px;
    }
    .stat-card[style*="grid-column"] .btn {
        width: 100%;
        justify-content: center;
        padding: 10px 14px;
        font-size: 13px !important;
    }

    /* ── DASHBOARD WIDGETS ── */
    .dashboard-widgets {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
        margin-top: 14px !important;
    }
    .dashboard-widgets .panel {
        border-radius: 12px !important;
    }
    .dashboard-widgets .panel h3 {
        padding: 12px 14px !important;
        font-size: 13px !important;
    }
    .dashboard-widgets table {
        font-size: 12px !important;
    }
    .dashboard-widgets th {
        padding: 8px 14px !important;
        font-size: 10px !important;
    }
    .dashboard-widgets td {
        padding: 8px 14px !important;
        font-size: 12px !important;
    }

    /* ── TABLES → MOBILE CARDS (main tables only) ── */
    .table-container {
        overflow: visible !important;
        background: transparent !important;
        padding: 0 !important;
        border: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
    }
    .table-container table,
    .table-container thead,
    .table-container tbody,
    .table-container th,
    .table-container td,
    .table-container tr {
        display: block;
    }
    .table-container thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }
    .table-container tbody tr {
        margin-bottom: 10px;
        background: #fff;
        border: 1px solid var(--border-light);
        border-radius: 12px;
        padding: 14px;
        box-shadow: 0 1px 4px rgba(0,0,0,0.03);
    }
    .table-container td {
        border: none !important;
        border-bottom: 1px solid #f1f5f9 !important;
        position: relative;
        padding: 8px 0 8px 42% !important;
        text-align: right !important;
        display: flex !important;
        justify-content: flex-end !important;
        align-items: center !important;
        min-height: 36px;
        font-size: 13px;
        line-height: 1.4;
        word-break: break-word;
    }
    .table-container td:last-child {
        border-bottom: none !important;
        padding-left: 0 !important;
        padding-top: 12px !important;
        display: flex !important;
        justify-content: center !important;
        gap: 8px;
        flex-wrap: wrap;
    }
    .table-container td:last-child .btn {
        flex: 1;
        min-width: 55px;
        max-width: 120px;
        justify-content: center;
        padding: 8px 6px;
        font-size: 12px !important;
    }
    .table-container td::before {
        position: absolute;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 38%;
        white-space: normal;
        text-align: left;
        font-weight: 600;
        color: #94a3b8;
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.2px;
        line-height: 1.3;
    }

    /* Vehicle Table labels */
    #vehiclesTable td:nth-of-type(1)::before { content: "Unit"; }
    #vehiclesTable td:nth-of-type(2)::before { content: "Plate"; }
    #vehiclesTable td:nth-of-type(3)::before { content: "Investor/Day"; }
    #vehiclesTable td:nth-of-type(4)::before { content: "Sell/Day"; }
    #vehiclesTable td:nth-of-type(5)::before { content: "Status"; }

    /* Bookings Table labels */
    #bookingsTable td:nth-of-type(1)::before { content: "Customer"; }
    #bookingsTable td:nth-of-type(2)::before { content: "Unit"; }
    #bookingsTable td:nth-of-type(3)::before { content: "Duration"; }
    #bookingsTable td:nth-of-type(4)::before { content: "Bill"; }
    #bookingsTable td:nth-of-type(5)::before { content: "Payment"; }

    /* Revenue Table labels */
    #revenueTable td:nth-of-type(1)::before { content: "Date"; }
    #revenueTable td:nth-of-type(2)::before { content: "Customer"; }
    #revenueTable td:nth-of-type(3)::before { content: "Addons"; }
    #revenueTable td:nth-of-type(4)::before { content: "Route Fee"; }
    #revenueTable td:nth-of-type(5)::before { content: "Investor"; }
    #revenueTable td:nth-of-type(6)::before { content: "Net Profit"; }

    /* Customers Table labels */
    #customersTable td:nth-of-type(1)::before { content: "Name"; }
    #customersTable td:nth-of-type(2)::before { content: "Phone"; }
    #customersTable td:nth-of-type(3)::before { content: "KTP/ID"; }
    #customersTable td:nth-of-type(4)::before { content: "Address"; }

    /* ── FULLCALENDAR ── */
    .fc {
        padding: 10px !important;
        border-radius: 12px !important;
    }
    .fc .fc-toolbar.fc-header-toolbar {
        flex-direction: column;
        gap: 6px;
        margin-bottom: 10px !important;
    }
    .fc-toolbar-chunk {
        display: flex;
        justify-content: center;
        width: 100%;
        flex-wrap: wrap;
        gap: 4px;
    }
    .fc .fc-toolbar-title {
        font-size: 15px !important;
    }
    .fc .fc-button {
        padding: 5px 8px !important;
        font-size: 11px !important;
    }
    .fc-view-harness {
        min-height: 300px;
    }
    .fc-daygrid-day-number {
        font-size: 11px !important;
        padding: 3px !important;
    }
    .fc-event {
        font-size: 9px !important;
        padding: 1px 3px !important;
    }

    /* ── MODALS: Bottom Sheet ── */
    .modal-backdrop {
        align-items: flex-end !important;
    }
    .modal.panel {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 20px !important;
        border-radius: 18px 18px 0 0 !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
        animation: slideUp 0.25s ease forwards;
    }
    .modal.modal-lg {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        border-radius: 18px 18px 0 0 !important;
    }
    .modal-header {
        position: sticky;
        top: 0;
        background: #fff;
        z-index: 10;
        padding: 14px 18px;
        margin-bottom: 0 !important;
        border-bottom: 1px solid var(--border-light);
        border-radius: 18px 18px 0 0;
    }
    .modal-header h2 {
        font-size: 16px !important;
    }
    .modal-body {
        padding: 14px !important;
    }

    @keyframes slideUp {
        from { transform: translateY(100%); opacity: 0; }
        to { transform: translateY(0); opacity: 1; }
    }

    /* ── FORMS ── */
    .form-row {
        flex-direction: column !important;
        gap: 0 !important;
    }
    .form-group {
        margin-bottom: 12px;
    }
    label {
        font-size: 12px !important;
        margin-bottom: 4px !important;
        letter-spacing: 0.1px;
    }
    input, select, textarea {
        padding: 10px 12px !important;
        font-size: 16px !important; /* Must be 16px+ to prevent iOS auto-zoom */
        border-radius: 8px !important;
    }
    .btn {
        padding: 10px 14px;
        font-size: 13px !important;
        border-radius: 8px !important;
    }
    .w-100, .btn.w-100 {
        width: 100%;
        justify-content: center;
    }

    /* Addon items */
    .addon-item {
        flex-direction: row !important;
        flex-wrap: nowrap;
        gap: 6px !important;
    }
    .addon-item .col { flex: 1 !important; }

    /* ── CALC BOX ── */
    .calc-box {
        padding: 12px !important;
        border-radius: 10px !important;
    }
    .calc-box h4 {
        font-size: 14px !important;
        margin-bottom: 10px !important;
    }
    .calc-row {
        font-size: 12px !important;
        margin-bottom: 6px !important;
    }

    /* ── SETTINGS ── */
    .saas-col-left, .saas-col-right {
        flex: 1 1 100% !important;
    }
    .saas-card {
        padding: 16px !important;
        border-radius: 14px !important;
        margin-bottom: 12px !important;
    }
    .saas-card h3 {
        font-size: 15px !important;
        margin-bottom: 14px !important;
        gap: 8px !important;
    }
    .saas-icon-wrapper {
        padding: 8px !important;
        border-radius: 8px !important;
    }
    .saas-icon-wrapper i {
        font-size: 16px !important;
    }
    .saas-input {
        padding: 10px 12px !important;
        font-size: 14px !important;
        border-radius: 8px !important;
    }
    .route-item {
        grid-template-columns: 1fr 1fr auto !important;
        gap: 6px !important;
        padding-bottom: 12px !important;
        margin-bottom: 12px !important;
    }
    .route-item label {
        font-size: 11px !important;
    }

    .sticky-footer {
        width: 100% !important;
        left: 0 !important;
        bottom: 56px !important; /* above tab bar */
        padding: 10px 16px !important;
        justify-content: center !important;
        border-radius: 0;
    }
    .sticky-footer .btn {
        width: 100%;
        justify-content: center;
    }

    /* ── Settings section padding adjustment ── */
    #settings-section {
        padding: 16px !important;
        padding-bottom: 140px !important; /* extra room for sticky + tab */
    }

    /* ── PIN GATE ── */
    #pin-gate .panel {
        width: 90% !important;
        padding: 28px 20px !important;
        border-radius: 16px !important;
    }
    #pin-gate h1 {
        font-size: 20px !important;
    }
    #pin-gate input {
        font-size: 20px !important;
        padding: 12px !important;
        letter-spacing: 6px !important;
    }

    /* ── INVOICE PREVIEW MODAL ── */
    #invoiceModal .modal.modal-lg {
        max-height: 92vh !important;
        display: flex !important;
        flex-direction: column !important;
    }
    #invoiceModal .modal-header {
        flex-shrink: 0;
    }
    .invoice-scroll-body {
        flex: 1 !important;
        overflow-y: auto !important;
        max-height: none !important;
        -webkit-overflow-scrolling: touch;
    }
    .invoice-footer-btn {
        position: sticky;
        bottom: 0;
        flex-shrink: 0;
    }
    .preview-wrapper {
        justify-content: flex-start !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 8px 12px !important;
    }
    .invoice-print {
        transform: scale(0.48) !important;
        transform-origin: top left !important;
        margin-bottom: -400px !important;
    }

    /* ── BREAKDOWN MODAL ── */
    #breakdownModal .modal.panel {
        max-width: 100% !important;
    }

    /* ── UNIT DETAIL MODAL ── */
    #unitDetailModal .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 6px !important;
    }
    #unitDetailModal .stat-card {
        gap: 8px !important;
    }

    /* ── BADGE ── */
    .badge {
        padding: 4px 8px !important;
        font-size: 11px !important;
    }

    /* ── Revenue stat cards text fix ── */
    #revenue-section .stat-card h3 {
        font-size: 10px !important;
        line-height: 1.2 !important;
    }
    #revenue-section .stat-card p {
        font-size: 15px !important;
    }
}

/* === SMALL PHONES (max-width: 380px) === */
@media (max-width: 380px) {
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 6px !important;
    }
    .stat-card p {
        font-size: 15px !important;
    }
    .sections-wrapper {
        padding: 12px !important;
        padding-bottom: 70px !important;
    }
    .section-title {
        font-size: 16px !important;
    }
}
