/* ===========================================================================
   Application shell.

   Only the frame lives here: header, navigation, view container, toasts.
   Everything inside a view is built from components.css.
   =========================================================================== */

html, body { min-height: 100%; }

.app {
    min-height: 100dvh;
    display: grid;
    /* Header, navigation, view. All three have to be named: with only two
       tracks the navigation inherits the 1fr row, stretches to full height and
       pushes the content to the bottom of the screen. */
    grid-template-rows: auto auto 1fr;
    /* Room for the mobile navigation bar and the home indicator. */
    padding-bottom: env(safe-area-inset-bottom);
}

/* --- Header ---------------------------------------------------------------- */

.appbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: var(--gap);
    padding: var(--gap) var(--gap-wide);
    padding-top: calc(var(--gap) + env(safe-area-inset-top));
    background: color-mix(in srgb, var(--wall) 88%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--wall-line);
}
.appbar__brand {
    font-family: var(--font-label);
    font-weight: 600;
    font-size: var(--step-1);
    letter-spacing: var(--tracking-tight);
    margin-right: auto;
}
.appbar__brand small {
    display: block;
    font-size: var(--step--1);
    font-weight: 500;
    color: var(--ink-faint);
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
}

/* Connection health belongs in the frame, not in a view: it is true of the
   whole installation rather than of whatever page is open. */
.health {
    display: flex;
    align-items: center;
    gap: var(--gap-tight);
    font-family: var(--font-label);
    font-size: var(--step--1);
    color: var(--ink-soft);
    white-space: nowrap;
}
.health::before {
    content: "";
    width: 7px; height: 7px;
    border-radius: var(--radius-pill);
    background: var(--ok);
}
.health.is-degraded::before { background: var(--warn); }
.health.is-down::before { background: var(--alert); }

/* --- Navigation ------------------------------------------------------------ */

.nav {
    display: flex;
    align-items: center;
    gap: var(--gap-tight);
    /* The pills used to sit flush against the header rule, which read as a
       rendering fault rather than as a design. */
    padding: var(--gap) var(--gap-wide);
    position: sticky;
    top: 0;
    z-index: 29;
    background: var(--wall);
}
.nav a {
    padding: 8px 16px;
    border-radius: var(--radius-pill);
    text-decoration: none;
    color: var(--ink-soft);
    font-family: var(--font-label);
    font-weight: 600;
    letter-spacing: 0.03em;
    white-space: nowrap;
    transition: background var(--tap), color var(--tap);
}
.nav a:hover { background: var(--wall-recess); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }

/* On a phone the navigation belongs under the thumb. */
@media (max-width: 720px) {
    .nav {
        position: fixed;
        inset: auto 0 0 0;
        top: auto;
        justify-content: space-around;
        padding: var(--gap-tight) var(--gap-tight)
                 calc(var(--gap-tight) + env(safe-area-inset-bottom));
        background: color-mix(in srgb, var(--wall-raised) 94%, transparent);
        backdrop-filter: blur(12px);
        border-top: 1px solid var(--wall-line);
        z-index: 40;
    }
    .nav a { flex: 1; text-align: center; padding: 10px 4px; font-size: var(--step--1); }
    .view { padding-bottom: 92px; }
    .pickbar { bottom: 78px; }
}

/* --- View ------------------------------------------------------------------ */

.view {
    padding: 0 var(--gap-wide) var(--gap-section);
    max-width: 1240px;
    width: 100%;
    margin: 0 auto;
}
@media (max-width: 480px) {
    .appbar { padding-left: var(--gap); padding-right: var(--gap); }
    .nav { padding-left: var(--gap); padding-right: var(--gap); }
    .view { padding-left: var(--gap); padding-right: var(--gap); }
}

.toolbar {
    display: flex;
    align-items: center;
    gap: var(--gap);
    flex-wrap: wrap;
    margin-bottom: var(--gap-wide);
}
.toolbar .chips { flex: 1; }

/* --- Login ------------------------------------------------------------------ */

.login {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: var(--gap-wide);
}
.login__card {
    width: min(380px, 100%);
    background: var(--wall-raised);
    border: 1px solid var(--wall-line);
    border-radius: var(--radius-tile);
    padding: var(--gap-section) var(--gap-wide) var(--gap-wide);
    box-shadow: var(--lift);
}
.login__brand {
    font-family: var(--font-label);
    font-weight: 600;
    font-size: var(--step-2);
    margin-bottom: var(--gap-tight);
}
.login__sub { color: var(--ink-soft); margin: 0 0 var(--gap-section); }
.login .btn { width: 100%; justify-content: center; }

/* --- Toasts ------------------------------------------------------------------ */

.toasts {
    position: fixed;
    left: 50%;
    bottom: calc(var(--gap-wide) + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    display: grid;
    gap: var(--gap-tight);
    z-index: 60;
    width: min(460px, calc(100vw - 2 * var(--gap)));
}
@media (max-width: 720px) { .toasts { bottom: 96px; } }

.toast {
    display: flex;
    align-items: center;
    gap: var(--gap);
    padding: var(--gap) var(--gap-wide);
    border-radius: var(--radius-control);
    background: var(--wall-raised);
    border: 1px solid var(--wall-line);
    border-left: 3px solid var(--ok);
    box-shadow: var(--lift);
    font-size: var(--step-0);
    animation: toast-in 180ms ease-out;
}
.toast--alert { border-left-color: var(--alert); }
.toast--warn  { border-left-color: var(--warn); }
.toast button { margin-left: auto; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* --- Settings ---------------------------------------------------------------- */

.settings { display: grid; gap: var(--gap-wide); max-width: 620px; }
.setting {
    display: grid;
    gap: var(--gap-tight);
    padding: var(--gap-wide);
    background: var(--wall-raised);
    border: 1px solid var(--wall-line);
    border-radius: var(--radius-tile);
}
.setting h3 { font-size: var(--step-1); }
.setting p { margin: 0; color: var(--ink-soft); font-size: var(--step--1); }
.setting__row { display: flex; gap: var(--gap-tight); flex-wrap: wrap; align-items: center; }

/* --- Skeletons ----------------------------------------------------------------- */

.skeleton {
    background: var(--wall-recess);
    border-radius: var(--radius-tile);
    aspect-ratio: 4 / 5.5;
    animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.55; } }

.visually-hidden {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ===========================================================================
   Administration
   =========================================================================== */

.list { display: grid; gap: var(--gap-tight); }

.listrow {
    display: flex;
    align-items: center;
    gap: var(--gap);
    padding: var(--gap) var(--gap-wide);
    background: var(--wall-raised);
    border: 1px solid var(--wall-line);
    border-radius: var(--radius-control);
}
.listrow__main { display: grid; gap: 2px; min-width: 0; flex: 1; }
.listrow__title { font-family: var(--font-label); font-weight: 600; }
.listrow__sub {
    font-size: var(--step--1);
    color: var(--ink-soft);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.listrow__actions { display: flex; gap: var(--gap-tight); flex: none; }
@media (max-width: 620px) {
    .listrow { flex-wrap: wrap; }
    .listrow__actions { width: 100%; }
    .listrow__actions .btn { flex: 1; }
}

.dot {
    width: 8px; height: 8px; flex: none;
    border-radius: var(--radius-pill);
    background: var(--offline);
}
.dot.is-ok { background: var(--ok); }
.dot.is-down { background: var(--alert); }

/* --- Dialog ------------------------------------------------------------------- */

.dialog {
    border: 1px solid var(--wall-line);
    border-radius: var(--radius-tile);
    background: var(--wall-raised);
    color: var(--ink);
    padding: 0;
    width: min(560px, calc(100vw - 2 * var(--gap)));
    max-height: min(86dvh, 900px);
    box-shadow: 0 24px 60px -20px #00000059;
}
.dialog::backdrop { background: #00000073; backdrop-filter: blur(2px); }
.dialog__form { display: grid; grid-template-rows: auto 1fr auto; max-height: inherit; }
.dialog__title {
    font-family: var(--font-label);
    font-size: var(--step-1);
    padding: var(--gap-wide) var(--gap-wide) var(--gap);
    border-bottom: 1px solid var(--wall-line);
}
.dialog__body { padding: var(--gap-wide); overflow-y: auto; }
.dialog__foot {
    display: flex;
    gap: var(--gap-tight);
    justify-content: flex-end;
    padding: var(--gap) var(--gap-wide);
    border-top: 1px solid var(--wall-line);
    background: var(--wall-recess);
}
.dialog__foot .btn:first-child { margin-right: auto; }
.dialog__section {
    font-family: var(--font-label);
    font-size: var(--step-0);
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    color: var(--ink-soft);
    margin: var(--gap-wide) 0 var(--gap);
    padding-top: var(--gap);
    border-top: 1px solid var(--wall-line);
}

.grid2 { display: grid; gap: var(--gap); grid-template-columns: 1fr 1fr; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } }

/* --- Check lists ----------------------------------------------------------------- */

.checklist {
    display: grid;
    gap: 2px;
    max-height: 190px;
    overflow-y: auto;
    padding: var(--gap-tight);
    background: var(--wall-recess);
    border: 1px solid var(--wall-line);
    border-radius: var(--radius-control);
}
.checkitem {
    display: flex;
    align-items: center;
    gap: var(--gap-tight);
    padding: 5px 6px;
    border-radius: var(--radius-control);
    cursor: pointer;
    font-size: var(--step-0);
}
.checkitem:hover { background: var(--wall-raised); }
.checkitem input { accent-color: var(--accent); width: 16px; height: 16px; }

/* --- Scene steps -------------------------------------------------------------------- */

.steprow {
    padding: var(--gap);
    margin-bottom: var(--gap);
    background: var(--wall-recess);
    border: 1px solid var(--wall-line);
    border-radius: var(--radius-control);
}
.steprow__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--gap-tight);
}
.steprow .field:last-child { margin-bottom: 0; }

/* --- Probe result ---------------------------------------------------------------------- */

.probe {
    padding: var(--gap);
    border-radius: var(--radius-control);
    background: var(--accent-faint);
    border: 1px solid var(--accent);
    font-size: var(--step--1);
}
.probe ul { margin: var(--gap-tight) 0 0; padding-left: 1.1rem; color: var(--warn); }

/* ===========================================================================
   Live movement, sorting, collapsible selection bar
   =========================================================================== */

/* Stop control. Only present while a cover is actually travelling: a button
   that does nothing most of the time teaches people to ignore it. */
.window__stop {
    position: absolute;
    left: 50%;
    top: 42%;
    transform: translate(-50%, -50%);
    width: 46px; height: 46px;
    border-radius: var(--radius-pill);
    border: 0;
    background: #000000A6;
    backdrop-filter: blur(4px);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    z-index: 4;
    animation: stop-in 160ms ease-out;
}
.window__stop:hover { background: #000000CC; }
.window__stop svg { width: 16px; height: 16px; }
@keyframes stop-in { from { opacity: 0; transform: translate(-50%, -50%) scale(0.85); } }

/* --- Sorting ------------------------------------------------------------------ */

.listrow.is-sortable { cursor: default; }
.handle {
    flex: none;
    width: 30px; height: 34px;
    display: grid;
    place-items: center;
    border: 0;
    background: transparent;
    color: var(--ink-faint);
    cursor: grab;
    border-radius: var(--radius-control);
    touch-action: none;
}
.handle:hover { color: var(--ink); background: var(--wall-recess); }
.handle:active { cursor: grabbing; }
.handle svg { width: 15px; height: 15px; }

.listrow.is-dragging {
    opacity: 0.9;
    box-shadow: var(--lift), 0 12px 28px -10px #00000059;
    border-color: var(--accent);
    position: relative;
    z-index: 5;
}
.listrow.is-drop-target { border-color: var(--accent); }

/* --- Selection bar, collapsible ---------------------------------------------- */

.pickbar__toggle {
    display: none;
    border: 0;
    background: transparent;
    color: var(--accent);
    font: inherit;
    font-family: var(--font-label);
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px;
}

@media (max-width: 720px) {
    /* On a phone the bar sits over the grid, so it starts as a single line and
       only opens when it is actually needed. */
    .pickbar { grid-template-columns: 1fr auto; align-items: center; }
    .pickbar__toggle { display: block; }
    .pickbar.is-collapsed .pickbar__sliders,
    .pickbar.is-collapsed .pickbar__actions { display: none; }
    .pickbar:not(.is-collapsed) { grid-template-columns: 1fr auto; }
    .pickbar:not(.is-collapsed) .pickbar__sliders,
    .pickbar:not(.is-collapsed) .pickbar__actions { grid-column: 1 / -1; }
}

/* --- Connection indicator ------------------------------------------------------ */

.health__mode {
    font-size: 10px;
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    color: var(--ink-faint);
    margin-left: var(--gap-tight);
}


/* --- Tile density -------------------------------------------------------------
   The grid's minimum column width is a variable so the same markup serves a
   phone in a pocket and a wall tablet across the room. */
.window-grid { grid-template-columns: repeat(auto-fill, minmax(var(--tile-min, 134px), 1fr)); }

.zoom { flex: none; gap: 2px; }
.chip--icon {
    width: 30px;
    padding: 4px 0;
    text-align: center;
    font-size: var(--step-0);
    line-height: 1;
}

/* At the smallest size the label would crowd the glass, so it tightens up. */
@media (max-width: 720px) {
    .window__label { padding: 5px var(--gap-tight); gap: 2px; }
    .window__name { font-size: var(--step--1); }
    .window__read { font-size: 11px; }
    .window__flag { padding: 4px var(--gap-tight); font-size: 11px; }
    .window__pick { width: 22px; height: 22px; opacity: 1; }
}
