:root {
    --tv-primary: rgb(2, 132, 199);
    --tv-primary-dark: #0b3a5b;
    --tv-border: rgba(11, 58, 91, 0.26);
    --tv-border-strong: rgba(11, 58, 91, 0.68);
    --tv-radius: 16px;
}

body { font-family: 'Roboto', sans-serif; }

h1, h2, h3, h4, h5, h6, .heading-text {
    font-family: 'Inter', sans-serif;
    font-weight: 700;
}

.subheading-text, .filter-label {
    font-family: 'Inter', sans-serif;
    font-weight: 500;
}

.material-symbols-outlined {
    font-family: 'Material Symbols Outlined';
    font-weight: normal;
    font-style: normal;
    font-size: 24px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    font-feature-settings: 'liga';
    -webkit-font-smoothing: antialiased;
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    vertical-align: middle;
}

.glass-panel {
    background: rgba(244, 250, 255, 0.82);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.floating-panel {
    background: rgba(244, 250, 255, 0.92);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid var(--tv-border);
}

.radius-ui { border-radius: var(--tv-radius); }

.tv-divider {
    height: 1px;
    width: 100%;
    background-color: var(--tv-border-strong);
}

.tv-header { border-color: var(--tv-border); }

.custom-scrollbar::-webkit-scrollbar { width: 4px; }
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
.custom-scrollbar::-webkit-scrollbar-thumb {
    background: #79a9c8;
    border-radius: 10px;
}

.accordion-button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    text-align: left;
}

.accordion-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.32s ease-in-out;
}

.accordion-content.open { max-height: 1000px; }

.accordion-icon { transition: transform 0.3s ease-in-out; }
.accordion-icon.open { transform: rotate(180deg); }

.filter-section {
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.82), rgba(231, 246, 255, 0.72));
    border: 1px solid var(--tv-border);
    border-radius: var(--tv-radius);
    padding: 12px;
    transition: border-color 0.24s ease;
}

.filter-section:hover { border-color: rgba(2, 132, 199, 0.48); }

.floating-calendar {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    right: 0;
    border: 1px solid var(--tv-border);
    border-radius: var(--tv-radius);
    background: rgba(255, 255, 255, 0.98);
    padding: 14px;
    opacity: 0;
    transform: translateY(-8px) scale(0.985);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 45;
}

.floating-calendar.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.preset-chip {
    border: 1px solid rgba(11, 58, 91, 0.28);
    background: rgba(234, 247, 255, 0.86);
    color: #0d3855;
    border-radius: 9999px;
    padding: 8px 12px;
    font-size: 12px;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    transition: all 0.2s ease;
}

.preset-chip:hover {
    border-color: rgba(2, 132, 199, 0.56);
    background: rgba(2, 132, 199, 0.14);
}

.preset-chip.active {
    border-color: var(--tv-primary);
    background: var(--tv-primary);
    color: #ffffff;
}

#custom-start, #custom-end { color: #0d3855; }

#summary-panel-container {
    transform: translate(-50%, -50%);
}

.summary-visible {
    opacity: 1;
    transform: translate(-50%, -50%);
    pointer-events: auto;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.summary-hidden {
    opacity: 0;
    transform: translate(-50%, calc(-50% - 12px));
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.metric-card {
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.15);
}

.page-shell {
    min-height: 100vh;
    padding-top: 64px;
    padding-left: 24px;
    padding-right: 24px;
    padding-bottom: 32px;
}

.tv-card {
    background: rgba(244, 250, 255, 0.92);
    border: 1px solid var(--tv-border);
    border-radius: var(--tv-radius);
    backdrop-filter: blur(12px);
}

.tv-table { width: 100%; border-collapse: collapse; }
.tv-table th, .tv-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--tv-border);
    font-size: 14px;
}
.tv-table th {
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    color: var(--tv-primary-dark);
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.05em;
}
.tv-table tr:hover td { background: rgba(2, 132, 199, 0.06); }
.tv-table tr.selected td { background: rgba(2, 132, 199, 0.12); }

.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 12px;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
}

.status-available { background: rgba(16, 185, 129, 0.15); color: #047857; }
.status-in_progress { background: rgba(242, 203, 41, 0.25); color: #92400e; }
.status-planned, .status-to_capture { background: rgba(255, 77, 214, 0.15); color: #9d174d; }
.status-unavailable { background: rgba(107, 114, 128, 0.2); color: #374151; }
.status-recently_added { background: rgba(2, 132, 199, 0.15); color: #0369a1; }

.breakdown-panel {
    position: absolute;
    top: 12px;
    right: 12px;
    width: min(280px, calc(100% - 24px));
    max-height: min(360px, calc(100% - 24px));
    overflow-y: auto;
    z-index: 25;
    display: none;
}

.breakdown-panel.open { display: flex; }

/* Map overlays — clear Mapbox attribution (bottom-left) and controls (bottom-right) */
.map-legend {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 240px;
    max-width: calc(100% - 80px);
    z-index: 20;
    padding: 0;
    overflow: hidden;
}

.map-legend-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: none;
    cursor: pointer;
    text-align: left;
}

.map-legend-title {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.map-legend-body {
    padding: 0 12px 12px;
    max-height: 220px;
    overflow-y: auto;
}

.map-legend--collapsed .map-legend-body {
    display: none;
}

.map-legend-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.map-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: #051e28;
    line-height: 1.3;
}

.legend-swatch {
    width: 16px;
    height: 4px;
    border-radius: 2px;
    flex-shrink: 0;
}

.legend-swatch-dash {
    background-image: repeating-linear-gradient(90deg, currentColor 0 4px, transparent 4px 7px);
    height: 4px;
}

.legend-swatch-tile {
    background: linear-gradient(135deg, #0284c7 25%, transparent 25%, transparent 50%, #0284c7 50%, #0284c7 75%, transparent 75%);
    background-size: 8px 8px;
    height: 12px;
    width: 12px;
    border: 1px solid var(--tv-border);
}

/* Map control column — draw, zoom, fullscreen stacked bottom-right */
#map .mapboxgl-ctrl-bottom-right.tv-map-controls-column {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-end !important;
    gap: 8px !important;
    bottom: 12px !important;
    right: 4px !important;
}

#map .mapboxgl-ctrl-bottom-right.tv-map-controls-column > * {
    float: none !important;
    clear: none !important;
    margin: 0 !important;
}

#map .mapboxgl-ctrl-bottom-right.tv-map-controls-column > .tv-draw-toolbar {
    order: 0;
    margin-right: 8px !important;
}

#map .mapboxgl-ctrl-bottom-right.tv-map-controls-column > .tv-zoom-toolbar {
    order: 1;
    margin-right: 8px !important;
}

#map .mapboxgl-ctrl-bottom-right.tv-map-controls-column > .tv-fullscreen-toolbar {
    order: 2;
    margin-right: 8px !important;
}

#map .mapboxgl-ctrl-bottom-right.tv-map-controls-column > .mapboxgl-ctrl-scale {
    order: 3;
    margin: 0;
    border: none;
    box-shadow: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.75);
    font-size: 11px;
    line-height: 1.2;
    text-align: right;
}

#map .mapboxgl-ctrl-bottom-right.tv-map-controls-column > .mapboxgl-ctrl-attrib {
    order: 4;
    margin: 0;
    background: transparent;
    box-shadow: none;
    text-align: right;
}

#map .mapboxgl-ctrl-bottom-right .mapboxgl-ctrl-attrib a {
    color: rgba(255, 255, 255, 0.65);
}

#main-content .mapboxgl-ctrl-bottom-left {
    bottom: 12px;
    left: 12px;
}

#main-content .mapboxgl-ctrl-bottom-right .mapboxgl-ctrl-group {
    margin: 0;
}

.tv-ctrl-fullscreen {
    background-image: none !important;
}

.tv-ctrl-fullscreen .material-symbols-outlined {
    font-size: 18px;
    color: #333;
    line-height: 1;
}

.tv-ctrl-fullscreen:hover .material-symbols-outlined {
    color: #000;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    top: 56px;
    background: rgba(5, 30, 40, 0.45);
    z-index: 35;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

@media (min-width: 768px) {
    .sidebar-backdrop { top: 64px; }
}

.sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

.sidebar-backdrop.hidden { display: none; }

/* Browser fullscreen */
#main-content:fullscreen,
#main-content:-webkit-full-screen,
#main-content:-moz-full-screen {
    position: fixed !important;
    inset: 0 !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none;
    z-index: 9999;
    background: #0f172a;
}

#main-content:fullscreen #map,
#main-content:-webkit-full-screen #map,
#main-content:-moz-full-screen #map {
    width: 100%;
    height: 100%;
}

/* Fallback when Fullscreen API is blocked (e.g. some iframes) */
body.map-fullscreen-fallback .tv-header,
body.map-fullscreen-fallback #sidebar,
body.map-fullscreen-fallback #toggle-container {
    display: none !important;
}

body.map-fullscreen-fallback #main-content {
    position: fixed !important;
    inset: 0 !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 9999;
}

.filter-select {
    width: 100%;
    background: var(--tv-surface-container-low, #e7f6ff);
    border: 1px solid var(--tv-border);
    border-radius: var(--tv-radius);
    padding: 10px 12px;
    font-size: 14px;
    color: #051e28;
}

.sidebar-metric {
    background: rgba(244, 250, 255, 0.92);
    border: 1px solid var(--tv-border);
    border-radius: var(--tv-radius);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Tablet & mobile map page */
#sidebar {
    z-index: 40;
}

@media (max-width: 1023px) {
    #sidebar {
        box-shadow: 4px 0 24px rgba(5, 30, 40, 0.18);
    }

    .map-legend {
        width: 200px;
        max-width: calc(100vw - 100px);
    }

    .breakdown-panel {
        top: auto;
        bottom: 12px;
        left: 12px;
        right: 12px;
        width: auto;
        max-height: 40vh;
    }
}

@media (max-width: 767px) {
    .map-legend {
        top: 8px;
        left: 8px;
        width: auto;
        min-width: 160px;
        max-width: calc(100vw - 56px);
    }

    .map-legend-item {
        font-size: 12px;
    }

    .sidebar-metrics {
        gap: 6px;
    }

    .sidebar-metric {
        padding: 8px;
    }

    #main-content .mapboxgl-ctrl-bottom-right {
        bottom: 8px;
        right: 4px;
    }

    #main-content .mapboxgl-ctrl-bottom-left {
        bottom: 8px;
        left: 8px;
    }
}

#main-content:fullscreen .mapboxgl-ctrl-bottom-right,
#main-content:-webkit-full-screen .mapboxgl-ctrl-bottom-right,
body.map-fullscreen-fallback .mapboxgl-ctrl-bottom-right {
    bottom: 12px;
    right: 12px;
}

#main-content .mapboxgl-ctrl-top-right {
    top: 12px;
    right: 12px;
}

.map-draw-toolbar {
    display: flex;
    flex-direction: column;
    width: 36px;
    background: #fff;
    border-radius: var(--tv-radius);
    border: 1px solid var(--tv-border);
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(5, 30, 40, 0.12);
}

.map-draw-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: #fff;
    color: #3f4850;
    cursor: pointer;
    border-bottom: 1px solid var(--tv-border);
    transition: background 0.15s ease, color 0.15s ease;
}

.map-draw-btn:last-child {
    border-bottom: none;
}

.map-draw-btn:hover {
    background: #e7f6ff;
    color: var(--tv-primary);
}

.map-draw-btn.active {
    background: var(--tv-primary);
    color: #fff;
}

.map-draw-btn .material-symbols-outlined,
#map .mapboxgl-ctrl .material-symbols-outlined {
    font-family: 'Material Symbols Outlined';
    font-size: 20px;
    line-height: 1;
}

.aoi-shapes-floating {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 25;
    max-width: min(280px, calc(100vw - 2rem));
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--tv-border);
    border-radius: var(--tv-radius);
    box-shadow: 0 8px 24px rgba(5, 30, 40, 0.12);
}

.aoi-shapes-floating.hidden {
    display: none;
}

.aoi-shapes-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.aoi-shape-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--tv-border);
    background: rgba(231, 246, 255, 0.9);
    color: #051e28;
    font-size: 12px;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.aoi-shape-chip.active {
    border-color: var(--tv-primary, #0284c7);
    background: rgba(2, 132, 199, 0.14);
    color: #0b3a5b;
}

.aoi-shape-chip-delete {
    font-size: 14px !important;
    line-height: 1;
    color: #5f6b73;
    border-radius: 999px;
    padding: 2px;
}

.aoi-shape-chip-delete:hover {
    color: #051e28;
    background: rgba(2, 132, 199, 0.12);
}

.aoi-stats-panel {
    background: linear-gradient(145deg, rgba(2, 132, 199, 0.08), rgba(231, 246, 255, 0.9));
    border: 1px solid rgba(2, 132, 199, 0.35);
    border-radius: var(--tv-radius);
    padding: 12px;
}

.aoi-tag {
    display: inline-block;
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 9999px;
    background: rgba(2, 132, 199, 0.12);
    color: #0b3a5b;
    font-family: 'Inter', sans-serif;
    font-weight: 500;
}

.location-search-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}

.location-search-icon {
    color: var(--tv-primary, #0284c7);
    font-size: 20px;
    line-height: 1;
}

.location-search-input {
    padding: 0;
    margin: 0;
    min-height: 0;
    height: 20px;
    line-height: 20px;
    border: 0;
    box-shadow: none;
    color: #051e28;
}

#location-suggestions.location-suggestions {
    position: fixed;
    z-index: 9999;
    margin: 0;
    padding: 6px 4px 6px 6px;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid var(--tv-border);
    border-radius: var(--tv-radius);
    box-shadow: none;
    min-height: 110px;
    max-height: min(280px, 42vh);
    overflow: hidden;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

#location-suggestions-list.location-suggestions-scroll {
    list-style: none;
    margin: 0;
    padding: 0 2px 0 0;
    flex: 1 1 auto;
    min-height: 0;
    max-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: rgba(2, 132, 199, 0.35) transparent;
}

#location-suggestions-list.location-suggestions-scroll > li {
    margin: 0;
    padding: 0;
}

#location-suggestions.location-suggestions:not(.hidden) {
    animation: location-suggestions-in 0.16s ease-out;
}

#location-suggestions-list.location-suggestions-scroll::-webkit-scrollbar {
    width: 4px;
}

#location-suggestions-list.location-suggestions-scroll::-webkit-scrollbar-thumb {
    background: rgba(2, 132, 199, 0.35);
    border-radius: 999px;
    border: 1px solid transparent;
    background-clip: padding-box;
}

#location-suggestions-list.location-suggestions-scroll::-webkit-scrollbar-track {
    background: transparent;
    margin: 8px 0;
    border-radius: 999px;
}

#location-suggestions-list.location-suggestions-scroll::-webkit-scrollbar-button {
    display: none;
    height: 0;
    width: 0;
}

@keyframes location-suggestions-in {
    from {
        opacity: 0;
        transform: translateY(-3px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#location-suggestions.location-suggestions.hidden {
    display: none !important;
}

#location-suggestions .location-suggestion-item {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-start;
    gap: 8px;
    width: 100%;
    text-align: left;
    padding: 7px 9px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 8px;
    font: inherit;
    color: inherit;
}

#location-suggestions .location-suggestion-item:hover,
#location-suggestions .location-suggestion-item:focus-visible {
    background: #e7f6ff;
    outline: none;
}

#location-suggestions .location-suggestion-icon {
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: rgba(2, 132, 199, 0.1);
    color: var(--tv-primary, #0284c7);
    font-size: 15px;
}

#location-suggestions .location-suggestion-content {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    flex: 1 1 auto;
}

#location-suggestions .location-suggestion-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
}

#location-suggestions .location-suggestion-type {
    flex: 0 0 auto;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--tv-primary, #0284c7);
    background: rgba(2, 132, 199, 0.1);
    border-radius: 999px;
    padding: 1px 6px;
    white-space: nowrap;
}

#location-suggestions .location-suggestion-primary {
    font-size: 13px;
    font-weight: 600;
    color: #051e28;
    line-height: 1.3;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#location-suggestions .location-suggestion-secondary {
    display: block;
    font-size: 11px;
    color: #5f6b73;
    line-height: 1.3;
}

#location-suggestions .location-suggestions-status,
#location-suggestions .location-suggestions-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    padding: 10px 9px;
    font-size: 12px;
    color: var(--tv-on-surface-variant, #5f6b73);
}

#location-suggestions .location-suggestions-status.is-loading::before {
    content: '';
    flex: 0 0 auto;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(2, 132, 199, 0.2);
    border-top-color: var(--tv-primary, #0284c7);
    border-radius: 50%;
    animation: location-suggestions-spin 0.7s linear infinite;
}

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

#location-search-content.open {
    overflow: visible;
}

/* Hide legacy mapbox-gl-draw rules if present */
.mapbox-gl-draw_ctrl-draw-btn {
    display: none !important;
}

@media (max-width: 1023px) {
    #main-content .mapboxgl-ctrl-top-right {
        top: 8px;
        right: 8px;
    }

    .map-draw-btn {
        width: 34px;
        height: 34px;
    }

    .map-draw-toolbar {
        width: 34px;
    }
}

@media (max-width: 767px) {
    .map-legend {
        max-width: calc(100vw - 56px);
    }

    #main-content .mapboxgl-ctrl-top-right {
        top: 52px;
        right: 8px;
    }
}

.login-card {
    max-width: 420px;
    width: 100%;
    margin: 0 auto;
}

.form-input {
    width: 100%;
    background: #e7f6ff;
    border: 1px solid var(--tv-border);
    border-radius: var(--tv-radius);
    padding: 12px 14px;
    font-size: 14px;
    color: #051e28;
}

.form-input:focus {
    outline: none;
    ring: 2px;
    border-color: var(--tv-primary);
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.2);
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #b91c1c;
    padding: 12px 16px;
    border-radius: var(--tv-radius);
    font-size: 14px;
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #047857;
    padding: 12px 16px;
    border-radius: var(--tv-radius);
    font-size: 14px;
}

.password-input-wrap {
    position: relative;
    display: flex;
    align-items: stretch;
}

.password-input-wrap .password-input {
    padding-right: 44px;
}

.password-toggle-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: #5a7a8f;
    border-radius: 10px;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

.password-toggle-btn:hover {
    color: var(--tv-primary);
    background: rgba(2, 132, 199, 0.08);
}

.password-toggle-icon {
    font-size: 20px;
    line-height: 1;
}

.otp-input {
    letter-spacing: 0.35em;
    text-align: center;
    font-size: 20px;
    font-weight: 600;
}
