/* ── Page header ─────────────────────────────────────────────── */
#page-header {
    background: var(--c-primary);
    color: #fff;
    padding: 8px 12px;
    margin: -12px -12px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: sticky;
    top: 0;
    z-index: 200;
    box-shadow: 0 2px 6px rgba(0,0,0,0.18);
}

#header-row1 {
    display: flex;
    align-items: center;
    gap: 8px;
}

#header-row2 {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

#back-btn {
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    font-size: 1.4rem;
    line-height: 1;
    flex: 0 0 auto;
}

#back-btn:hover { color: #fff; }

#page-title {
    font-size: var(--fs-lg);
    font-weight: 700;
    flex: 1;
}

#road-select {
    padding: 4px 8px;
    border-radius: 6px;
    border: none;
    font-size: var(--fs-sm);
    background: rgba(255,255,255,0.92);
    color: var(--c-text);
    cursor: pointer;
    flex: 0 0 auto;
}

#dir-tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    flex: 0 0 auto;
}

#header-update-time {
    margin-left: auto;
    font-size: var(--fs-xs);
    color: rgba(255,255,255,0.65);
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.dir-btn {
    padding: 4px 10px;
    border: 1.5px solid rgba(255,255,255,0.55);
    border-radius: 6px;
    background: transparent;
    color: #fff;
    cursor: pointer;
    font-size: var(--fs-sm);
    line-height: 1.4;
}

.dir-btn.active {
    background: rgba(255,255,255,0.22);
    border-color: #fff;
    font-weight: 600;
}

#refresh-btn {
    padding: 4px 9px;
    border: 1.5px solid rgba(255,255,255,0.55);
    border-radius: 6px;
    background: transparent;
    color: #fff;
    cursor: pointer;
    font-size: var(--fs-base);
    line-height: 1;
    flex: 0 0 auto;
}

#refresh-btn:active { background: rgba(255,255,255,0.18); }

@keyframes fw-spin { to { transform: rotate(360deg); } }
#refresh-btn.loading { animation: fw-spin 0.75s linear infinite; opacity: 0.65; }

#countdown {
    font-size: var(--fs-xs);
    color: rgba(255,255,255,0.75);
    flex: 0 0 auto;
}

/* ── Sub-bar ─────────────────────────────────────────────────── */
#sub-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
    margin-bottom: 10px;
    font-size: var(--fs-xs);
    color: var(--c-muted);
}

#legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 10px;
    align-items: center;
}

.lg-item {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.lg-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex: 0 0 auto;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    white-space: nowrap;
}

#update-time-wrap {
    margin-left: auto;
    white-space: nowrap;
}

/* ── Status ──────────────────────────────────────────────────── */
#status {
    text-align: center;
    padding: 16px;
    color: var(--c-muted);
    font-size: var(--fs-sm);
    min-height: 0;
}

#status:empty { display: none; }

/* ── Table ───────────────────────────────────────────────────── */
#table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

thead th {
    padding: 6px 8px;
    font-size: var(--fs-sm);
    font-weight: 600;
    white-space: nowrap;
}

.col-km    { width: 74px; }
.col-lanes { text-align: left; }

tfoot td {
    font-size: var(--fs-xs);
    padding: 5px 8px;
    color: var(--c-muted);
}

/* Both-directions mode: direction header row */
tr.dir-header td {
    background: var(--c-primary-dk);
    color: #fff;
    font-size: var(--fs-sm);
    font-weight: 600;
    padding: 6px 8px;
    text-align: center;
    letter-spacing: 0.5px;
}

/* Interchange milestone separator */
tr.section-sep td {
    background: var(--c-bg);
    color: var(--c-primary-dk);
    font-size: var(--fs-xs);
    font-weight: 600;
    padding: 5px 8px;
    text-align: center;
    border-top: 1px solid var(--c-primary-lt);
    border-bottom: 1px solid var(--c-primary-lt);
    letter-spacing: 0.3px;
}

/* Decorative lines flanking the interchange name */
tr.section-sep td::before,
tr.section-sep td::after {
    content: '';
    display: inline-block;
    width: 18%;
    height: 1px;
    background: var(--c-border);
    vertical-align: middle;
    margin: 0 8px;
}

/* Data rows */
td.mile {
    font-size: var(--fs-xs);
    color: var(--c-muted);
    white-space: nowrap;
    padding: 3px 6px;
    font-variant-numeric: tabular-nums;
    vertical-align: middle;
}

td.lanes {
    padding: 3px 6px;
    vertical-align: middle;
    text-align: left;
    border-bottom: none; /* row-level border used instead; cell border would sit at flex-content bottom, not row bottom */
}

/* Row separator for data rows — <tr> border is always at row bottom regardless of cell heights */
#vd-table tbody tr {
    border-bottom: 1px solid var(--c-border);
}

/* Side-by-side mode: right-align the inline-flex wrapper so chips sit near the km column */
td.lanes.dir-left  { text-align: right; }

/* Flex layout lives inside a wrapper so the td stays a proper table-cell and stretches to row height */
.lanes-inner {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
}

.lanes-inner.dir-left {
    flex-direction: row-reverse;
}

.col-dir-a { text-align: right; }
.col-dir-b { text-align: left; }

/* ── Lane chips ──────────────────────────────────────────────── */
.lane-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    min-height: 22px;
    padding: 2px 4px;
    border-radius: 4px;
    font-size: var(--fs-xs);
    font-weight: 600;
    margin: 1px 2px;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.3px;
}

.chip-occ {
    display: block;
    font-size: var(--fs-2xs);
    font-weight: 400;
    line-height: 1.2;
    letter-spacing: 0;
    opacity: 0.85;
}

/* Speed tiers */
.spd-free { background: #22c55e; color: #fff; }   /* ≥80 km/h */
.spd-ok   { background: #84cc16; color: #fff; }   /* 60–79    */
.spd-slow { background: #f97316; color: #fff; }   /* 40–59    */
.spd-jam  { background: #ef4444; color: #fff; }   /* <40      */
.spd-none { background: #e2e8f0; color: #94a3b8; } /* no data  */
.spd-err  { background: #fee2e2; color: #ef4444; } /* sensor error */

/* ── Co-located sensor separator ────────────────────────────── */
.lane-sep {
    width: 1px;
    height: 20px;
    align-self: center;
    background: var(--c-border);
    margin: 0 4px;
    flex: 0 0 auto;
}

/* ── Speed limit badge ───────────────────────────────────────── */
.speed-limit {
    margin-left: 8px;
    font-size: var(--fs-xs);
    font-weight: 400;
    color: var(--c-muted);
    background: var(--c-border);
    padding: 1px 6px;
    border-radius: 10px;
    vertical-align: middle;
    letter-spacing: 0;
}


/* ── CMS message row ─────────────────────────────────────────── */
tr.cms-row td {
    background: #fefce8;
    color: #713f12;
    font-size: var(--fs-xs);
    padding: 4px 8px;
    border-top: 1px solid #fef08a;
    border-bottom: 1px solid #fef08a;
}

td.cms-msg           { font-weight: 500; text-align: left; }
td.cms-msg.dir-left  { text-align: right; }

/* ── Locate button ───────────────────────────────────────────── */
#locate-btn {
    background: none;
    border: none;
    color: var(--c-muted);
    cursor: pointer;
    font-size: var(--fs-xs);
    padding: 0;
    white-space: nowrap;
}
#locate-btn:hover { color: var(--c-primary-dk); }
#locate-btn.active { color: var(--c-primary-dk); font-weight: 600; }
@keyframes fw-pulse { 0%,100% { opacity:1; } 50% { opacity:0.35; } }
#locate-btn.loading { animation: fw-pulse 1s ease-in-out infinite; pointer-events: none; }

/* ── User location row ───────────────────────────────────────── */
tr.user-location-sep td {
    background: var(--c-primary-lt);
    color: var(--c-primary-dk);
    font-size: var(--fs-xs);
    font-weight: 600;
    text-align: center;
    padding: 5px 8px;
    border-top: 2px solid var(--c-primary);
    border-bottom: 2px solid var(--c-primary);
}

/* ── ETag link button ────────────────────────────────────────── */
.etag-link-btn {
    display: flex;
    align-items: center;
    color: var(--c-primary-dk);
    font-size: var(--fs-xs);
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    padding: 2px 0;
}

.etag-link-btn:hover { text-decoration: underline; }

/* ── CCTV link ───────────────────────────────────────────────── */
.cctv-link {
    display: inline-block;
    margin-left: 4px;
    font-size: var(--fs-sm);
    text-decoration: none;
    vertical-align: middle;
    line-height: 1;
    opacity: 0.75;
}
.cctv-link:hover { opacity: 1; }

/* ── Feature toggle hide classes ────────────────────────────── */
#vd-table.hide-speedlimit .speed-limit { display: none; }
#vd-table.hide-occupancy  .chip-occ    { display: none; }
#vd-table.hide-cms        .cms-row     { display: none; }
#vd-table.hide-cctv       .cctv-link   { display: none; }

/* Mobile: tighten chips on narrow screens */
@media (max-width: 480px) {
    .lane-chip { min-width: 28px; min-height: 20px; font-size: var(--fs-xs); margin: 1px; }
    td.mile    { font-size: var(--fs-xs); width: 62px; }
}

/* Desktop: fix header bleed + constrain content width */
@media (min-width: 700px) {
    #page-header {
        margin: -20px -20px 12px;
        padding: 10px 20px;
    }
    #page-body {
        max-width: 1100px;
        margin: 0 auto;
    }
}
