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

:root {
    --southern-green:       #00703C;
    --southern-green-light: #00884A;
    --southern-green-dark:  #005a30;
    --southern-green-tint:  #f0f7f3;

    --bg:       #f2f4f7;
    --surface:  #ffffff;
    --surface2: #f8f9fb;
    --border:   #e4e7ec;
    --border2:  #d0d5dd;

    --text:     #101828;
    --text2:    #344054;
    --muted:    #667085;
    --dimmed:   #98a2b3;

    --accent:   #00703C;
    --green:    #00703C;
    --amber:    #b45309;
    --red:      #b91c1c;
    --blue:     #1d4ed8;

    --font: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── HEADER ──────────────────────────────────────────────────── */
.site-header {
    background: var(--southern-green);
    border-bottom: none;
    padding: 0 24px;
    height: 58px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.header-brand {
    display: flex;
    align-items: center;
    gap: 16px;
}
.brand-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: rgba(255,255,255,0.5);
    flex-shrink: 0;
}
.brand-name {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: #ffffff;
}
.header-nav {
    display: flex;
    gap: 2px;
    margin-left: 8px;
}
.nav-link {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    padding: 5px 12px;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
}
.nav-link:hover  { color: #fff; background: rgba(255,255,255,0.15); }
.nav-link.active { color: #fff; background: rgba(255,255,255,0.2);  }

.header-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: rgba(255,255,255,0.75);
}
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255,255,255,0.4);
    transition: background 0.3s;
}
.status-dot.live  { background: #86efac; }
.status-dot.error { background: #fca5a5; }
.last-update { font-size: 12px; color: rgba(255,255,255,0.5); }

/* ── DASHBOARD ───────────────────────────────────────────────── */
.dashboard {
    max-width: 1400px;
    margin: 0 auto;
    padding: 28px 24px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

/* ── SUMMARY CARDS ───────────────────────────────────────────── */
.summary-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
}
.summary-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px 22px;
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.summary-card::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--southern-green);
    border-radius: 0 0 12px 12px;
}
.summary-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.summary-value {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -1px;
    color: var(--text);
    line-height: 1;
    margin-bottom: 6px;
}
.summary-label {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

/* ── SECTION ─────────────────────────────────────────────────── */
.section { display: flex; flex-direction: column; gap: 12px; }
.section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.7px;
}

/* ── TRAIN GRID ──────────────────────────────────────────────── */
.train-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 14px;
}
.empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 64px 24px;
    color: var(--muted);
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.empty-icon {
    width: 44px;
    height: 44px;
    border: 2px solid var(--border2);
    border-radius: 50%;
    margin-bottom: 8px;
}
.empty-sub { font-size: 12px; color: var(--dimmed); }

/* ── TRAIN CARD ──────────────────────────────────────────────── */
.train-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    transition: box-shadow 0.2s, transform 0.1s;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.train-card:hover {
    box-shadow: 0 6px 20px rgba(0,0,0,0.1);
    transform: translateY(-1px);
}
.train-card.moving  { border-top: 3px solid var(--southern-green); }
.train-card.stopped { border-top: 3px solid #16a34a; }

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface2);
}
.card-train-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text2);
}
.card-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.badge-moving  { background: #dcfce7; color: #15803d; }
.badge-stopped { background: #dcfce7; color: #166534; }
.badge-idle    { background: #f3f4f6; color: #6b7280; }

.card-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.card-route {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}
.route-origin { color: var(--muted); }
.route-arrow  { color: var(--dimmed); font-size: 10px; }
.route-dest   { font-weight: 700; color: var(--text); }

.card-stats {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
}
.stat-item  { display: flex; flex-direction: column; gap: 3px; }
.stat-label {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.stat-value { font-size: 14px; font-weight: 600; color: var(--text); }

.speed-bar-wrap {
    background: #f0f7f3;
    border-radius: 4px;
    height: 4px;
    overflow: hidden;
}
.speed-bar {
    height: 100%;
    border-radius: 4px;
    background: var(--southern-green);
    transition: width 0.8s ease;
}

.card-next-stop {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--southern-green-tint);
    border: 1px solid #c6e6d4;
    border-radius: 8px;
    padding: 10px 12px;
}
.next-stop-label {
    font-size: 10px;
    color: var(--southern-green);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-weight: 600;
}
.next-stop-name  { font-size: 13px; font-weight: 600; margin-top: 3px; color: var(--text); }
.next-stop-dist  { font-size: 11px; color: var(--muted); }

.card-calling {
    font-size: 11px;
    color: var(--muted);
    line-height: 1.7;
}
.card-calling span { color: var(--text2); }

.card-driver {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
    padding-top: 10px;
    border-top: 1px solid var(--border);
}
.driver-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--surface2);
    border: 1px solid var(--border2);
    object-fit: cover;
}
.driver-name { color: var(--text2); font-weight: 500; }

/* ── DEPARTURE BOARD ─────────────────────────────────────────── */
.dep-board {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.dep-header {
    display: grid;
    grid-template-columns: 80px 1fr 140px 100px 160px 120px;
    gap: 16px;
    padding: 10px 20px;
    background: var(--southern-green);
    border-bottom: none;
    font-size: 11px;
    font-weight: 600;
    color: rgba(255,255,255,0.8);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.dep-row {
    display: grid;
    grid-template-columns: 80px 1fr 140px 100px 160px 120px;
    gap: 16px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    align-items: center;
    transition: background 0.15s;
    cursor: pointer;
}
.dep-row:last-child { border-bottom: none; }
.dep-row:hover      { background: var(--southern-green-tint); }

.dep-time   { font-family: monospace; font-size: 14px; font-weight: 700; color: var(--text); }
.dep-dest   { font-weight: 600; color: var(--text); }
.dep-driver { color: var(--muted); font-size: 13px; }
.dep-speed  { font-family: monospace; color: var(--text2); }

.dep-status {
    font-size: 10px;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 20px;
    display: inline-block;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.status-moving  { background: #dcfce7; color: #15803d; }
.status-stopped { background: #dcfce7; color: #166534; }

/* ── MAP PAGE ────────────────────────────────────────────────── */
.map-page {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 58px);
}
.map-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.map-toolbar-left  { display: flex; gap: 8px; }
.map-toolbar-right { font-size: 12px; color: var(--muted); }

.map-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text2);
    font-size: 12px;
    font-weight: 500;
    padding: 5px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s, border-color 0.15s;
    font-family: var(--font);
}
.map-btn:hover {
    background: var(--southern-green-tint);
    border-color: var(--southern-green);
    color: var(--southern-green);
}

.map-info { font-size: 12px; color: var(--muted); }

.map-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #e8f0eb;
}
#railMap {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
}
#railMap:active { cursor: grabbing; }

.map-tooltip {
    position: absolute;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 12px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 10;
    min-width: 200px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}
.map-tooltip.visible   { opacity: 1; }
.map-tooltip-name      {
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 8px;
    color: var(--text);
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}
.map-tooltip-row {
    color: var(--muted);
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
}
.map-tooltip-row span { color: var(--text2); font-weight: 500; text-align: right; }

.map-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    padding: 10px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
}
.legend-line {
    width: 24px;
    height: 3px;
    border-radius: 2px;
}
.legend-train-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--southern-green);
    border: 2px solid white;
    box-shadow: 0 0 0 1px var(--southern-green);
}

/* ── RESPONSIVE ──────────────────────────────────────────────── */
@media (max-width: 900px) {
    .summary-bar { grid-template-columns: repeat(2, 1fr); }
    .dep-header, .dep-row {
        grid-template-columns: 70px 1fr 80px 90px;
    }
    .dep-header > *:nth-child(3),
    .dep-header > *:nth-child(5),
    .dep-row    > *:nth-child(3),
    .dep-row    > *:nth-child(5) { display: none; }
}
@media (max-width: 600px) {
    .summary-bar { grid-template-columns: 1fr 1fr; }
    .dashboard   { padding: 16px; }
}