/* MAIN-9: the Power page. Colours come from theme.css, so the light and the dark theme both work */

#powerPage {
    max-width: 640px;
    margin: 0 auto;
}

/* The cog and the line under the title: which grid company and fee the prices are for */
.powerSubRow {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: -4px 0 8px -10px;
}

.powerCog {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: none;
    border: 0;
    border-radius: 8px;
    color: var(--ink-muted);
}

    .powerCog[aria-expanded="true"] {
        color: var(--accent-ink);
        background: var(--accent-soft-bg);
    }

.powerSub {
    margin: 0;
    font-size: 13px;
    color: var(--ink-muted);
    /* Centre the capitals, not the line box, on the cog: a font's ascent and descent differ from one device to the
       next, and with them where the text sits in its line. The box runs from the cap height to the baseline (from
       the x-height it put the ascenders and capitals too high). Browsers without it keep the line box */
    text-box: trim-both cap alphabetic;
}

.powerMessage {
    color: var(--ink-body);
}

.powerMessage.error {
    color: var(--danger);
}

#powerContent {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#powerContent[hidden] {
    display: none;
}

.powerSide,
.powerMain {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.powerCard {
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

/* ---------- settings ---------- */

.powerSettings {
    margin-bottom: 12px;
}

    .powerSettings[hidden] {
        display: none;
    }

.powerForm {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

    .powerForm[hidden] {
        display: none;
    }

    .powerForm label {
        margin-top: 4px;
        font-size: 13px;
        color: var(--ink-body);
    }

.powerCheck {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
}

.powerHourPick {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

    .powerHourPick select {
        width: auto;
    }

.powerLabel {
    font-size: 13px;
    color: var(--ink-muted);
}

.powerPill {
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.powerPill.known {
    background: var(--cell-released-bg);
    color: var(--cell-released-ink);
}

.powerPill.forecast {
    background: var(--cell-warn-bg);
    color: var(--cell-warn-ink);
}

.powerPill.rough {
    background: var(--surface-muted);
    color: var(--ink-body);
}

/* ---------- best time to charge ---------- */

.powerPlan {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.powerOptions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* One time to charge, where and when. All the rows are big, the best one a solid teal block with the Best pill. The
   accent fill doesn't flip in dark mode, so white text on it holds in both themes */
.powerOption {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 84px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
}

    .powerOption.pick {
        background: var(--accent);
        border-color: var(--accent);
        color: var(--on-accent);
    }

.powerBestPill {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 10px;
    border-radius: 999px;
    background: var(--on-accent);
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
    line-height: 16px; /*inside the label's own line, so the best row is no taller than the rest*/
    vertical-align: 1px;
}

.powerOptionMid {
    flex: 1;
    min-width: 0;
}

.powerOptionLabel {
    font-size: 14px;
    color: var(--ink-body);
}

.powerOption.pick .powerOptionLabel,
.powerOption.pick .powerOptionUnit {
    color: var(--on-accent);
}

.powerOptionWhen {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.2;
}

.powerOptionDay {
    margin-left: 8px;
    font-size: 14px;
    font-weight: 400;
    white-space: nowrap;
}

.powerOption.pick .powerOptionDay {
    color: var(--on-accent);
}

.powerOptionPrice {
    text-align: right;
}

.powerOptionKr {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* After the place and day on the other rows: how much dearer */
.powerOptionDiff {
    white-space: nowrap;
}

.powerOptionUnit {
    font-size: 13px;
    color: var(--ink-muted);
}

/* The narrowest phones: a little smaller, so the hours and the day still share a line */
@media (max-width: 340px) {
    .powerOptionWhen,
    .powerOptionKr {
        font-size: 24px;
    }
}

/* The 23:00 hint, under the rows where it decides whether to charge now or wait: an arrow for the way the next night goes */
.powerHint {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--surface-muted);
    font-size: 16px;
    line-height: 1.35;
}

    .powerHint[hidden] {
        display: none;
    }

    /* The arrow is a round badge, teal for falling prices and orange for rising, white arrow on it as on the Best row */
    .powerHint::before {
        flex: none;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: var(--accent);
        color: var(--on-accent);
        font-size: 26px;
        font-weight: 700;
        line-height: 1;
    }

    .powerHint.down::before {
        content: "↓";
    }

    .powerHint.up::before {
        content: "↑";
        background: var(--power-dear);
    }

    /* Too close to call: a sideways arrow on a plain grey badge */
    .powerHint.flat::before {
        content: "→";
        background: var(--line);
        color: var(--ink-body);
    }

.powerPlan h6 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

/* Charge for − 1 h +, on a row of its own under the 23:00 hint */
.powerChargeFor {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
    font-size: 13px;
    color: var(--ink-body);
}

.powerStepper {
    display: flex;
    align-items: center;
    gap: 2px;
}

    .powerStepper button {
        width: 44px;
        height: 44px;
        background: var(--surface);
        border: 1px solid var(--line-control);
        border-radius: 6px;
        color: var(--ink);
        font-size: 20px;
        line-height: 1;
    }

        .powerStepper button:disabled {
            color: var(--ink-faint);
        }

#hoursText {
    min-width: 44px;
    text-align: center;
    font-weight: 600;
}

.powerBestInfo {
    font-size: 13px;
    color: var(--ink-body);
}

.powerNote {
    margin: 6px 0 0;
    font-size: 12px;
    color: var(--ink-muted);
}

/* ---------- prices card ---------- */

.powerDays {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* One card: the published hours on top, then the Forecast block */
.powerPrices {
    padding: 0;
    overflow: hidden;
}

.powerDay {
    padding: 0;
    overflow: hidden;
}

/* A fold row: "Hourly prices" under the published graph, and the Forecast card's header. A title and a chevron that
   points down when closed and up when open */
.powerFold {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 48px;
    padding: 8px 14px;
    background: none;
    border: 0;
    border-top: 1px solid var(--line-soft);
    color: var(--ink);
    text-align: left;
}

.powerFoldTitle {
    font-weight: 600;
}

/* The Forecast card's header is its title, as on the two weeks card */
.powerForecast > .powerForecastHead {
    border-top: 0;
}

.powerForecast .powerFoldTitle {
    font-size: 15px;
}

/* Each forecast day under the header, one graph like the published one */
.powerForecast .powerDay {
    border-top: 1px solid var(--line-soft);
}

    .powerForecast .powerDay.open {
        background: var(--surface-panel);
    }

.powerChevron {
    flex: none;
    width: 8px;
    height: 8px;
    margin: 0 4px 4px 0;
    border-right: 2px solid var(--ink-muted);
    border-bottom: 2px solid var(--ink-muted);
    transform: rotate(45deg);
}

    .powerChevron.up {
        margin: 4px 4px 0 0;
        transform: rotate(-135deg);
    }

/* On a forecast day the chevron sits after the pill */
.powerDayTop .powerChevron {
    margin: 0 4px 4px 8px;
}

    .powerDayTop .powerChevron.up {
        margin: 4px 4px 0 8px;
    }

.powerDayHead {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    padding: 12px 14px;
    background: none;
    border: 0;
    color: var(--ink);
    text-align: left;
}

.powerDayTop {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.powerDayTitle {
    font-weight: 600;
}

.powerSpark {
    display: flex;
    gap: 1px;
    height: 36px;
}

.powerSparkHour {
    position: relative;
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: flex-end;
}

.powerSparkBar {
    border-radius: 1px;
    background: var(--power-bar);
}

    .powerSparkBar.win {
        background: var(--power-cheap);
    }

    .powerSparkBar.dear {
        background: var(--power-dear);
    }

    .powerSparkBar.past {
        background: var(--line-soft);
    }

/* Work's price in that hour: a line across the hour, over the bar when home is dearer. Faint outside your hours
   there - still shown, in case staying a bit longer pays */
.powerSparkWork {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--power-work);
}

    .powerSparkWork.off {
        opacity: .35;
    }

/* Where one day turns into the next, in a graph across midnight */
.powerSparkHour.newDay {
    margin-left: 4px;
}

/* ...and which part of it is which day */
.powerSparkDays {
    display: flex;
    gap: 1px;
    font-size: 11px;
    color: var(--ink-muted);
}

    .powerSparkDays span {
        min-width: 0;
        overflow: hidden;
        white-space: nowrap;
    }

        .powerSparkDays span + span {
            margin-left: 4px;
        }

/* The key in front of work's range under the graph */
.powerWorkKey {
    display: inline-block;
    width: 12px;
    height: 2px;
    margin-right: 6px;
    vertical-align: middle;
    background: var(--power-work);
}

.powerDaySum {
    font-size: 12px;
    color: var(--ink-muted);
}

.powerHours {
    border-top: 1px solid var(--line-soft);
}

/* Across midnight, the name over each day's hours */
.powerHourDay {
    padding: 8px 14px 2px;
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-muted);
}

.powerHour {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) 80px;
    align-items: center;
    gap: 10px;
    padding: 5px 14px;
}

    .powerHour.win {
        background: var(--accent-soft-bg);
    }

.powerHourTime {
    color: var(--ink-body);
    font-variant-numeric: tabular-nums;
}

.powerHourBars {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.powerHourBar {
    height: 10px;
    border-radius: 2px;
}

    .powerHourBar.work {
        height: 4px;
        background: var(--power-work);
    }

        .powerHourBar.work.off {
            opacity: .35;
        }

    .powerHourBar.cheap {
        background: var(--power-cheap);
    }

    .powerHourBar.normal {
        background: var(--power-bar);
    }

    .powerHourBar.dear {
        background: var(--power-dear);
    }

    /* Hours already gone: listed so the card always holds a whole day, but faint, like their bars in the graph */
    .powerHourBar.past {
        background: var(--line-soft);
    }

.powerHour.past .powerHourTime,
.powerHour.past .powerHourPrice {
    font-weight: 400;
    color: var(--ink-muted);
}

.powerHourPrice {
    text-align: right;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* On a working day the hours get a second price: the work chargers' */
.powerHours.withWork .powerHour {
    grid-template-columns: 44px minmax(0, 1fr) 72px 72px;
    gap: 8px;
}

.powerHourWork {
    text-align: right;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

    .powerHourWork.off {
        font-weight: 400;
        color: var(--ink-muted);
    }

.powerHourHead {
    padding-top: 6px;
    padding-bottom: 0;
    font-size: 12px;
}

    .powerHourHead span {
        font-weight: 600;
        color: var(--ink-muted);
    }

/* ---------- the last two weeks ---------- */

.powerHistory {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

    .powerHistory[hidden] {
        display: none;
    }

    .powerHistory h6 {
        margin: 0;
        font-size: 15px;
        font-weight: 600;
    }

.powerHistoryRow {
    display: grid;
    grid-template-columns: 92px 48px minmax(0, 1fr) 64px;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    border: 1px solid transparent;
    border-radius: 6px;
}

    .powerHistoryRow.coming {
        background: var(--accent-soft-bg);
        border-color: var(--accent-line);
    }

.powerHistoryDay {
    font-size: 13px;
    white-space: nowrap;
}

.powerHistoryRow.coming .powerHistoryDay {
    color: var(--accent-ink);
}

.powerHistoryTime {
    font-size: 12px;
    color: var(--ink-muted);
    font-variant-numeric: tabular-nums;
}

.powerHistoryBar {
    height: 8px;
    border-radius: 2px;
    background: var(--power-bar);
}

    .powerHistoryBar.top {
        background: var(--power-cheap);
    }

.powerHistoryKr {
    text-align: right;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* ---------- desktop ---------- */

/* A wide screen gets two columns: Settings and the Best time card on the left, staying in view while the prices
   scroll, and the prices card beside them. powerContent steps aside (display: contents) so Settings, outside it, can share its column - the message takes the days' place,
   as only one of them shows at a time. The last row takes what the days need beyond Settings, so Settings never
   stretches. Last in the file, so it wins */
@media (min-width: 992px) {
    #powerPage {
        display: grid;
        grid-template-columns: 360px minmax(0, 1fr);
        grid-template-rows: auto auto auto 1fr;
        grid-template-areas:
            "title title"
            "sub sub"
            "settings main"
            "side main";
        column-gap: 16px;
        align-items: start;
        max-width: none;
    }

    #powerPage > .page-title {
        grid-area: title;
    }

    .powerSubRow {
        grid-area: sub;
    }

    .powerSettings {
        grid-area: settings;
    }

    .powerMessage,
    .powerMain {
        grid-area: main;
    }

    #powerContent {
        display: contents;
    }

    .powerSide {
        grid-area: side;
        position: sticky;
        top: 12px;
    }

}