/* ── Page header (shared pattern with freeway) ───────────────── */
#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; }

#map-link {
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    font-size: var(--fs-sm);
    font-weight: 600;
    border: 1.5px solid rgba(255,255,255,0.45);
    border-radius: 6px;
    padding: 4px 9px;
    line-height: 1.4;
    flex: 0 0 auto;
    white-space: nowrap;
}
#map-link:hover { color: #fff; border-color: #fff; }

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

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

/* ── Direction section ───────────────────────────────────────── */
.dir-section {
    margin-bottom: 14px;
    border: 1px solid var(--c-border);
    border-radius: 10px;
    overflow: hidden;
}

.dir-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--c-bg);
    border-bottom: 1px solid var(--c-border);
}

.dir-label {
    font-weight: 700;
    font-size: var(--fs-base);
    color: var(--c-primary-dk);
}

.total-time {
    font-size: var(--fs-sm);
    color: var(--c-muted);
}

/* ── Single-direction timeline rows ──────────────────────────── */
.dir-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px 10px 14px;
    border-left: 4px solid var(--c-border);
    gap: 12px;
}

.dir-row.spd-free { border-left-color: #22c55e; }
.dir-row.spd-ok   { border-left-color: #84cc16; }
.dir-row.spd-slow { border-left-color: #f97316; }
.dir-row.spd-jam  { border-left-color: #ef4444; }

.dir-row-left  { flex: 1; }
.dir-row-right { text-align: right; flex-shrink: 0; }

.dir-row-meta {
    font-size: var(--fs-xs);
    color: var(--c-muted);
    font-variant-numeric: tabular-nums;
}

.dir-row-time {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--c-muted);
    font-variant-numeric: tabular-nums;
}

.dir-row.spd-free .dir-row-time { color: #15803d; }
.dir-row.spd-ok   .dir-row-time { color: #4d7c0f; }
.dir-row.spd-slow .dir-row-time { color: #c2410c; }
.dir-row.spd-jam  .dir-row-time { color: #b91c1c; }

/* ── Footer note ─────────────────────────────────────────────── */
#footer-note {
    text-align: center;
    font-size: var(--fs-xs);
    color: var(--c-muted);
    margin: 6px 0 12px;
}

/* ── Desktop ─────────────────────────────────────────────────── */
@media (min-width: 700px) {
    #page-header {
        margin: -20px -20px 12px;
        padding: 10px 20px;
    }
    #page-body {
        max-width: 640px;
        margin: 0 auto;
    }
    #page-body.both {
        max-width: 960px;
    }
}

/* ── Merged N/S section ──────────────────────────────────────── */
.merged-section {
    border: 1px solid var(--c-border);
    border-radius: 10px;
    /* overflow: hidden removed so .merged-summary can be position:sticky */
    margin-bottom: 14px;
}
/* Manually round the corners that overflow:hidden used to clip */
.merged-section > :first-child { border-radius: 10px 10px 0 0; }
.merged-section > :last-child  { border-radius: 0 0 10px 10px; }

.merged-summary {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 10px 16px;
    background: var(--c-bg);
    border-bottom: 1px solid var(--c-border);
    position: sticky;
    top: 0; /* overridden by JS to sit below #page-header */
    z-index: 50;
}

.merge-dir {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.merge-dir-right { align-items: flex-end; text-align: right; }

/* ── Timeline interchange nodes ──────────────────────────────── */
.timeline-node {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    background: var(--c-bg);
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--c-text);
    border-bottom: 1px solid var(--c-border);
}
.timeline-node::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--c-primary);
    flex-shrink: 0;
}

/* ── Segment rows (N time | S time) ─────────────────────────── */
.merged-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: center;
    border-left: 4px solid var(--c-border);
    border-right: 4px solid var(--c-border);
    padding: 10px 14px;
    gap: 8px;
}
.merged-row + .timeline-node { border-top: none; }

.merged-row.spd-a-free { border-left-color:  #22c55e; }
.merged-row.spd-a-ok   { border-left-color:  #84cc16; }
.merged-row.spd-a-slow { border-left-color:  #f97316; }
.merged-row.spd-a-jam  { border-left-color:  #ef4444; }
.merged-row.spd-b-free { border-right-color: #22c55e; }
.merged-row.spd-b-ok   { border-right-color: #84cc16; }
.merged-row.spd-b-slow { border-right-color: #f97316; }
.merged-row.spd-b-jam  { border-right-color: #ef4444; }

/* One-direction rows: gantry coverage gap on one side (not a live-data outage) */
.merged-row.one-dir { background: var(--c-bg); }

.merge-cell { display: flex; flex-direction: column; }
.merge-cell-a { align-items: flex-end;   text-align: right; }
.merge-cell-b { align-items: flex-start; text-align: left; }

.merge-time {
    font-size: 1.3rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--c-muted);
    font-variant-numeric: tabular-nums;
}
.merge-cell-a.spd-free .merge-time,
.merge-cell-b.spd-free .merge-time { color: #15803d; }
.merge-cell-a.spd-ok   .merge-time,
.merge-cell-b.spd-ok   .merge-time { color: #4d7c0f; }
.merge-cell-a.spd-slow .merge-time,
.merge-cell-b.spd-slow .merge-time { color: #c2410c; }
.merge-cell-a.spd-jam  .merge-time,
.merge-cell-b.spd-jam  .merge-time { color: #b91c1c; }

.merge-spd {
    font-size: var(--fs-xs);
    color: var(--c-muted);
    margin-top: 2px;
    font-variant-numeric: tabular-nums;
}

/* ── No-coverage gap indicator ───────────────────────────────────── */
.no-coverage-row {
    height: 20px;
    display: flex;
    align-items: center;
    padding: 0 16px;
    background: var(--c-bg);
    border-top: 1px dashed var(--c-border);
    border-bottom: 1px dashed var(--c-border);
    margin: 0;
}
.no-coverage-row::after {
    content: '此路段無雙向 ETag 資料';
    display: block;
    width: 100%;
    text-align: center;
    font-size: var(--fs-xs);
    color: var(--c-muted);
    opacity: 0.7;
}

@media (max-width: 480px) {
    .merged-row { padding: 8px 12px; }
    .merge-time  { font-size: 1.1rem; }
}
