/* ========================================
   Mobile Styles — < 768px
   Compact, condensed, responsive layout
   ======================================== */

@media (max-width: 767px) {
    :root {
        --header-h: 46px;
        --bottom-nav-h: 54px;
        --mobile-pad: 8px;
    }

    /* ————— Global mobile resets ————— */
    html, body {
        font-size: 13px;
        overflow: hidden;
        -webkit-text-size-adjust: 100%;
    }

    /* ————— HEADER: single compact row ————— */
    .header {
        height: var(--header-h);
        padding: 0 8px;
        gap: 6px;
    }
    .header-left {
        gap: 4px;
        flex-shrink: 0;
        min-width: 0;
    }
    .header-logo svg { width: 20px; height: 20px; }
    .header-title {
        font-size: 12px;
        font-weight: 600;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: clamp(40px, 15vw, 100px);
    }

    /* Hide header-center items; move to dropdown menu */
    .header-center {
        flex: 1;
        justify-content: flex-end;
        gap: 4px;
        overflow: visible;
        flex-wrap: nowrap;
    }
    /* Hide all buttons except undo/redo */
    .header-center .btn:not(#btn-undo):not(#btn-redo) {
        display: none !important;
    }
    .header-sep { display: none; }

    /* Undo/redo compact */
    #btn-undo, #btn-redo {
        padding: 3px 4px;
        font-size: 12px;
        min-height: 26px;
        min-width: 26px;
    }

    /* Show mobile hamburger menu button */
    .mobile-menu-btn {
        display: inline-flex !important;
        font-size: 22px;
        font-weight: 900;
        padding: 2px 6px;
        min-height: 28px;
        line-height: 1;
        color: var(--gold-light) !important;
    }

    .header-right {
        gap: 3px;
        flex-shrink: 0;
    }
    /* Hide desktop-only header-right items on mobile */
    #basemap-select { display: none; }
    #btn-logs { display: none; }
    #btn-info { display: none; }
    /* Hide merge button on mobile header – it's in tools tab */
    #btn-merge { display: none !important; }

    /* ————— Repurpose desktop layout: map stays visible, panels hidden ————— */
    .app-layout {
        display: flex;
        position: fixed;
        top: var(--header-h);
        left: 0;
        right: 0;
        bottom: var(--bottom-nav-h);
        z-index: 1;
    }
    .panel-left,
    .panel-right,
    .resize-handle {
        display: none !important;
    }
    .panel-center {
        flex: 1;
        width: 100%;
        height: 100%;
    }

    /* ————— BOTTOM NAVIGATION ————— */
    .mobile-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: var(--bottom-nav-h);
        background: var(--bg-panel);
        border-top: 1px solid var(--border);
        z-index: 900;
        padding: 0;
        /* safe area for notched phones */
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    .mobile-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        cursor: pointer;
        color: var(--text-muted);
        font-size: 9px;
        font-weight: 500;
        letter-spacing: 0.3px;
        text-transform: uppercase;
        padding: 4px 2px;
        -webkit-tap-highlight-color: transparent;
        transition: color 0.15s ease;
        border: none;
        background: none;
        user-select: none;
        position: relative;
    }
    .mobile-nav-item:active {
        background: rgba(255,255,255,0.04);
    }
    .mobile-nav-item.active {
        color: var(--primary);
    }
    .mobile-nav-item.active::after {
        content: '';
        position: absolute;
        top: 0;
        left: 25%;
        right: 25%;
        height: 2px;
        background: var(--primary);
        border-radius: 0 0 2px 2px;
    }
    .mobile-nav-item span:first-child {
        font-size: 18px;
        line-height: 1;
    }

    /* ————— MOBILE CONTENT PANELS ————— */
    .mobile-content {
        position: fixed;
        top: var(--header-h);
        left: 0;
        right: 0;
        bottom: var(--bottom-nav-h);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        background: var(--bg);
        z-index: 800;
        padding: var(--mobile-pad);
    }
    .mobile-content.hidden { display: none; }

    /* Section headers inside mobile panels */
    .mobile-content h3 {
        font-size: 12px;
        font-weight: 600;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.5px;
        margin: 0 0 6px 0;
        padding: 4px 0;
    }

    /* ————— LAYER ITEMS (mobile) ————— */
    .mobile-content .layer-item {
        padding: 6px 8px;
        min-height: 40px;
        gap: 4px 6px;
        border-radius: var(--radius-sm);
        margin-bottom: 2px;
        border-bottom: none;
        border: 1px solid var(--border);
    }
    .mobile-content .layer-item.active {
        background: rgba(10,132,255,0.08);
        border-color: var(--primary);
        border-left: 3px solid var(--primary);
    }
    .mobile-content .layer-icon {
        font-size: 14px;
    }
    .mobile-content .layer-name {
        font-size: 12px;
        font-weight: 600;
    }
    .mobile-content .layer-meta {
        font-size: 10px;
    }
    /* Always show actions on mobile (no hover on touch) */
    .mobile-content .layer-actions {
        opacity: 1 !important;
        pointer-events: auto !important;
    }
    .mobile-content .layer-actions .btn-icon {
        font-size: 14px;
        padding: 4px;
        min-width: 28px;
        min-height: 28px;
    }
    .mobile-content .layer-bottom-row {
        padding-left: 20px;
    }
    .mobile-content .layer-order-btns button {
        font-size: 11px;
        padding: 2px 6px;
        min-width: 24px;
        min-height: 24px;
    }

    /* ————— FIELD ITEMS (mobile) ————— */
    .mobile-content .field-item {
        padding: 4px 6px;
        min-height: 34px;
        gap: 4px;
        font-size: 11px;
    }
    .mobile-content .field-item .field-name {
        font-size: 11px;
    }
    .mobile-content .field-item .field-type {
        font-size: 9px;
        padding: 1px 4px;
    }
    .mobile-content .field-item input[type="checkbox"] {
        width: 14px;
        height: 14px;
    }

    /* ————— BUTTONS: compact mobile sizing ————— */
    .btn {
        min-height: 36px;
        padding: 6px 10px;
        font-size: 12px;
        gap: 4px;
        border-radius: var(--radius-sm);
    }
    .btn-sm {
        min-height: 30px;
        padding: 4px 8px;
        font-size: 11px;
    }

    /* Tool button grid in mobile panels */
    .mobile-content .btn-secondary {
        flex: 1 1 calc(50% - 4px);
        min-width: 0;
        justify-content: center;
        font-size: 11px;
        padding: 6px 4px;
        min-height: 34px;
    }

    /* ————— MODALS: full-width bottom sheet style ————— */
    .modal-overlay {
        align-items: flex-end;
    }
    .modal {
        min-width: unset;
        width: 100vw;
        max-width: 100vw;
        max-height: 88vh;
        border-radius: 16px 16px 0 0;
        animation: slideUp 0.2s ease;
    }
    .modal-header {
        padding: 10px 12px;
        font-size: 14px;
        gap: 8px;
    }
    .modal-header .btn-icon {
        min-width: 28px;
        min-height: 28px;
    }
    .modal-body {
        padding: 10px 12px;
        font-size: 13px;
    }
    .modal-footer {
        padding: 8px 12px;
        gap: 6px;
        /* Account for bottom nav / safe area */
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0));
    }
    .modal-footer .btn {
        flex: 1;
        justify-content: center;
    }

    /* Bottom sheet */
    .bottom-sheet {
        max-height: 80vh;
        border-top-left-radius: 14px;
        border-top-right-radius: 14px;
    }
    .bottom-sheet-header {
        padding: 6px 12px 8px;
        font-size: 15px;
    }
    .bottom-sheet-body {
        padding: 0 12px 12px;
    }

    /* ————— FORMS: compact inputs ————— */
    input[type="text"],
    input[type="number"],
    input[type="url"],
    input[type="search"],
    select,
    textarea {
        padding: 6px 8px;
        font-size: 13px;
        min-height: 34px;
        border-radius: var(--radius-sm);
    }
    .form-group {
        margin-bottom: 8px;
    }
    .form-group label {
        font-size: 11px;
        margin-bottom: 2px;
    }
    .input-with-btn {
        gap: 3px;
    }

    /* Checkbox / radio */
    .checkbox-row {
        min-height: 36px;
        padding: 4px 0;
        font-size: 12px;
        gap: 6px;
    }
    .checkbox-row input[type="checkbox"],
    .checkbox-row input[type="radio"] {
        width: 16px;
        height: 16px;
    }

    /* Toggle */
    .toggle {
        font-size: 12px;
        gap: 6px;
    }
    .toggle-track {
        width: 32px;
        height: 18px;
    }
    .toggle-track::after {
        width: 14px;
        height: 14px;
    }
    .toggle input:checked + .toggle-track::after {
        transform: translateX(14px);
    }

    /* ————— DATA TABLE: scrollable compact ————— */
    .data-table-wrap {
        max-height: 200px;
        -webkit-overflow-scrolling: touch;
        border-radius: var(--radius-sm);
    }
    .data-table {
        font-size: 10px;
    }
    .data-table th {
        padding: 4px 6px;
        font-size: 10px;
        white-space: nowrap;
    }
    .data-table td {
        padding: 3px 6px;
        max-width: 120px;
    }

    /* ————— TABS: scrollable, compact ————— */
    .tabs {
        overflow-x: auto;
        scrollbar-width: none;
        flex-wrap: nowrap;
    }
    .tabs::-webkit-scrollbar { display: none; }
    .tab {
        padding: 8px 10px;
        font-size: 11px;
        flex-shrink: 0;
        white-space: nowrap;
    }

    /* ————— PHOTO GRID: compact ————— */
    .photo-grid {
        grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
        gap: 4px;
    }
    .photo-card .photo-info {
        padding: 2px 4px;
        font-size: 9px;
    }

    /* ————— WIZARD STEPS: compact inline ————— */
    .wizard-steps {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
        gap: 2px;
        margin-bottom: 10px;
    }
    .wizard-steps::-webkit-scrollbar { display: none; }
    .wizard-step span.step-text { display: none; }
    .wizard-step-num {
        width: 20px;
        height: 20px;
        font-size: 10px;
    }
    .wizard-step-line {
        width: 12px;
    }

    /* ————— TOAST: full-width on mobile ————— */
    .toast-container {
        top: calc(var(--header-h) + 4px);
        right: 6px;
        left: 6px;
    }
    .toast {
        max-width: unset;
        padding: 8px 10px;
        font-size: 12px;
        gap: 6px;
    }
    .toast-details { font-size: 10px; }
    .toast-details-body { font-size: 9px; padding: 4px; }

    /* ————— LOGS PANEL: compact ————— */
    .logs-panel {
        height: 180px;
        bottom: var(--bottom-nav-h);
        font-size: 10px;
    }
    .logs-header {
        padding: 3px 6px;
        flex-wrap: wrap;
    }
    .logs-header h3 { font-size: 11px; }
    .logs-toolbar {
        gap: 4px;
        padding: 2px 6px;
        flex-wrap: wrap;
    }
    .logs-toolbar input {
        width: 100px;
        font-size: 10px;
        padding: 2px 6px;
    }
    .logs-toolbar select {
        font-size: 10px;
        padding: 2px 4px;
    }
    .logs-toolbar .btn {
        min-height: 24px;
        padding: 2px 4px;
        font-size: 11px;
    }

    /* ————— EMPTY STATE: compact ————— */
    .empty-state {
        padding: 24px 16px;
        gap: 8px;
    }
    .empty-state svg {
        width: 36px;
        height: 36px;
    }
    .empty-state p {
        font-size: 12px;
        max-width: 200px;
    }

    /* ————— BADGES: smaller ————— */
    .badge {
        padding: 1px 6px;
        font-size: 10px;
    }

    /* ————— PANEL SECTIONS (used in mobile panels) ————— */
    .panel-section {
        margin-bottom: 8px;
        border-radius: var(--radius-sm);
    }
    .panel-section-header {
        padding: 6px 8px;
        font-size: 11px;
    }
    .panel-section-body {
        padding: 6px;
    }

    /* ————— DROP ZONE (import) ————— */
    .drop-zone {
        padding: 20px 12px;
        font-size: 12px;
    }

    /* ————— ERROR / INFO / WARNING / SUCCESS BOXES ————— */
    .error-box,
    .success-box,
    .info-box,
    .warning-box {
        padding: 8px 10px;
        font-size: 12px;
        border-radius: var(--radius-sm);
    }

    /* ————— PROGRESS BAR ————— */
    .progress-bar-container {
        height: 16px;
        margin: 6px 0;
    }
    .progress-bar-text {
        font-size: 10px;
    }

    /* ————— MAP CONTAINER: fills the center panel ————— */
    #map-container {
        width: 100%;
        height: 100%;
    }
    /* Leaflet popup compact */
    #map-container .leaflet-popup-content {
        max-width: 250px;
        font-size: 11px;
        margin: 8px 10px;
    }
    #map-container .leaflet-popup-content td,
    #map-container .leaflet-popup-content th {
        padding: 1px 4px;
        font-size: 10px;
    }

    /* Map overlay */
    .map-overlay,
    .map-overlay-msg {
        padding: 14px 20px;
        font-size: 13px;
    }
    .map-overlay svg {
        width: 36px;
        height: 36px;
    }

    /* ————— SCROLLBAR: thinner on mobile ————— */
    ::-webkit-scrollbar { width: 3px; height: 3px; }

    /* ————— UTILITY: extra compact padding helpers ————— */
    .p-8 { padding: 6px; }
    .p-12 { padding: 8px; }
    .gap-8 { gap: 4px; }
    .gap-12 { gap: 6px; }
    .mb-8 { margin-bottom: 6px; }
    .mt-8 { margin-top: 6px; }

    /* ————— MAP CONTROLS: smaller on mobile ————— */
    .leaflet-control-zoom a {
        width: 28px !important;
        height: 28px !important;
        line-height: 28px !important;
        font-size: 14px !important;
    }
    .leaflet-control-attribution {
        font-size: 8px !important;
        padding: 1px 4px !important;
    }
}

/* ————— Extra-small screens (< 380px) ————— */
@media (max-width: 379px) {
    :root {
        --header-h: 38px;
        --bottom-nav-h: 48px;
    }
    .header-title { display: none; }
    .header-logo svg { width: 18px; height: 18px; }
    .mobile-nav-item {
        font-size: 7px;
    }
    .mobile-nav-item span:first-child {
        font-size: 15px;
    }
    .mobile-content .btn-secondary {
        flex: 1 1 100%;
        font-size: 11px;
    }
    .modal {
        max-height: 92vh;
    }
}

/* ————— Tablet tweaks (768–1024) ————— */
@media (min-width: 768px) and (max-width: 1024px) {
    .panel-left { width: 260px; min-width: 200px; }
    .panel-right { width: 240px; min-width: 180px; }
    .header-center .btn span.btn-icon-text + span { display: none; }
    .btn { font-size: 12px; padding: 5px 10px; }
    .btn-sm { font-size: 11px; padding: 3px 8px; }
}

/* ————— Draw toolbar mobile ————— */
@media (max-width: 767px) {
    .draw-toolbar {
        top: auto;
        bottom: 56px;
        left: 8px;
        right: 8px;
        transform: none;
        min-width: 0;
    }
    .draw-tool-btn {
        padding: 8px 6px;
        font-size: 11px;
    }
}

/* ————— Desktop: hide mobile elements ————— */
@media (min-width: 768px) {
    .mobile-nav { display: none !important; }
    .mobile-content { display: none !important; }
}
