/* Device Portal design language.
   Brand: BrainLit blue #004177 (hover #00335e), navy #052847, accent #8ABAFF, as in the touchscreen
   and config tool apps. Type: Inter for the UI, a system monospace for hostnames and versions.
   Surfaces: a cool grey canvas, white cards with a 14 px radius and a soft shadow.
   Chrome: a light, blurred top bar on portal pages; a navy bar on a device session, so the
   dark frame says "you are inside a device". */
:root {
    --brand: #004177;
    --brand-hover: #00335e;
    --brand-soft: #e7f0fa;
    --navy: #052847;
    --accent: #8ABAFF;
    --link: #0b63c4;
    --bg: #f3f5f8;
    --card: #ffffff;
    --text: #0f1f33;
    --muted: #64748b;
    --faint: #94a3b8;
    --line: #d6dde6;
    --line-soft: #e8edf3;
    --row-hover: #f6f9fc;
    --ok: #15803d;
    --ok-soft: #dcfce7;
    --warn: #b45309;
    --warn-soft: #fef3c7;
    --danger: #b91c1c;
    --danger-soft: #fee2e2;
    --topbar-h: 48px;
    --radius: 14px;
    --radius-s: 10px;
    --radius-button: 10px;
    --shadow-card: 0 1px 2px rgba(15, 31, 51, .04), 0 10px 30px -12px rgba(15, 31, 51, .12);
    --shadow-button: 0 1px 2px rgba(0, 65, 119, .25), inset 0 1px 0 rgba(255, 255, 255, .12);
    --shadow-button-hover: 0 3px 10px -2px rgba(0, 65, 119, .45), inset 0 1px 0 rgba(255, 255, 255, .12);
    --ring: 0 0 0 3px rgba(11, 99, 196, .22);
    --font: "Inter", "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
    --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* Author display rules (flex notices and the like) must never override the hidden attribute. */
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }

/* Type scale: 24 page title / 15 body / 14 tables, buttons, dialog / 13 hints, meta / 12 eyebrows, table heads / 11 badges */
body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.45;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    font-feature-settings: "cv11", "ss01";
}

a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--brand); }

.mono { font-family: var(--mono); font-size: 13.5px; letter-spacing: -.01em; }

/* ---------- cards ---------- */
.card {
    max-width: 480px;
    margin: 8vh auto;
    padding: 36px 40px;
    background: var(--card);
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
}

.card.wide { max-width: 960px; margin-top: 28px; padding: 30px 36px 32px; }

.card .logo {
    display: block;
    width: 200px;
    height: auto;
    margin: 4px auto 28px;
}

.card.login { text-align: center; }
.card.login h1 { font-size: 26px; margin-bottom: 8px; }
.card.login p { color: var(--muted); margin: 0 auto 22px; max-width: 34ch; }
.card.login button.primary { min-width: 160px; padding: 10px 22px; font-size: 15px; }
.card.login .staff-link { margin-top: 30px; padding-top: 18px; border-top: 1px solid var(--line-soft); font-size: 13px; }

/* Sign-in and other single cards sit on a tinted canvas so the page is not just grey. */
body:has(> main.card:not(.wide)) {
    background:
        radial-gradient(900px 480px at 50% -10%, rgba(138, 186, 255, .35), transparent 70%),
        radial-gradient(700px 400px at 100% 100%, rgba(0, 65, 119, .08), transparent 70%),
        var(--bg);
}

/* ---------- headings ---------- */
h1 {
    font-size: 24px;
    line-height: 1.2;
    margin: 0 0 14px;
    color: var(--text);
    font-weight: 650;
    letter-spacing: -.02em;
}
h1 .count { font-size: 13px; font-weight: 500; color: var(--brand); margin-left: 10px; padding: 2px 9px; border-radius: 999em; background: var(--brand-soft); letter-spacing: 0; vertical-align: 3px; }
a.back-link { display: inline-block; margin: -6px 0 10px; font-size: 13px; font-weight: 500; color: var(--muted); text-decoration: none; }
a.back-link:hover { color: var(--brand); }

h2.installation {
    font-size: 12px;
    margin: 30px 0 8px;
    color: var(--muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    display: flex; align-items: center; gap: 10px;
}
h2.installation::after { content: ""; flex: 1; height: 1px; background: var(--line-soft); }
h2.installation .count { font-weight: 600; color: var(--faint); text-transform: none; letter-spacing: 0; }

h3.subgroup { font-size: 15px; margin: 18px 0 4px; color: var(--text); font-weight: 600; letter-spacing: -.01em; }
h3.subgroup .count { font-weight: 500; color: var(--faint); margin-left: 8px; font-size: 13px; }

p { line-height: 1.55; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.5; }

pre {
    background: var(--bg);
    border: 1px solid var(--line-soft);
    padding: 12px 14px;
    border-radius: var(--radius-s);
    overflow: auto;
    font-size: 13px;
    font-family: var(--mono);
}

/* ---------- controls ---------- */
button, .button {
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.2;
    padding: 8px 16px;
    border-radius: var(--radius-button);
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: background-color .15s, box-shadow .15s, border-color .15s, transform .05s;
}
button:hover, .button:hover { background: var(--row-hover); border-color: #c3ccd8; }
button:active, .button:active { transform: translateY(1px); }
button:focus-visible, .button:focus-visible, a:focus-visible { outline: none; box-shadow: var(--ring); }

button.primary, .button {
    background: linear-gradient(180deg, #0b4f8c, var(--brand));
    border-color: var(--brand);
    color: #fff;
    box-shadow: var(--shadow-button);
}
button.primary:hover, .button:hover {
    background: linear-gradient(180deg, #0a4580, var(--brand-hover));
    border-color: var(--brand-hover);
    color: #fff;
    box-shadow: var(--shadow-button-hover);
}

button.danger { background: #fff; border-color: #f1b7b7; color: var(--danger); box-shadow: none; }
button.danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }

button.link, a.link { background: none; border: 1px solid transparent; color: var(--link); padding: 6px 10px; box-shadow: none; border-radius: 8px; text-decoration: none; }
button.link:hover, a.link:hover { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
button:disabled, button:disabled:hover { opacity: .45; cursor: default; box-shadow: none; transform: none; }
button.primary:disabled { background: var(--brand); }

form.inline { display: inline; margin: 0; }
form.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 12px 0 6px; }
form.row label.hint { display: inline-flex; align-items: center; gap: 6px; }

input[type="text"], input[type="email"], select {
    font: inherit;
    font-size: 14px;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
    height: 38px;
    padding: 0 12px;
    transition: border-color .15s, box-shadow .15s;
}
input[type="text"]::placeholder, input[type="email"]::placeholder { color: var(--faint); }
input[type="text"]:hover, input[type="email"]:hover, select:hover { border-color: #c3ccd8; }
input[type="text"]:focus, input[type="email"]:focus, select:focus { outline: none; border-color: var(--link); box-shadow: var(--ring); }
form.row input[type="text"], form.row input[type="email"] { min-width: 260px; }
select { padding-right: 32px; appearance: none; -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%2364748b' stroke-width='1.6' stroke-linecap='round'/></svg>");
    background-repeat: no-repeat; background-position: right 12px center; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--brand); width: 15px; height: 15px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 14px; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line-soft); }
th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; padding-top: 6px; padding-bottom: 8px; }
tbody tr { transition: background-color .12s; }
tbody tr:hover { background: var(--row-hover); }
tbody tr:last-child td { border-bottom: 0; }

.badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px;
    border-radius: 999em;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: .01em;
    background: var(--line-soft);
    color: var(--muted);
    white-space: nowrap;
}
.badge.online, .badge.offline, .badge.unknown { padding-left: 8px; }
.badge.online::before, .badge.offline::before, .badge.unknown::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.online { background: var(--ok-soft); color: var(--ok); }
.badge.online::before { box-shadow: 0 0 0 3px rgba(21, 128, 61, .15); }
.badge.offline { background: var(--danger-soft); color: var(--danger); }
.badge.unknown { background: var(--line-soft); color: var(--muted); }
.badge.manager { background: var(--brand-soft); color: var(--brand); margin-left: 6px; }
.badge.off { background: var(--warn-soft); color: var(--warn); margin-left: 6px; }
.since { margin-left: 8px; color: var(--faint); font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }

td.version { font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: visible; }
td.version.outdated { color: var(--warn); font-weight: 600; }
td.version.outdated::after { content: " \2191"; font-weight: 400; }
td.place { color: var(--muted); }

/* People lists: the two action columns sit at the right edge, each as narrow as its widest label. */
table.users td.action { width: 1%; white-space: nowrap; text-align: right; padding-left: 16px; }
table.users td.action button.link { padding: 4px 8px; }
form.rename { margin: -8px 0 14px; }
form.rename input[type="text"] { min-width: 260px; }

table.devices { table-layout: fixed; }
table.devices col.c-host { width: 22%; }
table.devices col.c-status { width: 23%; }
table.devices col.c-version { width: 11%; }
table.devices col.c-place { width: 14%; }
table.devices col.c-action { width: 30%; }
table.devices td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
table.devices td.action { text-align: right; white-space: nowrap; overflow: visible; padding-left: 0; }
table.devices td.action button, table.devices td.action .button { padding: 6px 13px; font-size: 13px; line-height: normal; vertical-align: middle; }
table.devices td.host .mono { margin-left: 2px; font-weight: 500; }

button.toggle {
    width: 24px; height: 24px; padding: 0; margin-right: 6px; line-height: 22px;
    border: 1px solid transparent; background: none; color: var(--link); border-radius: 6px; font-size: 17px;   /* the same arrow size as the Access disclosure */
    transition: transform .15s, background-color .15s, color .15s;
}
button.toggle:hover { background: var(--line-soft); color: var(--text); }
button.toggle[aria-expanded="true"] { transform: rotate(90deg); color: var(--brand); }
tr.details > td { white-space: normal; background: var(--row-hover); padding: 12px 16px 14px 44px; box-shadow: inset 3px 0 0 var(--accent); }
tr.details:hover > td { background: var(--row-hover); }
dl.device-details {
    display: grid; grid-template-columns: max-content 1fr max-content 1fr max-content 1fr;
    gap: 6px 20px; margin: 0; font-size: 13px;
}
dl.device-details dt { color: var(--muted); white-space: nowrap; }
dl.device-details dd { margin: 0; font-variant-numeric: tabular-nums; white-space: nowrap; font-family: var(--mono); font-size: 12.5px; }
details.access { margin-top: 12px; font-size: 13px; }
details.access summary { cursor: pointer; color: var(--link); width: max-content; font-weight: 500; }
details.access summary:hover { color: var(--brand); }
p.access-none { margin: 12px 0 0; font-size: 13px; color: var(--faint); }
details.access p { margin: 6px 0 0; line-height: 1.6; }
table.access { width: auto; min-width: 420px; max-width: 100%; margin-top: 8px; background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--radius-s); font-size: 13px; overflow: hidden; }
table.access th, table.access td { padding: 7px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.access tr:last-child td { border-bottom: 0; }
table.access td.mono { white-space: nowrap; }
table.access .badge.manager { font-size: 11px; padding: 1px 7px; }
@media (max-width: 900px) {
    dl.device-details { grid-template-columns: max-content 1fr; }
    table.devices col.c-place, table.devices td.place, table.devices thead th:nth-child(4) { display: none; }
    table.devices col.c-host { width: 42%; } table.devices col.c-status { width: 26%; } table.devices col.c-version { width: 12%; }
}
@media (max-width: 640px) {
    table.devices col.c-version, table.devices td.version, table.devices thead th:nth-child(3) { display: none; }
    table.devices .since { display: none; }
}

table.devices tr.share td { padding-top: 2px; padding-bottom: 10px; border-bottom: 1px solid var(--line-soft); }
table.devices tr.share button.link { padding: 0 4px; font-size: 13px; text-decoration: underline; }

.badge.note { background: #fff4d6; color: #7a4b00; border: 1px solid #f1dca0; margin-left: 6px; font-weight: 500; }
form.name-installation { margin-left: 10px; display: inline-flex; gap: 4px; align-items: center; }
form.name-installation input[type="text"], form.name-installation button[type="submit"], form.name-installation button.cancel { display: none; }
form.name-installation.editing input[type="text"], form.name-installation.editing button[type="submit"], form.name-installation.editing button.cancel { display: inline-block; }
form.name-installation.editing button.open { display: none; }
form.name-installation input[type="text"] { height: 28px; padding: 0 8px; font-size: 13px; width: 180px; }
form.name-installation button.link { padding: 2px 6px; font-size: 13px; }
@media (max-width: 640px) { form.name-installation { margin-left: 0; margin-top: 6px; flex-basis: 100%; } form.name-installation input[type="text"] { flex: 1; width: auto; } }

/* ---------- browser shell ---------- */
.button.shell { padding: 5px 8px; font-size: 12.5px; font-weight: 700; letter-spacing: 0; background: #0b1220; border-color: #0b1220; color: #9ee7a8; min-width: 0; }
.button.shell:hover { background: #162238; border-color: #162238; color: #c6f5cc; }
body.shell-page { background: #0b1220; }
html:has(body.shell-page), body.shell-page { overflow: hidden; height: 100%; overscroll-behavior: none; }
body.shell-page #term { position: fixed; top: var(--topbar-h); left: 0; right: 0; height: calc(100vh - var(--topbar-h)); padding: 6px 8px; box-sizing: border-box; }
body.shell-page .shell-keys { position: fixed; top: var(--topbar-h); left: 0; right: 0; display: flex; gap: 6px; padding: 6px 8px; overflow-x: auto; background: #111a2b; border-bottom: 1px solid #243352; z-index: 5; -webkit-overflow-scrolling: touch; }
body.shell-page .shell-keys button { flex: 0 0 auto; min-width: 44px; height: 34px; padding: 0 10px; font: 600 13px/1 var(--mono); color: #cfe3ff; background: #1b2740; border: 1px solid #2d3d5e; border-radius: 8px; }
body.shell-page .shell-keys button.armed, .shell-overlay .shell-keys button.armed { background: #3b82f6; border-color: #3b82f6; color: #fff; }
body.shell-page .shell-keys:not([hidden]) ~ #term { top: calc(var(--topbar-h) + 47px); }
body.shell-page .topbar { position: fixed; }

/* the shell's bar, the same on the page and in the overlay, whatever the body carries */
.topbar.shell-bar { background: var(--brand); border-bottom: 0; color: #fff; box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
.topbar.shell-bar .brand img { height: 20px; }
.topbar.shell-bar .device { background: rgba(255, 255, 255, .14); color: #fff; border: 1px solid rgba(255, 255, 255, .14); padding: 3px 10px; }
.topbar.shell-bar .device.mono { font-family: var(--mono); font-weight: 500; font-size: 13px; letter-spacing: 0; }
.topbar.shell-bar .badge { margin-left: 4px; }
.topbar.shell-bar button.danger { padding: 6px 13px; }

/* the shell as an overlay on the device list */
.shell-overlay { position: fixed; inset: 0; z-index: 60; background: #0b1220; }
.shell-overlay .topbar { position: absolute; top: 0; left: 0; right: 0; }
.shell-overlay .shell-keys { position: absolute; top: var(--topbar-h); left: 0; right: 0; display: flex; gap: 6px; padding: 6px 8px; overflow-x: auto; background: #111a2b; border-bottom: 1px solid #243352; }
.shell-overlay .shell-keys button { flex: 0 0 auto; min-width: 44px; height: 34px; padding: 0 10px; font: 600 13px/1 var(--mono); color: #cfe3ff; background: #1b2740; border: 1px solid #2d3d5e; border-radius: 8px; }
.shell-overlay .shell-keys button.armed { background: #3b82f6; border-color: #3b82f6; color: #fff; }
.shell-overlay .shell-term { position: absolute; left: 0; right: 0; padding: 6px 8px; box-sizing: border-box; }
.shell-overlay .shell-term .xterm { height: 100%; }
body.shell-open { overflow: hidden; background: #0b1220; }
html:has(body.shell-open) { background: #0b1220; }
body.shell-page .xterm { height: 100%; }

/* ---------- notices ---------- */
.notice {
    font-size: 14px;
    padding: 11px 16px;
    border-radius: var(--radius-s);
    background: var(--brand-soft);
    border: 1px solid #cfe0f3;
    color: var(--brand);
    margin-bottom: 16px;
    display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px;
}
.notice a, .notice button.link { text-decoration: underline; padding: 0 2px; border: 0; background: none; }
.notice a:hover, .notice button.link:hover { background: none; }
.notice .open-session { white-space: nowrap; }
.notice .open-session form { margin: 0; }
.notice .open-session button.link { font-size: inherit; }
.notice.error { background: var(--danger-soft); border-color: #f3c2c2; color: var(--danger); }
.button.resume, .button.resume:hover { background: var(--accent); border-color: var(--accent); color: var(--navy); text-decoration: none; box-shadow: none; }
.button.resume:hover { background: #a3c8ff; }

/* ---------- top bar ---------- */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 22px;
    background: rgba(255, 255, 255, .86);
    -webkit-backdrop-filter: saturate(160%) blur(10px);
    backdrop-filter: saturate(160%) blur(10px);
    border-bottom: 1px solid var(--line-soft);
    color: var(--text);
    z-index: 10;
}
.topbar > * { flex-shrink: 0; white-space: nowrap; }
.topbar form.inline { display: inline-flex; align-items: center; gap: 2px; }
.topbar .brand { display: flex; align-items: center; margin-right: 18px; }
.topbar .brand img { height: 20px; width: auto; display: block; }
.topbar .device { background: var(--brand-soft); color: var(--brand); padding: 3px 10px; border-radius: 999em; font-size: 12.5px; font-weight: 600; letter-spacing: .02em; }
.topbar .customer { color: var(--muted); font-size: 13px; }
.topbar .user { color: var(--muted); font-size: 13px; margin: 0 4px 0 10px; max-width: 260px; min-width: 40px; flex-shrink: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar a.link, .topbar button.link { font-size: 14px; font-weight: 500; color: var(--text); padding: 5px 10px; border-radius: 999em; text-decoration: none; }
.topbar a.link:hover, .topbar button.link:hover { background: var(--line-soft); color: var(--brand); text-decoration: none; }
.topbar .spacer { flex: 1; }
.topbar select { height: 31px; padding: 0 30px 0 10px; font-size: 13.5px; }
.topbar button.danger, .topbar button.primary { padding: 6px 13px; }

body:not(.session) .topbar + main { margin-top: calc(var(--topbar-h) + 24px); }

/* A device session: the bar is the config tool's brand blue, flat, so it meets the top of the
   sidebar (#004177 before its gradient starts) as one frame around the device UI. */
body.session .topbar {
    background: var(--brand);
    border-bottom: 0;
    color: #fff;
    box-shadow: none;
    -webkit-backdrop-filter: none; backdrop-filter: none;
}
body.session .topbar .device { background: rgba(255, 255, 255, .14); color: #fff; border: 1px solid rgba(255, 255, 255, .14); padding: 3px 10px; }

body.session .topbar .device.mono { font-family: var(--mono); font-weight: 500; font-size: 13px; letter-spacing: 0; }
body.session .topbar .user { margin-left: 14px; }
body.session .topbar .customer, body.session .topbar .user { color: rgba(255, 255, 255, .72); }
body.session .topbar a.link, body.session .topbar button.link { color: #fff; }
body.session .topbar a.link:hover, body.session .topbar button.link:hover { background: rgba(255, 255, 255, .12); color: #fff; }
body.session .topbar select { background-color: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .22); color: #fff;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='white' stroke-width='1.6' stroke-linecap='round'/></svg>"); }
body.session .topbar select option, body.session .topbar select optgroup { color: var(--text); background: #fff; }
body.session .topbar button.primary { background: var(--accent); border-color: var(--accent); color: var(--navy); box-shadow: none; }
body.session .topbar button.danger { background: transparent; border-color: rgba(255, 255, 255, .35); color: #fff; margin-left: 6px; }
body.session .topbar button.danger:hover { background: var(--danger); border-color: var(--danger); }
body.session .topbar .badge.offline { background: var(--danger-soft); }

body.session iframe#device {
    position: fixed;
    top: var(--topbar-h); left: 0; right: 0; bottom: 0;
    width: 100%;
    height: calc(100% - var(--topbar-h));
    border: 0;
    background: #fff;
}

body.error { padding: 24px; background: #fff; }

/* The session bar carries the most; it sheds the least important pieces first. */
@media (max-width: 1180px) { body.session .topbar .user { display: none; } }
@media (max-width: 1100px) { body.session .topbar a.link, body.session .topbar .device:not(.mono) { display: none; } }
@media (max-width: 800px) { body.session .topbar form.inline:has(select) { display: none; } }
@media (max-width: 640px) {
    body.session .topbar .brand img { height: 18px; }
    body.session .topbar .device.mono { flex-shrink: 1; min-width: 60px; overflow: hidden; text-overflow: ellipsis; }
    body.session .topbar button.danger { padding: 6px 10px; }
}
@media (max-width: 640px) {
    .card { margin: 16px; padding: 24px 20px; }
    .card.wide { margin: 16px; padding: 22px 18px; }
    .topbar { gap: 4px; padding: 0 12px; }
    .topbar .brand { margin-right: 6px; }
    .topbar .customer, .topbar .user { display: none; }
    h1 { font-size: 21px; }
}

/* ---------- activity ---------- */
table.activity td.when { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; width: 130px; font-size: 13px; }
table.activity td.who { white-space: nowrap; width: 240px; overflow: hidden; text-overflow: ellipsis; }
table.activity td.who .hint { color: var(--faint); margin-left: 4px; }
table.activity.compact { font-size: 13px; }
table.activity.compact td { padding: 7px 10px; }
table.activity td.what .mono { font-size: 13px; }
form.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 10px 0 16px; }
button.filter-clear { padding: 4px 8px; font-size: 13px; }
/* Inputs that deserve room on a desktop; on a phone they take the line and never widen the page. */
input.wide-input { max-width: 100%; }
input.wide-input.w320 { min-width: 320px; }
input.wide-input.w360 { min-width: 360px; }
input.wide-input.w380 { min-width: 380px; }
form.filters input[type="text"] { min-width: 180px; }

/* ---------- update dialog ---------- */
button.update { margin-right: 6px; }
button.update.attention { border-color: #f0c66a; color: var(--warn); background: var(--warn-soft); }
button.update.attention:hover { background: #fde68a; }
dialog.deploy { border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 0; width: min(560px, 92vw); box-shadow: 0 24px 60px -12px rgba(5, 40, 71, .45); color: var(--text); }
dialog.deploy::backdrop { background: rgba(5, 40, 71, .45); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.deploy-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px 0; margin: 0; }
.deploy-head h2 { font-size: 18px; margin: 0; color: var(--text); font-weight: 650; letter-spacing: -.01em; }
.deploy-head h2 .mono { font-size: 16px; color: var(--brand); }
.deploy-head button.link { color: var(--faint); font-size: 16px; padding: 4px 8px; }
.deploy-body { font-size: 14px; padding: 8px 22px 20px; }
.deploy-body fieldset { border: 1px solid var(--line-soft); border-radius: var(--radius-s); padding: 10px 14px 12px; margin: 10px 0; background: var(--row-hover); }
.deploy-body legend { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; padding: 0 6px; }
.deploy-body fieldset label { display: block; padding: 6px 0; }
.deploy-body fieldset label .hint { margin-left: 6px; display: block; padding-left: 22px; }
.deploy-body p.row { margin-top: 16px; }
.deploy-body p.row.end { display: flex; justify-content: flex-end; }   /* a lone Close sits where a dialog's closing button is expected */
table.progress { font-size: 14px; table-layout: fixed; width: 100%; }
table.progress td { padding: 9px 6px; vertical-align: top; }
table.progress td.pkg { font-weight: 600; width: 110px; }
table.progress td.target { font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; width: 80px; }
table.progress td.bar { width: 130px; }
table.progress td.state { font-size: 13px; line-height: 1.35; }   /* a long status wraps instead of widening the dialog */
dialog.deploy { overflow-x: hidden; }
table.progress tr.refused td.state { color: var(--danger); }
table.progress tr.done td.state { color: var(--ok); }
.meter { height: 8px; background: var(--line-soft); border-radius: 999px; overflow: hidden; }
.meter > div { height: 100%; background: linear-gradient(90deg, var(--brand), #2f7fd1); width: 0; transition: width .4s; border-radius: 999px; }

/* ---------- device tools (details panel) and the DALI dialog ---------- */
.tools { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 13px; }
.tools-label { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; margin-right: 4px; }
.tools button.link { padding: 3px 8px; font-size: 13px; }
.notice.warn { background: var(--warn-soft); border-color: #f3dc9a; color: var(--warn); display: block; }
dialog.dali .deploy-body p.working { color: var(--muted); }
dialog.dali .deploy-body p.working::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 8px; vertical-align: -1px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--brand); animation: spin .8s linear infinite; }
dialog.dali p.result { font-size: 16px; margin: 6px 0; }
dialog.dali p.result strong { font-size: 28px; color: var(--brand); margin-right: 6px; font-variant-numeric: tabular-nums; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- waiting: the bar while a connect runs, the device area while the device loads ---------- */
button.connecting { cursor: progress; }
button.connecting .btn-spinner { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .35); border-top-color: #fff; animation: spin .8s linear infinite; vertical-align: -2px; }
body.session .loading {
    position: fixed; top: var(--topbar-h); left: 0; right: 0; bottom: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
    background: #fff; color: var(--text); z-index: 5; text-align: center;
}
body.session .loading p { margin: 0; font-size: 15px; }
body.session .loading p.hint { margin-top: 2px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line-soft); border-top-color: var(--brand); animation: spin .8s linear infinite; margin-bottom: 10px; }

/* staff quick add to their own customer: a round +/- on the row, "+ all" on the installation heading */
button.mine-btn {
    width: 28px; height: 28px; padding: 0; margin-right: 8px; border-radius: 50%;
    border: 1.5px solid var(--brand); background: #fff; color: var(--brand);
    position: relative; display: inline-block; vertical-align: middle;
    transition: background-color .15s, color .15s, transform .05s;
}
/* The plus is two bars drawn by the button; the minus keeps the horizontal one. */
button.mine-btn::before, button.mine-btn::after {
    content: ""; position: absolute; top: 50%; left: 50%; background: currentColor; border-radius: 1px;
    transform: translate(-50%, -50%);
}
button.mine-btn::before { width: 12px; height: 2px; }
button.mine-btn::after { width: 2px; height: 12px; }
button.mine-btn.on::after { display: none; }
button.mine-btn:hover { background: var(--brand-soft); border-color: var(--brand); }
button.mine-btn.on { background: var(--brand); color: #fff; }
button.mine-btn.on:hover { background: var(--danger); border-color: var(--danger); }
h3.subgroup form.mine-all { margin-left: 10px; vertical-align: middle; }
h3.subgroup form.mine-all button.link { font-size: 12.5px; font-weight: 500; padding: 2px 8px; }

/* refresh on the device lists */
/* same spot on both device lists: the end of the heading line */
h1 a.link.refresh, h1 button.link.refresh { font-size: 13px; font-weight: 500; white-space: nowrap; margin-left: 12px; vertical-align: 3px; letter-spacing: 0; }
h1 form.sync { margin-left: 0; vertical-align: 3px; }
h1 form.sync button.link.refresh { margin-left: 6px; vertical-align: baseline; }

/* report links in the device details */
.tools.reports .report { padding: 3px 8px; border-radius: 8px; text-decoration: none; }
.tools.reports .report.missing { color: var(--faint); cursor: default; text-decoration: line-through; text-decoration-color: var(--line); }
.tools.reports a.report.available { color: var(--link); }
.tools.reports a.report.available:hover { background: var(--brand-soft); color: var(--brand); }

/* folded installations on the staff list */
section.installation-group.folded h3.subgroup { display: flex; align-items: center; gap: 6px; }
section.installation-group.folded h3.subgroup button.toggle { margin-right: 2px; }
section.installation-group.folded h3.subgroup .online-count { margin-left: 4px; font-weight: 400; }
section.installation-group.folded .rows-lazy { margin-left: 30px; }
#search-results h3.subgroup { margin-top: 18px; }

/* ---------- phones ---------- */
/* Data tables become stacked rows below 640 px: the head goes, each row is a small card and
   the cells flow in reading order with the actions last. The device tables keep their own
   column rules above. */
@media (max-width: 640px) {
    .card.wide { margin: 8px; padding: 18px 14px 20px; }
    body:not(.session) .topbar + main { margin-top: calc(var(--topbar-h) + 12px); }
    h1 { font-size: 20px; }
    h2.installation { font-size: 15px; }
    p.hint { font-size: 13px; }

    .topbar { padding: 0 10px; gap: 2px; }
    .topbar a.link, .topbar button.link { font-size: 13px; padding: 4px 6px; }
    .topbar .device:not(.mono) { display: none; }
    /* the wordmark goes; the logo's icon, at its left edge, stays */
    body:not(.session) .topbar .brand { margin-right: 4px; }
    body:not(.session) .topbar .brand img { width: 24px; height: 22px; object-fit: cover; object-position: left center; }

    form.row { gap: 8px; }
    html, body { overflow-x: hidden; }   /* nothing on a phone may push the page sideways */

    /* installation headings, two lines each: the arrow, the name and the count; then, indented
       past the arrow, the online figure with every tool after it on the same line */
    section.installation-group h3.subgroup { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
    section.installation-group h3.subgroup .name { flex: 1 1 0; min-width: 0; overflow-wrap: anywhere; }   /* takes the line between the arrow and the count, wrapping inside it */
    section.installation-group h3.subgroup .count { flex: 0 0 auto; margin-left: 0; white-space: nowrap; }
    /* a full-width pseudo item between the count and the rest forces the second line; the rest is ordered after it */
    section.installation-group h3.subgroup::after { content: ""; flex-basis: 100%; height: 0; order: 1; }
    section.installation-group h3.subgroup .online-count, section.installation-group h3.subgroup form.mine-all,
    section.installation-group h3.subgroup form.name-installation, section.installation-group h3.subgroup .badge.note { order: 2; }
    section.installation-group.folded h3.subgroup .online-count { flex: 0 0 auto; white-space: nowrap; margin-left: 32px; font-weight: 400; }
    section.installation-group h3.subgroup form.mine-all { margin-left: 0; }
    section.installation-group h3.subgroup form.mine-all button.link { white-space: nowrap; padding: 2px 0; }
    section.installation-group h3.subgroup .badge.note { margin-left: 0; }
    section.installation-group h3.subgroup form.name-installation { margin-left: 0; margin-top: 0; flex-basis: auto; }
    section.installation-group h3.subgroup form.name-installation.editing { flex-basis: 100%; margin-left: 32px; }
    section.installation-group.mine h3.subgroup form.mine-all { margin-left: 0; }
    input.wide-input { min-width: 0 !important; width: 100%; }
    form.row input[type="text"], form.row input[type="email"], form.row select { min-width: 0; width: 100%; flex: 1 1 100%; }
    table.devices > tbody > tr > td.status { white-space: normal; text-align: right; }   /* several badges wrap under each other */
    form.row button { flex: 1 1 auto; }
    form.filters { flex-wrap: wrap; }
    form.filters select, form.filters input { width: 100%; }

    table.users thead, table.activity thead, table.customers thead, table.access thead { display: none; }
    table.users, table.users tbody, table.users tr, table.users td,
    table.activity, table.activity tbody, table.activity tr, table.activity td,
    table.customers, table.customers tbody, table.customers tr, table.customers td { display: block; width: auto; }
    table.users tr, table.activity tr, table.customers tr { padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
    table.users td, table.activity td, table.customers td { padding: 1px 0; border: 0; white-space: normal; overflow: visible; }

    /* users: e-mail, then account and last sign-in as meta, then the actions side by side */
    table.users td:nth-child(1) { font-weight: 500; }
    table.users td:nth-child(2), table.users td:nth-child(3) { display: inline-block; color: var(--muted); font-size: 13px; margin-right: 12px; }
    /* a user row: e-mail, then account and last sign-in filling the line, then the actions on a line of their own */
    table.users tr { display: flex; flex-wrap: wrap; align-items: baseline; }
    table.users td:nth-child(1) { flex: 1 1 100%; }
    table.users td:nth-child(2) { flex: 0 0 auto; }
    table.users td:nth-child(3) { flex: 1 1 auto; }
    table.users td.action { flex: 0 0 auto; display: block; width: auto; text-align: left; padding: 4px 8px 0 0; }

    /* a device row on a phone: hostname and status on the first line, the buttons in a row
       of their own underneath, right-aligned; the details and share rows span the width */
    /* child combinators throughout: the access table inside a details row is a table of its own */
    table.devices, table.devices > tbody { display: block; }
    table.devices > colgroup, table.devices > thead { display: none; }
    table.devices > tbody > tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 8px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line-soft); }
    table.devices > tbody > tr > td { display: block; padding: 0; border: 0; overflow: visible; }
    table.devices > tbody > tr > td.host { grid-column: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    table.devices > tbody > tr > td.host .mono { font-size: 12.5px; letter-spacing: -.02em; }
    table.devices > tbody > tr > td.status { grid-column: 2; justify-self: end; }
    table.devices > tbody > tr > td.action { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; align-items: center; white-space: normal; padding: 6px 0 0; text-align: right; }
    table.devices > tbody > tr > td.action button, table.devices > tbody > tr > td.action .button { margin: 0; padding: 5px 11px; font-size: 13px; }
    table.devices > tbody > tr.details, table.devices > tbody > tr.share { display: block; padding: 0; }
    table.devices > tbody > tr.details > td { padding: 10px 12px 12px 14px; }
    table.devices > tbody > tr.share > td { padding: 2px 0 8px; }
    table.access td { white-space: normal; overflow-wrap: anywhere; }
    form.rename input[type="text"] { min-width: 0; width: 100%; }
    form.filters input[type="text"] { min-width: 0; }
    .notice .open-session { white-space: normal; }

    /* activity: when and who on one line, what below */
    table.activity td.when, table.activity td.who { display: inline-block; width: auto; font-size: 12.5px; margin-right: 10px; }
    table.activity td.what { padding-top: 3px; }

    /* customers: name, then counts, then manage */
    table.customers td:nth-child(2)::before { content: "Users: "; color: var(--muted); }
    table.customers td:nth-child(3)::before { content: "Devices: "; color: var(--muted); }
    table.customers td:nth-child(2), table.customers td:nth-child(3) { display: inline-block; font-size: 13px; margin-right: 12px; }
    table.customers td:last-child { padding-top: 4px; }

    table.access { min-width: 0; width: 100%; }
    table.access th, table.access td { padding: 6px 8px; }

    dl.device-details { grid-template-columns: 1fr; }
    dl.device-details dt { margin-top: 6px; }

    dialog.deploy { width: calc(100vw - 16px); max-height: calc(100vh - 16px); overflow: auto; }
    .deploy-head { padding: 14px 14px 0; }
    .deploy-body { padding: 8px 14px 16px; }
    .deploy-body fieldset { padding: 8px 10px 10px; }
}
