/*
 * day-plan.css — the office's plan of a day: who does what when, and what is still open.
 *
 * <div class="app-plan" data-view="day | cockpit" data-show="list | detail">
 *   <section class="app-plan-rail" aria-labelledby="id-title">        (the open work, or the people)
 *     <header class="app-plan-rail-head">
 *       <h2 class="app-plan-rail-title" id="id-title">Offen</h2>
 *       <span class="app-badge" data-tone="neutral">9</span>
 *     </header>
 *     <div class="app-plan-rail-search">[search field]</div>            (optional)
 *     <ul class="app-plan-rail-list" role="list">
 *       <li><a class="app-plan-rail-item" href aria-current="page | true">
 *         [avatar]                                                      (optional: a person)
 *         <span class="app-plan-rail-text">
 *           <span class="app-plan-rail-label">Spar Ansfelden</span>
 *           <span class="app-plan-rail-detail">Sparkasse</span>         (optional)
 *         </span>
 *         <span class="app-plan-rail-value" data-tone="warning">+20 Min.</span>   (optional)
 *       </a></li>
 *     </ul>
 *     <p class="app-plan-rail-empty">Alles eingeplant</p>               (in place of the list)
 *   </section>
 *   <div class="app-plan-main">
 *     <div class="app-plan-bar">                                         (a region under 960 only)
 *       [button: the open work, "9 offen"]
 *       <div class="app-plan-switcher">[‹] [menu: the person] [›]</div>   (a region under 560 only)
 *     </div>
 *     <div class="app-plan-board">
 *       <div class="app-plan-grid">
 *         <div class="app-plan-corner" style="grid-column: 1; grid-row: 1 / 3"></div>
 *         <div class="app-plan-team" style="grid-column: 2 / span 3; grid-row: 1">Linz Kälte</div>
 *         <div class="app-plan-person" style="grid-column: 2; grid-row: 2" data-team-start data-chosen>
 *           [avatar, compact]
 *           <span class="app-plan-person-text"><span class="app-plan-person-name">Jonas</span><span class="app-plan-person-load">6,5/8,5 Std.</span></span>
 *         </div>
 *         <div class="app-plan-edge" style="grid-column: 2 / span 8; grid-row: 3 / 7"></div>
 *         <div class="app-plan-line" style="grid-column: 2 / span 8; grid-row: 7" data-kind="core"></div>
 *         <div class="app-plan-lane" style="grid-column: 2; grid-row: 3 / 85" data-team-start></div>
 *         <div class="app-plan-off" style="grid-column: 2; grid-row: 71 / 85"></div>
 *         <a class="app-plan-visit" href data-state="planned | done | late" style="grid-column: 2; grid-row: 23 / 39">
 *           <span class="app-plan-visit-title">Ordensklinikum</span>
 *           <span class="app-plan-visit-detail">A-2026-0143</span>    (or "+20 Min." in the warning text, when late)
 *         </a>
 *         <div class="app-plan-slot" style="grid-column: 4; grid-row: 51 / 63"><span class="app-plan-visit-title">Spar Ansfelden</span></div>
 *         <div class="app-plan-now" style="grid-column: 2 / span 8; grid-row: 33"></div>
 *         <div class="app-plan-times" style="grid-column: 1; grid-row: 3 / 85" aria-hidden="true">
 *           <span class="app-plan-hour" style="grid-row: 5 / span 2">07:00</span>
 *           <span class="app-plan-now-time" style="grid-row: 31 / span 2">10:45</span>
 *         </div>
 *       </div>
 *     </div>
 *   </div>
 * </div>
 *
 * The plan reads down by the clock and across by the people, in their teams. Every row of the
 * grid is one step of the rhythm: a quarter of an hour in the core hours takes two, one at the
 * edges of the day, so the hours people work stand tall and the early and late ones stay in
 * sight without the scroll. Where each thing stands (a visit, a person's own shift, the hour
 * lines, now) is the screen's to write, as grid lines, from the times; the sheet only says how
 * it looks. A visit is white with a ring and says only whom it is for, and its order number
 * when it is tall enough (the number wraps out of sight otherwise). Done turns muted; late is
 * the one tone, with its delay in words. Outside a person's shift the lane is hatched. Now is
 * the accent line, and so is the slot a wizard suggests. Nothing else has a colour.
 *
 * The grid scrolls sideways inside its panel, never the page, the times staying at the start.
 * Under a region of 960 the open work leaves the side for a button that opens it; under 560 one
 * person fills the grid at a time, snapping from one to the next, and the switcher above says
 * who. The cockpit puts the people beside the map (map.css); under 560 the list and the map are
 * one pane at a time, as a split view's are.
 */
@layer components {
    .app-plan {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: var(--app-space-board);
        align-items: stretch;
        min-inline-size: 0;
    }

    .app-plan-main {
        position: relative;
        display: flex;
        flex-direction: column;
        gap: var(--app-space-inline);
        min-inline-size: 0;
    }

    @container app-region (width >= 960px) {
        .app-plan[data-view="day"] {
            grid-template-columns: var(--app-column-width-xl) minmax(0, 1fr);
        }

        .app-plan[data-view="cockpit"] {
            grid-template-columns: var(--app-sidebar-width) minmax(0, 1fr);
        }

        /* The map takes what the screen leaves under the page's header, so the people and the
           map end on one line with the screen. */
        .app-plan[data-view="cockpit"] > .app-plan-main {
            min-block-size: calc(var(--app-page-height) - var(--app-bar-height) - 2 * var(--app-space-page) - var(--app-control-height) - var(--app-space-page-gap));
        }
    }

    .app-plan-main > .app-map {
        flex: 1 0 auto;
    }

    @container app-region (width >= 560px) and (width < 960px) {
        .app-plan[data-view="cockpit"] {
            grid-template-columns: var(--app-column-width-xl) minmax(0, 1fr);
        }
    }

    /* The open work stands beside the plan only where the plan keeps room for its people. */
    @container app-region (width < 960px) {
        .app-plan[data-view="day"] > .app-plan-rail {
            display: none;
        }
    }


    @container app-region (width < 560px) {
        .app-plan[data-show="list"] > .app-plan-main,
        .app-plan[data-show="detail"] > .app-plan-rail {
            display: none;
        }
    }

    /* ------------------------------------------------------------------ the rail */

    .app-plan-rail {
        display: flex;
        flex-direction: column;
        gap: var(--app-space-inline);
        min-inline-size: 0;
        padding: var(--app-space-board-lane);
        border-radius: var(--app-radius-card);
        background: var(--app-color-surface);
        box-shadow: 0 0 0 var(--app-border-width) var(--app-color-line);
    }

    .app-plan-rail-head {
        display: flex;
        align-items: center;
        gap: var(--app-space-inline);
        min-block-size: var(--app-control-height);
        padding: 0 var(--app-space-inline);
    }

    .app-plan-rail-title {
        min-inline-size: 0;
        color: var(--app-color-text);
        font-family: var(--app-font-display);
        font-size: var(--app-text-heading-size);
        font-weight: var(--app-text-heading-weight);
        line-height: var(--app-text-heading-leading);
    }

    /* The search says what it is by its placeholder and its name; its label is for assistive
       technology only, where the rail has no room for a line of its own. */
    .app-plan-rail-search .app-field-label {
        position: absolute;
        inline-size: var(--app-border-width);
        block-size: var(--app-border-width);
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .app-plan-rail-list {
        display: flex;
        flex-direction: column;
        padding: 0;
        list-style: none;
    }

    .app-plan-rail-list > li {
        display: flex;
        flex-direction: column;
    }

    .app-plan-rail-item {
        display: flex;
        align-items: center;
        gap: var(--app-space-choice);
        min-block-size: var(--app-control-height);
        padding: var(--app-space-list-inset) var(--app-space-inline);
        border-radius: var(--app-radius-nav-item);
        color: var(--app-color-text);
        text-decoration: none;
        transition: background-color var(--app-duration-hover) var(--app-easing);
    }

    @media (hover: hover) {
        .app-plan-rail-item:hover:not([aria-current]) {
            background: var(--app-color-row-hover);
        }
    }

    .app-plan-rail-item:focus-visible {
        outline: var(--app-focus-ring-width) solid var(--app-color-focus);
        outline-offset: calc(-1 * var(--app-focus-ring-width));
    }

    .app-plan-rail-item[aria-current] {
        background: var(--app-color-nav-current);
    }

    .app-plan-rail-item[aria-current] .app-plan-rail-label {
        color: var(--app-color-nav-current-text);
    }

    /* The chosen one is told by the accent: its round turns solid. */
    .app-plan-rail-item[aria-current] .app-avatar,
    .app-plan-person[data-chosen] .app-avatar {
        background: var(--app-color-accent);
        color: var(--app-color-text-on-accent);
    }

    .app-plan-rail-text {
        display: flex;
        flex: 1 1 auto;
        flex-direction: column;
        min-inline-size: 0;
    }

    .app-plan-rail-label {
        overflow: hidden;
        font-size: var(--app-text-body-size);
        font-weight: var(--app-text-value-weight);
        line-height: var(--app-text-body-leading);
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-plan-rail-detail {
        overflow: hidden;
        color: var(--app-color-text-muted);
        font-size: var(--app-text-help-size);
        line-height: var(--app-text-help-leading);
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-plan-rail-value {
        flex: none;
        color: var(--app-color-text-muted);
        font-size: var(--app-text-help-size);
        font-variant-numeric: tabular-nums;
        line-height: var(--app-text-help-leading);
    }

    .app-plan-rail-value[data-tone="warning"] {
        color: var(--app-color-warning-text);
        font-weight: var(--app-text-value-weight);
    }

    .app-plan-rail-empty {
        padding: var(--app-space-list-inset) var(--app-space-inline);
        color: var(--app-color-text-subtle);
        font-size: var(--app-text-body-size);
        line-height: var(--app-text-body-leading);
    }

    @media (pointer: coarse) {
        .app-plan-rail-item {
            min-block-size: var(--app-link-list-row-touch);
        }
    }

    /* ------------------------------------------------------- the bar over the grid */

    /* Under a region of 960: the button to the open work, and under 560 the switcher that
       names the one person shown and steps to the next. */
    .app-plan-bar {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--app-space-inline);
    }

    .app-plan-switcher {
        display: none;
    }

    @container app-region (width >= 960px) {
        .app-plan-bar {
            display: none;
        }
    }

    @container app-region (width < 560px) {
        .app-plan-switcher {
            display: flex;
            flex: 1 1 auto;
            align-items: center;
            justify-content: space-between;
            gap: var(--app-space-list-inset);
        }
    }

    .app-plan-bar:not(:has(> .app-button)) {
        display: none;
    }

    @container app-region (width < 560px) {
        .app-plan-bar:not(:has(> .app-button)) {
            display: flex;
        }
    }

    /* ------------------------------------------------------------------- the grid */

    .app-plan-board {
        min-inline-size: 0;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        border-radius: var(--app-radius-card);
        background: var(--app-color-surface);
        box-shadow: 0 0 0 var(--app-border-width) var(--app-color-line);
        scrollbar-width: thin;
    }

    .app-plan-grid {
        display: grid;
        grid-template-rows: auto auto;
        grid-template-columns: var(--app-agenda-time);
        grid-auto-rows: var(--app-space-inline);
        grid-auto-columns: minmax(var(--app-column-width-m), 1fr);
    }

    /* The head: the teams over their people. The corner stays with the times. */
    .app-plan-corner {
        position: sticky;
        inset-inline-start: 0;
        z-index: 1;
        background: var(--app-color-surface);
        box-shadow: inset 0 calc(-1 * var(--app-border-width)) 0 var(--app-color-line-strong);
    }

    .app-plan-team {
        overflow: hidden;
        padding: var(--app-space-list-inset) var(--app-space-inline);
        color: var(--app-color-text-subtle);
        font-size: var(--app-text-label-size);
        font-weight: var(--app-text-label-weight);
        line-height: var(--app-text-label-leading);
        text-overflow: ellipsis;
        white-space: nowrap;
        box-shadow:
            inset var(--app-border-width) 0 0 var(--app-color-line-strong),
            inset 0 calc(-1 * var(--app-border-width)) 0 var(--app-color-line);
    }

    .app-plan-person {
        display: flex;
        align-items: center;
        gap: var(--app-space-inline);
        min-inline-size: 0;
        padding: var(--app-space-list-inset) var(--app-space-inline);
        box-shadow:
            inset var(--app-border-width) 0 0 var(--app-color-line),
            inset 0 calc(-1 * var(--app-border-width)) 0 var(--app-color-line-strong);
    }

    .app-plan-person[data-team-start] {
        box-shadow:
            inset var(--app-border-width) 0 0 var(--app-color-line-strong),
            inset 0 calc(-1 * var(--app-border-width)) 0 var(--app-color-line-strong);
    }

    .app-plan-person-text {
        display: flex;
        flex-direction: column;
        min-inline-size: 0;
    }

    .app-plan-person-name {
        overflow: hidden;
        color: var(--app-color-text);
        font-size: var(--app-text-label-size);
        font-weight: var(--app-text-label-weight);
        line-height: var(--app-text-label-leading);
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-plan-person-load {
        color: var(--app-color-text-subtle);
        font-size: var(--app-text-help-size);
        font-variant-numeric: tabular-nums;
        line-height: var(--app-text-help-leading);
        white-space: nowrap;
    }

    /* The body: the edges of the day a shade off the white, the hours as lines, each person a
       lane with a line at its start, a stronger one where a team starts. */
    .app-plan-edge {
        background: var(--app-color-page);
    }

    .app-plan-line {
        box-shadow: inset 0 var(--app-border-width) 0 var(--app-color-line);
    }

    .app-plan-line[data-kind="core"] {
        box-shadow: inset 0 var(--app-border-width) 0 var(--app-color-line-strong);
    }

    .app-plan-lane {
        box-shadow: inset var(--app-border-width) 0 0 var(--app-color-line);
    }

    .app-plan-lane[data-team-start] {
        box-shadow: inset var(--app-border-width) 0 0 var(--app-color-line-strong);
    }

    /* Outside the person's own shift: faint stripes, as a progress bar's still ones. */
    .app-plan-off {
        background: repeating-linear-gradient(-45deg, var(--app-color-surface-muted) 0 var(--app-progress-stripe), transparent var(--app-progress-stripe) calc(2 * var(--app-progress-stripe)));
    }

    /* A visit: whom it is for, and the number when it is tall enough; a line too many wraps
       into a column out of sight. It leaves a step free under it and to each side. */
    .app-plan-visit,
    .app-plan-slot {
        display: flex;
        flex-flow: column wrap;
        align-content: flex-start;
        align-self: start;
        justify-self: center;
        column-gap: var(--app-space-inline);
        inline-size: calc(100% - 2 * var(--app-space-list-inset));
        block-size: calc(100% - var(--app-space-list-inset));
        overflow: hidden;
        padding: var(--app-space-list-inset) var(--app-space-inline);
        border-radius: var(--app-radius-option);
        background: var(--app-color-surface);
        color: var(--app-color-text);
        text-decoration: none;
        box-shadow: inset 0 0 0 var(--app-border-width) var(--app-color-line-strong);
    }

    .app-plan-visit {
        transition: background-color var(--app-duration-hover) var(--app-easing);
    }

    @media (hover: hover) {
        .app-plan-visit:hover {
            background: var(--app-color-surface-hover);
        }
    }

    .app-plan-visit:focus-visible {
        outline: var(--app-focus-ring-width) solid var(--app-color-focus);
        outline-offset: calc(-1 * var(--app-focus-ring-width));
    }

    .app-plan-visit-title,
    .app-plan-visit-detail {
        inline-size: 100%;
        overflow: hidden;
        font-size: var(--app-text-label-size);
        line-height: var(--app-text-label-leading);
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-plan-visit-title {
        font-weight: var(--app-text-label-weight);
    }

    .app-plan-visit-detail {
        color: var(--app-color-text-muted);
        font-variant-numeric: tabular-nums;
    }

    .app-plan-visit[data-state="done"] {
        background: var(--app-color-page);
        color: var(--app-color-text-subtle);
        box-shadow: inset 0 0 0 var(--app-border-width) var(--app-color-line);
    }

    .app-plan-visit[data-state="done"] .app-plan-visit-detail {
        color: var(--app-color-text-subtle);
    }

    .app-plan-visit[data-state="late"] {
        background: var(--app-color-warning-soft);
        box-shadow: inset 0 0 0 var(--app-border-width) var(--app-color-warning);
    }

    .app-plan-visit[data-state="late"] .app-plan-visit-detail {
        color: var(--app-color-warning-text);
        font-weight: var(--app-text-value-weight);
    }

    /* The slot a wizard suggests, before it is taken: the accent, dashed. */
    .app-plan-slot {
        background: var(--app-color-accent-subtle);
        color: var(--app-color-accent-text);
        box-shadow: none;
        outline: var(--app-border-width-strong) dashed var(--app-color-accent);
        outline-offset: calc(-1 * var(--app-border-width-strong));
    }

    /* Now: the accent line over the people, its time at the start. */
    .app-plan-now {
        box-shadow: inset 0 var(--app-border-width-strong) 0 var(--app-color-accent);
    }

    /* The times stay at the start while the people scroll by. */
    .app-plan-times {
        position: sticky;
        inset-inline-start: 0;
        z-index: 1;
        display: grid;
        grid-template-rows: subgrid;
        background: var(--app-color-surface);
    }

    .app-plan-hour,
    .app-plan-now-time {
        justify-self: end;
        padding: 0 var(--app-space-inline);
        color: var(--app-color-text-subtle);
        font-size: var(--app-text-help-size);
        font-variant-numeric: tabular-nums;
        line-height: var(--app-text-help-leading);
    }

    .app-plan-now-time {
        z-index: 1;
        justify-self: center;
        padding: 0 var(--app-space-list-inset);
        border-radius: var(--app-radius-option);
        background: var(--app-color-accent);
        color: var(--app-color-text-on-accent);
        font-weight: var(--app-text-strong-weight);
    }

    /* A narrow region: one person at a time, snapping from one to the next; the switcher above
       names them, so the head steps aside. */
    @container app-region (width < 560px) {
        .app-plan-board {
            scroll-snap-type: x mandatory;
            scroll-padding-inline-start: var(--app-agenda-time);
        }

        .app-plan-grid {
            grid-auto-columns: calc(100% - var(--app-agenda-time));
        }

        .app-plan-lane {
            scroll-snap-align: start;
        }

        .app-plan-corner,
        .app-plan-team,
        .app-plan-person {
            display: none;
        }
    }

    /* ------------------------------------------------------------ the wizard's picks */

    /* The people a wizard suggests: one row each, its name, the one reason, the free slot. A
       radio group: the chosen one is pressed, as a toggle chip is. */
    .app-plan-picks {
        display: flex;
        flex-direction: column;
        gap: var(--app-space-list-inset);
    }

    .app-plan-pick {
        position: relative;
        display: flex;
        align-items: center;
        gap: var(--app-space-choice);
        padding: var(--app-space-inline);
        border-radius: var(--app-radius-button);
        color: var(--app-color-text);
        cursor: pointer;
        transition: background-color var(--app-duration-hover) var(--app-easing);
    }

    .app-plan-pick-input {
        position: absolute;
        inset: 0;
        margin: 0;
        border-radius: inherit;
        opacity: 0;
        cursor: pointer;
        appearance: none;
    }

    @media (hover: hover) {
        .app-plan-pick:hover:not(:has(:checked)) {
            background: var(--app-color-surface-hover);
        }
    }

    .app-plan-pick:has(:focus-visible) {
        outline: var(--app-focus-ring-width) solid var(--app-color-focus);
        outline-offset: var(--app-focus-ring-offset);
    }

    .app-plan-pick:has(:checked) {
        background: var(--app-color-accent-soft);
        box-shadow: inset 0 0 0 var(--app-border-width) var(--app-color-accent);
    }

    .app-plan-pick:has(:checked) .app-avatar {
        background: var(--app-color-accent);
        color: var(--app-color-text-on-accent);
    }

    .app-plan-pick:has(:checked) :is(.app-plan-pick-name, .app-plan-pick-slot) {
        color: var(--app-color-accent-text);
    }

    .app-plan-pick-text {
        display: flex;
        flex: 1 1 auto;
        flex-direction: column;
        min-inline-size: 0;
    }

    .app-plan-pick-name {
        overflow: hidden;
        font-size: var(--app-text-body-size);
        font-weight: var(--app-text-value-weight);
        line-height: var(--app-text-body-leading);
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-plan-pick-reason {
        color: var(--app-color-text-muted);
        font-size: var(--app-text-help-size);
        line-height: var(--app-text-help-leading);
    }

    .app-plan-pick-slot {
        flex: none;
        font-size: var(--app-text-body-size);
        font-variant-numeric: tabular-nums;
        font-weight: var(--app-text-value-weight);
        line-height: var(--app-text-body-leading);
    }

    /* The day the plan shows, between its arrows. */
    .app-plan-date {
        min-inline-size: var(--app-column-width-m);
        color: var(--app-color-text);
        font-size: var(--app-text-body-size);
        font-variant-numeric: tabular-nums;
        font-weight: var(--app-text-value-weight);
        line-height: var(--app-text-body-leading);
        text-align: center;
    }

    /* Forced colours (a Windows contrast theme): shadows and backgrounds are gone, so frames
       are outlines and a chosen state is the system highlight. */
    @media (forced-colors: active) {
        .app-plan-rail,
        .app-plan-board,
        .app-plan-visit {
            outline: var(--app-border-width) solid var(--app-color-forced-line);
            outline-offset: calc(-1 * var(--app-border-width));
        }

        .app-plan-now {
            border-block-start: var(--app-border-width-strong) solid var(--app-color-forced-current);
        }

        .app-plan-rail-item[aria-current],
        .app-plan-pick:has(:checked) {
            forced-color-adjust: none;
            background: var(--app-color-forced-current);
            color: var(--app-color-forced-current-text);
        }
    }
}
