/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2C3E50;
    --secondary-color: #3498DB;
    --accent-color: #E74C3C;
    --background-light: #ECF0F1;
    --background-dark: #1A1A1A;
    --text-light: #FFFFFF;
    --text-dark: #2C3E50;
    --border-color: #BDC3C7;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-large: 0 4px 16px rgba(0, 0, 0, 0.15);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: var(--text-dark);
    background-color: var(--background-light);
    overflow: hidden;
    height: 100vh;
}

body.dark-mode {
    background-color: var(--background-dark);
    color: var(--text-light);
}

/* App Container */
#app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: var(--text-light);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-large);
    z-index: 1000;
    flex-shrink: 0;
}

.header-content h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 5px;
}

.header-content p {
    font-size: 12px;
    opacity: 0.9;
}

.header-controls {
    display: flex;
    gap: 10px;
}

.btn-icon {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 10px 15px;
    font-size: 18px;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

/* Main Container */
main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Map Container */
.map-container {
    flex: 1;
    position: relative;
    background-color: #E8EEF7;
}

.leaflet-container {
    background-color: #E8EEF7;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Remove tile grid boundaries */
.leaflet-tile {
    outline: none !important;
    border: none !important;
}

.leaflet-tile-pane canvas {
    outline: none !important;
    border: none !important;
}

/* Control Panel */
.control-panel {
    width: 320px;
    background: white;
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 20px;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    z-index: 999;
    max-height: calc(100vh - 70px);
}

body.dark-mode .control-panel {
    background: #2A2A2A;
    color: var(--text-light);
    border-right-color: #444;
}

.panel-section {
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

body.dark-mode .panel-section {
    border-bottom-color: #444;
}

.panel-section:last-child {
    border-bottom: none;
}

.panel-section h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--primary-color);
}

body.dark-mode .panel-section h3 {
    color: var(--secondary-color);
}

/* Filter Group */
.filter-group {
    margin-bottom: 15px;
}

.filter-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
}

.filter-group select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 13px;
    background-color: white;
    cursor: pointer;
    transition: all 0.3s ease;
}

.filter-group select:hover {
    border-color: var(--secondary-color);
}

.filter-group select:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

body.dark-mode .filter-group select {
    background-color: #3A3A3A;
    color: var(--text-light);
    border-color: #555;
}

/* Info Box */
.info-box {
    background: var(--background-light);
    padding: 12px;
    border-radius: 6px;
    font-size: 13px;
    margin-top: 10px;
}

body.dark-mode .info-box {
    background: #3A3A3A;
    color: var(--text-light);
}

.info-box p {
    margin-bottom: 6px;
}

.info-box p:last-child {
    margin-bottom: 0;
}

/* Statistics Box */
.stats-box {
    background: var(--background-light);
    padding: 12px;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.6;
}

body.dark-mode .stats-box {
    background: #3A3A3A;
    color: var(--text-light);
}

/* Legend */
.legend {
    font-size: 12px;
}

.legend h4 {
    font-size: 13px;
    margin-bottom: 10px;
    color: var(--primary-color);
}

body.dark-mode .legend h4 {
    color: var(--secondary-color);
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
}

.legend-color {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    margin-right: 10px;
    border: 1px solid #999;
}

/* About Text */
.about-text {
    font-size: 12px;
    line-height: 1.5;
    color: #666;
}

body.dark-mode .about-text {
    color: #AAA;
}

/* Info Panel */
.info-panel {
    position: fixed;
    right: 0;
    top: 70px;
    width: 480px;           /* wider to fit band tables */
    max-height: calc(100vh - 70px);
    background: white;
    border-left: 1px solid var(--border-color);
    box-shadow: var(--shadow-large);
    z-index: 998;
    overflow-y: auto;
    transform: translateX(0);
    transition: transform 0.3s ease;
}

body.dark-mode .info-panel {
    background: #2A2A2A;
    color: var(--text-light);
    border-left-color: #444;
}

.info-panel.hidden {
    transform: translateX(100%);
}

.panel-header {
    background: var(--primary-color);
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.panel-header h3 {
    margin: 0;
    font-size: 16px;
}

.btn-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.panel-content {
    padding: 20px;
    font-size: 13px;
}

/* Settings Panel */
.settings-panel {
    position: fixed;
    right: 0;
    top: 70px;
    width: 350px;
    max-height: calc(100vh - 70px);
    background: white;
    border-left: 1px solid var(--border-color);
    box-shadow: var(--shadow-large);
    z-index: 1001;
    overflow-y: auto;
    transform: translateX(0);
    transition: transform 0.3s ease;
}

body.dark-mode .settings-panel {
    background: #2A2A2A;
    color: var(--text-light);
    border-left-color: #444;
}

.settings-panel.hidden {
    transform: translateX(100%);
}

.setting-group {
    margin-bottom: 15px;
}

.setting-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
}

.setting-group input[type="range"] {
    width: 100%;
    cursor: pointer;
}

.setting-group input[type="checkbox"] {
    margin-right: 8px;
    cursor: pointer;
}

#opacity-value {
    font-weight: 600;
    color: var(--secondary-color);
}

/* Buttons */
.btn-primary {
    background: var(--secondary-color);
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    width: 100%;
    transition: all 0.3s ease;
}

.btn-primary:hover {
    background: #2980B9;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn-primary:active {
    transform: translateY(0);
}

/* Loading Indicator */
.loading-indicator {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: var(--primary-color);
    color: white;
    padding: 20px 25px;
    border-radius: 8px;
    box-shadow: var(--shadow-large);
    z-index: 997;
    display: flex;
    align-items: center;
    gap: 15px;
    transition: opacity 0.3s ease;
}

.loading-indicator.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary-color);
    color: white;
    padding: 15px 25px;
    border-radius: 6px;
    box-shadow: var(--shadow-large);
    z-index: 997;
    max-width: 400px;
    text-align: center;
    animation: slideUp 0.3s ease;
}

.toast.hidden {
    display: none;
}

.toast.success {
    background: #2ECC71;
}

.toast.error {
    background: #E74C3C;
}

.toast.info {
    background: #3498DB;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Leaflet Popup */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
    box-shadow: var(--shadow-large);
}

.leaflet-popup-content {
    font-size: 13px;
    line-height: 1.6;
}

.leaflet-popup-tip {
    background: white;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .control-panel {
        width: 280px;
    }
    
    .info-panel,
    .settings-panel {
        width: 300px;
    }
}

@media (max-width: 768px) {
    .header-content h1 {
        font-size: 20px;
    }
    
    .control-panel {
        width: 100%;
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 50%;
        border-left: none;
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
        transform: translateY(100%);
        transition: transform 0.3s ease;
    }
    
    .control-panel.open {
        transform: translateY(0);
    }
    
    .info-panel,
    .settings-panel {
        width: 100%;
        right: auto;
        left: 0;
    }
}

/* ── Site detail table (used inside info panel) ─────────── */
.detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

.detail-table th,
.detail-table td {
    padding: 4px 7px;
    border: 1px solid #ddd;
    text-align: left;
    vertical-align: top;
}

.detail-table th {
    background: #f0f4f8;
    font-weight: 600;
    color: #444;
    white-space: nowrap;
    width: 110px;
}

.detail-table td {
    color: #222;
    word-break: break-word;
}

body.dark-mode .detail-table th {
    background: #3a3a3a;
    color: #ccc;
    border-color: #555;
}

body.dark-mode .detail-table td {
    color: #ddd;
    border-color: #555;
}

/* Sector <details> expand/collapse indicator */
details > summary {
    list-style: none;
    user-select: none;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
    content: '▶';
    font-size: 9px;
    margin-right: 6px;
    color: #888;
    transition: transform 0.2s;
    display: inline-block;
}
details[open] > summary::before {
    transform: rotate(90deg);
}

/* Band table alternating rows */
#tower-info-content tbody tr:nth-child(even) {
    background: #f7f9fb;
}
#tower-info-content tbody tr:hover {
    background: #e8f4fb;
}

body.dark-mode #tower-info-content tbody tr:nth-child(even) {
    background: #2e2e2e;
}
body.dark-mode #tower-info-content tbody tr:hover {
    background: #3a4a55;
}
body.dark-mode #tower-info-content tbody td {
    border-color: #555;
    color: #ddd;
}
body.dark-mode #tower-info-content thead th {
    background: #2a3a45;
    color: #bbb;
    border-color: #555;
}

/* ── Map Search Box ─────────────────────────────────────── */
.map-search {
    position: fixed;
    /* vertically: just below the header (~70px) + 12px gap */
    top: calc(70px + 12px);
    /* horizontally: centred over the map area (right of the 320px panel) */
    left: calc(320px + (100vw - 320px) / 2);
    transform: translateX(-50%);
    z-index: 1100;          /* above Leaflet controls (z-index 1000) */
    width: min(500px, calc(100vw - 360px));
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    pointer-events: auto;
}

.map-search-input-wrap {
    display: flex;
    align-items: center;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.25);
    padding: 0 12px;
    height: 46px;
    gap: 8px;
}

body.dark-mode .map-search-input-wrap {
    background: #2a2a2a;
    box-shadow: 0 2px 12px rgba(0,0,0,0.5);
}

.map-search-icon {
    font-size: 17px;
    flex-shrink: 0;
    line-height: 1;
    opacity: 0.6;
}

.map-search-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 15px;
    background: transparent;
    color: var(--text-dark);
    min-width: 0;
}

body.dark-mode .map-search-input {
    color: var(--text-light);
}

.map-search-input::placeholder {
    color: #aaa;
}

.map-search-clear {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: #888;
    padding: 0 2px;
    line-height: 1;
    flex-shrink: 0;
    transition: color 0.2s;
}

.map-search-clear:hover {
    color: #333;
}

body.dark-mode .map-search-clear:hover {
    color: #eee;
}

.map-search-results {
    list-style: none;
    margin: 4px 0 0;
    padding: 0;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    overflow: hidden;
    max-height: 280px;
    overflow-y: auto;
}

body.dark-mode .map-search-results {
    background: #2a2a2a;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

.map-search-results.hidden {
    display: none;
}

.map-search-results li {
    padding: 10px 14px;
    font-size: 13px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    line-height: 1.4;
    color: var(--text-dark);
    transition: background 0.15s;
}

body.dark-mode .map-search-results li {
    color: var(--text-light);
    border-bottom-color: #3a3a3a;
}

.map-search-results li:last-child {
    border-bottom: none;
}

.map-search-results li:hover,
.map-search-results li.active {
    background: #e8f4fb;
}

body.dark-mode .map-search-results li:hover,
body.dark-mode .map-search-results li.active {
    background: #2a3a45;
}

.map-search-results li.search-no-results {
    color: #888;
    cursor: default;
    font-style: italic;
}

.map-search-results li.search-no-results:hover {
    background: transparent;
}

.map-search-result-name {
    font-weight: 600;
}

.map-search-result-detail {
    font-size: 11px;
    color: #777;
    margin-top: 2px;
}

body.dark-mode .map-search-result-detail {
    color: #aaa;
}

/* On small screens, full-width search box */
@media (max-width: 768px) {
    .map-search {
        top: calc(70px + 8px);
        left: 8px;
        right: 8px;
        width: auto;
        transform: none;
        z-index: 1100;
    }
}

@media (max-width: 1024px) {
    .map-search {
        left: calc(280px + (100vw - 280px) / 2);
    }
}

/* Print Styles */
@media print {
    .header,
    .control-panel,
    .info-panel,
    .settings-panel,
    .loading-indicator,
    .leaflet-control {
        display: none !important;
    }
}
