/* ============================================
   TfGM SCOOT Incident Detection Dashboard
   ============================================ */

:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-hover: #242733;
    --border: #2a2d3a;
    --text: #e4e6ef;
    --text-muted: #8b8fa3;
    --accent: #4f8ff7;
    --high: #ef4444;
    --medium: #f59e0b;
    --low: #3b82f6;
    --ok: #22c55e;
    --none: #6b7280;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

header h1 {
    font-size: 18px;
    font-weight: 600;
}

.header-right {
    display: flex;
    gap: 20px;
    font-size: 13px;
    color: var(--text-muted);
}

.badge {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-ok { background: rgba(34, 197, 94, 0.15); color: var(--ok); }
.badge-error { background: rgba(239, 68, 68, 0.15); color: var(--high); }

/* Region tabs */
#region-tabs {
    display: flex;
    gap: 4px;
    padding: 8px 24px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.tab {
    padding: 6px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.tab:hover { background: var(--bg-hover); color: var(--text); }
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Main layout */
main {
    padding: 16px 24px;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 90px);  /* viewport minus header + tabs */
}

#dashboard-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.grid {
    display: grid;
    gap: 16px;
    margin-bottom: 16px;
}

.map-table-grid {
    grid-template-columns: 1.5fr 1fr;
    flex: 1;
    min-height: 0;
    margin-bottom: 0;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
}

.card h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.stats-card {
    display: flex;
    flex-direction: column;
    padding: 12px 16px;
}

.stats-card h3 { margin-bottom: 8px; }

.stats-card .stats-grid {
    flex: 1;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px;
    border-radius: 6px;
    background: var(--bg);
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.stat-label-high { color: var(--high); }
.stat-label-medium { color: var(--medium); }
.stat-label-low { color: var(--low); }

.stat-high { color: var(--high); }
.stat-medium { color: var(--medium); }
.stat-low { color: var(--low); }

/* Top bar: stats + filters same height */
.grid:first-child {
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
}

/* Filter panel */
.filter-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 16px;
}

.filter-card h3 { margin-bottom: 2px; }

.filter-row {
    display: flex;
    gap: 24px;
}

.filter-row .filter-group { flex: 1; }

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.filter-buttons {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
}

.filter-btn:hover { background: var(--bg-hover); color: var(--text); }
.filter-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Colour-coded severity filter buttons */
.filter-btn.filter-high.active { background: var(--high); border-color: var(--high); }
.filter-btn.filter-medium.active { background: var(--medium); border-color: var(--medium); }
.filter-btn.filter-low.active { background: var(--low); border-color: var(--low); }
.filter-btn.filter-high:not(.active) { color: var(--high); border-color: rgba(239, 68, 68, 0.4); }
.filter-btn.filter-medium:not(.active) { color: var(--medium); border-color: rgba(245, 158, 11, 0.4); }
.filter-btn.filter-low:not(.active) { color: var(--low); border-color: rgba(59, 130, 246, 0.4); }

.filter-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg);
    outline: none;
    cursor: pointer;
}

.filter-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

.filter-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
}

.filter-match-count {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: auto;
    padding-top: 4px;
    border-top: 1px solid var(--border);
}

/* Map */
.map-card {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#map {
    flex: 1;
    min-height: 300px;
    border-radius: 6px;
    background: #1a1d27;
}

/* Table */
.table-card {
    overflow-y: auto;
    min-height: 0;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    position: sticky;
    top: 0;
    background: var(--bg-card);
    text-align: left;
    padding: 8px 10px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    text-transform: uppercase;
}

tbody td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}

tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--bg-hover); }

.severity-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.severity-high { background: rgba(239, 68, 68, 0.15); color: var(--high); }
.severity-medium { background: rgba(245, 158, 11, 0.15); color: var(--medium); }
.severity-low { background: rgba(59, 130, 246, 0.15); color: var(--low); }
.severity-none { background: rgba(107, 114, 128, 0.15); color: var(--none); }

.empty {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 10px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.hidden { display: none; }

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 24px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.modal-header h2 { font-size: 18px; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
}

.modal-close:hover { color: var(--text); }

/* Modal mini map */
#modal-map {
    height: 200px;
    border-radius: 6px;
    background: #1a1d27;
    margin-bottom: 16px;
}

.modal-info-bar {
    display: flex;
    gap: 16px;
    align-items: center;
    padding: 10px 12px;
    background: var(--bg);
    border-radius: 6px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.modal-info-item {
    font-size: 13px;
    color: var(--text-muted);
}

.modal-info-item strong {
    color: var(--text);
}

.signal-list {
    list-style: none;
    padding: 0;
}

.signal-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 4px;
    background: var(--bg);
}

.signal-name { font-weight: 500; }
.signal-prob { color: var(--text-muted); }

.progress-bar {
    width: 100px;
    height: 6px;
    background: var(--bg);
    border-radius: 3px;
    overflow: hidden;
    display: inline-block;
    vertical-align: middle;
    margin-left: 8px;
}

.progress-fill {
    height: 100%;
    border-radius: 3px;
}

/* Responsive */
@media (max-width: 1024px) {
    .grid:first-child,
    .map-table-grid { grid-template-columns: 1fr !important; }
}
