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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #1a1a2e;
    color: #e0e0e0;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

main {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

header {
    background: #16213e;
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #0f3460;
}

header h1 {
    font-size: 1.3rem;
    color: #e94560;
}

#status {
    display: flex;
    gap: 20px;
    font-size: 0.85rem;
}

#train-count {
    color: #53d8fb;
    font-weight: 600;
}

#last-update {
    color: #888;
}

#tabs {
    display: flex;
    gap: 0;
    background: #16213e;
    border-bottom: 2px solid #0f3460;
}

.tab-btn {
    padding: 10px 24px;
    background: transparent;
    color: #888;
    border: none;
    border-right: 1px solid #0f3460;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: background 0.2s, color 0.2s;
}

.tab-btn:hover {
    background: rgba(15, 52, 96, 0.5);
    color: #e0e0e0;
}

.tab-btn.active {
    background: #1a1a2e;
    color: #e94560;
}

.tab-content {
    display: none;
    flex: 1;
    overflow: hidden;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

#map-tab {
    flex: 1;
    height: 100%;
    flex-direction: column;
}

#map-tab #map {
    flex: 1;
    width: 100%;
    height: 100%;
    min-height: 0;
}

.status-connected {
    color: #4caf50;
    font-weight: 600;
}

.status-disconnected {
    color: #ff5252;
    font-weight: 600;
}

#train-table-container {
    flex: 1;
    width: 100%;
    overflow: auto;
    padding: 16px;
}

#train-table,
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

#train-table thead,
.data-table thead {
    background: #16213e;
    position: sticky;
    top: 0;
    z-index: 10;
}

#train-table th,
.data-table th {
    padding: 12px 16px;
    text-align: left;
    color: #e94560;
    font-weight: 600;
    border-bottom: 2px solid #0f3460;
    white-space: nowrap;
}

#train-table td,
.data-table td {
    padding: 10px 16px;
    border-bottom: 1px solid #0f3460;
    white-space: nowrap;
}

#train-table tbody tr:hover {
    background: rgba(15, 52, 96, 0.5);
}

#train-table tbody tr:nth-child(even) {
    background: rgba(15, 52, 96, 0.2);
}

#train-table tbody tr:nth-child(even):hover {
    background: rgba(15, 52, 96, 0.5);
}

#legend {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(22, 33, 62, 0.95);
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid #0f3460;
    z-index: 1000;
    font-size: 0.85rem;
}

#legend h3 {
    margin-bottom: 8px;
    color: #e94560;
    font-size: 0.9rem;
}

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

.marker-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    border: 2px solid #fff;
}

.marker-dot.on-time {
    background: #4caf50;
}

.marker-dot.delayed {
    background: #ffc107;
}

.marker-dot.cancelled {
    background: #f44336;
}

.map-error {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    color: #888;
    text-align: center;
}

#stats-container {
    flex: 1;
    overflow: auto;
    padding: 16px;
}

#stats-container h2 {
    font-size: 1rem;
    color: #e94560;
    margin: 20px 0 8px;
}

#stats-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    font-size: 0.85rem;
}

#stats-controls label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: #888;
}

#stats-controls select {
    background: #16213e;
    color: #e0e0e0;
    border: 1px solid #0f3460;
    border-radius: 4px;
    padding: 6px 8px;
}

.stats-note {
    margin-top: 12px;
    font-size: 0.8rem;
    color: #888;
}

.data-table {
    margin-bottom: 8px;
}

@media (max-width: 640px) {
    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
        padding: 10px 16px;
    }

    #train-table-container,
    #stats-container {
        padding: 8px;
    }

    #train-table th,
    #train-table td,
    .data-table th,
    .data-table td {
        padding: 6px 8px;
    }
}

#alerts {
    background: #3a2a10;
    border-bottom: 1px solid #6b4e1a;
    color: #ffd27a;
    font-size: 0.85rem;
    padding: 8px 24px;
}

#alerts summary {
    cursor: pointer;
    font-weight: 600;
}

#alerts ul {
    list-style: none;
    margin-top: 8px;
    max-height: 30vh;
    overflow: auto;
}

#alerts li {
    padding: 6px 0;
    border-top: 1px solid rgba(255, 210, 122, 0.2);
    color: #f0e0c0;
}

#alerts .alert-meta {
    color: #b8a070;
    font-size: 0.75rem;
}
