/*
 * panels.css
 *
 * The dashboard panels: where they sit, what they are made of, and how the
 * charts inside them are painted. Loaded after globe.css, which is where the
 * palette, the two typefaces and the globe stage itself are defined.
 *
 * The layout has exactly two states, and the screen chooses between them:
 *
 *   Wider than it is high   three panels down the left edge and three down the
 *                           right, each a third of the page wide and a third of
 *                           it high, over the outer thirds of the page.
 *
 *   Higher than it is wide  one strip along the bottom, a third of the page
 *                           high, scrolling left and right through all six.
 *
 * Nothing in JavaScript measures the window to decide that. The two aspect
 * ratio media queries below are the whole mechanism.
 *
 * The panels float over the globe rather than taking space from it, and nothing
 * here touches --globe-stage-width or --globe-stage-height. That is deliberate.
 * globe.js refits the planet to its container, so handing it a third of the page
 * would take the planet from 495 pixels across to 293 on a 1600 by 900 screen:
 * the Panels button would be a zoom control as well as a switch, and it would
 * throw away whatever zoom had been set by hand. Left alone, toggling the panels
 * changes nothing whatsoever about the globe's size. In portrait it is lifted,
 * which is a move and not a resize; see the rule for that below.
 *
 * What that costs is on landscape screens near square. The middle column is a
 * third of the page wide and the planet is 0.55 of the page's tighter dimension
 * across, so a screen wider than about 1.65:1 has the planet sitting inside that
 * column with room to spare, and anything squarer has its edge pass behind the
 * rails. A planet partly behind a panel is a dashboard; a planet that changes
 * size when a button is pressed is a bug.
 *
 * Portrait has no such trade, because of the lift. The planet is 0.55 of the
 * width there and the room above the strip is two thirds of the height, and the
 * width is the smaller of the two on any portrait screen, so it always clears.
 *
 * The panels are also switched off entirely by the Panels button, which puts
 * data-panels="off" on the body. In that state nothing here applies at all.
 */

/*
 * The status ramp for the choke point panel. Three steps, ordered by severity,
 * and separate from anything else on the page: a status colour means a state
 * and is never reused to tell one series apart from another.
 *
 * The pair that decides whether a ramp like this works is amber against green,
 * because that is the one red-green colour blindness collapses first. These
 * three were checked rather than picked: the closest pair separates by dE 8.0
 * under protanopia, and all three clear 3:1 contrast against the panel
 * background. Even so, every row that uses them also writes its state out as a
 * word, so the colour is the second thing carrying the reading rather than the
 * only thing.
 */
:root {
    --status-clear: #17c96b;
    --status-busy: #ffcf5c;
    --status-critical: #ff5555;
}

/* ------------------------------------------------------------------
 * Layout: portrait, and any screen that is not wider than it is high
 *
 * This is the base state, matching the resume's own mobile-first
 * stylesheet: the narrow layout is written plainly and the wide one is
 * the media query.
 * ------------------------------------------------------------------ */

/*
 * The strip covers the bottom third, so the middle of the window is no longer
 * the middle of what can be seen: a planet centred in the window sits with its
 * lower edge against the top of the strip. The stage is lifted to put the
 * planet back in the space that is left.
 *
 * A sixth of the page would centre it exactly in that space, at a third of the
 * way down. It sits a quarter of the way up instead, which is three quarters of
 * that: high enough to be clear of the strip and out of the way of the control
 * bar, and low enough not to look like it is being pushed off the top.
 *
 * This is a move and not a resize. The stage keeps its full height, so the
 * planet keeps its size and whatever zoom was set by hand, which is the whole
 * point of the panels not touching the stage variables. Relative positioning
 * rather than a negative margin, so there is no chance of the margin collapsing
 * through the body and taking the rest of the page with it.
 */
body[data-panels="on"] #globe-stage {
    top: -12.5vh;
}

@supports (height: 100dvh) {
    body[data-panels="on"] #globe-stage {
        top: -12.5dvh;
    }
}

#panel-region {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 33.3333vh;
    z-index: 1;

    display: flex;
    flex-direction: row;
    gap: 8px;
    padding: 8px;

    /*
     * The strip scrolls sideways through all six panels. Snapping makes a flick
     * land on a panel rather than halfway between two, which on a tile carrying
     * a chart is the difference between reading it and nearly reading it.
     */
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;

    /*
     * The strip can be thrown with the mouse as well as with a finger, so it
     * says so. panels.js handles the drag itself, since a mouse has no native
     * way to drag a scroll container, and swaps this for the closed hand while
     * one is in progress.
     */
    cursor: grab;
}

#panel-region.is-dragging {
    cursor: grabbing;

    /*
     * A drag across a chart would otherwise sweep up the text in it and leave
     * the panel highlighted. Applied only while dragging, so text in a panel
     * can still be selected the rest of the time.
     */
    -webkit-user-select: none;
    user-select: none;
}

@supports (height: 100dvh) {
    #panel-region {
        height: 33.3333dvh;
    }
}

body[data-panels="off"] #panel-region {
    display: none;
}

#panel-region > .panel {
    /*
     * Not quite the full width: the sliver of the next panel showing past the
     * right edge is what says the strip scrolls at all. A panel that exactly
     * filled the screen would look like the only one there is.
     */
    flex: 0 0 calc(100% - 46px);
    scroll-snap-align: start;
}

/*
 * A thin scrollbar in the page's own greens rather than the platform's default
 * grey slab, which on a black page reads as a piece of another application.
 */
#panel-region {
    scrollbar-width: thin;
    scrollbar-color: var(--accent-dim) transparent;
}

#panel-region::-webkit-scrollbar {
    height: 6px;
}

#panel-region::-webkit-scrollbar-track {
    background: transparent;
}

#panel-region::-webkit-scrollbar-thumb {
    background: var(--accent-dim);
    border-radius: 3px;
}

/* ------------------------------------------------------------------
 * Layout: screens wider than they are high
 * ------------------------------------------------------------------ */

@media (min-aspect-ratio: 1/1) {

    /*
     * Nothing is covering the bottom of the page in this layout, so the planet
     * goes back to the middle of the window, which is also the middle of the
     * gap between the two rails.
     */
    body[data-panels="on"] #globe-stage {
        top: 0;
    }

    /*
     * The control bar is a third of the page wide and sits over the same middle
     * column the globe does, so it is squared off with the rails either side of
     * it: 8px is the panel region's padding, and therefore the distance from the
     * top of the page to the top of the first panel in each rail. The bar's top
     * edge lands on the same line.
     *
     * It is set here rather than in globe.css because this is the file that
     * knows what the panels are doing. Both rules name the same element at the
     * same specificity and this file is loaded second, so this one wins.
     */
    #globe-controls {
        top: 8px;
    }

    #panel-region {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        height: auto;

        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        grid-template-rows: 1fr 1fr 1fr;
        gap: 8px;
        padding: 8px;
        overflow: visible;

        /*
         * Nothing scrolls in the rail layout: the six panels are a grid that
         * fits the page exactly. The grab cursor from the strip would be a
         * promise there is nothing behind.
         */
        cursor: default;

        /*
         * The grid covers the whole page so that its outer columns land exactly
         * on the outer thirds, which means the empty middle column is lying
         * over the globe. Letting it take pointer events there would kill
         * dragging and zooming across the entire planet, so the region takes
         * none and the panels take their own back.
         */
        pointer-events: none;
    }

    #panel-region > .panel {
        pointer-events: auto;
        flex: none;
    }

    /*
     * Panels 1 to 3 fill the left column top to bottom, 4 to 6 the right. The
     * placement is by position in the source order, so reordering
     * DASHBOARD_PANELS reorders the rails and nothing here has to change.
     */
    #panel-region > .panel:nth-child(1) {
        grid-column: 1;
        grid-row: 1;
    }

    #panel-region > .panel:nth-child(2) {
        grid-column: 1;
        grid-row: 2;
    }

    #panel-region > .panel:nth-child(3) {
        grid-column: 1;
        grid-row: 3;
    }

    #panel-region > .panel:nth-child(4) {
        grid-column: 3;
        grid-row: 1;
    }

    #panel-region > .panel:nth-child(5) {
        grid-column: 3;
        grid-row: 2;
    }

    #panel-region > .panel:nth-child(6) {
        grid-column: 3;
        grid-row: 3;
    }

}

/* ------------------------------------------------------------------
 * The panel itself
 *
 * The resume's document panel is a dark warm panel colour inside a heavy green
 * rule, with a lighter elevated strip for its chrome and a VT323 tag naming the
 * section. A panel here is that shape at tile size: the same two backgrounds,
 * the same tag face, and a quieter border, because six of them at the resume's
 * 4px bright green would be six rectangles competing with the planet between
 * them.
 * ------------------------------------------------------------------ */

.panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;

    background: var(--bg-panel);
    border: 2px solid var(--accent-dim);
    border-radius: 4px;
    font-family: var(--font-mono);
    color: var(--text-primary);
}

.panel-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 5px 10px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-subtle);
}

/*
 * The muted text on a panel - the index in the head, the caption under a
 * headline reading, the source line in the foot - is the secondary text colour
 * held back with opacity, rather than the palette's dim green.
 *
 * The resume uses that dim green for its own muted text and it works there, at
 * 16px in a wide column. At 10px on the panel background it lands near 2:1
 * against it, which is under any threshold worth quoting and legible mostly to
 * somebody who already knows what it says.
 */
.panel-index {
    flex: none;
    font-size: 11px;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    opacity: 0.55;
}

.panel-title {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    font-family: var(--font-console);
    font-size: 20px;
    line-height: 1.1;
    letter-spacing: 2px;
    color: var(--accent-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/*
 * SAMPLE against LIVE. Every panel currently says SAMPLE, and it is meant to be
 * read: the numbers below it are invented, and a tile that shows invented
 * numbers without saying so is worse than an empty one.
 */
.panel-status {
    flex: none;
    padding: 1px 6px;
    border: 1px solid var(--accent-dim);
    border-radius: 2px;
    font-size: 9px;
    letter-spacing: 0.14em;
    color: var(--text-secondary);
}

.panel-status[data-status="sample"] {
    border-color: var(--status-busy);
    color: var(--status-busy);
}

.panel-status[data-status="live"] {
    border-color: var(--status-clear);
    color: var(--status-clear);
}

.panel-body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 10px;
    overflow: hidden;
}

.panel-foot {
    flex: none;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    padding: 3px 10px 4px 10px;
    border-top: 1px solid var(--border-subtle);
    font-size: 10px;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    opacity: 0.6;
}

.panel-source,
.panel-note {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.panel-note {
    text-align: right;
}

/* ------------------------------------------------------------------
 * The headline reading at the top of a panel
 * ------------------------------------------------------------------ */

.panel-hero {
    flex: none;
}

.panel-hero-line {
    display: flex;
    align-items: baseline;
    gap: 6px;
    min-width: 0;
}

.panel-hero-value {
    font-size: clamp(22px, 4.2vh, 38px);
    font-weight: 700;
    line-height: 1.05;
    letter-spacing: 0.02em;
    color: var(--text-primary);
}

.panel-hero-unit {
    font-size: 11px;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.panel-hero-caption {
    margin-top: 2px;
    font-size: 10px;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    opacity: 0.6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ------------------------------------------------------------------
 * Indicator rows: a reading and its sparkline, side by side
 *
 * Two of these in the greenhouse gas panel and four in the resource panel, in
 * boxes of the same height, so the rows share the space rather than being sized
 * for either case.
 * ------------------------------------------------------------------ */

.panel-body-rows {
    justify-content: space-around;
}

.indicator-row {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 0;
    flex: 1 1 auto;
}

.indicator-reading {
    flex: 0 0 46%;
    min-width: 0;
}

.indicator-label {
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--accent-primary);
}

.indicator-value-line {
    display: flex;
    align-items: baseline;
    gap: 5px;
    min-width: 0;
}

.indicator-value {
    font-size: clamp(16px, 2.6vh, 24px);
    font-weight: 700;
    line-height: 1.15;
    color: var(--text-primary);
}

.indicator-unit {
    font-size: 10px;
    color: var(--text-secondary);
    white-space: nowrap;
}

/*
 * The delta is plain text in the ordinary muted colour, with no arrow and no
 * red or green on it. Which direction is the bad one is not the dashboard's
 * call to make: a rising wheat price and a rising methane concentration are not
 * the same kind of fact, and colouring both as alarm would be the editorial
 * layer these feeds were chosen for not having.
 */
.indicator-delta {
    margin-top: 1px;
    font-size: 10px;
    letter-spacing: 0.02em;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ------------------------------------------------------------------
 * Chart hosts
 *
 * A host is measured by panels.js and its SVG is built at that exact pixel
 * size, so the box is the chart's authority on how big it is. It is
 * position: relative because the tooltip is placed inside it.
 * ------------------------------------------------------------------ */

.chart-host {
    position: relative;
    min-width: 0;
    min-height: 0;
}

.chart-host-sparkline {
    flex: 1 1 auto;
    align-self: stretch;
    max-height: 64px;
}

.chart-host-plot {
    flex: 1 1 auto;
}

.chart-host svg {
    display: block;
}

/* ------------------------------------------------------------------
 * Chart marks
 *
 * Thin marks, recessive grid, and text in text colours rather than in the
 * colour of the thing it labels.
 * ------------------------------------------------------------------ */

.chart-line {
    fill: none;
    stroke: var(--accent-secondary);
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.chart-area {
    fill: var(--accent-primary);
    fill-opacity: 0.13;
    stroke: none;
}

.chart-end-dot {
    fill: var(--accent-secondary);
}

.chart-grid-line {
    stroke: var(--border-subtle);
    stroke-width: 1;
    stroke-opacity: 0.6;
}

.chart-axis-label {
    fill: var(--text-secondary);
    fill-opacity: 0.75;
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.04em;
}

.chart-bar-value {
    fill: var(--text-primary);
    fill-opacity: 0.9;
}

.chart-bar {
    fill: var(--accent-primary);
    fill-opacity: 0.85;
    transition: fill-opacity 120ms ease;
}

.chart-bar.is-hovered {
    fill: var(--accent-secondary);
    fill-opacity: 1;
}

.chart-crosshair {
    stroke: var(--accent-secondary);
    stroke-width: 1;
    stroke-dasharray: 3 3;
    opacity: 0;
}

.chart-crosshair.is-visible {
    opacity: 0.7;
}

/*
 * The focus dot carries a 2px ring in the panel's own background colour, so it
 * stays a distinct object where it lands on top of the line it belongs to
 * rather than merging into it.
 */
.chart-focus-dot {
    fill: var(--text-primary);
    stroke: var(--bg-panel);
    stroke-width: 2;
    opacity: 0;
}

.chart-focus-dot.is-visible {
    opacity: 1;
}

.chart-tooltip {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 2;
    padding: 3px 7px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.3;
    color: var(--text-primary);
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 100ms ease;
}

.chart-tooltip.is-visible {
    opacity: 1;
}

/* ------------------------------------------------------------------
 * The event ticker
 * ------------------------------------------------------------------ */

.panel-body-ticker {
    gap: 4px;
}

.ticker-list {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
    padding: 0;
    list-style: none;
    overflow: hidden;
}

.ticker-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
    border-bottom: 1px dotted var(--border-subtle);
    font-size: 11px;
}

.ticker-item:last-child {
    border-bottom: none;
}

.ticker-magnitude {
    flex: none;
    width: 38px;
    font-weight: 700;
    color: var(--text-primary);
}

/*
 * The bar is measured against a fixed ceiling of magnitude 8 rather than
 * against the largest event on the list, so a quiet day reads as a quiet day
 * instead of looking exactly like every other day.
 */
.ticker-bar-track {
    flex: none;
    width: 46px;
    height: 6px;
    background: var(--bg-elevated);
    border-radius: 3px;
    overflow: hidden;
}

.ticker-bar-fill {
    display: block;
    height: 100%;
    background: var(--accent-primary);
    border-radius: 0 3px 3px 0;
}

.ticker-place {
    flex: 1 1 auto;
    min-width: 0;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ticker-age {
    flex: none;
    color: var(--text-secondary);
    opacity: 0.6;
    white-space: nowrap;
}

/* ------------------------------------------------------------------
 * Status bars
 * ------------------------------------------------------------------ */

.panel-body-status {
    justify-content: space-between;
    gap: 4px;
}

.status-heading {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
    margin-bottom: 3px;
    font-size: 11px;
}

.status-label {
    flex: 1 1 auto;
    min-width: 0;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-value {
    flex: none;
    font-weight: 700;
    color: var(--text-primary);
}

.status-state {
    flex: none;
    font-size: 9px;
    letter-spacing: 0.12em;
    white-space: nowrap;
}

.status-bar-track {
    height: 8px;
    background: var(--bg-elevated);
    border-radius: 4px;
    overflow: hidden;
}

.status-bar-fill {
    height: 100%;
    border-radius: 0 4px 4px 0;
}

.status-row[data-state="clear"] .status-bar-fill {
    background: var(--status-clear);
}

.status-row[data-state="clear"] .status-state {
    color: var(--status-clear);
}

.status-row[data-state="busy"] .status-bar-fill {
    background: var(--status-busy);
}

.status-row[data-state="busy"] .status-state {
    color: var(--status-busy);
}

.status-row[data-state="congested"] .status-bar-fill {
    background: var(--status-critical);
}

.status-row[data-state="congested"] .status-state {
    color: var(--status-critical);
}

/* ------------------------------------------------------------------
 * Small screens
 *
 * Every size above was set for a panel a third of a 1080 line screen high.
 * On a phone that panel is a good deal shorter, so the chrome comes down to
 * leave the numbers and the charts the room.
 * ------------------------------------------------------------------ */

@media (max-width: 700px) {

    .panel-title {
        font-size: 17px;
        letter-spacing: 1px;
    }

    .panel-head {
        padding: 4px 8px;
    }

    .panel-body {
        padding: 6px 8px;
    }

    .panel-hero-caption,
    .panel-foot {
        font-size: 9px;
    }

    .indicator-reading {
        flex-basis: 44%;
    }

}
