/*
 * Theme tokens.
 *
 * Dark is the base because that is what this product has always been and what an unconfigured
 * install should keep looking like. Light arrives two ways: automatically for users whose OS
 * asks for it, and explicitly via [data-theme] when the user or the tenant has chosen.
 *
 * Cascade order matters and is relied on by ThemeService::cssVariables(), which injects a
 * tenant's accent using exactly this shape:
 *   1. :root                                  -> dark defaults
 *   2. @media light + :not([data-theme=dark]) -> follow the OS, unless overridden to dark
 *   3. [data-theme=light|dark]                -> an explicit choice always wins
 *
 * --on-accent is the foreground for anything sitting *on* the accent. It is a token rather than
 * a hardcoded near-black because a tenant's brand colour may be bright (yellow, lime), where
 * white text is unreadable and dark text is required. ThemeService computes it per accent.
 */
:root {
    color-scheme: dark;
    --bg: #0B1220;
    --surface: #131C2E;
    --surface-2: #1E293B;
    --border: #26334A;
    --text: #FFFFFF;
    --text-muted: #94A3B8;
    --accent: #00C2FF;
    --accent-hover: #4FD5FF;
    --on-accent: #0B1220;
    --ok: #22C55E;
    --warn: #F59E0B;
    --crit: #F04452;
    --info: #7B61FF;
    --login-grad-a: #0B1220;
    --login-grad-b: #131C2E;
}

/*
 * Light palette. The status colours are not the dark ones reused: #4ade80 on white is about
 * 1.6:1 and effectively invisible, so each has a darker sibling that actually reads.
 */
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        color-scheme: light;
        --bg: #F4F7FB;
        --surface: #FFFFFF;
        --surface-2: #EDF2F9;
        --border: #D6DEEA;
        --text: #0B1220;
        --text-muted: #475569;
        --accent: #0A66FF;
        --accent-hover: #0850CC;
        --on-accent: #FFFFFF;
        --ok: #15803D;
        --warn: #B45309;
        --crit: #C0261F;
        --info: #6D4AFF;
        --login-grad-a: #EDF2F9;
        --login-grad-b: #FFFFFF;
    }
}

:root[data-theme="light"] {
    color-scheme: light;
    --bg: #F4F7FB;
    --surface: #FFFFFF;
    --surface-2: #EDF2F9;
    --border: #D6DEEA;
    --text: #0B1220;
    --text-muted: #475569;
    --accent: #0A66FF;
    --accent-hover: #0850CC;
    --on-accent: #FFFFFF;
    --ok: #15803D;
    --warn: #B45309;
    --crit: #C0261F;
    --info: #6D4AFF;
    --login-grad-a: #EDF2F9;
    --login-grad-b: #FFFFFF;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0B1220;
    --surface: #131C2E;
    --surface-2: #1E293B;
    --border: #26334A;
    --text: #FFFFFF;
    --text-muted: #94A3B8;
    --accent: #00C2FF;
    --accent-hover: #4FD5FF;
    --on-accent: #0B1220;
    --ok: #22C55E;
    --warn: #F59E0B;
    --crit: #F04452;
    --info: #7B61FF;
    --login-grad-a: #0B1220;
    --login-grad-b: #131C2E;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
.muted { color: var(--text-muted); }

/* Top nav */
.top-nav {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.top-nav .brand a {
    font-weight: 700;
    font-size: 19px;
    color: var(--text);
}
.top-nav .nav-links {
    list-style: none;
    display: flex;
    gap: 4px;
    margin: 0;
    padding: 0;
    flex: 1;
}
.top-nav .nav-links a {
    display: block;
    padding: 6px 12px;
    border-radius: 4px;
    color: var(--text);
}
.top-nav .nav-links a:hover {
    background: var(--surface-2);
    text-decoration: none;
}
.user-menu {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
}
.user-menu span { font-size: 14px; }

.main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}
.page-header h2 { margin: 0; font-size: 23px; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    font-size: 15px;
    text-decoration: none;
}
.btn:hover { background: var(--border); text-decoration: none; }
.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
.btn-block { width: 100%; }
.btn-secondary { background: transparent; }
.btn-danger { color: var(--crit); border-color: var(--crit); }

/* Forms */
form input[type=text], form input[type=email], form input[type=password],
form input[type=number], form input[type=url], form select, form textarea {
    display: block;
    width: 100%;
    padding: 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 15px;
    margin-bottom: 12px;
}
form input:focus, form select:focus, form textarea:focus {
    outline: none;
    border-color: var(--accent);
}
form label { display: block; font-size: 14px; color: var(--text-muted); margin-bottom: 4px; }
form .input { margin-bottom: 16px; }
form .input.checkbox { display: flex; gap: 8px; align-items: center; }
form .input.checkbox label { margin: 0; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; }

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: 6px;
    /* Not `overflow: hidden` — a row's action menu is absolutely positioned and must be
       able to escape the table box. Corners are rounded per-cell instead (below). */
    overflow: visible;
}
.data-table th, .data-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.data-table th {
    background: var(--surface-2);
    font-weight: 600;
    font-size: 14px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.data-table tr:last-child td { border-bottom: none; }
/* Replaces the clipping that `overflow: hidden` used to provide. */
.data-table thead tr:first-child th:first-child { border-top-left-radius: 6px; }
.data-table thead tr:first-child th:last-child { border-top-right-radius: 6px; }
.data-table tbody tr:last-child td:first-child { border-bottom-left-radius: 6px; }
.data-table tbody tr:last-child td:last-child { border-bottom-right-radius: 6px; }
.data-table .actions { white-space: nowrap; }
.data-table .actions a, .data-table .actions form { display: inline-block; margin-right: 8px; }
.data-table .actions form button {
    background: none;
    border: none;
    color: var(--crit);
    cursor: pointer;
    padding: 0;
    font-size: 15px;
}

/* Row actions collapsed into a menu: items stack full-width and keep dropdown styling
   rather than the inline link/button treatment above. */
.data-table .actions .dropdown { margin: 0; }
.data-table .actions .dropdown-menu a,
.data-table .actions .dropdown-menu form { display: block; margin-right: 0; width: 100%; }
.data-table .actions .dropdown-menu form button.dropdown-item {
    color: var(--text);
    padding: 8px 12px;
    font-size: 15px;
    width: 100%;
}
.data-table .actions .dropdown-menu form button.dropdown-item:hover,
.data-table .actions .dropdown-menu form button.dropdown-item:focus { background: var(--border); }
.data-table .actions .dropdown-menu .dropdown-item.is-danger,
.data-table .actions .dropdown-menu form button.dropdown-item.is-danger { color: var(--crit); }
/* Menus on the last rows would open off the bottom of the table; flip them upward. */
.dropdown-menu.drop-up { top: auto; bottom: calc(100% + 4px); }

.checkbox-inline {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 15px;
    margin-top: 8px;
    cursor: pointer;
}
.checkbox-inline input { margin-top: 3px; flex: 0 0 auto; }

/* Bulk selection toolbar above a table */
.bulk-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 10px;
}
.bulk-bar[hidden] { display: none; }
.bulk-count { font-size: 14px; color: var(--text-muted); }
.bulk-bar select {
    padding: 6px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
}
.bulk-bar select[hidden] { display: none; }
.data-table .bulk-cell { width: 34px; text-align: center; padding-right: 0; }
.data-table .bulk-cell input { cursor: pointer; }

/* Dashboard switcher in the page header */
.dashboard-switch-name {
    display: inline-block;
    max-width: 190px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
}
.dashboard-switch-all {
    border-top: 1px solid var(--border);
    margin-top: 4px;
    padding-top: 8px;
    color: var(--text-muted);
}

/* Filter box above a long multi-select */
.select-filter {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
}
.select-filter-input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 6px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
}
.select-filter-input:focus {
    outline: none;
    border-color: var(--accent);
}
.select-filter-count { font-size: 13px; white-space: nowrap; }

/* Hardware health sensor tiles */
.sensor-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 10px;
    margin: 12px 0 18px;
}
.sensor-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}
.sensor-tile-label {
    font-size: 13px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sensor-tile-value { font-size: 21px; font-weight: 600; }
.sensor-tile-unit { font-size: 14px; color: var(--text-muted); margin-left: 3px; font-weight: 400; }
.sensor-tile-bad { border-color: var(--crit); }
.sensor-tile-bad .sensor-tile-value { color: var(--crit); }

/* Detected hardware chip */
.model-chip {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
}
.badge-super_admin { background: rgba(248, 113, 113, 0.15); color: var(--crit); }
.badge-admin { background: rgba(96, 165, 250, 0.15); color: var(--info); }
.badge-viewer { background: rgba(154, 164, 178, 0.15); color: var(--text-muted); }
.badge-up { background: rgba(74, 222, 128, 0.15); color: var(--ok); }
.badge-down { background: rgba(248, 113, 113, 0.15); color: var(--crit); }
.badge-unknown { background: rgba(154, 164, 178, 0.15); color: var(--text-muted); }

/* Flash messages */
.message {
    padding: 12px 16px;
    border-radius: 4px;
    margin-bottom: 16px;
}
.message.success { background: rgba(74, 222, 128, 0.1); color: var(--ok); border: 1px solid rgba(74, 222, 128, 0.3); }
.message.error { background: rgba(248, 113, 113, 0.1); color: var(--crit); border: 1px solid rgba(248, 113, 113, 0.3); }
.message.warning { background: rgba(251, 191, 36, 0.1); color: var(--warn); border: 1px solid rgba(251, 191, 36, 0.3); }
.message.info { background: rgba(96, 165, 250, 0.1); color: var(--info); border: 1px solid rgba(96, 165, 250, 0.3); }

/* Login */
.login-body {
    background: linear-gradient(135deg, var(--login-grad-a) 0%, var(--login-grad-b) 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-main { width: 360px; }
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 32px;
}
.login-card h1 {
    margin: 0 0 4px;
    font-size: 25px;
    text-align: center;
}
.login-card .muted { text-align: center; margin-bottom: 24px; }

/* Dashboard grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 16px;
    grid-auto-rows: 80px;
}
.widget {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 16px 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}
.widget-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.widget-title {
    font-size: 14px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.widget-actions { display: flex; gap: 6px; }
.mini-link { font-size: 13px; color: var(--text-muted); }
.mini-link:hover { color: var(--text); text-decoration: none; }
.mini-link-danger:hover { color: var(--crit); }
.widget-body { flex: 1; min-height: 0; position: relative; }
.widget-body canvas { width: 100% !important; height: 100% !important; }

/* Dropdown menu (page-header actions) */
.dropdown { position: relative; display: inline-block; }
.dropdown-toggle .dropdown-caret { margin-left: 4px; font-size: 13px; }
.dropdown.open .dropdown-toggle,
.dropdown-toggle[aria-expanded="true"] { background: var(--border); }
.dropdown-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    min-width: 200px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
    padding: 4px;
    z-index: 100;
    display: flex;
    flex-direction: column;
}
.dropdown-menu[hidden] { display: none; }
.dropdown-item {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: 0;
    color: var(--text);
    padding: 8px 12px;
    font-size: 15px;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    font-family: inherit;
}
.dropdown-item:hover,
.dropdown-item:focus { background: var(--border); color: var(--text); outline: none; text-decoration: none; }
.dropdown-item.is-active { background: var(--accent); color: var(--on-accent); }
.dropdown-item.is-active:hover { background: var(--accent-hover); }

/* Arrange / resize mode */
.arrange-bar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; margin: 0 0 12px;
    padding: 8px 12px;
    background: var(--surface); border: 1px dashed var(--border); border-radius: 6px;
}
.arrange-bar[hidden] { display: none; }
.arrange-bar-actions { display: flex; gap: 8px; }
.dashboard-grid.editing .widget {
    outline: 1px dashed var(--border-strong, #4b5563);
    user-select: none;
}
.dashboard-grid.editing .widget-head { cursor: grab; }
.dashboard-grid.editing .widget.dragging,
.dashboard-grid.editing .widget.resizing {
    opacity: 0.85;
    cursor: grabbing;
    z-index: 5;
}
.widget-resize-handle {
    position: absolute;
    right: 2px; bottom: 2px;
    width: 16px; height: 16px;
    cursor: nwse-resize;
    display: none;
    background:
        linear-gradient(135deg, transparent 0 7px, var(--text-muted) 7px 9px, transparent 9px 11px, var(--text-muted) 11px 13px, transparent 13px);
    border-radius: 2px;
    touch-action: none;
}
.dashboard-grid.editing .widget-resize-handle { display: block; }
.widget-drag-ghost {
    /* color-mix keeps the tint tied to the tenant's accent; the rgba() fallback is the
       product blue for browsers without it. */
    background: rgba(78, 161, 255, 0.10);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    border: 1px dashed var(--accent);
    border-radius: 6px;
    pointer-events: none;
}

/* Widget: summary stats */
/*
 * Widget: summary statistics.
 *
 * Rewritten because the previous grid escaped its own card. Three things caused that: columns
 * with an 80px minimum that a value like "1,284,930" cannot fit; units concatenated into the
 * number, so "24.71 ms" wrapped onto a second line; and a 100%-height grid with no minimum,
 * which overflowed the fixed-height widget body and printed over the title.
 */
.widget-summary {
    display: grid;
    /* Wide enough for a seven-digit sample count at the value size, so figures never collide
       with the next column. Five stats then land as 5 / 3+2 / 2+2+1 as the widget narrows,
       instead of overlapping. */
    grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
    gap: 11px 16px;
    /* Centre the stats when there is spare room, but fall back to top-aligned the moment the
       content is taller than the widget. Plain `center` keeps centring while overflowing, which
       clips the first and last rows simultaneously — content is lost off BOTH ends and scrolling
       starts halfway down. `safe` is precisely the keyword for this; the unprefixed declaration
       above it is the fallback for browsers that do not understand it. */
    align-content: center;
    align-content: safe center;
    /* min-height:0 lets the grid shrink inside the flex body instead of overflowing it, and
       the scroll is a backstop for a widget sized smaller than its content. */
    height: 100%;
    min-height: 0;
    overflow: auto;
    padding-right: 2px;
}

.widget-summary .stat {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.widget-summary .stat-label {
    font-size: 13px;
    font-weight: 650;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    /* A long label truncates rather than wrapping and shoving the value down a line. */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.widget-summary .stat-value {
    /* 20px rather than 22: three rows of stats then fit a two-column-wide widget without
       needing to scroll at all, which is the case that was breaking. */
    font-size: 20px;
    font-weight: 700;
    line-height: 1.15;
    /* Tabular figures so columns of numbers line up and do not jitter as values change. */
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Unit rides with the number at a smaller size, so it reads as a unit rather than as part of
   the figure — and can never be orphaned onto its own line. */
.widget-summary .stat-unit {
    margin-left: 3px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.widget-summary .stat-value.warn { color: var(--warn); }
.widget-summary .stat-value.crit { color: var(--crit); }
/* Keep the unit legible against a coloured value rather than inheriting the alarm colour. */
.widget-summary .stat-value.warn .stat-unit,
.widget-summary .stat-value.crit .stat-unit { color: inherit; opacity: 0.75; }

/* Widget: text */
.widget-text h4 { margin: 6px 0 4px; font-size: 16px; }
.widget-text p { margin: 4px 0; color: var(--text); font-size: 14px; }

/* Widget config form */
.widget-config { border: 1px solid var(--border); padding: 8px 16px; margin-bottom: 16px; border-radius: 4px; }
.widget-config legend { color: var(--text-muted); font-size: 13px; padding: 0 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.device-color-rows { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 12px; margin: 4px 0 8px; }
.device-color-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.device-color-row input[type="color"] { width: 28px; height: 22px; padding: 0; border: 1px solid var(--border); background: transparent; border-radius: 4px; cursor: pointer; flex: 0 0 auto; }
.device-color-row span { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
form select[multiple] { padding: 4px 6px; height: auto; }
.grid-input { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }

/* Widget edit page */
.widget-edit { display: grid; grid-template-columns: minmax(360px, 1fr) minmax(360px, 1.4fr); gap: 24px; align-items: start; }
.widget-edit-form { min-width: 0; }
.widget-edit-preview { min-width: 0; position: sticky; top: 16px; }
.preview-heading { display: flex; align-items: center; gap: 12px; font-size: 15px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin: 0 0 8px; }
.preview-range { padding: 4px 8px; background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 4px; font-size: 14px; }
.preview-grid { grid-auto-rows: 50px; }
@media (max-width: 1024px) {
    .widget-edit { grid-template-columns: 1fr; }
    .widget-edit-preview { position: static; }
}

/* Status grid widget */
.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
}
.status-cell {
    aspect-ratio: 1;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    padding: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: default;
}
.status-cell.up { background: rgba(74, 222, 128, 0.2); color: var(--ok); }
.status-cell.down { background: rgba(248, 113, 113, 0.2); color: var(--crit); }
.status-cell.unknown { background: rgba(154, 164, 178, 0.15); color: var(--text-muted); }
.status-cell.disabled { background: rgba(154, 164, 178, 0.08); color: var(--text-muted); opacity: 0.6; }

/* Modbus values widget */
.modbus-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
}
.modbus-tile {
    display: block;
    padding: 10px 12px;
    border-radius: 6px;
    background: rgba(154, 164, 178, 0.08);
    border-left: 3px solid var(--text-muted);
    text-decoration: none;
    color: inherit;
    overflow: hidden;
}
.modbus-tile:hover { background: rgba(154, 164, 178, 0.14); }
.modbus-label { font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modbus-value { font-size: 23px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.modbus-units { font-size: 14px; font-weight: 400; color: var(--text-muted); margin-left: 2px; }
.modbus-sub { font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modbus-sub.error { color: var(--crit); }
.modbus-tile.ok { border-left-color: var(--ok); }
.modbus-tile.warn { background: rgba(251, 191, 36, 0.10); border-left-color: var(--warn, #fbbf24); }
.modbus-tile.crit { background: rgba(248, 113, 113, 0.12); border-left-color: var(--crit); }
.modbus-tile.error { background: rgba(248, 113, 113, 0.10); border-left-color: var(--crit); }
.modbus-tile.unknown { border-left-color: var(--text-muted); opacity: 0.85; }

/* Color swatch */
.color-swatch { display: inline-block; width: 16px; height: 16px; border-radius: 3px; vertical-align: middle; border: 1px solid var(--border); }

/* Group chip */
.group-chip {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(78, 161, 255, 0.15);
    border-left: 3px solid var(--chip, var(--accent));
    font-size: 13px;
}

/* Page header extras */
.page-header h2 small { font-size: 15px; font-weight: 400; margin-left: 8px; }
.page-header-actions { display: flex; align-items: center; gap: 12px; }

/* Device detail */
.device-meta { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 16px; margin-bottom: 24px; }
.device-meta dl { margin: 0; display: grid; grid-template-columns: 120px 1fr; gap: 6px 16px; }
.device-meta dt { color: var(--text-muted); font-size: 14px; }
.device-meta dd { margin: 0; }

.page-subheader { display: flex; justify-content: space-between; align-items: center; margin: 16px 0 12px; }
.page-subheader h3 { margin: 0; font-size: 17px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

.range-tabs { display: flex; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 2px; }
.range-tab { padding: 4px 12px; border-radius: 3px; color: var(--text-muted); font-size: 14px; }
.range-tab:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.range-tab.active { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.range-tab.active:hover { background: var(--accent-hover); color: var(--on-accent); }
/* Range tabs that are buttons (custom picker) rather than links. */
.range-tab-button { border: 0; background: transparent; font-family: inherit; cursor: pointer; line-height: inherit; }

/* Custom range picker */
.custom-range-panel {
    display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap;
    margin: 0 0 12px;
    padding: 10px 12px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
}
.custom-range-panel[hidden] { display: none; }
.custom-range-panel label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--text-muted); margin: 0; }
.custom-range-panel input { margin: 0; width: auto; color-scheme: dark; }
.custom-range-hint { font-size: 13px; color: var(--warn); }

/* Widget detail modal */
.chart-modal {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(6, 9, 13, 0.72);
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
}
.chart-modal[hidden] { display: none; }
.chart-modal-panel {
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    width: min(1200px, 100%); max-height: 100%;
    display: flex; flex-direction: column;
    padding: 16px 20px 12px;
}
.chart-modal-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.chart-modal-head h3 { margin: 0; font-size: 17px; }
.chart-modal-close {
    background: none; border: 0; color: var(--text-muted);
    font-size: 25px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.chart-modal-close:hover { color: var(--text); }
.chart-modal-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap; margin: 12px 0;
}
.chart-modal-actions { display: flex; gap: 8px; }
.chart-modal-body { flex: 1; min-height: 0; }
/* The modal reuses .widget so dashboard.js renders into it unchanged. */
.chart-modal-body .widget { height: min(62vh, 620px); padding: 0; border: 0; background: transparent; }
.chart-modal-foot { font-size: 13px; margin-top: 8px; }
body.modal-open { overflow: hidden; }
.widget-zoom { background: none; border: 0; font-size: 14px; cursor: pointer; padding: 0 2px; font-family: inherit; }

.chart-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin: 12px 0; }
.chart-summary > div { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 10px 14px; }
.chart-summary strong { display: block; font-size: 19px; margin-top: 2px; }

.chart-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 16px; margin-bottom: 16px; height: 360px; }
.chart-wrap-small { height: 160px; }

/* Empty state */
.empty-state { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 32px; text-align: center; }

/* Dashboard summary cards */
/*
 * On-call summary panels. These carried their dark-palette colours inline, which meant they
 * stayed dark on a light page — the one place on the site where the theme did not follow.
 */
.oncall-now { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.oncall-card {
    flex: 1; min-width: 280px; padding: 18px; border-radius: 6px;
    background: var(--surface); border: 1px solid var(--border);
}
.oncall-card h3 { margin-top: 0; }
.oncall-card .oncall-headline { font-size: 22px; margin: 6px 0; }
.oncall-card .oncall-when { font-size: 18px; margin: 6px 0; }

.summary-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 24px; }
.summary-card { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 16px; }
.summary-card .label { font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.summary-card .value { font-size: 30px; font-weight: 700; margin-top: 4px; }
.summary-card .value.ok { color: var(--ok); }
.summary-card .value.warn { color: var(--warn); }
.summary-card .value.crit { color: var(--crit); }

/* Dashboard device grid */
.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
}
.device-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--text-muted);
    border-radius: 4px;
    padding: 8px 10px;
    color: var(--text);
    text-decoration: none;
    display: block;
}
.device-tile:hover { background: var(--surface-2); text-decoration: none; }
.device-tile.up { border-left-color: var(--ok); }
.device-tile.down { border-left-color: var(--crit); }
.device-tile.unknown { border-left-color: var(--text-muted); }
.device-tile.disabled { border-left-color: var(--text-muted); opacity: 0.5; }
.device-tile .name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-tile .meta { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ── Authentication: MFA enrolment, recovery codes, account forms ───────────── */

/* The QR + step list need more room than the 360px sign-in column. */
.login-main:has(.login-card-wide) { width: 460px; }
.login-card-wide { padding: 32px 36px; }

.mfa-steps {
    margin: 0 0 20px;
    padding-left: 20px;
    color: var(--text-muted);
    font-size: 14px;
}
.mfa-steps li { margin-bottom: 4px; }

/* White plate behind the QR: scanners cope badly with an inverted (dark) code. */
.mfa-qr {
    display: flex;
    justify-content: center;
    padding: 12px;
    margin-bottom: 16px;
    background: #fff;
    border-radius: 6px;
}
.mfa-qr svg { display: block; width: 220px; height: 220px; }

.mfa-secret-label { text-align: center; font-size: 13px; margin-bottom: 4px; }
.mfa-secret {
    text-align: center;
    margin: 0 0 20px;
}
.mfa-secret code {
    display: inline-block;
    padding: 8px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 16px;
    letter-spacing: 0.08em;
}

.recovery-codes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    list-style: none;
    margin: 20px 0;
    padding: 16px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
}
.recovery-codes code {
    font-size: 15px;
    letter-spacing: 0.05em;
}

.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 24px;
    max-width: 560px;
}

.btn-small {
    padding: 2px 10px;
    font-size: 13px;
    margin-left: 8px;
}

/* Amber is light in dark mode and dark in light mode, so the label colour has to follow the
   surface rather than being pinned to one of them. */
.badge-warning {
    background: var(--warn);
    color: var(--surface);
}

/* ── Billing: quota meters, plan cards, notices ─────────────────────────────── */

.quota-bar {
    display: inline-block;
    width: 140px;
    height: 6px;
    margin-left: 10px;
    vertical-align: middle;
    background: var(--surface-2);
    border-radius: 3px;
    overflow: hidden;
}
.quota-fill { display: block; height: 100%; }
.quota-ok   { background: var(--ok); }
.quota-warn { background: var(--warn); }
.quota-crit { background: var(--crit); }

.notice {
    padding: 12px 16px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
    border-left-width: 3px;
    border-radius: 4px;
    background: var(--surface);
}
.notice-ok   { border-left-color: var(--ok); }
.notice-warn { border-left-color: var(--warn); }
.notice-crit { border-left-color: var(--crit); }

.plan-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}
.plan-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    display: flex;
    flex-direction: column;
}
/* The plan you are on should be findable at a glance, not read for. */
.plan-card-current { border-color: var(--accent); }
.plan-card h4 { margin: 0 0 8px; font-size: 17px; }
.plan-price { margin: 0 0 12px; font-size: 23px; font-weight: 600; }
.plan-price .muted { font-size: 14px; font-weight: 400; }
.plan-features {
    list-style: none;
    padding: 0;
    margin: 0 0 16px;
    font-size: 14px;
    /* Push the button to the card's bottom so a row of cards lines up despite
       differing feature counts. */
    flex: 1;
}
.plan-features li { padding: 3px 0; border-bottom: 1px solid var(--border); }
.plan-features li:last-child { border-bottom: 0; }

.badge-ok { background: var(--ok); color: var(--surface); }
.badge-muted { background: var(--surface-2); color: var(--text-muted); }

.btn-disabled {
    opacity: 0.55;
    cursor: default;
    pointer-events: none;
}

/* ── Tenant branding ────────────────────────────────────────────────────────── */

/* Height-constrained rather than width, so wide and square logos both sit correctly
   in the nav without the caller having to know which they uploaded. */
.brand-logo {
    display: block;
    height: 28px;
    width: auto;
    max-width: 220px;
}

.brand-mark {
    margin: 0 0 4px;
    text-align: center;
}
.brand-mark img {
    display: inline-block;
    height: 40px;
    width: auto;
    max-width: 100%;
}

.theme-toggle {
    padding: 2px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 15px;
    line-height: 1.4;
    cursor: pointer;
}
.theme-toggle:hover { background: var(--border); text-decoration: none; }

.logo-preview {
    display: inline-block;
    padding: 12px 16px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    /* Checkerboard: transparent logos are the recommended format, and without this you
       cannot tell transparency from a white background. */
    background-color: var(--surface-2);
    background-image:
        linear-gradient(45deg, rgba(128, 128, 128, 0.18) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(128, 128, 128, 0.18) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, rgba(128, 128, 128, 0.18) 75%),
        linear-gradient(-45deg, transparent 75%, rgba(128, 128, 128, 0.18) 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.logo-preview img { display: block; height: 48px; width: auto; max-width: 320px; }

.theme-colour-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
}
.theme-colour-row input[type=color] {
    width: 100%;
    height: 40px;
    padding: 2px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
}

/* The previews are pinned to literal dark/light values, not theme tokens: the whole point is
   to show how an accent looks in the mode you are NOT currently viewing. */
.swatch-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    border-radius: 6px;
    border: 1px solid var(--border);
}
.swatch-dark  { background: #131C2E; }
.swatch-light { background: #ffffff; }
.swatch-chip {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex: none;
}
.swatch-btn {
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    color: var(--on-accent);
}

/* Tenant logo on exported reports. Print-only: the on-screen printable view already shows
   the nav, so this would duplicate it. */
.print-brand { display: none; }
@media print {
    .print-brand { display: block; margin-bottom: 12px; }
    .print-brand img { height: 36px; width: auto; }
}

/* ── CMS editor ─────────────────────────────────────────────────────────────── */

.cms-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 16px;
    align-items: start;
}
@media (max-width: 900px) {
    .cms-grid { grid-template-columns: 1fr; }
}

.wysiwyg {
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 12px;
}
.wysiwyg-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: 6px 8px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.wysiwyg-toolbar button {
    min-width: 32px;
    padding: 4px 8px;
    border: 1px solid transparent;
    border-radius: 3px;
    background: transparent;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
}
.wysiwyg-toolbar button:hover { background: var(--border); }
.wysiwyg-sep {
    width: 1px;
    height: 18px;
    margin: 0 6px;
    background: var(--border);
}
.wysiwyg-source { margin-left: auto; }

.wysiwyg-surface {
    min-height: 320px;
    padding: 16px 18px;
    background: var(--surface);
    color: var(--text);
    font-size: 16px;
    line-height: 1.65;
    overflow-y: auto;
}
.wysiwyg-surface:focus { outline: none; }
.wysiwyg-surface h2 { font-size: 22px; margin: 20px 0 8px; }
.wysiwyg-surface h3 { font-size: 18px; margin: 16px 0 6px; }
.wysiwyg-surface p { margin: 0 0 12px; }
.wysiwyg-surface ul, .wysiwyg-surface ol { padding-left: 24px; margin: 0 0 12px; }
.wysiwyg-surface:empty::before {
    content: 'Start writing…';
    color: var(--text-muted);
}

/* Rich-text and source are two views of one field: exactly one is visible at a time. */
.wysiwyg .wysiwyg-source-field,
.wysiwyg .input:has(.wysiwyg-source-field) { display: none; }
.wysiwyg.is-source .wysiwyg-surface { display: none; }
.wysiwyg.is-source .wysiwyg-source-field,
.wysiwyg.is-source .input:has(.wysiwyg-source-field) { display: block; }
.wysiwyg .wysiwyg-source-field {
    width: 100%;
    border: 0;
    border-radius: 0;
    margin: 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 14px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   PulseGrid theme layer
   ───────────────────────────────────────────────────────────────────────────
   Adopts the PulseGrid template's visual language — cyan accent, deep navy
   panels, gradient cards, uppercase micro-labels, tinted status badges — on top
   of the existing token system, so per-tenant accent overrides keep working.

   ONE DELIBERATE DEPARTURE: the template sets type at 8–11px throughout. That is
   too small to read comfortably for a dashboard people watch all day, and it
   directly contradicts the readability pass done earlier. The look is adopted;
   the type scale is not. Micro-labels keep the uppercase + letter-spacing
   treatment that carries the style, at a legible size.
   ═══════════════════════════════════════════════════════════════════════════ */

body {
    /* Inter is the template's face; the rest is the existing system stack, since
       there is no webfont pipeline here and a network fetch per page is not worth it. */
    font-family: Montserrat, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Cards and panels gain the template's subtle vertical gradient and lift. */
.widget,
.form-card,
.data-table,
.plan-card,
.notice,
.login-card {
    background: linear-gradient(145deg,
        color-mix(in srgb, var(--surface) 96%, white 4%),
        var(--surface));
    box-shadow: 0 16px 42px rgba(0, 0, 0, 0.18);
}

/* Table headers: uppercase, tracked, quiet — the template's most recognisable detail. */
.data-table th {
    background: color-mix(in srgb, var(--bg) 45%, var(--surface-2));
    font-weight: 800;
    letter-spacing: 0.75px;
}

/* Status badges become tinted outlines rather than solid fills. Solid blocks of
   colour fight with the accent for attention; a tinted pill reads as state. */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    border: 1px solid;
    border-radius: 4px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.35px;
}
.badge-ok,
.badge-super_admin {
    color: var(--ok);
    background: color-mix(in srgb, var(--ok) 12%, transparent);
    border-color: color-mix(in srgb, var(--ok) 26%, transparent);
}
.badge-warning,
/* The on-call and alert templates ask for `badge-warn`. Nothing defined it, so those badges
   picked up the bare `.badge` rule above — a pill with `border: 1px solid` and no colour of its
   own, which renders as an empty outline around plain text. */
.badge-warn,
.badge-admin {
    color: var(--warn);
    background: color-mix(in srgb, var(--warn) 12%, transparent);
    border-color: color-mix(in srgb, var(--warn) 26%, transparent);
}
.badge-crit {
    color: var(--crit);
    background: color-mix(in srgb, var(--crit) 12%, transparent);
    border-color: color-mix(in srgb, var(--crit) 26%, transparent);
}
.badge-viewer,
.badge-muted {
    color: var(--text-muted);
    background: color-mix(in srgb, var(--text-muted) 10%, transparent);
    border-color: color-mix(in srgb, var(--text-muted) 22%, transparent);
}

/* Buttons: flat, tracked, with the accent reserved for the primary action. */
.btn {
    font-weight: 700;
    letter-spacing: 0.2px;
}
.btn-primary {
    box-shadow: 0 0 22px color-mix(in srgb, var(--accent) 22%, transparent);
}

/* Inputs get the template's focus ring rather than a bare border colour change. */
form input:focus,
form select:focus,
form textarea:focus {
    border-color: color-mix(in srgb, var(--accent) 55%, transparent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}

/* Section eyebrow — the small tracked cyan kicker above headings. */
.eyebrow {
    color: var(--accent);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.4px;
    margin-bottom: 6px;
}

/* Nav: active item marked with an inset accent rule, as in the template. */
.top-nav .nav-links a {
    font-weight: 620;
    color: var(--text-muted);
}
.top-nav .nav-links a:hover {
    color: var(--text);
    background: color-mix(in srgb, var(--text) 4%, transparent);
}
.top-nav .nav-links a.active {
    color: var(--text);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    box-shadow: inset 2px 0 var(--accent);
}

/* Live indicator: the pulsing dot from the template's topbar. */
.live-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ok);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 10%, transparent);
}

/* ═══════════════════════════════════════════════════════════════════════════
   App shell — sidebar + topbar (PulseGrid structure)

   Replaces the horizontal top nav. Thirteen destinations in one row wrapped onto
   two lines and conveyed no grouping; vertically they fit and can sit under
   headings, so "where is billing" has an obvious answer.
   ═══════════════════════════════════════════════════════════════════════════ */

body.has-shell { margin: 0; }

.shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar-w, 236px) minmax(0, 1fr);
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w, 236px);
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: color-mix(in srgb, var(--bg) 60%, var(--surface));
    border-right: 1px solid var(--border);
    z-index: 30;
    transition: transform 0.25s ease;
}

.sidebar .brand {
    height: 64px;
    flex: none;
    display: flex;
    align-items: center;
    padding: 0 18px;
    border-bottom: 1px solid var(--border);
}
.sidebar .brand a {
    display: flex;
    align-items: center;
    gap: 11px;
    font-weight: 800;
    font-size: 17px;
    color: var(--text);
}
.sidebar .brand a:hover { text-decoration: none; }
.brand-text { letter-spacing: -0.2px; }

.nav {
    flex: 1;
    overflow-y: auto;
    padding: 14px 10px;
}
.nav-label {
    margin: 16px 10px 6px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    opacity: 0.75;
}
.nav-label:first-child { margin-top: 0; }

.nav a {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 38px;
    padding: 0 10px;
    margin: 2px 0;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 620;
}
.nav a:hover {
    background: color-mix(in srgb, var(--text) 5%, transparent);
    color: var(--text);
    text-decoration: none;
}
.nav a.active {
    color: var(--text);
    background: color-mix(in srgb, var(--accent) 13%, transparent);
    box-shadow: inset 2px 0 var(--accent);
}
.nav-glyph {
    width: 18px;
    flex: none;
    text-align: center;
    font-size: 14px;
    opacity: 0.85;
}

.side-status {
    flex: none;
    margin: 12px;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: color-mix(in srgb, var(--text) 2%, transparent);
    color: var(--text-muted);
    font-size: 13px;
}

/* Main column */
.shell-main {
    grid-column: 2;
    min-width: 0;
    /* Deliberately NOT .main: that class still carries the old centred max-width used by the
       logged-out layout, which pushed this column's content sideways. */
}

.topbar {
    height: 64px;
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 24px;
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}
.crumb { font-size: 14px; color: var(--text-muted); font-weight: 650; }
.spacer { flex: 1; }
.menu {
    display: none;
    border: 0;
    background: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
}
/* Square icon button in the topbar — same footprint whatever glyph it holds. */
.topbtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex: none;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 6px;
    background: none;
    color: var(--text-muted);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
}
.topbtn:hover {
    border-color: var(--border);
    background: var(--surface-2);
    color: var(--text);
    text-decoration: none;
}

/* Account menu. The name, role and actions were four loose elements competing for attention;
   they are now one control that opens a menu. */
.user-dropdown { flex: none; }
.user-trigger {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 4px 8px 4px 4px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: none;
    color: var(--text);
    cursor: pointer;
    text-align: left;
}
.user-trigger:hover { border-color: var(--border); background: var(--surface-2); }
.user-trigger .dropdown-caret { color: var(--text-muted); font-size: 12px; }

.avatar {
    width: 32px;
    height: 32px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 6px;
    background: color-mix(in srgb, var(--accent) 16%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent) 32%, transparent);
    color: var(--accent);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.02em;
}

.user-meta { display: flex; flex-direction: column; line-height: 1.25; }
.user-name { font-size: 14px; font-weight: 650; color: var(--text); }
/* The role belongs here as quiet context, not as a coloured badge shouting SUPER_ADMIN. */
.user-role { font-size: 12px; color: var(--text-muted); }

.content {
    max-width: 1500px;
    margin: 0 auto;
    padding: 24px 26px 48px;
}

.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 25;
}

@media (max-width: 900px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { transform: translateX(-100%); }
    body.menu-open .sidebar { transform: none; }
    body.menu-open .overlay { display: block; }
    .shell-main { grid-column: 1; }
    .menu { display: block; }
    .topbar { padding: 0 14px; }
    .content { padding: 20px 15px 40px; }
    .user-meta { display: none; }
}

/* Inline plan-assignment control in the tenant table. */
.inline-form { display: flex; align-items: center; gap: 6px; margin: 0; }
.inline-form .input { margin: 0; }
.inline-select {
    width: auto;
    min-width: 110px;
    margin: 0 !important;
    padding: 5px 8px !important;
    font-size: 13px !important;
}

/* ── Brand mark ─────────────────────────────────────────────────────────────── */

.brand-mark { display: block; flex: none; }

/* Sign-in / marketing card lockup: mark and wordmark on one baseline. */
.brand-mark-lockup {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 0 0 4px;
}
.brand-mark-lockup img { display: block; flex: none; }
.brand-mark-lockup span { line-height: 1; }

/* Group filter above the devices list */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-size: 14px;
    color: var(--text-muted);
}
.filter-bar select {
    padding: 6px 10px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
}

/* Monitoring chips on the devices list (SNMP / 5G) */
.mon-chips { white-space: nowrap; }
.mon-chip {
    display: inline-block;
    padding: 1px 7px;
    margin-right: 4px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
    color: var(--text-muted);
    cursor: default;
}
.mon-chip.is-ok { border-color: var(--ok); color: var(--ok); background: rgba(74, 222, 128, 0.12); }
.mon-chip.is-error { border-color: var(--crit); color: var(--crit); background: rgba(248, 113, 113, 0.12); }

/* Widget list view — reorder/delete without scrolling the dashboard grid */
.widget-list tbody tr { cursor: default; }
.widget-list tbody tr.is-dragging { opacity: 0.45; }
.widget-list-handle {
    cursor: grab;
    color: var(--text-muted);
    font-size: 16px;
    letter-spacing: 2px;
    user-select: none;
}
.widget-list-handle:active { cursor: grabbing; }
.widget-list [data-move] {
    background: none;
    border: 0;
    cursor: pointer;
    padding: 2px 4px;
    font-size: 14px;
}

/* Dashboard background image — a fixed layer behind the page, under every widget */
.dashboard-bg {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
}
.bg-preview {
    max-width: 420px;
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}
.bg-preview img { display: block; width: 100%; height: auto; }

/* Bulk-action bar options on the widget list — only the chosen action's inputs show */
.bulk-option { display: inline-flex; align-items: center; gap: 8px; }
.bulk-option[hidden] { display: none; }

/* Publicly shared dashboard — full screen, no chrome */
body.shared-view { padding: 16px 20px 8px; }
.shared-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.shared-brand { display: flex; align-items: center; gap: 12px; }
.shared-brand h1 { margin: 0; font-size: 20px; font-weight: 600; }
.shared-logo { height: 30px; width: auto; }
.shared-meta { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-muted); }
.shared-footer { margin-top: 14px; font-size: 12px; text-align: right; }
/* Nothing on this page is a destination: the renderers emit links the viewer cannot follow, and
   the template strips their hrefs — this stops them still looking clickable. */
.shared-grid a { color: inherit; text-decoration: none; cursor: default; }
/* The share view's range tabs sit in its header rather than the app's page-header row. */
.shared-meta .range-tabs { margin-right: 4px; }
