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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    display: flex;
    height: 100vh;
    overflow: hidden;
}

#sidebar {
    width: 420px;
    min-width: 420px;
    background: #1a1a2e;
    color: #e0e0e0;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

h1 {
    font-size: 1.4em;
    color: #fff;
    margin-bottom: 0;
}

.subtitle {
    font-size: 0.85em;
    color: #888;
    margin-bottom: 8px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.control-group label {
    font-size: 0.8em;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

select, input[type="text"], input[type="number"] {
    background: #16213e;
    border: 1px solid #333;
    color: #e0e0e0;
    padding: 8px 10px;
    border-radius: 4px;
    font-size: 0.9em;
}

/* Dataset combobox */
.service-combobox {
    position: relative;
}

#service-search {
    width: 100%;
    font-size: 0.85em;
    padding: 8px 10px;
}

#service-search::placeholder {
    color: #666;
}

.service-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 280px;
    overflow-y: auto;
    background: #16213e;
    border: 1px solid #4a9eff;
    border-top: none;
    border-radius: 0 0 4px 4px;
    z-index: 1000;
}

.service-dropdown.open {
    display: block;
}

.service-dropdown .group-label {
    padding: 5px 10px;
    font-size: 0.7em;
    color: #4a9eff;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: #0d1525;
    position: sticky;
    top: 0;
}

.service-dropdown .service-option {
    padding: 6px 10px;
    font-size: 0.82em;
    cursor: pointer;
    color: #e0e0e0;
    transition: background 0.1s;
}

.service-dropdown .service-option:hover {
    background: #1e3a5f;
}

#service-selected {
    font-size: 0.8em;
    color: #4a9eff;
    min-height: 1.2em;
}

#service-selected .clear-service {
    color: #888;
    margin-left: 6px;
    cursor: pointer;
    font-size: 0.9em;
}

#service-selected .clear-service:hover {
    color: #e0e0e0;
}

select {
    cursor: pointer;
}

select:focus, input:focus {
    outline: none;
    border-color: #4a9eff;
}

input.input-required {
    border-color: #e74c3c;
    box-shadow: 0 0 0 1px rgba(231, 76, 60, 0.3);
}

select optgroup {
    color: #4a9eff;
    font-style: normal;
    font-weight: 600;
}

select option {
    color: #e0e0e0;
    background: #16213e;
}

.radius-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

input[type="range"] {
    flex: 1;
    accent-color: #4a9eff;
}

input[type="number"] {
    width: 70px;
    text-align: center;
}

button#search-btn {
    background: #4a9eff;
    color: #fff;
    border: none;
    padding: 10px;
    border-radius: 4px;
    font-size: 1em;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

button#search-btn:hover:not(:disabled) {
    background: #3a8eef;
}

button#search-btn:disabled {
    background: #333;
    color: #666;
    cursor: not-allowed;
}

.status {
    font-size: 0.85em;
    color: #888;
    min-height: 1.2em;
}

.status.error {
    color: #ff6b6b;
}

.status.loading {
    color: #4a9eff;
}

/* Suggested datasets row (always visible) */
.suggested-datasets {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: center;
}

/* Empty state / first-visit hint */
.empty-state {
    text-align: center;
    padding: 16px 8px;
    color: #888;
    font-size: 0.85em;
    line-height: 1.5;
}

.suggested-label {
    font-size: 0.8em;
    color: #666;
    margin-right: 2px;
}

.suggested-btn {
    background: #16213e;
    border: 1px solid #333;
    color: #4a9eff;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8em;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, border-color 0.15s;
}

.suggested-btn:hover {
    background: #1e3a5f;
    border-color: #4a9eff;
}

.empty-results-hint {
    text-align: center;
    padding: 12px 8px;
    color: #888;
    font-size: 0.82em;
    line-height: 1.4;
}

#results-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
}

.result-item {
    background: #16213e;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 0.8em;
    cursor: pointer;
    transition: border-color 0.15s;
}

.result-item:hover {
    border-color: #4a9eff;
}

.result-item .result-distance {
    color: #4a9eff;
    font-weight: 600;
}

.result-item .result-summary {
    color: #ccc;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-item .result-incident {
    color: #e0e0e0;
    font-weight: 600;
}

.result-item .result-time {
    color: #888;
    font-size: 0.85em;
    margin-left: 4px;
}

#map-container {
    flex: 1;
    position: relative;
    height: 100vh;
}

#map {
    width: 100%;
    height: 100%;
}

/* Loading overlay on map */
.map-loading {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.15);
    align-items: center;
    justify-content: center;
}
.map-loading.active {
    display: flex;
}
.map-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(74, 158, 255, 0.25);
    border-top-color: #4a9eff;
    border-radius: 50%;
    animation: map-spin 0.8s linear infinite;
}
@keyframes map-spin {
    to { transform: rotate(360deg); }
}

/* Location grouping in sidebar */
.location-group {
    font-size: 0.72em;
    color: #4a9eff;
    padding: 2px 10px;
    cursor: pointer;
    text-align: center;
}

.location-group:hover {
    text-decoration: underline;
}

/* Marker cluster overrides */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
    background-color: rgba(74, 158, 255, 0.25);
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
    background-color: rgba(74, 158, 255, 0.7);
    color: #fff;
    font-weight: 600;
    font-size: 12px;
}

/* Leaflet popup styling */
.leaflet-popup-content-wrapper {
    border-radius: 6px;
    max-width: 350px;
}

.leaflet-popup-content {
    margin: 10px 14px;
    font-size: 0.85em;
    line-height: 1.5;
    max-height: 300px;
    overflow-y: auto;
}

.popup-table {
    width: 100%;
    border-collapse: collapse;
}

.popup-table td {
    padding: 2px 6px 2px 0;
    vertical-align: top;
}

.popup-table td:first-child {
    color: #666;
    font-size: 0.85em;
    white-space: nowrap;
    font-weight: 500;
}

.popup-table td:last-child {
    word-break: break-word;
}

.popup-directions {
    margin-top: 8px;
    font-size: 0.9em;
}

.popup-directions a {
    color: #4a9eff;
    text-decoration: none;
}

.popup-directions a:hover {
    text-decoration: underline;
}

/* Status legend and badges for polled services */
.status-legend {
    display: flex;
    gap: 12px;
    padding: 6px 10px;
    background: #16213e;
    border: 1px solid #333;
    border-radius: 4px;
    font-size: 0.75em;
    color: #aaa;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-right: 2px;
}

.result-item .legend-dot {
    width: 8px;
    height: 8px;
    margin-right: 4px;
}

.status-badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 10px;
    color: #fff;
    font-size: 0.85em;
    font-weight: 600;
}

/* Date range inputs */
.date-row {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-wrap: wrap;
}

.date-row input[type="datetime-local"] {
    flex: 1;
    background: #16213e;
    border: 1px solid #333;
    color: #e0e0e0;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 0.75em;
    min-width: 0;
}

.date-row input[type="datetime-local"]:focus {
    outline: none;
    border-color: #4a9eff;
}

.date-sep {
    color: #666;
    font-size: 0.8em;
}

.date-nav {
    background: #16213e;
    border: 1px solid #333;
    color: #4a9eff;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    line-height: 1;
    transition: border-color 0.15s;
}

.date-nav:hover {
    border-color: #4a9eff;
}

/* Sparkline / time histogram */
.sparkline {
    background: #16213e;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 8px 10px 4px;
}

.sparkline-bars {
    display: flex;
    align-items: flex-end;
    gap: 1px;
    height: 48px;
}

.sparkline-bar {
    border-radius: 1px 1px 0 0;
    min-width: 2px;
    cursor: default;
    transition: opacity 0.15s;
}

.sparkline-bar:hover {
    opacity: 0.8;
}

.sparkline-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.65em;
    color: #666;
    margin-top: 2px;
}

/* Sidebar footer links */
#sidebar-footer-links {
    margin-top: auto;
    padding-top: 16px;
    display: flex;
    gap: 8px;
    justify-content: center;
}

#sidebar-footer-links button {
    color: #4a9eff;
    font-size: 0.82em;
    background: none;
    padding: 8px 14px;
    border: 1px solid #333;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, border-color 0.15s;
}

#sidebar-footer-links button:hover {
    background: #16213e;
    border-color: #4a9eff;
}

/* Bug report modal */
.bug-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.bug-modal-overlay.open {
    display: flex;
}

.bug-modal {
    background: #1a1a2e;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 24px;
    width: 480px;
    max-width: 90vw;
    max-height: 85vh;
    overflow-y: auto;
    color: #e0e0e0;
}

.bug-modal h2 {
    color: #fff;
    font-size: 1.2em;
    margin-bottom: 8px;
}

.bug-modal-desc {
    font-size: 0.82em;
    color: #888;
    margin-bottom: 16px;
    line-height: 1.4;
}

.bug-modal label {
    font-size: 0.8em;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: block;
    margin-bottom: 4px;
}

.bug-modal textarea {
    width: 100%;
    background: #16213e;
    border: 1px solid #333;
    color: #e0e0e0;
    padding: 8px 10px;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: inherit;
    resize: vertical;
    margin-bottom: 12px;
}

.bug-modal textarea:focus {
    outline: none;
    border-color: #4a9eff;
}

.bug-disclaimer {
    font-size: 0.82em;
    color: #e0c56a;
    margin-bottom: 12px;
}

.bug-debug-preview {
    background: #0d1525;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 0.72em;
    color: #666;
    margin-bottom: 16px;
    font-family: monospace;
    white-space: pre-wrap;
    max-height: 120px;
    overflow-y: auto;
}

.bug-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.bug-modal-actions button {
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 0.9em;
    cursor: pointer;
    font-weight: 600;
    border: none;
}

#bug-cancel {
    background: #333;
    color: #e0e0e0;
}

#bug-cancel:hover {
    background: #444;
}

#bug-submit {
    background: #4a9eff;
    color: #fff;
}

#bug-submit:hover {
    background: #3a8eef;
}

#bug-submit:disabled {
    background: #333;
    color: #666;
    cursor: not-allowed;
}

.bug-status {
    font-size: 0.82em;
    margin-top: 8px;
    min-height: 1.2em;
}

.bug-status.error {
    color: #ff6b6b;
}

.bug-status.success {
    color: #2ecc71;
}

/* About modal */
.about-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.about-modal-overlay.open {
    display: flex;
}

.about-modal {
    background: #1a1a2e;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 24px;
    width: 520px;
    max-width: 90vw;
    max-height: 85vh;
    overflow-y: auto;
    color: #e0e0e0;
}

.about-modal h2 {
    color: #fff;
    font-size: 1.2em;
    margin-bottom: 16px;
}

.about-content h3 {
    color: #4a9eff;
    font-size: 0.9em;
    margin: 16px 0 6px;
}

.about-content p {
    font-size: 0.85em;
    line-height: 1.5;
    color: #ccc;
    margin-bottom: 8px;
}

.about-content ul {
    list-style: none;
    padding: 0;
    margin: 4px 0 8px;
}

.about-content li {
    font-size: 0.85em;
    line-height: 1.5;
    color: #ccc;
    padding: 3px 0;
}

.about-content .legend-dot {
    display: inline-block;
    vertical-align: middle;
}

.about-content a {
    color: #4a9eff;
    text-decoration: none;
}

.about-content a:hover {
    text-decoration: underline;
}

.about-modal-actions {
    margin-top: 16px;
    text-align: right;
}

#about-close {
    background: #333;
    color: #e0e0e0;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 0.9em;
    cursor: pointer;
    font-weight: 600;
}

#about-close:hover {
    background: #444;
}

/* Record detail modal */
.record-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.record-modal-overlay.open {
    display: flex;
}

.record-modal {
    background: #1a1a2e;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 24px;
    width: 520px;
    max-width: 90vw;
    max-height: 85vh;
    overflow-y: auto;
    color: #e0e0e0;
}

.record-modal h2 {
    color: #fff;
    font-size: 1.2em;
    margin-bottom: 16px;
}

.record-modal-actions {
    margin-top: 16px;
    text-align: right;
}

#record-modal-close {
    background: #333;
    color: #e0e0e0;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 0.9em;
    cursor: pointer;
    font-weight: 600;
}

#record-modal-close:hover {
    background: #444;
}

.no-pin-badge {
    position: relative;
    display: inline-block;
    font-size: 0.75em;
    color: #95a5a6;
    margin-left: 6px;
    line-height: 1;
    vertical-align: middle;
}

.no-pin-badge::after {
    content: "";
    position: absolute;
    left: -1px;
    right: -1px;
    top: 45%;
    height: 1.5px;
    background: #e74c3c;
    transform: rotate(-30deg);
}

.no-location-notice {
    color: #95a5a6;
    font-size: 0.85em;
    padding: 8px 0;
    margin-bottom: 8px;
    border-bottom: 1px solid #333;
}

/* Mobile */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    #sidebar {
        width: 100%;
        min-width: unset;
        max-height: 45vh;
        min-height: 200px;
    }

    #map-container {
        height: 55vh;
    }
}
