/* Vega frontend — minimal, warm-tones styling
 *
 * Design intent: feels like a home-control app, not an enterprise
 * dashboard.  Warmer palette than barkend (which is JCDP green).
 */

:root {
    /* Techtaria brand palette — sourced from logo.svg */
    --brand-sage: #8fb495;   /* house + circuitry */
    --brand-clay: #d28a64;   /* node accents */
    --brand-ink:  #14130e;   /* dark ink */

    --bg:        #f4f1e9;   /* warm natural paper */
    --surface:   #ffffff;
    --primary:   #4a7256;   /* deep sage — brand accent, darkened for legibility on white */
    --primary-dark: #3a5a44;
    --text:      #221f1a;   /* near-ink */
    --text-mute: #7a716a;
    --border:    #e3dcd2;
    --error:     #c0392b;
    --success:   #2d8b3c;
    --ok:        #9aa0a6;   /* ISA-101: normal/OK = neutral gray (NOT green) */
    --ok-soft:   #cbc4b7;   /* quiet OK accent for tile borders */
}

/* Techtaria logo mark */
.brand-logo    { display: block; height: 76px; width: auto; margin: 0 auto 12px; }
.brand-mark    { display: flex; align-items: center; gap: 8px; }
.brand-logo-sm { height: 30px; width: auto; display: block; flex-shrink: 0; }

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, sans-serif;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

body.pwa-standalone { padding-top: env(safe-area-inset-top); }

/* Greyscale brand watermark — a plain background on the (transparent) chat area.
   NOT a fixed body pseudo-element: that triggers iOS Safari's address-bar/viewport
   glitch and is hidden behind the opaque panels anyway. */

.hidden { display: none !important; }

/* ─── Auth panels ─── */
.auth-panel {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 24px;
}
.auth-card {
    background: var(--surface); padding: 40px 32px;
    border-radius: 14px; box-shadow: 0 4px 24px rgba(40, 25, 15, 0.08);
    width: 100%; max-width: 420px; text-align: center;
}
.brand {
    font-family: "DM Serif Display", Georgia, serif;
    font-size: 38px; font-weight: 400; color: var(--primary);
    letter-spacing: -0.01em;
}
.brand-sub {
    color: var(--text-mute); margin-top: 4px; margin-bottom: 32px;
}
.auth-card input[type="text"] {
    width: 100%; padding: 12px 14px; font-size: 16px;
    border: 1px solid var(--border); border-radius: 8px;
    margin-bottom: 16px; background: var(--bg);
}
.auth-card input:focus { outline: 2px solid var(--primary); }
#login-help {
    margin-top: 16px; color: var(--text-mute); font-size: 14px;
}

/* ─── Buttons ─── */
button.primary {
    background: var(--primary); color: white;
    padding: 12px 24px; font-size: 16px; font-weight: 600;
    border: none; border-radius: 8px; cursor: pointer;
    transition: background 0.15s;
}
button.primary:hover { background: var(--primary-dark); }
button.primary:disabled { opacity: 0.5; cursor: not-allowed; }

button.link {
    background: none; border: none; color: var(--text-mute);
    cursor: pointer; font-size: 14px; padding: 4px 8px;
}
button.link:hover { color: var(--primary); }

/* ─── Main app layout ─── */
#app {
    display: flex; flex-direction: column;
    /* dvh tracks the *visible* viewport so the top bar isn't hidden under the
       mobile browser address bar (the 100vh dynamic-toolbar bug). */
    height: 100vh; height: 100dvh;
    max-height: 100vh; max-height: 100dvh; overflow: hidden;
}

#topbar {
    display: grid; align-items: center;
    grid-template-columns: 1fr auto 1fr;
    padding: 12px 20px; background: var(--surface);
    border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#topbar > .brand-small  { justify-self: start; }
#topbar > .scope-indicator { justify-self: center; }
#topbar > .topbar-right { justify-self: end; }
/* When scope-indicator is hidden the grid still reserves the center
   column; spread the brand to take more space. */
#topbar > .scope-indicator.hidden + .topbar-right { /* no-op stub */ }
.brand-small {
    font-family: "DM Serif Display", Georgia, serif;
    font-weight: 400; color: var(--primary); font-size: 22px;
}
.topbar-right {
    display: flex; align-items: center; gap: 12px;
    color: var(--text-mute); font-size: 14px;
}

.scope-indicator {
    display: flex; align-items: center; gap: 6px; font-size: 14px;
}
.scope-label { color: var(--text-mute); font-size: 13px; }
.scope-dropdown-wrap { position: relative; }
.scope-button {
    background: var(--bg); border: 1px solid var(--border);
    padding: 5px 10px 5px 12px; border-radius: 6px;
    font-family: ui-monospace, monospace; font-size: 13px;
    color: var(--text); cursor: pointer;
    display: inline-flex; align-items: center; gap: 6px;
    transition: border-color 0.15s, background 0.15s;
}
.scope-button:hover { border-color: var(--primary); background: var(--surface); }
.scope-button[aria-expanded="true"] { border-color: var(--primary); }
.scope-caret { color: var(--text-mute); font-size: 10px; line-height: 1; }

/* Anchored dropdown panel under the scope button */
.scope-dropdown {
    position: absolute; top: calc(100% + 6px); right: 0; min-width: 280px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    z-index: 50; overflow: hidden;
    animation: scope-dropdown-in 0.12s ease-out;
}
@keyframes scope-dropdown-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}
.scope-dropdown-header {
    padding: 10px 14px 6px;
    color: var(--text-mute); font-size: 11px; text-transform: uppercase;
    letter-spacing: 0.05em; font-weight: 600;
}
.scope-dropdown ul {
    list-style: none; padding: 4px 0 6px; margin: 0;
    max-height: 320px; overflow-y: auto;
}
.scope-dropdown li { margin: 0; }
.scope-item {
    width: 100%; background: transparent; border: none;
    padding: 9px 14px; cursor: pointer; color: var(--text);
    display: flex; align-items: center; gap: 10px;
    font-size: 13px; text-align: left;
    transition: background 0.1s;
}
.scope-item:hover { background: var(--bg); }
.scope-item.active {
    background: var(--bg);
    border-left: 3px solid var(--primary);
    padding-left: 11px;
}
.scope-item-name {
    flex: 1; font-family: ui-monospace, monospace; font-weight: 500;
}
.scope-item-meta { color: var(--text-mute); font-size: 11px; }

.scope-health-dot {
    width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.scope-health-healthy  { background: var(--ok); }
.scope-health-stale    { background: #f59e0b; }
.scope-health-alert    { background: #f97316; }
.scope-health-critical { background: var(--error); }
.scope-health-unknown  { background: var(--text-mute); opacity: 0.6; }

.scope-loading, .scope-error {
    padding: 12px 14px; color: var(--text-mute); font-size: 12px;
}
.scope-error { color: var(--error); }

/* ─── User manager drawer (admin) ─── */
.icon-button {
    background: transparent; border: 1px solid var(--border);
    color: var(--text-mute); cursor: pointer;
    padding: 4px 6px; border-radius: 6px;
    transition: border-color 0.15s, color 0.15s;
    display: inline-flex; align-items: center; justify-content: center;
}
.icon-button:hover { border-color: var(--primary); color: var(--primary); }
.user-manager {
    position: fixed; inset: 0; z-index: 70;
    background: rgba(0,0,0,0.4);
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
}
.user-manager-card {
    background: var(--surface);
    border-radius: 12px;
    width: 100%; max-width: 720px; max-height: 90vh;
    display: flex; flex-direction: column;
    box-shadow: 0 18px 48px rgba(0,0,0,0.2);
}
.user-manager-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}
.user-manager-header h2 { margin: 0; font-size: 17px; }
#user-manager-close {
    background: none; border: none; color: var(--text-mute);
    font-size: 22px; cursor: pointer; padding: 0 6px;
}
.user-manager-body {
    overflow-y: auto; padding: 8px 20px 12px;
    flex: 1;
}
.user-manager-footer {
    padding: 10px 20px; font-size: 11px; color: var(--text-mute);
    border-top: 1px solid var(--border);
}
.user-manager-loading, .user-manager-error {
    padding: 30px 12px; text-align: center; color: var(--text-mute);
}
.user-manager-error { color: var(--error); }

.user-row {
    border-bottom: 1px solid var(--border);
    padding: 14px 0;
}
.user-row:last-child { border-bottom: none; }
.user-row-header {
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.user-row-name strong { font-size: 14px; }
.user-self-badge {
    margin-left: 8px;
    padding: 1px 6px; border-radius: 8px;
    background: var(--bg); border: 1px solid var(--border);
    font-size: 10px; color: var(--text-mute);
    text-transform: uppercase; letter-spacing: 0.04em;
}
.user-row-actions { display: flex; gap: 8px; align-items: center; }
.user-role-select {
    font-size: 12px; padding: 3px 6px;
    border: 1px solid var(--border); border-radius: 4px;
    background: var(--bg); color: var(--text);
}
.user-delete-btn { color: var(--error) !important; font-size: 12px; }
.user-row-meta {
    font-size: 11px; color: var(--text-mute);
    margin: 4px 0 8px;
}
.user-row-endpoints {
    background: var(--bg); border-radius: 6px;
    padding: 8px 10px; font-size: 12px;
    display: flex; flex-direction: column; gap: 6px;
}
.user-endpoint-checkbox {
    display: inline-flex; align-items: center; gap: 6px;
    cursor: pointer;
}
.user-endpoint-checkbox input:disabled { cursor: not-allowed; }
.user-endpoint-checkbox input:disabled + span { color: var(--text-mute); }
.user-endpoint-wildcard {
    padding-bottom: 6px; border-bottom: 1px dashed var(--border);
}
.user-endpoint-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 4px 12px;
}

.user-manager-toolbar {
    padding: 12px 20px 0;
    display: flex; gap: 10px; align-items: center;
}
.user-search {
    flex: 1;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    font-size: 13px; color: var(--text);
    font-family: inherit;
}
.user-search:focus { outline: none; border-color: var(--primary); }
#btn-new-user { font-size: 13px; padding: 6px 14px; flex-shrink: 0; }
.user-row-orphan {
    background: linear-gradient(to right, #fef3c7 0%, transparent 30%);
}
.user-orphan-badge {
    margin-left: 8px;
    padding: 1px 6px; border-radius: 8px;
    background: #f59e0b; color: white;
    font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.04em;
}
.user-reinvite-btn { color: var(--primary) !important; font-size: 12px; }

/* Per-user credential list (admin) */
.user-row-credentials {
    margin-top: 8px;
    font-size: 12px;
}
.user-row-credentials summary {
    cursor: pointer;
    color: var(--text-mute);
    padding: 4px 0;
    list-style: revert;
    font-weight: 600;
    user-select: none;
}
.user-row-credentials summary:hover { color: var(--primary); }
.user-row-credentials[open] summary { color: var(--text); }
.user-creds-body {
    padding-top: 6px;
    display: flex; flex-direction: column; gap: 4px;
}
.user-cred-row {
    display: flex; align-items: center; gap: 12px;
    padding: 6px 10px;
    background: var(--bg);
    border-radius: 6px;
    font-size: 12px;
}
.user-cred-info { flex: 1; min-width: 0; }
.user-cred-info strong { font-size: 13px; color: var(--text); }
.user-cred-meta {
    color: var(--text-mute);
    font-size: 11px;
    margin-top: 2px;
    overflow-wrap: anywhere;
}
.user-cred-meta code { font-family: ui-monospace, monospace; }
.user-cred-revoke {
    color: var(--error) !important;
    font-size: 11px;
    flex-shrink: 0;
}
.user-creds-empty {
    padding: 8px 10px;
    color: var(--text-mute);
    font-size: 12px;
    line-height: 1.5;
}
.user-creds-error {
    padding: 8px 10px;
    color: var(--error);
    font-size: 12px;
}

/* New-user form + invite URL modal */
.user-form-card {
    background: var(--surface);
    border-radius: 12px;
    width: 100%; max-width: 480px;
    box-shadow: 0 18px 48px rgba(0,0,0,0.2);
    display: flex; flex-direction: column;
}
.user-form-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}
.user-form-header h2 { margin: 0; font-size: 17px; }
#new-user-close, #invite-url-close {
    background: none; border: none; color: var(--text-mute);
    font-size: 22px; cursor: pointer; padding: 0 6px;
}
.user-form-body {
    padding: 16px 20px 18px;
    display: flex; flex-direction: column; gap: 12px;
}
.user-form-row {
    display: flex; flex-direction: column; gap: 4px;
    font-size: 13px;
}
.user-form-row > span:first-child {
    color: var(--text-mute); font-size: 12px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.04em;
}
.user-form-row input[type="text"],
.user-form-row input[type="email"],
.user-form-row select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
}
.user-form-row input:focus, .user-form-row select:focus {
    outline: none; border-color: var(--primary);
}
.user-form-hint {
    color: var(--text-mute); font-size: 11px;
    margin-top: 4px;
}
.user-form-admin-note {
    padding: 8px 12px;
    background: var(--bg);
    border-left: 3px solid var(--primary);
    color: var(--text-mute);
    font-size: 12px;
    border-radius: 4px;
}
.user-form-actions {
    display: flex; justify-content: flex-end; gap: 10px;
    margin-top: 8px;
}

.invite-url-box {
    display: flex; gap: 8px;
    margin: 8px 0;
}
.invite-url-box input {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-family: ui-monospace, monospace;
    font-size: 12px;
    overflow: hidden;
}
#invite-url-copy { font-size: 12px; padding: 6px 14px; }

/* ─── Help modal ─── */
.help-modal-card {
    background: var(--surface);
    border-radius: 12px;
    width: 100%; max-width: 720px; max-height: 88vh;
    display: flex; flex-direction: column;
    box-shadow: 0 18px 48px rgba(0,0,0,0.2);
}
.help-modal-header {
    padding: 14px 22px;
    border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    flex-shrink: 0;
}
.help-modal-header h2 { margin: 0; font-size: 18px; }
#help-modal-close {
    background: none; border: none; color: var(--text-mute);
    font-size: 24px; cursor: pointer; padding: 0 6px; line-height: 1;
}
.help-modal-body {
    padding: 8px 24px 20px;
    overflow-y: auto;
    flex: 1;
    line-height: 1.55;
    font-size: 14px;
    color: var(--text);
}
.help-section {
    margin: 18px 0;
}
.help-section h3 {
    margin: 0 0 8px;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--primary);
    font-weight: 700;
}
.help-section p { margin: 0 0 8px; }
.help-section ul {
    margin: 4px 0 8px 0;
    padding-left: 20px;
}
.help-section li { margin: 4px 0; }
.help-dl {
    margin: 0;
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 8px 14px;
}
.help-dl dt {
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.help-dl dd {
    margin: 0;
    color: var(--text-mute);
}
.help-pill {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1px 8px;
    font-family: ui-monospace, monospace;
    font-size: 12px;
}
.help-examples { color: var(--text-mute); font-style: italic; }
.help-examples li::before {
    content: "›  ";
    color: var(--primary);
    font-style: normal;
    margin-right: 4px;
}
.help-warnings { color: var(--text-mute); }
.help-tip {
    background: var(--bg);
    border-left: 3px solid var(--primary);
    padding: 8px 12px;
    margin-top: 8px !important;
    border-radius: 4px;
    font-size: 13px;
}
.help-toggle-row {
    display: flex; gap: 12px;
    padding: 10px 12px;
    background: var(--bg);
    border-radius: 6px;
    cursor: pointer;
    align-items: flex-start;
}
.help-toggle-row input[type="checkbox"] { margin-top: 3px; }
.help-toggle-row span { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.help-toggle-row strong { font-size: 14px; }
.help-toggle-row small { color: var(--text-mute); font-size: 12px; line-height: 1.5; }
@media (max-width: 600px) {
    .help-dl {
        grid-template-columns: 1fr;
        gap: 4px;
    }
    .help-dl dd { padding-left: 8px; }
}

/* ─── System status modal (ChatBot / C&C drill-down) ─── */
.system-status-modal-card {
    background: var(--surface);
    border-radius: 12px;
    width: 100%; max-width: 540px;
    padding: 18px 20px 20px;
    box-shadow: 0 18px 48px rgba(0,0,0,0.2);
}
.system-status-modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 8px;
}
.system-status-modal-header h2 { margin: 0; font-size: 17px; }
#system-status-modal-close {
    background: none; border: none; color: var(--text-mute);
    font-size: 22px; cursor: pointer; padding: 0 6px;
}
.ss-overall {
    padding: 6px 10px;
    border-radius: 6px;
    background: var(--bg);
    font-size: 13px;
    margin-bottom: 12px;
}
.ss-overall-ok      { border-left: 3px solid var(--ok-soft); }
.ss-overall-warn    { border-left: 3px solid #f59e0b; }
.ss-overall-critical{ border-left: 3px solid var(--error); }
.ss-overall-unknown { border-left: 3px solid var(--text-mute); }

.ss-service-list { list-style: none; padding: 0; margin: 0; }
.ss-service-list li {
    display: grid;
    grid-template-columns: 12px 1fr;
    grid-template-rows: auto auto;
    align-items: baseline;
    gap: 2px 8px;
    padding: 8px 0;
    border-bottom: 1px dashed var(--border);
    font-size: 12px;
}
.ss-service-list li:last-child { border-bottom: none; }
.ss-dot {
    grid-row: 1 / span 2;
    width: 8px; height: 8px; border-radius: 50%;
    margin-top: 5px;
}
.ss-dot-ok       { background: var(--ok); }
.ss-dot-warn     { background: #f59e0b; }
.ss-dot-critical { background: var(--error); }
.ss-dot-unknown  { background: var(--text-mute); opacity: 0.5; }
.ss-name {
    font-weight: 600; color: var(--text);
}
.ss-detail {
    color: var(--text-mute); font-size: 11.5px;
    grid-column: 2;
    overflow-wrap: anywhere;
}
.ss-footnote {
    margin-top: 10px;
    color: var(--text-mute);
    font-size: 11px;
    font-style: italic;
}

.scope-item.locked {
    opacity: 0.55; cursor: not-allowed;
}
.scope-item.locked:hover { background: transparent; }
.scope-item-locked { font-size: 11px; margin-left: auto; }

/* ─── Global system-status (ChatBot + C&C) in topbar ─── */
.system-status {
    display: flex; gap: 14px; align-items: center;
    font-size: 12px;
}
.system-status-item {
    display: inline-flex; gap: 6px; align-items: center;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    color: var(--text);
    line-height: 1;
}
.system-status-item:hover, .system-status-item:focus {
    border-color: var(--primary);
    background: var(--surface);
    outline: none;
}
.system-status-icon {
    width: 14px; height: 14px;
    color: var(--text-mute);
    flex-shrink: 0;
}
.system-status-item:hover .system-status-icon { color: var(--primary); }
.system-status-label {
    font-size: 11.5px; font-weight: 600;
    letter-spacing: 0.01em;
}
.system-status-dot {
    width: 8px; height: 8px; border-radius: 50%;
    margin-left: 2px;
}
.system-status-dot-ok       { background: var(--ok); }
.system-status-dot-warn     { background: #f59e0b; }
.system-status-dot-critical { background: var(--error); }
.system-status-dot-unknown  { background: var(--text-mute); opacity: 0.5; }
@media (max-width: 700px) {
    .system-status-label { display: none; }
    .system-status-item { padding: 4px 7px; }
}

/* ─── Endpoint alert bar (criticals above sensor strip) ─── */
.endpoint-alert-bar {
    display: flex; flex-direction: column; gap: 2px;
    padding: 8px 16px;
    background: #fef2f2;
    border-bottom: 1px solid var(--border);
    border-left: 4px solid var(--error);
    flex-shrink: 0;
}
.alert-row {
    display: flex; gap: 8px; align-items: center;
    font-size: 13px; color: var(--text);
}
.alert-icon { font-size: 16px; flex-shrink: 0; }
.alert-text strong { font-weight: 700; }
.alert-warn { color: #92400e; }
.alert-critical { color: #991b1b; }

/* ─── Tile click-to-expand popover ─── */
.tile-detail {
    position: fixed; z-index: 60;
    width: 360px; max-width: calc(100vw - 16px);
    max-height: 280px; overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 10px 28px rgba(0,0,0,0.18);
    animation: tile-detail-in 0.12s ease-out;
}
@keyframes tile-detail-in {
    from { opacity: 0; transform: scale(0.96); }
    to   { opacity: 1; transform: scale(1); }
}
.tile-detail-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 14px; border-bottom: 1px solid var(--border);
    font-size: 13px; font-weight: 600;
}
#tile-detail-close {
    background: none; border: none; color: var(--text-mute);
    font-size: 18px; cursor: pointer; padding: 0 6px;
}
#tile-detail-body { padding: 10px 14px; font-size: 12px; }
.tile-detail-section { margin-bottom: 12px; }
.tile-detail-section:last-child { margin-bottom: 0; }
.tile-detail-h {
    font-weight: 600; margin-bottom: 4px;
    display: flex; gap: 6px; align-items: center;
}
.tile-detail-kv {
    display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px;
    margin: 0;
}
.tile-detail-kv dt {
    color: var(--text-mute); font-size: 11px;
    text-transform: uppercase; letter-spacing: 0.04em;
}
.tile-detail-kv dd {
    margin: 0; font-family: ui-monospace, monospace; font-size: 12px;
    overflow-wrap: anywhere;
}
.tile-detail-tag {
    padding: 1px 6px; border-radius: 3px;
    background: var(--bg); border: 1px solid var(--border);
    font-size: 10px; text-transform: uppercase;
}
.tile-detail-tag-up   { background: #f1f0ee; border-color: var(--ok-soft); color: #5b5750; }
/* ISA-101: a down link in a failover design is standby, not an alarm → neutral */
.tile-detail-tag-down { background: #f1f0ee; border-color: #9aa0a6; color: #5b5750; }

/* ─── Tile label as a link (HA / Frigate) ─── */
.sensor-tile-label-link {
    color: var(--primary); text-decoration: none;
    font-weight: 600;
}
.sensor-tile-label-link:hover { text-decoration: underline; }

/* ─── Conversation row with delete button ─── */
.convo-row {
    display: flex; align-items: stretch; gap: 0; min-width: 0;
}
/* width:auto + min-width:0 stop the preview button from claiming the whole row
   (its base .convo-item rule sets width:100%, which otherwise pushes the × past
   #convo-list's overflow-x:hidden clip edge — invisible on the 260px sidebar). */
.convo-row .convo-item { flex: 1 1 auto; width: auto; min-width: 0; }
.convo-delete {
    flex: 0 0 auto;   /* never shrink/grow — always keep room for the × */
    background: transparent; border: none; cursor: pointer;
    color: var(--text-mute); padding: 2px 8px; margin-right: 2px;
    font-size: 20px; line-height: 1; font-weight: 700;
    opacity: 1;  /* always clearly visible (works on touch + desktop) */
    border-radius: 6px;
    transition: background 0.12s, color 0.12s;
}
.convo-delete:hover, .convo-delete:focus-visible {
    color: var(--error); background: rgba(0,0,0,0.06);
}

/* ─── Confirm-delete modal ─── */
.confirm-delete {
    position: fixed; inset: 0; z-index: 80;
    background: rgba(0,0,0,0.4);
    display: flex; align-items: center; justify-content: center;
}
.confirm-delete-card {
    background: var(--surface); border-radius: 12px;
    padding: 20px 24px; max-width: 380px;
    box-shadow: 0 16px 40px rgba(0,0,0,0.18);
}
.confirm-delete-card p { margin: 0 0 16px; font-size: 14px; }
.confirm-delete-actions {
    display: flex; justify-content: flex-end; gap: 10px; align-items: center;
}
button.danger {
    background: var(--error) !important; color: white !important;
    border-color: var(--error) !important;
}

/* ─── Main layout (sidebar + chat) ─── */
#main {
    flex: 1; display: flex; overflow: hidden;
}

/* ─── Sidebar ─── */
#sidebar {
    width: 260px; background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    padding: 16px 12px; gap: 12px;
    overflow: hidden;   /* the conversation list scrolls, not the whole sidebar */
}
#new-convo-btn {
    width: 100%; font-size: 14px; padding: 10px; flex-shrink: 0;
}
/* Only the conversation list scrolls; bottom padding clears the fixed
   docs/Techtaria cluster so the last item is never hidden behind it. */
#convo-list {
    list-style: none; display: flex; flex-direction: column; gap: 4px;
    flex: 1 1 auto; min-height: 0;
    overflow-x: hidden; overflow-y: auto;   /* no horizontal scrollbar */
}
.convo-item {
    width: 100%; background: transparent; border: none;
    padding: 10px 12px; border-radius: 8px;
    text-align: left; cursor: pointer; color: var(--text);
    display: flex; justify-content: space-between; align-items: center;
    gap: 8px; transition: background 0.15s;
}
.convo-item:hover { background: var(--bg); }
#convo-list li.active .convo-item {
    background: var(--bg); border-left: 3px solid var(--primary);
    padding-left: 9px;
}
.convo-preview {
    flex: 1; overflow: hidden; white-space: nowrap;
    text-overflow: ellipsis; font-size: 13px;
}
.convo-time {
    color: var(--text-mute); font-size: 11px; flex-shrink: 0;
}

@media (max-width: 700px) {
    /* Sidebar becomes an off-canvas drawer opened by the hamburger. */
    #sidebar {
        position: fixed; top: 0; bottom: 0; left: 0;
        width: 280px; max-width: 82vw; z-index: 60;
        transform: translateX(-100%); transition: transform .22s ease;
        box-shadow: 2px 0 16px rgba(20,19,14,0.28);
    }
    #sidebar.open { transform: translateX(0); }
    .hamburger-btn { display: inline-flex; }
    /* Top bar wraps to extra rows so every status + Sign out stays visible. */
    #topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 8px 10px; }
    .topbar-right { flex-wrap: wrap; justify-content: flex-end; gap: 6px 8px; margin-left: auto; }
}

/* ─── Sensor strip (live dashboard between topbar + messages) ─── */
.sensor-strip {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 10px 16px 12px;
    display: flex; flex-direction: column; gap: 6px;
    flex-shrink: 0;
}
#sensor-strip-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr));
    gap: 8px;
}
#sensor-strip-grid.sensor-strip-grid-simple {
    grid-template-columns: minmax(200px, 1.6fr) repeat(auto-fill, minmax(120px, 1fr));
}
.sensor-strip-toggle {
    margin-left: auto; font-size: 11px;
    background: none; border: 1px solid var(--border);
    padding: 2px 8px; border-radius: 4px;
    color: var(--text-mute); cursor: pointer;
}
.sensor-strip-toggle:hover { border-color: var(--primary); color: var(--primary); }
.sensor-tile-icon-row {
    display: flex; align-items: center; gap: 8px;
}
.battery-icon, .signal-icon, .terminal-icon {
    flex-shrink: 0; color: var(--text);
}
.brand-icon { width: 100%; height: auto; max-width: 56px; }
.brand-icon-wrap {
    display: flex; align-items: center; justify-content: center;
    flex: 1; padding: 6px 0 2px;
    min-height: 44px;
}
.sensor-tile-brand {
    align-items: stretch;
}
.sensor-tile-clickable {
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s, border-color 0.1s;
}
.sensor-tile-clickable:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0,0,0,0.08);
    border-color: var(--primary);
}
.sensor-tile-clickable:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
}
.brand-tile-value-row {
    display: flex; align-items: center; gap: 8px;
}
.brand-tile-value-row .brand-icon { width: 28px; max-width: 28px; }
.brand-tile-value-text {
    font-family: ui-monospace, monospace; font-weight: 600;
    font-size: 16px;
}
.sensor-tile-system {
    grid-column: span 2;
}
@media (max-width: 480px) {
    .sensor-tile-system { grid-column: span 2; }
}
.sys-subs {
    display: flex; flex-wrap: wrap; gap: 8px 12px;
    margin-top: 4px;
    font-size: 10px;
    color: var(--text-mute);
}
.sys-sub {
    display: inline-flex; align-items: center; gap: 4px;
    text-transform: uppercase; letter-spacing: 0.04em;
}
#sensor-strip-meta {
    display: flex; justify-content: space-between; align-items: baseline;
    font-size: 11px; color: var(--text-mute);
}
#sensor-strip-endpoint {
    font-family: ui-monospace, monospace; font-weight: 600;
    color: var(--text);
}
.sensor-strip-age { font-style: italic; }

.sensor-tile {
    min-width: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    display: flex; flex-direction: column; gap: 2px;
    min-height: 64px;
    transition: border-color 0.15s, background 0.15s;
}
.sensor-tile-label {
    font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-mute); font-weight: 600;
}
.sensor-tile-value {
    font-size: 18px; font-weight: 600; color: var(--text);
    line-height: 1.1;
    font-family: ui-monospace, monospace;
}
.sensor-tile-value-small {
    font-size: 12px; font-weight: 500; color: var(--text-mute);
}
.sensor-tile-sub {
    font-size: 11px; color: var(--text-mute); margin-top: 2px;
}

.sensor-tile-ok       { border-left-color: var(--ok-soft); }
.sensor-tile-warn     { border-left-color: #f59e0b; }
.sensor-tile-critical { border-left-color: var(--error); background: #fef2f2; }
.sensor-tile-unknown  { border-left-color: var(--text-mute); opacity: 0.85; }
.sensor-tile-error    { border-left-color: var(--error); }
/* ISA-18.2 shelved alarm: neutral + dashed left edge marks an alarm the
   operator has intentionally silenced for this site (expected-degraded),
   distinct from genuinely-unknown. Acknowledged, not hidden. */
.sensor-tile-shelved  { border-left-style: dashed; border-left-color: var(--text-mute); opacity: 0.8; }
.sys-sub-shelf        { margin-left: 3px; color: var(--text-mute); font-size: 0.85em; }

/* Multi-row tile for NICs + WireGuard peers */
.sensor-tile-multi { min-height: 64px; }
.sensor-nic-list {
    display: flex; flex-direction: column; gap: 3px;
    margin-top: 2px;
}
.sensor-nic-row {
    display: flex; align-items: center; gap: 6px;
    font-size: 11px; color: var(--text);
}
.sensor-wg-local-ip {
    padding-bottom: 4px;
    border-bottom: 1px dashed var(--border);
    margin-bottom: 2px;
}
.sensor-nic-row code {
    font-family: ui-monospace, monospace; font-size: 11px;
    color: var(--text); font-weight: 600;
}
.sensor-nic-ip {
    color: var(--text-mute); font-size: 11px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sensor-nic-dot {
    width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.sensor-nic-dot-ok       { background: var(--ok); }
.sensor-nic-dot-warn     { background: #f59e0b; }
.sensor-nic-dot-critical { background: var(--error); }
.sensor-nic-dot-unknown  { background: var(--text-mute); opacity: 0.5; }
/* ISA-101: present-but-idle failover/optional link (e.g. wwan0 standby,
   eth0 unplugged). Neutral medium gray = normal, not an alarm. */
.sensor-nic-dot-standby  { background: #9aa0a6; }

.sensor-tag {
    display: inline-block;
    padding: 0 5px; border-radius: 3px;
    background: var(--bg); border: 1px solid var(--border);
    font-size: 9px; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-mute);
}

@media (max-width: 480px) {
    .sensor-strip { padding: 8px 10px; }
    #sensor-strip-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
    }
    .sensor-tile-value { font-size: 16px; }
    .sensor-tile-sub { font-size: 10px; }
}

/* ─── Chat ─── */
#chat {
    flex: 1; min-height: 0; display: flex; flex-direction: column;
    overflow: hidden; position: relative;
}
/* Greyscale brand watermark: the inset IS the border; `contain` scales it to the
   panel without ever clipping (a single background-size value sets width only,
   which overflowed the height). Sits behind content via z-index. */
#chat::before {
    /* Percentage insets keep clear margin from the sensor strip (top) and the
       composer (bottom) and shrink the mark so it doesn't crowd those bars. */
    content: ""; position: absolute; inset: 26% 20% 22%; z-index: 0; pointer-events: none;
    background: url("logo-watermark.svg") no-repeat center center;
    background-size: contain;
}
#chat > * { position: relative; z-index: 1; }
#messages {
    flex: 1; min-height: 0; overflow-y: auto; padding: 20px;
    display: flex; flex-direction: column; gap: 16px;
    max-width: 900px; width: 100%; margin: 0 auto;
}

.message { display: flex; gap: 12px; align-items: flex-start; }
.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }

.message-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--primary); color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px; flex-shrink: 0;
}

.message-content {
    background: var(--surface); padding: 12px 16px;
    border-radius: 12px; max-width: 70%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.message.user .message-content {
    background: var(--primary); color: white;
}
.message-sender {
    font-size: 12px; font-weight: 600; color: var(--text-mute);
    margin-bottom: 4px;
}
.message-text {
    line-height: 1.5; white-space: pre-wrap; word-wrap: break-word;
}

.pills {
    display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px;
}
.pill {
    padding: 3px 10px; border-radius: 12px; font-size: 12px;
    background: var(--bg); color: var(--text-mute);
    border: 1px solid var(--border);
}
.pill.tool { color: var(--primary); border-color: var(--primary); }
.pill.scope {
    color: var(--text-mute); border-color: var(--border);
    font-family: ui-monospace, monospace;
}

.message.streaming .message-text::after {
    content: '▌'; color: var(--primary);
    animation: blink 0.8s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

.error-note {
    color: var(--error); font-size: 13px; margin-top: 6px;
}

/* ─── Composer ─── */
#composer {
    display: flex; gap: 8px; padding: 16px 20px;
    background: var(--surface); border-top: 1px solid var(--border);
    max-width: 900px; width: 100%; margin: 0 auto;
}
#message-input {
    flex: 1; padding: 12px 14px; font-size: 16px;
    border: 1px solid var(--border); border-radius: 24px;
    background: var(--bg);
}
#message-input:focus { outline: 2px solid var(--primary); }
#send-btn { border-radius: 24px; padding: 12px 24px; }

/* ─── Error banner ─── */
.error-banner {
    position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
    background: var(--error); color: white; padding: 10px 20px;
    border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 100; font-size: 14px;
}

/* ─── Modal ─── */
.modal {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 50; padding: 24px;
}
.modal-card {
    background: var(--surface); padding: 24px; border-radius: 12px;
    min-width: 320px; max-width: 480px;
}
.modal-card h2 { margin-bottom: 16px; font-size: 18px; }
.modal-card ul { list-style: none; }
.modal-card li button {
    width: 100%; text-align: left; padding: 10px 12px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 6px; margin-bottom: 6px; cursor: pointer;
    font-family: ui-monospace, monospace; font-size: 14px;
}
.modal-card li button:hover { border-color: var(--primary); color: var(--primary); }
.modal-note {
    margin-top: 12px; padding: 10px; background: var(--bg);
    border-radius: 6px; font-size: 13px; color: var(--text-mute);
}

/* ─── Mesh-direct action panel (ISA-101 color discipline) ──────────────
 * Buttons follow consequence-of-action color, NOT identity:
 *   - Default (Ping, Status_request): neutral gray. Safe, no state
 *     change on the endpoint, so no alarm color used.
 *   - Warn (Restart HA): amber. Reversible disruption (HA restart is
 *     ~30s and recovers).
 *   - Crit (Reboot): red. Irreversible-in-the-short-term action; matches
 *     ISA-101 alarm color = "operator must think before clicking."
 * If you change these to "all blue" or "all the brand color", you've
 * removed the visual cue that distinguishes pingable from destructive.
 */
.mesh-action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 8px 0 4px;
}
.mesh-action-btn {
    padding: 6px 12px;
    border: 1px solid var(--border, #555);
    background: var(--tile-bg, #2a2a2a);
    color: var(--text, #ddd);
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    transition: filter 80ms;
}
.mesh-action-btn:hover  { filter: brightness(1.2); }
.mesh-action-btn:active { filter: brightness(0.9); }
.mesh-action-btn-warn {
    border-color: #b78a3f;
    color: #e7c181;
}
.mesh-action-btn-crit {
    border-color: #a94340;
    color: #e07a78;
}
.mesh-action-feedback {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted, #999);
    min-height: 16px;
}
.tile-detail-hint {
    margin: 6px 0 0;
    font-size: 11px;
    color: var(--text-muted, #888);
    font-style: italic;
}

/* ─── Meshtastic L3 detail card (advanced view) ──────────────────────
 * Wider than a normal tile because it carries metadata + an inline
 * action panel.  Spans two grid columns on the advanced strip.
 *
 * ISA-101 / HP-HMI:
 *   - Tile border + label color reflect LINK HEALTH only
 *     (sensor-tile-ok/warn/critical applied by the JS).
 *   - Action button colors reflect CONSEQUENCE-OF-ACTION (per the
 *     mesh-action-btn / -warn / -crit classes above).  Don't conflate.
 */
.sensor-tile-meshtastic {
    grid-column: span 2;
    min-height: 140px;
}
.mesh-card-kv {
    margin: 6px 0 0;
    padding: 0;
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 2px 10px;
    font-size: 12px;
    color: var(--text, #ddd);
}
.mesh-card-kv dt {
    color: var(--text-muted, #888);
    font-weight: normal;
}
.mesh-card-kv dd {
    margin: 0;
}
.mesh-card-actions {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border, #444);
}
.mesh-card-actions-label {
    font-size: 11px;
    color: var(--text-muted, #888);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}
.mesh-card-hint {
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-muted, #888);
    font-style: italic;
    line-height: 1.3;
}

/* Banner shown when the SPA is loaded at a non-canonical origin
   (typically the retired hearth.empire12.net URL).  Fixed-top,
   amber, ISA-101 "action needed" coloring without being alarmist. */
#move-banner {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 9999;
    background: #b87333;
    color: #fff;
    padding: 10px 16px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
#move-banner a {
    color: #fff;
    text-decoration: underline;
    font-weight: 600;
}
body.with-move-banner {
    padding-top: 44px;
}

/* ─── Bottom-left corner: documentation + brand link ─── */
/* Footer pinned to the bottom of the left nav panel (in-flow, not hovering). */
#corner-bl {
    margin-top: auto; width: 100%; flex-shrink: 0;
    padding-top: 12px; border-top: 1px solid var(--border);
    display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.corner-docs-btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 7px 12px; font-size: 13px; font-weight: 600;
    color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
    box-shadow: 0 1px 3px rgba(20,19,14,0.08); transition: border-color .15s, background .15s;
}
.corner-docs-btn:hover { border-color: var(--brand-sage); background: #f7f5f0; }
.corner-docs-btn svg { color: var(--brand-sage); }
#techtaria-link {
    font-family: "DM Serif Display", Georgia, serif;
    font-size: 28px; font-weight: 400; letter-spacing: .01em;
    color: var(--primary); text-decoration: none; text-align: center;
}
#techtaria-link:hover { color: var(--primary-dark); text-decoration: none; }

/* ─── Documentation overlay ─── */
.docs-overlay {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(20,19,14,0.45);
    display: flex; align-items: center; justify-content: center; padding: 24px;
}
.docs-overlay.hidden { display: none; }
.docs-panel {
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    width: min(960px, 100%); height: min(800px, 92vh);
    display: flex; flex-direction: column; overflow: hidden;
    box-shadow: 0 12px 40px rgba(20,19,14,0.25);
}
.docs-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.docs-title { display: flex; align-items: center; gap: 10px; }
.docs-title h2 { font-size: 17px; font-weight: 700; color: var(--text); }
.docs-logo { height: 24px; width: auto; }
.docs-scope { color: var(--text-mute); font-size: 13px; }
.docs-close {
    background: none; border: none; font-size: 24px; line-height: 1;
    color: var(--text-mute); cursor: pointer; padding: 0 4px;
}
.docs-close:hover { color: var(--text); }
.docs-body { display: flex; flex: 1; min-height: 0; }
.docs-nav {
    width: 210px; flex-shrink: 0; border-right: 1px solid var(--border);
    padding: 12px 8px; overflow-y: auto; background: #faf8f4;
}
.docs-nav-group {
    font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-mute); padding: 12px 10px 4px;
}
.docs-nav-item {
    display: block; width: 100%; text-align: left;
    padding: 9px 10px; margin-bottom: 2px; font-size: 14px;
    color: var(--text); background: none; border: none; border-radius: 6px;
    border-left: 3px solid transparent; cursor: pointer;
}
.docs-nav-item:hover { background: #f0ece4; }
.docs-nav-item.active {
    background: #eef3ee; border-left-color: var(--brand-sage); font-weight: 600;
}
.docs-content { flex: 1; min-width: 0; overflow-y: auto; padding: 22px 26px; }
.docs-content:focus { outline: none; }
.docs-set-head { margin-bottom: 18px; }
.docs-set-head h3 { font-size: 19px; font-weight: 700; color: var(--text); }
.docs-intro { color: var(--text-mute); font-size: 14px; margin-top: 4px; }
.docs-loading, .docs-empty {
    color: var(--text-mute); text-align: center; padding: 60px 20px; font-size: 15px;
}
.docs-empty-icon {
    font-size: 30px; color: var(--brand-sage); margin-bottom: 10px;
}
.docs-empty-sub { font-size: 12px; margin-top: 8px; }

/* device cards / rows */
.docs-area {
    font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-mute); margin: 20px 0 8px; font-weight: 600;
}
.docs-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.docs-card, .docs-row {
    border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; background: var(--surface);
}
.docs-list { display: flex; flex-direction: column; gap: 10px; }
.docs-card-h, .docs-row-h { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.docs-card-name, .docs-row-name { font-weight: 600; color: var(--text); font-size: 14px; }
.docs-card-tag {
    font-size: 11px; color: var(--text-mute); background: #f0ece4;
    border-radius: 4px; padding: 1px 7px;
}
.docs-card-sum { color: var(--text); font-size: 13.5px; margin-top: 6px; line-height: 1.45; }
.docs-card-meta { color: var(--text-mute); font-size: 12px; margin-top: 6px; }
.docs-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.docs-chip {
    font-size: 11.5px; color: var(--text); background: #f0ece4;
    border: 1px solid var(--border); border-radius: 12px; padding: 2px 9px;
}
.docs-sub { margin-top: 8px; }
.docs-sub-h {
    font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--text-mute); font-weight: 600;
}
.docs-sub ul { margin: 3px 0 0 18px; }
.docs-sub li { font-size: 13.5px; color: var(--text); line-height: 1.5; }

/* timeline (changes + changelog) */
.docs-timeline { display: flex; flex-direction: column; gap: 14px; }
.docs-tl-item { display: flex; gap: 14px; }
.docs-tl-date { color: var(--text-mute); font-size: 12px; min-width: 84px; flex-shrink: 0; padding-top: 2px; }
.docs-tl-title { font-weight: 600; color: var(--text); font-size: 14px; display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.docs-cl { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }
.docs-cl summary { cursor: pointer; display: flex; gap: 10px; align-items: baseline; }
.docs-cl-title { font-weight: 600; color: var(--text); font-size: 14px; }
.docs-cl-body { margin-top: 8px; font-size: 13px; color: var(--text); line-height: 1.5; }
.docs-cl-body h4 { font-size: 13px; margin: 10px 0 3px; }
.docs-cl-body ul { margin: 4px 0 4px 18px; }
.docs-cl-body code { background: #f0ece4; padding: 1px 4px; border-radius: 3px; font-size: 12px; }

/* exception-only status dots (ISA-101) */
.docs-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; display: inline-block; }
.docs-dot-critical { background: var(--error); }
.docs-dot-warn { background: #f59e0b; }
.docs-dot-standby { background: #9aa0a6; }

@media (max-width: 640px) {
    .docs-body { flex-direction: column; }
    .docs-nav { width: auto; border-right: none; border-bottom: 1px solid var(--border);
                display: flex; flex-wrap: wrap; gap: 4px; }
    .docs-nav-group { width: 100%; padding: 6px 6px 2px; }
    .docs-nav-item { width: auto; border-left: none; border-bottom: 3px solid transparent; }
    .docs-nav-item.active { border-left: none; border-bottom-color: var(--brand-sage); }
}

/* ─── New-chat empty state + suggestion prompts ─── */
.chat-empty {
    flex: 1; display: flex; align-items: center; justify-content: center;
    text-align: center; padding: 20px;
}
.chat-empty-inner { max-width: 460px; width: 100%; }
.chat-empty-title { font-size: 22px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.chat-empty-sub { color: var(--text-mute); font-size: 14px; margin-bottom: 18px; }
.chat-suggestions { display: flex; flex-direction: column; gap: 8px; }
.chat-suggestion {
    width: 100%; text-align: left; padding: 12px 14px; font-size: 14px;
    color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
    transition: border-color .15s, background .15s;
}
.chat-suggestion:hover { border-color: var(--brand-sage); background: #f7f5f0; }


/* ─── Collapsible status strip (expand on demand; never pushes the composer off) ─── */
.sensor-strip { flex-shrink: 0; }
.sensor-strip-header {
    width: 100%; display: flex; align-items: center; justify-content: space-between;
    background: none; border: none; cursor: pointer; padding: 2px 2px;
    font-size: 13px; font-weight: 600; color: var(--text);
}
.sensor-strip-title { letter-spacing: .01em; }
.sensor-strip-chevron { color: var(--text-mute); font-size: 12px; }
#sensor-strip-body { display: none; }
.sensor-strip.expanded #sensor-strip-body {
    display: block; margin-top: 8px;
    max-height: 45vh; overflow-y: auto; overflow-x: hidden;   /* cap + scroll, no h-scroll */
}
#composer { flex-shrink: 0; }   /* chat input is always visible */

/* Mobile navigation: hamburger opens the sidebar as an off-canvas drawer */
.hamburger-btn { display: none; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(20,19,14,0.4); z-index: 55; }
.sidebar-backdrop.open { display: block; }

/* ─── Mobile topbar declutter: move System / status / Sign out into the drawer ─── */
.sidebar-extras {
    display: flex; flex-direction: column; gap: 10px; flex-shrink: 0;
    padding-top: 10px; border-top: 1px solid var(--border);
}
.sidebar-extras:empty { display: none; }
.sidebar-extras .scope-indicator,
.sidebar-extras .system-status { display: flex; flex-wrap: wrap; }
.sidebar-extras #btn-logout { align-self: flex-start; }

@media (max-width: 700px) {
    /* This block is last in source, so it reliably wins the earlier base rule. */
    .hamburger-btn { display: inline-flex; }
    #user-name { display: none; }
}
/* In the drawer there's room — show the status labels (hidden in the compact topbar) */
.sidebar-extras .system-status-label { display: inline; }
.sidebar-extras .system-status { gap: 10px; }

/* Home-status rollup badge: "OK" neutral, "Problem" red (ISA-101: colour only for the exception) */
.sensor-strip-header-left { display: inline-flex; align-items: center; gap: 8px; }
.sensor-strip-overall {
    font-size: 11px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
    padding: 1px 8px; border-radius: 10px;
    background: #ece8e0; color: var(--text-mute); border: 1px solid var(--border);
}
.sensor-strip-overall.problem { background: #fdecea; color: #a3271b; border-color: var(--error); }
.sensor-strip-overall.unknown { opacity: .55; }
/* Actionable (Problem/Offline) — tap to start a troubleshooting chat. */
.sensor-strip-overall.actionable { cursor: pointer; }
.sensor-strip-overall.actionable::after { content: " ›"; font-weight: 700; }
.sensor-strip-overall.actionable:hover { filter: brightness(0.97); }
.sensor-strip-overall.actionable:focus-visible {
    outline: 2px solid var(--error); outline-offset: 1px;
}

/* ─── Stale / unreachable data integrity (ISA: never imply live data is current) ─── */
.sensor-strip-overall.stale { background: #fff4e5; color: #92400e; border-color: #f59e0b; }
.sensor-strip-age.stale { color: #92400e; font-weight: 600; }
.sensor-strip.sensor-stale #sensor-strip-grid { opacity: 0.55; }   /* last-known values dimmed */

/* Exception navigation: flash the offending tile when the strip is opened */
@keyframes tileFlash { 0%,100% { box-shadow: none; } 30% { box-shadow: 0 0 0 3px rgba(192,57,43,0.5); } }
.sensor-tile-flash { animation: tileFlash 1.6s ease; }

/* ─── Profile / Settings dialog ─── */
.profile-card {
    background: var(--surface); border-radius: 12px; width: min(520px, 100%);
    max-height: 88vh; display: flex; flex-direction: column; overflow: hidden;
    box-shadow: 0 12px 40px rgba(20,19,14,0.25);
}
.profile-header { display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; border-bottom: 1px solid var(--border); }
.profile-header h2 { font-size: 17px; font-weight: 700; color: var(--text); }
.profile-tabs { display: flex; gap: 4px; padding: 6px 12px 0; border-bottom: 1px solid var(--border); }
.profile-tab { background: none; border: none; padding: 9px 12px; font-size: 14px;
    color: var(--text-mute); cursor: pointer; border-bottom: 2px solid transparent; }
.profile-tab.active { color: var(--text); font-weight: 600; border-bottom-color: var(--brand-sage); }
.profile-body { padding: 18px; overflow-y: auto; }
.profile-pane { display: flex; flex-direction: column; gap: 14px; }
.profile-pane.hidden { display: none; }
.pf-field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-mute); }
.pf-field input, .pf-field select { padding: 9px 11px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 14px; color: var(--text); background: var(--bg); }
.pf-field input:focus, .pf-field select:focus { outline: 2px solid var(--primary); }
.pf-hint { color: var(--text-mute); font-weight: 400; font-size: 12px; }
.pf-actions { display: flex; align-items: center; gap: 12px; margin-top: 2px; }
.pf-msg { font-size: 13px; color: var(--text-mute); }
.pf-msg.ok { color: var(--success); }
.pf-msg.err { color: var(--error); }
.pf-intro { font-size: 13px; color: var(--text-mute); }
.pf-passkeys { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.pf-passkey { display: flex; align-items: center; justify-content: space-between;
    padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
.pf-passkey-meta { font-size: 12px; color: var(--text-mute); }
.pf-channels { display: flex; flex-direction: column; gap: 8px; padding: 10px 0;
    border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.pf-toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.pf-toggle.pf-disabled { color: var(--text-mute); cursor: default; }
.pf-alarms-head { font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-mute); font-weight: 600; }
.pf-alarms { display: flex; flex-direction: column; gap: 10px; }
.pf-alarm { display: flex; align-items: flex-start; gap: 10px; }
.pf-alarm input { margin-top: 3px; flex-shrink: 0; }
.pf-alarm-label { font-size: 14px; color: var(--text); }
.pf-alarm-desc { font-size: 12px; color: var(--text-mute); }

/* ─── a11y polish ─── */
button:focus-visible, a:focus-visible, select:focus-visible,
input:focus-visible, [tabindex]:focus-visible, .sensor-strip-header:focus-visible {
    outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px;
}
@media (max-width: 700px) {
    .icon-button, .hamburger-btn { min-width: 40px; min-height: 40px; }
}

/* Activity timeline events (ISA: colour only on the problem) */
.docs-ev-icon { font-weight: 700; margin-right: 6px; }
.docs-ev-raised .docs-ev-icon  { color: var(--error); }
.docs-ev-cleared .docs-ev-icon { color: var(--text-mute); }

/* ─── Guided resolution ─── */
.guidance-card { background: var(--surface); border-radius: 12px; width: min(460px, 100%);
    max-height: 88vh; display: flex; flex-direction: column; overflow: hidden;
    box-shadow: 0 12px 40px rgba(20,19,14,0.25); }
.guidance-header { display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; border-bottom: 1px solid var(--border); }
.guidance-header h2 { font-size: 17px; font-weight: 700; color: var(--text); }
.guidance-body { padding: 18px; overflow-y: auto; }
.guidance-explain { font-size: 14px; color: var(--text); line-height: 1.5; }
.guidance-steps-head { font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-mute); font-weight: 600; margin: 14px 0 6px; }
.guidance-steps { margin: 0 0 0 18px; }
.guidance-steps li { font-size: 14px; color: var(--text); line-height: 1.5; margin-bottom: 4px; }
.guidance-actions { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; }
/* alert-bar rows are now tappable buttons */
.alert-row { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
    background: none; border: none; cursor: pointer; padding: 4px 2px; font: inherit; color: inherit; }
.alert-row:hover .alert-help { text-decoration: underline; }
.alert-help { margin-left: auto; font-size: 12px; color: var(--text-mute); white-space: nowrap; flex-shrink: 0; }

/* ─── Severe weather / FEMA alert banner (NWS) ─── */
.weather-bar { display: flex; flex-direction: column; gap: 4px; padding: 8px 16px;
    border-bottom: 1px solid var(--border); flex-shrink: 0;
    border-left: 4px solid #f59e0b; background: #fff8ec; }
.weather-bar.hidden { display: none; }
.weather-bar-critical { border-left-color: var(--error); background: #fef2f2; }
.weather-bar-info { border-left-color: var(--text-mute); background: var(--bg); }
.weather-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.weather-icon { flex-shrink: 0; }

/* ─── Local panel (News / Mesh / Social) — right slide-in ─── */
.local-panel { position: fixed; inset: 0; z-index: 100; background: rgba(20,19,14,0.35);
    display: flex; justify-content: flex-end; }
.local-panel.hidden { display: none; }
.local-card { background: var(--surface); width: min(380px, 100%); height: 100%;
    display: flex; flex-direction: column; box-shadow: -2px 0 16px rgba(20,19,14,0.25); }
.local-header { display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; border-bottom: 1px solid var(--border); }

/* Around you (Places concierge) */
.local-around { font-size: 13px; color: var(--text); }
.around-group { margin-bottom: 12px; }
.around-cat { font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-mute); font-weight: 700; margin-bottom: 4px; }
.around-item { display: block; text-decoration: none; color: var(--text);
    padding: 6px 0; border-bottom: 1px solid var(--border); }
.around-item:last-child { border-bottom: none; }
.around-item:hover .around-name { text-decoration: underline; }
.around-name { display: block; font-size: 13px; line-height: 1.3; }
.around-meta { display: block; font-size: 11px; color: var(--text-mute); margin-top: 1px; }
.local-header h2 { font-size: 17px; font-weight: 700; color: var(--text); }
.local-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 20px; }
.local-section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-mute); font-weight: 700; margin-bottom: 8px; }
.local-soon { font-size: 13px; color: var(--text-mute); line-height: 1.5; }
.local-news { font-size: 13px; color: var(--text); line-height: 1.5; }
.local-news .wx-alert { padding: 8px 10px; border-radius: 8px; margin-bottom: 6px;
    border-left: 3px solid #f59e0b; background: #fff8ec; }
.local-news .wx-alert.critical { border-left-color: var(--error); background: #fef2f2; }
.local-news .wx-clear { color: var(--text-mute); }

/* Current conditions + 3-day forecast (Local panel) */
.wx-current { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.wx-temp { font-size: 30px; font-weight: 700; color: var(--text); line-height: 1; }
.wx-cond { font-size: 13px; color: var(--text-mute); }
.wx-days { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.wx-day { text-align: center; padding: 8px 4px; border: 1px solid var(--border); border-radius: 8px; }
.wx-day-name { font-size: 11px; color: var(--text-mute); font-weight: 600; }
.wx-day-temp { font-size: 16px; font-weight: 700; color: var(--text); margin: 2px 0; }
.wx-day-text { font-size: 10px; color: var(--text-mute); line-height: 1.2; }

/* Neighborhood-mesh radio status */
.local-mesh { margin-bottom: 8px; }
.mesh-status { font-size: 13px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.mesh-dot { width: 8px; height: 8px; border-radius: 50%; background: #9aa0a6; flex-shrink: 0; }
.mesh-stale .mesh-dot { background: #f59e0b; }
.mesh-unknown { color: var(--text-mute); }

/* Weather card background icons (faint, behind text) */
.wx-current { position: relative; overflow: hidden; }
.wx-current > .wx-temp, .wx-current > .wx-cond { position: relative; z-index: 1; }
.wx-bg { position: absolute; right: 8px; top: -6px; font-size: 52px; opacity: .65; pointer-events: none; }
.wx-day { position: relative; overflow: hidden; }
.wx-day > :not(.wx-day-bg) { position: relative; z-index: 1; }
.wx-day-bg { position: absolute; right: 2px; bottom: -4px; font-size: 34px; opacity: .6; pointer-events: none; }

/* Local news headlines (Local panel) */
.news-list { margin-top: 12px; }
.news-head { font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-mute); font-weight: 700; margin-bottom: 6px;
    padding-top: 10px; border-top: 1px solid var(--border); }
.news-note { font-size: 12px; color: var(--text-mute); line-height: 1.4; padding: 6px 0 2px; }
.news-item { display: flex; align-items: flex-start; gap: 8px;
    padding: 7px 0; border-bottom: 1px solid var(--border); }
.news-item:last-child { border-bottom: none; }
.news-link { flex: 1; text-decoration: none; color: var(--text); min-width: 0; }
.news-link:hover .news-title { text-decoration: underline; }
.news-title { display: block; font-size: 13px; line-height: 1.35; }
.news-meta { display: block; font-size: 11px; color: var(--text-mute); margin-top: 2px; }
.news-sum { flex-shrink: 0; background: none; border: 1px solid var(--border);
    border-radius: 6px; color: var(--text-mute); cursor: pointer;
    padding: 4px; line-height: 0; margin-top: 1px; }
.news-sum:hover { color: var(--text); border-color: var(--text-mute); }
.news-sum:focus-visible { outline: 2px solid var(--primary); }

/* Article summary modal */
.news-summary-card { max-width: 560px; }
.news-summary-tag { font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-mute); font-weight: 700; margin-bottom: 8px; }
.news-summary-body { font-size: 14px; line-height: 1.6; color: var(--text); white-space: pre-wrap; }
.news-summary-open { display: inline-block; margin-top: 16px; font-size: 13px;
    color: var(--primary); text-decoration: none; }
.news-summary-open:hover { text-decoration: underline; }

/* Settings → Local (Around-you categories + news feeds) */
.pf-places-cats { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 14px; margin-bottom: 6px; }
.pf-feeds { list-style: none; padding: 0; margin: 0 0 12px; }
.pf-feed-meta { color: var(--text-mute); font-size: 13px; padding: 8px 0; }
.pf-feed-row { display: flex; align-items: center; gap: 10px; padding: 8px 0;
    border-bottom: 1px solid var(--border); }
.pf-feed-info { flex: 1; min-width: 0; }
.pf-feed-name { display: block; font-size: 13px; color: var(--text); }
.pf-feed-url { display: block; font-size: 11px; color: var(--text-mute);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pf-feed-del { flex-shrink: 0; color: var(--text-mute); }
.pf-feed-del:hover { color: var(--error); }
.pf-feed-add { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.pf-feed-add input { flex: 1; min-width: 140px; padding: 8px 10px;
    border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
    background: var(--surface); color: var(--text); }
.pf-feed-add input:focus { outline: 2px solid var(--primary); }

/* Neighborhood mesh chat */
.mesh-chat { border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
    padding: 8px; height: 180px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.mesh-empty { color: var(--text-mute); font-size: 13px; text-align: center; margin: auto; }
.mesh-msg { font-size: 13px; max-width: 85%; }
.mesh-in { align-self: flex-start; }
.mesh-out { align-self: flex-end; text-align: right; }
.mesh-meta { font-size: 11px; color: var(--text-mute); }
.mesh-body { background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    padding: 5px 9px; color: var(--text); display: inline-block; }
.mesh-out .mesh-body { background: #eef3ee; }
.mesh-pending { font-style: italic; }
.mesh-form { display: flex; gap: 6px; margin-top: 8px; }
.mesh-form input { flex: 1; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
    font-size: 14px; background: var(--surface); color: var(--text); }
.mesh-form input:focus { outline: 2px solid var(--primary); }
.mesh-send { padding: 8px 14px; }
