/**
 * mapcad.css
 * Styles for MAP&CAD module
 */

/* =============== MAPCAD PAGE LAYOUT =============== */
#pageMapcad {
    display: flex;
    flex-direction: row;
    height: calc(100vh - 120px);
    background: #f8fafc;
    position: relative;
}

/* =============== SIDEBAR LEFT =============== */
.mapcad-sidebar {
    width: 300px;
    min-width: 280px;
    max-width: 320px;
    background: white;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.05);
}

.mapcad-sidebar-header {
    padding: 16px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    display: flex;
    align-items: center;
    gap: 10px;
}

.mapcad-sidebar-header h2 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.mapcad-sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

/* =============== SIDEBAR SECTIONS =============== */
.mapcad-section {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    margin-bottom: 12px;
    overflow: hidden;
}

.mapcad-section-header {
    padding: 10px 12px;
    background: #f3f4f6;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
}

.mapcad-section-header:hover {
    background: #e5e7eb;
}

.mapcad-section-header h3 {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: #374151;
    display: flex;
    align-items: center;
    gap: 6px;
}

.mapcad-section-toggle {
    font-size: 14px;
    color: #6b7280;
    transition: transform 0.2s;
}

.mapcad-section.collapsed .mapcad-section-toggle {
    transform: rotate(-90deg);
}

.mapcad-section.collapsed .mapcad-section-content {
    display: none;
}

.mapcad-section-content {
    padding: 12px;
}

/* =============== FILE UPLOAD =============== */
.mapcad-upload-area {
    border: 2px dashed #d1d5db;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    background: #fefce8;
    cursor: pointer;
    transition: all 0.2s;
}

.mapcad-upload-area:hover {
    border-color: #f59e0b;
    background: #fef3c7;
}

.mapcad-upload-area.dragover {
    border-color: #f59e0b;
    background: #fef3c7;
}

.mapcad-upload-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.mapcad-upload-text {
    font-size: 13px;
    color: #6b7280;
    margin: 0;
}

.mapcad-upload-hint {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 6px;
}

/* =============== FORM CONTROLS =============== */
.mapcad-form-group {
    margin-bottom: 12px;
}

.mapcad-form-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: #374151;
    margin-bottom: 4px;
}

.mapcad-form-group select,
.mapcad-form-group input[type="text"],
.mapcad-form-group input[type="number"] {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
    background: white;
}

.mapcad-form-group select:focus,
.mapcad-form-group input:focus {
    outline: none;
    border-color: #f59e0b;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
}

/* =============== LAYER LIST =============== */
.mapcad-layer-list {
    max-height: 200px;
    overflow-y: auto;
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: white;
    border-radius: 4px;
    margin-bottom: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.15s;
}

.layer-item:hover {
    background: #fef3c7;
}

.layer-item input[type="checkbox"] {
    margin: 0;
}

/* =============== MAP CONTAINER =============== */
.mapcad-map-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: 0;
}

#mapcadMap {
    flex: 1;
    min-height: 400px;
    z-index: 1;
}

/* =============== COORDS DISPLAY =============== */
.mapcad-coords-bar {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: rgba(255, 255, 255, 0.95);
    padding: 6px 12px;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    font-size: 11px;
    display: flex;
    gap: 12px;
    font-family: monospace;
}

.mapcad-coords-bar span {
    color: #374151;
}

/* =============== RIGHT PANEL =============== */
.mapcad-panel-right {
    width: 280px;
    min-width: 250px;
    max-width: 300px;
    background: white;
    border-left: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.05);
}

.mapcad-panel-header {
    padding: 14px 16px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: white;
}

.mapcad-panel-header h3 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
}

.mapcad-panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

/* =============== BUTTONS =============== */
.mapcad-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.mapcad-btn-primary {
    background: #f59e0b;
    color: white;
}

.mapcad-btn-primary:hover {
    background: #d97706;
}

.mapcad-btn-secondary {
    background: #e5e7eb;
    color: #374151;
}

.mapcad-btn-secondary:hover {
    background: #d1d5db;
}

.mapcad-btn-success {
    background: #10b981;
    color: white;
}

.mapcad-btn-success:hover {
    background: #059669;
}

.mapcad-btn-danger {
    background: #ef4444;
    color: white;
}

.mapcad-btn-danger:hover {
    background: #dc2626;
}

.mapcad-btn-block {
    width: 100%;
}

.mapcad-btn-sm {
    padding: 5px 10px;
    font-size: 11px;
}

.mapcad-btn-group {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

/* =============== INFO BOXES =============== */
.mapcad-info-box {
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 12px;
}

.mapcad-info-box.success {
    background: #ecfdf5;
    border-color: #10b981;
}

.mapcad-info-box.warning {
    background: #fefce8;
    border-color: #f59e0b;
}

.mapcad-info-box p {
    margin: 0;
    font-size: 12px;
    color: #374151;
}

/* =============== LOADING OVERLAY =============== */
.mapcad-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.mapcad-loading-content {
    text-align: center;
}

.mapcad-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e5e7eb;
    border-top-color: #f59e0b;
    border-radius: 50%;
    animation: mapcad-spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

@keyframes mapcad-spin {
    to {
        transform: rotate(360deg);
    }
}

/* =============== EXPORT DIALOG =============== */
.mapcad-export-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.mapcad-export-content {
    background: white;
    border-radius: 12px;
    width: 400px;
    max-width: 90vw;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.mapcad-export-header {
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.mapcad-export-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.mapcad-export-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #6b7280;
}

.mapcad-export-body {
    padding: 20px;
}

.mapcad-export-footer {
    padding: 16px 20px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* =============== MARKER STYLES =============== */
.mapcad-marker-icon {
    background: transparent;
}

.cad-text-marker {
    white-space: nowrap;
}

/* =============== RESPONSIVE =============== */
@media (max-width: 1024px) {
    #pageMapcad {
        flex-direction: column;
        height: auto;
    }

    .mapcad-sidebar {
        width: 100%;
        max-width: none;
        border-right: none;
        border-bottom: 1px solid #e2e8f0;
    }

    .mapcad-sidebar-content {
        max-height: 300px;
    }

    .mapcad-map-container {
        min-height: 50vh;
    }

    .mapcad-panel-right {
        width: 100%;
        max-width: none;
        border-left: none;
        border-top: 1px solid #e2e8f0;
    }
}

/* =============== MOBILE - iPhone 6 (375x667) =============== */
@media (max-width: 480px) {
    #pageMapcad {
        flex-direction: column;
        height: calc(100vh - 60px);
        position: relative;
    }

    /* Map takes full screen underneath */
    .mapcad-map-container {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        min-height: 100%;
        z-index: 1;
    }

    /* Sidebar - Floating bottom sheet */
    .mapcad-sidebar {
        position: fixed;
        bottom: 50px;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        max-height: 50vh;
        background: white;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        z-index: 1000;
        transform: translateY(calc(100% - 48px));
        transition: transform 0.3s ease;
        display: flex;
        flex-direction: column;
    }

    /* When expanded */
    .mapcad-sidebar.expanded {
        transform: translateY(0);
    }

    /* Handle bar for dragging */
    .mapcad-sidebar::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: #d1d5db;
        border-radius: 2px;
        z-index: 10;
    }

    /* Sidebar tabs on mobile - always visible at bottom */
    .mapcad-sidebar .sidebar-tabs {
        order: -1;
        flex-shrink: 0;
        padding: 20px 8px 8px;
        background: #f9fafb;
        border-radius: 16px 16px 0 0;
        display: flex;
        gap: 4px;
    }

    .mapcad-sidebar .sidebar-tab {
        flex: 1;
        padding: 10px 6px;
        font-size: 10px;
        text-align: center;
        background: white;
        border-radius: 8px;
        border: 1px solid #e5e7eb;
    }

    .mapcad-sidebar .sidebar-tab.active {
        background: #fef3c7;
        border-color: #f59e0b;
        color: #92400e;
    }

    /* Sidebar content scrollable */
    .mapcad-sidebar-content {
        flex: 1;
        overflow-y: auto;
        padding: 8px;
        max-height: calc(50vh - 60px);
        -webkit-overflow-scrolling: touch;
    }

    /* Sections more compact */
    .mapcad-section {
        margin-bottom: 8px;
    }

    .mapcad-section-header {
        padding: 8px 10px;
    }

    .mapcad-section-header h3 {
        font-size: 11px;
    }

    .mapcad-section-content {
        padding: 8px;
    }

    /* Buttons larger for touch */
    .mapcad-btn {
        min-height: 40px;
        font-size: 12px;
    }

    /* Forms larger for touch */
    .mapcad-form-group select,
    .mapcad-form-group input {
        font-size: 16px !important;
        /* Prevent iOS zoom */
        min-height: 44px;
        padding: 10px;
    }

    /* Coordinates bar repositioned */
    .mapcad-coords-bar {
        bottom: auto;
        top: 10px;
        left: 10px;
        font-size: 10px;
        padding: 4px 8px;
    }

    /* Hide right panel on mobile */
    .mapcad-panel-right {
        display: none;
    }

    /* Export dialog mobile */
    .mapcad-export-content,
    .mapcad-dialog-content {
        width: 95vw;
        max-height: 80vh;
        margin: 10px;
    }
}

/* =============== MOBILE TOGGLE BUTTON =============== */
.mapcad-mobile-toggle {
    display: none;
    position: fixed;
    bottom: 60px;
    right: 10px;
    width: 48px;
    height: 48px;
    background: #f59e0b;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 20px;
    box-shadow: 0 2px 10px rgba(245, 158, 11, 0.4);
    z-index: 1001;
    cursor: pointer;
}

@media (max-width: 480px) {
    .mapcad-mobile-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* =============== SIDEBAR TABS =============== */
.mapcad-tabs {
    display: flex;
    border-bottom: 1px solid #e5e7eb;
}

.mapcad-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    font-size: 12px;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
}

.mapcad-tab:hover {
    color: #374151;
    background: #f9fafb;
}

.mapcad-tab.active {
    color: #f59e0b;
    border-bottom-color: #f59e0b;
}

.mapcad-tab-content {
    display: none;
}

.mapcad-tab-content.active {
    display: block;
}

/* =============== CALIBRATION UI =============== */
.mapcad-calibrate-point {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: #fef3c7;
    border-radius: 6px;
    margin-bottom: 8px;
}

.mapcad-calibrate-point .point-num {
    width: 24px;
    height: 24px;
    background: #f59e0b;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 12px;
}

.mapcad-calibrate-point .point-coords {
    flex: 1;
    font-size: 11px;
    font-family: monospace;
}

/* =============== LEGEND =============== */
.mapcad-legend {
    position: absolute;
    bottom: 50px;
    right: 10px;
    background: white;
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    font-size: 11px;
}

.mapcad-legend h4 {
    margin: 0 0 8px 0;
    font-size: 12px;
    color: #374151;
}

.mapcad-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.mapcad-legend-color {
    width: 14px;
    height: 14px;
    border-radius: 3px;
}

/* =============== CALIBRATION DIALOG STYLES =============== */
.mapcad-dialog-content {
    background: white;
    border-radius: 12px;
    width: 500px;
    max-width: 95vw;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    max-height: 90vh;
    overflow-y: auto;
}

.mapcad-dialog-header {
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.mapcad-dialog-header h3 {
    margin: 0;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.mapcad-dialog-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #6b7280;
    transition: color 0.15s;
}

.mapcad-dialog-close:hover {
    color: #374151;
}

.mapcad-dialog-body {
    padding: 20px;
}

.mapcad-dialog-footer {
    padding: 16px 20px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* Calibration Tabs */
.mapcad-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
}

.mapcad-tab {
    flex: 1;
    padding: 10px 12px;
    text-align: center;
    font-size: 12px;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    transition: all 0.15s;
}

.mapcad-tab:hover {
    background: #e5e7eb;
    color: #374151;
}

.mapcad-tab.active {
    background: #fef3c7;
    border-color: #f59e0b;
    color: #92400e;
}

/* Crosshair cursor for map point picking */
#mapcadMap.mapcad-crosshair {
    cursor: crosshair !important;
}

#mapcadMap.mapcad-crosshair .leaflet-container {
    cursor: crosshair !important;
}

#mapcadMap.mapcad-crosshair .leaflet-interactive {
    cursor: crosshair !important;
}

/* Calibration preview map */
#calibCadPreview {
    cursor: crosshair;
}

#calibCadPreview .leaflet-container {
    background: #f5f5f5;
}

/* Calib marker styles */
.calib-marker {
    background: transparent;
}