/* --- 1. The Section Container --- */
#current {
    max-width: 80em;       /* Cap it so it doesn't get absurdly wide */
    margin: 1.5rem;     /* Center the whole section */
}

/* --- 2. The Table Wrapper (Surface) --- */
#current table {
    display: block;        /* Nuke display: table */
    width: 100%;
    background: var(--theme-bg); 
    border-radius: 12px;
    border: 1px solid var(--theme-fg_muted);
    overflow: hidden;
    box-shadow: 10px 10px 5px 0px color-mix(in srgb, var(--obs-ink) 30%, transparent);
}

/* --- 3. The Responsive Grid Logic --- */
#current tbody {
    display: grid;
    /* This creates the 'side-by-side' columns when space allows */
    grid-template-columns: repeat(auto-fit, minmax(30em, 1fr));
    gap: 0 20px;           /* Horizontal gap between columns */
    padding: 10px;
}

/* --- 4. The Row as a Data Card --- */
#current tr {
    display: flex;         /* Use Flex to align the 4 items in a row */
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid var(--theme-fg_muted);
    background: transparent;
    transition: background 0.2s ease;
}

#current tr:hover {
    background: var(--theme-bg_accent);
}

/* --- 5. Internal Column Alignment (The 4 Cells) --- */

#current th, #current td {
    white-space: nowrap; 
    min-height: 3ex;
}

/* Label (Seeing, Wind, etc) */

#current th {
    font-weight: 700;
    color: var(--theme-fg_muted);
    min-width: 11em;
    width: 10em;
    text-align: left;
}

/* Value (The Data) */
#current td:nth-child(2) {
    flex: 1;
    text-align: right;
    color: var(--theme-fg);
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-weight: 700;
    font-size: 1rem;
    min-width: 10em;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    overflow: visible;
    /* long values ("Physical roofs" mid-transition, several "Reasons")
       wrap instead of overlapping the neighbouring cells; short ones
       never do */
    white-space: normal;
}

/* Unit (%, m/s) */
#current td:nth-child(3) {
    width: 6.5em;
    min-width: 6.5em;
    color: var(--theme-fg_muted);
    font-size: 0.9rem;
    padding-left: 8px;
    text-align: left;
}

/* Trend (Arrow) */
#current td:nth-child(4) {
    width: 2em;
    min-width: 2em;
    text-align: center;
    font-size: 1.1rem;
    color: var(--theme-fg_muted);
}

#current tr:first-child td:nth-child(1) {
    color: var(--theme-fg_accent); 
}

/* --- 6. Closing limits, freshness and tooltips --- */
/* A dot beside a reading that has a real closing limit (limitRow() in
   current.js); state colours, because they mean state. */
.limit-dot {
    display: inline-block;
    width: 0.55em;
    height: 0.55em;
    border-radius: 50%;
    margin-left: 8px;
    flex-shrink: 0;
}
.limit-dot.ok   { background: var(--obs-good); }   /* within the limit      */
.limit-dot.warn { background: var(--obs-warn); }   /* lagging, not yet over */
.limit-dot.bad  { background: var(--obs-bad); }    /* past the limit        */
.limit-dot.gap  { background: var(--obs-mute); }   /* no data               */

/* "45s ago" beside the Date (UTC) row's freshness dot */
.freshness-age {
    margin-left: 6px;
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--theme-fg_muted);
}

/* A :hover tooltip, not title="": the table is replaced every 30 s and a
   native title needs a fresh mouseenter, so it never showed under a still
   mouse. Touch never hovers, so current.js toggles .tooltip-active on tap.
   Unscoped so the timeline's segments share it. */
[data-tooltip] {
    cursor: help;
    position: relative;
}
[data-tooltip]:hover::after,
[data-tooltip].tooltip-active::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 15px;
    margin-bottom: 6px;
    background: var(--obs-ink);
    color: var(--obs-paper);
    border: 1px solid var(--obs-mute);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    white-space: nowrap;
    box-shadow: 0 4px 10px color-mix(in srgb, var(--obs-ink) 40%, transparent);
    pointer-events: none;
    z-index: 20;
}

/* --- 7. The expected status, as a banner across the grid --- */
#current tr.status-row {
    grid-column: 1 / -1;
    justify-content: center;
    gap: 12px;
}
#current tr.status-row th {
    width: auto;
    min-width: 0;
    text-align: center;
    font-size: 1.3rem;
    color: var(--theme-fg);
}
#current tr.status-row td:nth-child(2) {
    flex: 0 1 auto;
    justify-content: center;
    font-size: 1.3rem;
    color: var(--theme-fg);   /* not the accent: a green "Closed" reads as good */
}
#current tr.status-row td:nth-child(3),
#current tr.status-row td:nth-child(4),
#current tr.status-row td:nth-child(5) {
    display: none;
}

/* the disclaimer sits beside #current-table, so the 30 s refresh keeps it */
#current .limits-note {
    margin: 10px 0 0;
    font-size: 0.78rem;
    color: var(--obs-mute);
    text-align: center;
}

/* --- 8. Physical roof status, the last 48 h --- */
/* the page's cards stack from the top instead of spreading over the
   height of <main> (a flex row that wraps, style.css) */
main:has(> #status-timeline) { align-content: flex-start; }

/* the same card as the table above: the ink, a hairline, the shadow */
#status-timeline {
    align-self: flex-start;
    max-width: 80em;
    width: calc(100% - 3rem);
    margin: 1.5rem;
    padding: 12px 15px;
    background: var(--theme-bg);
    color: var(--theme-fg);
    border-radius: 12px;
    border: 1px solid var(--theme-fg_muted);
    box-shadow: 10px 10px 5px 0px color-mix(in srgb, var(--obs-ink) 30%, transparent);
}
#status-timeline h3 {
    margin: 0 0 8px;
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--theme-fg_muted);
}

/* every bar, the aggregate and the per-roof ones, shares one grid so the
   lanes line up with the strip and the axis under them all */
.timeline-row {
    display: grid;
    grid-template-columns: 2.4rem minmax(0, 1fr);
    align-items: center;
    column-gap: 6px;
}
.timeline-row-label {
    font-size: 0.7rem;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    color: var(--theme-fg_muted);
    text-align: right;
    white-space: nowrap;
}
.timeline-rows { display: flex; flex-direction: column; gap: 3px; margin-top: 6px; }
.timeline-rows .timeline-row { min-height: 12px; }
.timeline-lanes {
    display: flex;
    flex-direction: column;
    gap: 1px;
    width: 100%;
    border-radius: 3px;
    overflow: hidden;
    border: 1px solid var(--obs-mute);
    background: var(--theme-bg_muted);
}
.timeline-lane { display: flex; width: 100%; height: 10px; }
.timeline-lanes.split .timeline-lane { height: 6px; }

.timeline-strip {
    display: flex;
    width: 100%;
    height: 28px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--obs-mute);
    background: var(--theme-bg_muted);
}
.timeline-segment {
    height: 100%;
    min-width: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.timeline-segment.open   { background: var(--obs-good); }
.timeline-segment.closed { background: var(--obs-bad); }
.timeline-segment.gap    { background: var(--obs-mute); }

.timeline-label {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--obs-paper);
    text-shadow: 0 1px 2px color-mix(in srgb, var(--obs-ink) 55%, transparent);
    white-space: nowrap;
    padding: 0 4px;
}

/* The ticks under the strip: .timeline-tick is an unshifted anchor at its
   time, .tick-mark stays centred on it, and .tick-label leans left, centre
   or right on its own so text at either edge stays on the strip
   (renderAxis() in status_timeline.js says why they cannot share one
   transform). */
.timeline-axis {
    position: relative;
    height: 32px;
    margin-top: 2px;
}
.timeline-tick {
    position: absolute;
    top: 0;
}
.tick-mark {
    position: absolute;
    top: 0;
    left: 0;
    transform: translateX(-50%);
    width: 1px;
    height: 6px;
    background: var(--obs-mute);
}
.tick-label {
    position: absolute;
    top: 9px;
    left: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.3;
    font-size: 0.68rem;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    color: var(--theme-fg_muted);
    white-space: nowrap;
}
.tick-date {
    font-size: 0.6rem;
    color: var(--obs-mute);
}
.tick-label.align-left   { transform: translateX(0);     align-items: flex-start; }
.tick-label.align-center { transform: translateX(-50%);  align-items: center; }
.tick-label.align-right  { transform: translateX(-100%); align-items: flex-end; }

.timeline-legend {
    display: flex;
    gap: 18px;
    margin-top: 8px;
    font-size: 0.8rem;
    color: var(--theme-fg_muted);
}
.timeline-legend .limit-dot {
    margin-left: 0;
    margin-right: 6px;
}
.timeline-loading {
    color: var(--theme-fg_muted);
    font-size: 0.85rem;
    padding: 4px 8px;
}

/* --- 9. A phone --- */
/* the four cells of a row (label, value, unit, trend) asked for 29 em and
   a phone has about 22: the label and the unit give way, the value keeps
   its width, and the units wrap under the value if they must */
@media screen and (max-width: 600px) {
    #current { margin: 0.75rem; }
    /* one column that can shrink: the 30 em minimum of the two-column
       grid was wider than the phone and pushed the values off the card */
    #current tbody { grid-template-columns: minmax(0, 1fr); padding: 6px; }
    #current tr { padding: 10px 8px; }
    #current th { min-width: 6.5em; width: 6.5em; font-size: 0.9rem; white-space: normal; }
    #current td:nth-child(2) { min-width: 6em; font-size: 0.95rem; }
    #current td:nth-child(3) { width: 3.5em; min-width: 3.5em; font-size: 0.8rem; padding-left: 4px; white-space: normal; }
    #current td:nth-child(4) { width: 1.4em; min-width: 1.4em; }
    #status-timeline { margin: 0.75rem; width: calc(100% - 1.5rem); padding: 10px 8px; }
    .timeline-row { grid-template-columns: 1.8rem minmax(0, 1fr); }
    .timeline-label { font-size: 0.6rem; }
}
