/* ===== Base Reset ===== */
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    background-color: #121212;
    color: #e0e0e0;
}

/* ===== Layout ===== */
.page-wrapper {
    display: flex;
    flex-direction: column;
    height: 100dvh;
}

header {
    flex-shrink: 0;
}

#main-content-wrapper {
    display: flex;
    flex-direction: row;
    flex-grow: 1;
    overflow: hidden;
    height: 100%;
}

#map {
    position: relative;
    width: 100%;
    height: 100%;
    z-index: 0;
    flex-grow: 1;
}

/* ===== Text Readability ===== */
.text-white, .text-white-50, .spinner-text, .form-check-label, .navbar-brand, .nav-link {
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
}

#statsTimeLabel, .card-title, .badge {
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
}

/* ===== Spinner / Loading Overlay ===== */
#spinner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.spinner-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.loader {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

.spinner-text {
    margin-top: 10px;
    font-weight: bold;
    color: white;
    font-size: 16px;
    text-align: center;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
}

.progress {
    width: 200px;
    height: 14px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 7px;
    margin-top: 15px;
    overflow: hidden;
    display: none;
}

.progress-bar {
    height: 100%;
    background-color: #40E0D0;
    width: 0%;
    transition: width 0.3s ease;
    background-image: linear-gradient(45deg, rgba(255,255,255,.15) 25%, transparent 25%, transparent 50%, rgba(255,255,255,.15) 50%, rgba(255,255,255,.15) 75%, transparent 75%, transparent);
    background-size: 1rem 1rem;
    animation: progress-bar-stripes 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes progress-bar-stripes {
    from { background-position: 1rem 0; }
    to { background-position: 0 0; }
}

/* ===== Generate Button ===== */
.tp-generate-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 36px;
    border: 1px solid rgba(74, 222, 128, 0.4);
    border-radius: 12px;
    background: rgba(22, 163, 74, 0.55);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow:
        0 4px 20px rgba(22, 163, 74, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.tp-generate-btn:hover {
    background: rgba(22, 163, 74, 0.7);
    border-color: rgba(74, 222, 128, 0.55);
    box-shadow:
        0 6px 28px rgba(22, 163, 74, 0.45),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.tp-generate-btn:active {
    background: rgba(22, 163, 74, 0.6);
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

/* ===== Desktop Sidebar (Override Bootstrap Offcanvas) ===== */
@media (min-width: 992px) {
    #settingsButton {
        display: none !important;
    }

    #settingsPanel {
        position: relative !important;
        visibility: visible !important;
        transform: none !important;
        width: 25% !important;
        min-width: 300px !important;
        max-width: none !important;
        border-left: 1px solid rgba(255, 255, 255, 0.1) !important;
        height: 100% !important;
        flex-shrink: 0;
        z-index: 1 !important;
        display: flex !important;
        flex-direction: column;
        margin-top: 0 !important;
    }

    #settingsPanel .btn-close {
        display: none;
    }

    #settingsPanel .offcanvas-header {
        display: flex;
        padding: 1rem;
    }

    #settingsPanel .offcanvas-body {
        padding: 1rem;
        overflow-y: auto;
    }
}

/* Glass sidebar background */
#settingsPanel {
    background: rgba(15, 15, 20, 0.75) !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

#settingsPanel .offcanvas-header {
    border-bottom-color: rgba(255, 255, 255, 0.08) !important;
}

/* ===== Leaflet Overrides ===== */
path.leaflet-interactive:focus {
    outline: none;
}

.leaflet-control-credits.leaflet-bar a {
    background-color: rgba(0, 0, 0, 0.5) !important;
    color: #fff !important;
    border-bottom: none !important;
    width: 23px !important;
    height: 23px !important;
    line-height: 23px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: background-color 0.2s;
    backdrop-filter: blur(4px);
    flex-shrink: 0 !important;
}

.leaflet-control-credits.leaflet-bar a:hover {
    background-color: rgba(0, 0, 0, 0.7) !important;
    color: #fff !important;
}

.leaflet-control-credits.leaflet-bar a i {
    font-size: 0.9rem !important;
}

.leaflet-control-credits {
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    border-radius: 0 8px 8px 0 !important;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3) !important;
}

.leaflet-bar {
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    border-radius: 8px !important;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3) !important;
    background-color: transparent !important;
}

.leaflet-bar a {
    background-color: rgba(0, 0, 0, 0.5) !important;
    color: #fff !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
    width: 34px !important;
    height: 34px !important;
    line-height: 34px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    backdrop-filter: blur(4px);
}

.leaflet-bar a:last-child {
    border-bottom: none !important;
}

.leaflet-bar a:hover {
    background-color: rgba(0, 0, 0, 0.7) !important;
    color: #fff !important;
}

.leaflet-touch .leaflet-bar a {
    width: 34px !important;
    height: 34px !important;
    line-height: 34px !important;
}

.leaflet-touch .leaflet-control-credits.leaflet-bar a {
    width: 23px !important;
    height: 23px !important;
    line-height: 23px !important;
}

/* ===== Google Search ===== */
#googleSearchContainer {
    z-index: 2000;
}

.pac-container {
    z-index: 99999 !important;
}

/* ===== Map Overlay Controls ===== */
#includeBuildingsContainer {
    position: absolute;
    top: 60px;
    left: 60px;
    z-index: 1500;
    display: inline-block;
    background: rgba(33, 33, 33, 0.8);
    padding: 4px 6px;
    border: 1px solid #333;
    border-radius: 4px;
    font-family: sans-serif;
    font-size: 14px;
    color: #e0e0e0;
}

#includeRoadsContainer {
    position: absolute;
    top: 90px;
    left: 60px;
    z-index: 1500;
    display: inline-block;
    background: rgba(33, 33, 33, 0.8);
    padding: 4px 6px;
    border: 1px solid #333;
    border-radius: 4px;
    font-family: sans-serif;
    font-size: 14px;
    color: #e0e0e0;
}

/* ===== Info Box ===== */
#infoBox {
    position: relative;
    display: inline-block;
    width: 100%;
    padding: 10px 14px;
    border-radius: 6px;
    font-family: system-ui, sans-serif;
    font-size: 14px;
    z-index: 1500;
    backdrop-filter: blur(6px);
    border: 1px solid rgba(120, 120, 120, 0.3);
    background-color: rgba(255, 255, 255, 0.85);
    color: #212529;
}

[data-bs-theme="dark"] #infoBox {
    background-color: rgba(30, 32, 36, 0.85);
    color: #dee2e6;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ===== Vertical Exaggeration Control ===== */
#verticalControl {
    position: absolute;
    bottom: 25px;
    right: 10px;
    background: rgba(33, 33, 33, 0.8);
    padding: 8px 12px;
    border: 0 solid #333;
    border-radius: 10px;
    font-family: sans-serif;
    font-size: 14px;
    z-index: 1500;
    max-width: 350px;
    color: #e0e0e0;
}

/* ===== Button Container (Single Tile Center) ===== */
#buttonContainer {
    text-align: center;
    width: auto;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    display: none;
}

#buttonContainer button {
    margin: 2px;
}

/* ===== STL Viewer ===== */
#closeStl {
    position: fixed;
    top: 10%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    display: block;
}

#stl_cont {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    border: 2px solid #333;
    z-index: 2000;
    display: none;
    overflow: hidden;
}

#stl_controls {
    position: absolute;
    top: 5px;
    right: 5px;
    z-index: 2100;
}

#stl_controls button {
    margin: 0.2em;
}

/* ===== Credits ===== */
#creditBox {
    position: absolute;
    bottom: 8px;
    right: 36px;
    padding: 0 8px;
    font-family: system-ui, sans-serif;
    font-size: 11px;
    height: 23px;
    line-height: 23px;
    border-radius: 8px 0 0 8px;
    z-index: 1500;
    white-space: nowrap;
    background-color: rgba(0, 0, 0, 0.5);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-right: none;
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

#creditBox a {
    color: #dee2e6;
    text-decoration: none;
}

#creditBox a:hover {
    color: #fff;
    text-decoration: underline;
}

/* ===== Drag Handle (Multi-Tile) ===== */
.drag-handle-icon {
    display: inline-block;
    background: #0B0F19;
    border: 2px dashed #333;
    color: white;
    padding: 3px 8px;
    font-family: sans-serif;
    font-size: 12px;
    cursor: move;
}

/* ===== Basemap Options ===== */
#basemapOptions {
    display: none;
    margin-top: 4px;
    background: rgba(33, 33, 33, 0.95);
    border: 1px solid #555;
    border-radius: 4px;
    padding: 4px;
    color: #e0e0e0;
}

#basemapOptions div {
    padding: 2px 4px;
    cursor: pointer;
}

#basemapOptions div:hover {
    background: #444;
}

/* ===== Settings Button ===== */
#settingsButton {
    background-color: #0B0F19;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    padding: 0;
    color: #FFFFFF;
}

/* ===== Stats Map ===== */
.map-tile-dark {
    filter: brightness(0.7) contrast(1.1) grayscale(0.5);
}

#statsMap {
    background-color: #212529 !important;
}

#statsMapContainer:-webkit-full-screen { width: 100%; height: 100%; }
#statsMapContainer:fullscreen { width: 100%; height: 100%; }

#statsMapContainer:fullscreen #statsMap {
    height: 100% !important;
}

/* ===== Tile View Tooltip ===== */
.tile-view-tooltip {
    background-color: #0d6efd !important;
    border: 1px solid #0d6efd !important;
    color: white !important;
    font-weight: bold;
    border-radius: 4px;
    padding: 2px 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    white-space: nowrap;
}

/* ===== Geoman (Custom Shape Drawing) ===== */
.leaflet-pm-toolbar, .leaflet-pm-toolbar * {
    visibility: visible !important;
    opacity: 1 !important;
}

.leaflet-pm-actions-container {
    display: flex !important;
    flex-direction: row !important;
}

.leaflet-pm-actions-container a {
    width: auto !important;
    padding: 0 8px !important;
    margin: 0 2px !important;
}

.leaflet-pm-toolbar {
    z-index: 20000 !important;
    display: flex !important;
    flex-direction: column !important;
}

.leaflet-top.leaflet-left {
    z-index: 20000 !important;
    display: block !important;
    visibility: visible !important;
}

.leaflet-control-container .leaflet-top.leaflet-left {
    pointer-events: auto !important;
}

/* ===== Button Overrides (White on Dark Map) ===== */
.btn-outline-primary, .btn-primary, [aria-label="Mode selection"] .btn, [aria-label="Shape selection"] .btn {
    --si-btn-color: #FFFFFF !important;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8) !important;
    color: rgba(255, 255, 255, 0.7) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    background-color: transparent !important;
}

.btn-outline-primary:hover, .btn-primary:hover, .btn-outline-primary.active, .btn-primary.active,
[aria-label="Mode selection"] .btn:hover, [aria-label="Shape selection"] .btn:hover,
[aria-label="Mode selection"] .btn.active, [aria-label="Shape selection"] .btn.active {
    background-color: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(255, 255, 255, 0.4) !important;
    color: #fff !important;
}

[aria-label="Mode selection"] .btn i, [aria-label="Shape selection"] .btn i,
[aria-label="Mode selection"] .btn svg, [aria-label="Shape selection"] .btn svg,
[aria-label="Mode selection"] .btn, [aria-label="Shape selection"] .btn {
    color: inherit !important;
    fill: currentColor !important;
}

/* ===== Sidebar ===== */
.tp-sidebar {
    padding: 1rem !important;
}

.tp-sidebar .form-label {
    text-shadow: none;
}

.tp-num-input {
    width: 72px;
    min-width: 72px;
    text-align: center;
}

/* Accordion styling */
.tp-accordion .accordion-item {
    background: rgba(255, 255, 255, 0.04) !important;
    border: 1px solid rgba(255, 255, 255, 0.06) !important;
}

.tp-accordion .accordion-button {
    background: transparent !important;
    color: #dee2e6 !important;
    font-size: 0.875rem;
    font-weight: 500;
    text-shadow: none;
}

.tp-accordion .accordion-button:not(.collapsed) {
    background: rgba(255, 255, 255, 0.04) !important;
    color: #fff !important;
    box-shadow: none !important;
}

.tp-accordion .accordion-button::after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='rgba(255,255,255,0.5)'%3E%3Cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E") !important;
}

.tp-accordion .accordion-button:not(.collapsed)::after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='rgba(255,255,255,0.7)'%3E%3Cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E") !important;
}

.tp-accordion .accordion-button:focus {
    box-shadow: none !important;
}

.tp-accordion .accordion-body {
    background: transparent !important;
}

/* Form controls in sidebar - match glass theme */
#settingsPanel .form-select,
#settingsPanel .form-control {
    background-color: rgba(255, 255, 255, 0.06) !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
    color: #dee2e6 !important;
}

#settingsPanel .form-select:focus,
#settingsPanel .form-control:focus {
    background-color: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    box-shadow: none !important;
}

#settingsPanel .form-control-color {
    padding: 2px !important;
}

/* ===== Export Modal ===== */
#buttonModal .btn-outline-light:hover {
    background-color: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.25);
    transform: translateX(2px);
    transition: all 0.15s ease;
}

#buttonModal .btn-outline-light {
    transition: all 0.15s ease;
    text-shadow: none !important;
}

#buttonModal .btn-primary {
    background-color: #0d6efd !important;
    border-color: #0d6efd !important;
    color: #fff !important;
    text-shadow: none !important;
}

#buttonModal .btn-primary:hover {
    background-color: #0b5ed7 !important;
    border-color: #0a58ca !important;
}

#buttonModal .btn-link {
    text-shadow: none !important;
}

/* ===== Model Analysis Panel ===== */
.tp-analysis-panel {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    padding: 12px;
}

.tp-stat-card {
    background: rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    padding: 8px 10px;
    text-align: center;
}

.tp-stat-value {
    font-size: 0.82rem;
    font-weight: 600;
    color: #fff;
    line-height: 1.3;
    white-space: nowrap;
}

.tp-stat-label {
    font-size: 0.62rem;
    color: rgba(255, 255, 255, 0.4);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-top: 2px;
}

.tp-layer-bar {
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.06);
    overflow: hidden;
}

.tp-layer-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s ease;
}

.tp-manifold-ok {
    color: #4ade80;
}

.tp-manifold-warn {
    color: #fbbf24;
}

/* Analyze button */
#runAnalysisBtn {
    color: rgba(255, 255, 255, 0.7) !important;
    text-shadow: none !important;
    background: transparent !important;
}

#runAnalysisBtn:hover {
    color: #fff !important;
    background: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
}

/* Analysis spinner */
.tp-analysis-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 20px 0;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.8rem;
}

.tp-analysis-spinner .spinner-border {
    width: 16px;
    height: 16px;
    border-width: 2px;
}

/* ===== Close Viewer Button ===== */
.tp-close-viewer-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 28px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 12px;
    background: rgba(15, 15, 20, 0.5);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.tp-close-viewer-btn:hover {
    background: rgba(15, 15, 20, 0.7);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateX(-50%) translateY(-1px);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

.tp-close-viewer-btn:active {
    transform: translateX(-50%) translateY(0);
    background: rgba(15, 15, 20, 0.6);
}

.tp-close-viewer-btn .bx {
    font-size: 1.2rem;
}

/* ===== Mobile Safe Area ===== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .page-wrapper {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ===== Responsive: Small Phones ===== */
@media (max-width: 576px) {
    #settingsButton {
        width: 40px;
        height: 40px;
    }

    .card-title {
        font-size: 0.95rem;
    }

    .card-text {
        font-size: 0.85rem;
    }
}

/* ===== Responsive: Tablets ===== */
@media (max-width: 768px) {
    #map {
        height: 100%;
    }

    #settingsButton {
        top: 10px;
        right: 10px;
    }

    #creditBox {
        bottom: 85px;
        left: 8px;
        padding: 1px 6px;
        font-size: 10px;
    }

    .modal-dialog {
        margin: 0.5rem;
    }

    .modal-body button {
        padding: 10px;
        margin: 5px;
    }

    #buttonModal .btn-lg {
        width: 100%;
        margin: 0.5rem 0;
    }

    .card-title {
        font-size: 1rem;
        line-height: 1.3;
    }

    .card-text {
        font-size: 0.875rem;
    }

    .card-body {
        padding: 0.75rem;
    }

    .card-text ul {
        padding-left: 1.25rem;
    }

    .card-text li {
        margin-bottom: 0.25rem;
    }

    .navbar-brand {
        font-size: 1.1rem;
    }

    .navbar-brand img {
        width: 80px;
    }

    .input-group-sm {
        width: 100%;
    }

    #advancedModal .form-label {
        font-size: 0.9rem;
        margin-bottom: 0.25rem;
    }

    #advancedModal .mb-4 {
        margin-bottom: 1rem !important;
    }

    #advancedModal .modal-footer {
        padding: 0.5rem;
    }
}
