/* RouteRisk - Flight Delay Network Visualization */

:root {
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --bg-panel: rgba(255, 255, 255, 0.97);
    --text-primary: #1a1a2e;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --accent: #64748b;
    --border: #e2e8f0;
    --risk-low: #2ecc71;
    --risk-medium: #f39c12;
    --risk-high: #e74c3c;
    --risk-severe: #8e44ad;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

/* Header */
#app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    height: 50px;
}

#app-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

#summary-stats {
    display: flex;
    gap: 1.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

#summary-stats span {
    padding: 0.2rem 0.6rem;
    background: var(--bg-primary);
    border-radius: 4px;
}

/* Main layout */
#app-main {
    display: grid;
    grid-template-columns: 250px 1fr 320px;
    height: calc(100vh - 50px);
}

/* Controls panel */
#controls-panel {
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    padding: 1rem;
    overflow-y: auto;
}

#controls-panel h2 {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.control-group {
    margin-bottom: 1.25rem;
}

.control-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}

.control-group input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

.control-group input[type="checkbox"] {
    accent-color: var(--accent);
    margin-right: 0.4rem;
}

#apply-filters {
    width: 100%;
    padding: 0.5rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
}

#apply-filters:hover {
    opacity: 0.9;
}

/* Legend */
#default-legend h3,
#layer-legend h3 {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

#default-legend > div,
#layer-legend > div {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
}

.legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* Visualization container */
#viz-container {
    position: relative;
    overflow: hidden;
    background: #ffffff;
}

#edge-canvas,
#node-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#edge-canvas {
    pointer-events: none;
}

#node-svg {
    pointer-events: all;
}

.airport-node {
    cursor: pointer;
    transition: opacity 0.15s;
}

.airport-node:hover {
    stroke-width: 2px !important;
    stroke: #334155;
}

.airport-node.dimmed {
    opacity: 0.2;
}

.airport-node.highlighted {
    stroke-width: 3px !important;
    stroke: #1e293b;
}

/* Tooltip */
#tooltip {
    display: none;
    position: absolute;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem 0.8rem;
    font-size: 0.8rem;
    color: var(--text-primary);
    pointer-events: none;
    z-index: 100;
    max-width: 250px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

/* Loading overlay */
#loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(248, 249, 250, 0.85);
    z-index: 50;
}

#loading-overlay.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

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

#loading-overlay p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Info panel */
#info-panel {
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    padding: 1rem;
    overflow-y: auto;
}

.info-placeholder {
    text-align: center;
    color: var(--text-muted);
    padding-top: 3rem;
    font-size: 0.85rem;
}

#info-content h2 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

#info-content > p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

/* Stats grid */
.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.stat {
    background: var(--bg-primary);
    padding: 0.6rem;
    border-radius: 6px;
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-label {
    display: block;
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Info panel sections */
#info-content h3 {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
    margin-top: 1rem;
}

/* Route list */
.route-list {
    list-style: none;
}

.route-list li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
}

.route-dest {
    font-weight: 600;
    min-width: 35px;
}

.route-flights {
    flex: 1;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.route-risk {
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-weight: 600;
    text-transform: uppercase;
}

.risk-low { background: #d1fae5; color: #065f46; }
.risk-medium { background: #fef3c7; color: #78350f; }
.risk-high { background: #fee2e2; color: #991b1b; }
.risk-severe { background: #ede9fe; color: #5b21b6; }

/* View Data button */
.data-actions {
    margin-top: 1rem;
}

.view-data-btn {
    width: 100%;
    padding: 0.5rem;
    background: var(--bg-primary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
}

.view-data-btn:hover {
    background: var(--border);
    color: var(--text-primary);
}

/* Data explorer modal */
.de-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.de-overlay.visible {
    display: flex;
}

.de-modal {
    background: var(--bg-secondary);
    border-radius: 8px;
    width: 720px;
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
}

.de-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.de-title {
    font-size: 1rem;
    font-weight: 700;
}

.de-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0 0.3rem;
    line-height: 1;
}

.de-close:hover {
    color: var(--text-primary);
}

.de-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding: 0 1rem;
}

.de-tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 600;
}

.de-tab.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent);
}

.de-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.de-loading {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem 0;
    font-size: 0.85rem;
}

/* Data table */
.de-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.de-table th,
.de-table td {
    padding: 0.4rem 0.6rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.de-table th {
    color: var(--text-secondary);
    font-weight: 600;
    white-space: nowrap;
    width: 140px;
}

.de-table tbody tr:nth-child(even) {
    background: var(--bg-primary);
}

.de-section td {
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    padding-top: 0.8rem;
    background: none !important;
}

/* Routes table - all cols auto width */
.de-routes-table th {
    width: auto;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.de-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    border-top: 1px solid var(--border);
}

.de-pagination {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.de-page-btn {
    padding: 0.25rem 0.6rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.de-page-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.de-export {
    padding: 0.3rem 0.8rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
}

.de-export:hover {
    opacity: 0.9;
}

/* Delay causes chart */
#delay-causes-chart {
    margin-bottom: 0.5rem;
}

#delay-causes-chart text {
    fill: var(--text-secondary);
}

/* Layer toggle */
#layer-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    margin-bottom: 1.25rem;
}

#layer-toggle h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    font-weight: 700;
}

.layer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--border);
}

.layer-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.layer-row-label {
    font-size: 0.85rem;
    color: var(--text-primary);
    font-weight: 500;
}

.layer-row-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.1rem;
}

/* iOS-style toggle switch */
.layer-switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
}

.layer-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.layer-switch-track {
    position: absolute;
    inset: 0;
    background: #cbd5e1;
    border-radius: 24px;
    cursor: pointer;
    transition: background 0.2s;
}

.layer-switch-track::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: white;
    top: 3px;
    left: 3px;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.layer-switch input:checked + .layer-switch-track {
    background: #22c55e;
}

.layer-switch input:checked + .layer-switch-track::after {
    transform: translateX(18px);
}

.layer-radio {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
    cursor: pointer;
}

.layer-radio input[type="radio"] {
    accent-color: var(--accent);
    margin-right: 0.3rem;
}

.layer-legend-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.layer-legend-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
}

.layer-legend-hint {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.6rem;
    font-style: italic;
}

/* Propagation flight dots — frozen on edges after animation */
.flight-dot {
    pointer-events: all;
    transition: r 0.15s;
}

.flight-dot:hover {
    r: 7;
}

/* Chain layer — search */
.chain-search-wrap {
    position: relative;
    margin-top: 0.75rem;
}

.chain-search {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    outline: none;
}

.chain-search:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(100, 116, 139, 0.15);
}

.chain-autocomplete {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 6px 6px;
    max-height: 240px;
    overflow-y: auto;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.chain-ac-item {
    padding: 0.45rem 0.75rem;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    gap: 0.5rem;
    align-items: baseline;
}

.chain-ac-item:hover,
.chain-ac-item.active {
    background: var(--bg-primary);
}

.chain-ac-name {
    color: var(--text-muted);
    font-size: 0.75rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chain-ac-empty {
    padding: 0.6rem 0.75rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Chain layer — navigation */
.chain-nav {
    margin-bottom: 0.5rem;
}

.chain-nav-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 0.78rem;
    cursor: pointer;
    padding: 0.2rem 0;
    font-weight: 500;
}

.chain-nav-btn:hover {
    color: var(--text-primary);
}

/* Chain layer — verdict panel */
.chain-verdict-section {
    margin: 1rem 0;
}

.chain-verdict-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.82rem;
    border-radius: 4px;
}

.chain-verdict-row:hover {
    background: var(--bg-primary);
}

.chain-traffic-light {
    font-size: 1.2rem;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.chain-verdict-label {
    font-weight: 600;
    min-width: 80px;
}

.chain-verdict-pct {
    flex: 1;
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.chain-verdict-avg {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.chain-badge {
    display: inline-block;
    font-size: 0.6rem;
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    vertical-align: middle;
    margin-left: 0.3rem;
}

.chain-badge-best {
    background: #d1fae5;
    color: #065f46;
}

.chain-badge-worst {
    background: #fee2e2;
    color: #991b1b;
}

.chain-recommendation {
    background: var(--bg-primary);
    padding: 0.6rem 0.75rem;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0.75rem 0;
    text-align: center;
}

.chain-explain-btn {
    width: 100%;
    padding: 0.6rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
}

.chain-explain-btn:hover {
    opacity: 0.9;
}

/* Chain layer — carrier grid */
.chain-carrier-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.4rem;
}

.chain-carrier-item {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    padding: 0.3rem 0.5rem;
    background: var(--bg-primary);
    border-radius: 4px;
    font-size: 0.78rem;
}

.chain-carrier-code {
    font-weight: 600;
}

.chain-carrier-pct {
    color: var(--text-muted);
    font-size: 0.72rem;
}

.chain-carrier-best {
    background: #d1fae5;
    border: 1px solid #a7f3d0;
}

.chain-carrier-worst {
    background: #fee2e2;
    border: 1px solid #fecaca;
}

/* Chain layer — destination list */
.chain-dest-list {
    list-style: none;
}

.chain-dest-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.3rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
    cursor: pointer;
}

.chain-dest-item:hover {
    background: var(--bg-primary);
}

.chain-dest-code {
    font-weight: 700;
    min-width: 35px;
}

.chain-dest-name {
    flex: 1;
    color: var(--text-secondary);
    font-size: 0.75rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chain-dest-flights {
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* Chain layer — time window tabs */
.chain-time-tabs {
    display: flex;
    margin: 0.75rem 0;
    border-bottom: 2px solid var(--border);
}

.chain-time-tab {
    flex: 1;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.5rem 0.4rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 600;
    margin-bottom: -2px;
    text-align: center;
}

.chain-time-tab.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent);
}

.chain-time-tab:hover:not(.active) {
    color: var(--text-secondary);
}

.chain-explain-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    font-style: italic;
}

.chain-propagation-note {
    font-size: 0.78rem;
    color: var(--text-secondary);
    background: #f1f5f9;
    border-left: 3px solid var(--accent);
    padding: 0.5rem 0.75rem;
    margin: 0.75rem 0;
    line-height: 1.4;
}

/* Chain layer — info panel lists */
.chain-list {
    list-style: none;
}

.chain-list li {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.78rem;
}

.chain-list li:hover {
    background: var(--bg-primary);
}

.chain-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.chain-route {
    font-weight: 600;
    min-width: 65px;
}

.chain-count {
    flex: 1;
    color: var(--text-secondary);
    font-size: 0.72rem;
}

.chain-corr {
    font-size: 0.68rem;
    padding: 0.1rem 0.35rem;
    background: var(--bg-primary);
    border-radius: 3px;
    color: var(--text-muted);
}
