/*
 * timer.css — the work timer: time on site, started, paused and finished by hand.
 *
 * <div class="app-timer" role="group" aria-labelledby="id-label" data-state="idle | running | paused | done" data-disabled>
 *   <span class="app-field-label" id="id-label">Arbeitszeit</span>
 *   <div class="app-timer-panel">
 *     <div class="app-timer-reading">
 *       <p class="app-timer-status">
 *         <span class="app-timer-dot" aria-hidden="true"></span>
 *         <span class="app-timer-state">Läuft</span>
 *         <span class="app-timer-since">seit 08:14</span>
 *       </p>
 *       <time class="app-timer-time" role="timer" datetime="PT1H23M5S">1:23:05</time>
 *     </div>
 *     <div class="app-timer-actions">
 *       [button: Starten · Pause · Fortsetzen]  [button: Beenden; while running or paused]
 *     </div>
 *   </div>
 * </div>
 *
 * The reading is the time worked, without the pauses, in display figures that do not jump as
 * they tick. Over it, the state: running in the success tone, paused in the warning tone, each
 * with a dot, and since when; finished, from when to when. The time comes from timestamps, so it
 * is right after the app slept; fsm-ui.js moves the seconds on the device, nothing travels per
 * tick. The first button keeps its place through the states (Starten, Pause, Fortsetzen), so
 * focus stays on it. In a region narrower than 560 (a phone) the actions go under the reading
 * and share its width: large targets for a gloved hand.
 *
 * role="timer" is not announced as it ticks; the state is text, and the buttons say what they do.
 */
@layer components {
    .app-timer {
        display: flex;
        flex-direction: column;
        gap: var(--app-space-label);
        min-inline-size: 0;
    }

    .app-timer-panel {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: var(--app-space-field);
        padding: var(--app-space-gutter-narrow);
        border-radius: var(--app-radius-field);
        background: var(--app-color-surface);
        box-shadow: inset 0 0 0 var(--app-border-width) var(--app-color-line);
    }

    .app-timer-reading {
        display: flex;
        flex-direction: column;
        gap: var(--app-space-timer);
        min-inline-size: 0;
    }

    .app-timer-status {
        display: flex;
        align-items: center;
        gap: var(--app-space-inline);
        min-inline-size: 0;
        color: var(--app-color-text-muted);
        font-size: var(--app-text-help-size);
        line-height: var(--app-text-help-leading);
    }

    /* A border, not a fill, so a contrast theme keeps it. */
    .app-timer-dot {
        display: none;
        flex: none;
        inline-size: var(--app-timer-dot);
        block-size: var(--app-timer-dot);
        border: calc(var(--app-timer-dot) / 2) solid currentcolor;
        border-radius: 50%;
    }

    .app-timer-state {
        font-weight: var(--app-text-label-weight);
    }

    .app-timer-since {
        overflow: hidden;
        color: var(--app-color-text-subtle);
        font-variant-numeric: tabular-nums;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-timer-time {
        color: var(--app-color-text);
        font-size: var(--app-text-timer-size);
        font-weight: var(--app-text-timer-weight);
        font-variant-numeric: tabular-nums;
        line-height: var(--app-text-timer-leading);
        letter-spacing: var(--app-text-display-tracking);
    }

    .app-timer-actions {
        display: flex;
        flex-wrap: wrap;
        gap: var(--app-space-actions);
    }

    .app-timer:is([data-state="running"], [data-state="paused"]) .app-timer-dot {
        display: block;
    }

    .app-timer[data-state="running"] .app-timer-status {
        color: var(--app-color-success-text);
    }

    .app-timer[data-state="paused"] .app-timer-status {
        color: var(--app-color-warning-text);
    }

    .app-timer[data-state="paused"] .app-timer-time {
        color: var(--app-color-text-muted);
    }

    .app-timer[data-state="idle"] .app-timer-time {
        color: var(--app-color-text-subtle);
    }

    /* Off: the disabled surface and buttons. The state and the reading are text, not controls,
       and still say how much was worked: muted, never below contrast. */
    .app-timer[data-disabled] .app-timer-panel {
        background: var(--app-color-surface-disabled);
    }

    .app-timer[data-disabled] :is(.app-timer-status, .app-timer-time) {
        color: var(--app-color-text-muted);
    }

    /* In a narrow region (a phone): the actions under the reading, over its width. */
    @container app-region (width < 560px) {
        .app-timer-actions {
            flex: 1 0 100%;
        }

        .app-timer-actions > .app-button {
            flex: 1;
        }
    }

    @media (forced-colors: active) {
        .app-timer-panel {
            outline: var(--app-border-width) solid var(--app-color-forced-line);
            outline-offset: calc(-1 * var(--app-border-width));
        }
    }
}
