/* === WA Gateway — True Black Grok Style === */

:root {
    --bg:            #000000;
    --bg-elevated:   #141414;
    --bg-hover:      rgba(255,255,255,0.08);
    --bg-active:     rgba(255,255,255,0.12);
    --border:        #262626;
    --border-bright: #444444;
    --text:          #ffffff;
    --text-secondary:#b8b8b8;
    --text-muted:    #8f8f8f;
    --accent:        #e4e4e7;
    --accent-hover:  #ffffff;
    --danger:        #ef4444;
    --ok:            #22c55e;
    --warn:          #f59e0b;
    --info:          #3b82f6;

    --sidebar-width: 200px;
    --pad:           32px;
    --gap:           16px;
    --radius-sm:     6px;
    --radius-md:     10px;
    --radius-lg:     12px;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* === Light theme: palette swap only; every component reads these variables === */
[data-theme="light"] {
    --bg:            #ffffff;
    --bg-elevated:   #f4f4f5;
    --bg-hover:      rgba(0,0,0,0.06);
    --bg-active:     rgba(0,0,0,0.09);
    --border:        #e4e4e7;
    --border-bright: #d4d4d8;
    --text:          #18181b;
    --text-secondary:#52525b;
    --text-muted:    #71717a;
    --accent:        #18181b;
    --accent-hover:  #000000;
}

/* Hardcoded white-alpha surfaces that need a light-mode counterpart */
[data-theme="light"] .slot-avatar.empty { background: rgba(0,0,0,0.04); }
[data-theme="light"] .sidebar { box-shadow: none; }

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

html,
body {
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* === Layout === */
.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.login-layout {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 2rem;
    background: var(--bg);
}

.login-box {
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.login-box form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-box form button {
    margin-top: 0.5rem;
}

/* === Brand === */
.brand-text {
    font-size: 1.5rem;
    font-weight: 700;
}

.sup {
    position: relative;
    top: -1em;
    font-size: 0.6em;
    font-weight: 700;
    line-height: 0;
}

/* === Sidebar === */
.sidebar {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    padding: 1rem 0.75rem;
    overflow-y: auto;
    background: var(--bg);
    border-right: 1px solid var(--border);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
    padding: 0 0.75rem;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    text-decoration: none;
}

.sidebar-brand:hover {
    text-decoration: none;
}

.sidebar-brand svg {
    color: var(--text);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    list-style: none;
}

.sidebar-nav li {
    width: 100%;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: left;
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all 0.1s ease;
}

.sidebar-nav a svg {
    flex-shrink: 0;
    color: var(--text-muted);
    transition: color 0.1s ease;
}

.sidebar-nav a:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.sidebar-nav a:hover svg {
    color: var(--text-secondary);
}

.sidebar-nav a[aria-current="page"] {
    color: var(--text);
    background: var(--bg-active);
}

.sidebar-nav a[aria-current="page"] svg {
    color: var(--text);
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

/* Anchor and toggle button share one rule: identical box, identical alignment */
.sidebar-footer a,
.sidebar-footer .theme-toggle {
    display: flex;
    align-items: center;
    justify-content: flex-start; /* overrides the global button centering */
    gap: 0.875rem;
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-muted);
    text-align: left;
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all 0.1s ease;
}

.sidebar-footer a:hover,
.sidebar-footer .theme-toggle:hover {
    color: var(--text);
    background: var(--bg-hover);
    text-decoration: none;
    opacity: 1; /* overrides the global button hover dim */
}

/* === Theme toggle: button reset only; visuals come from the shared rule === */
.theme-toggle {
    font-family: inherit;
    line-height: inherit;
    background: transparent;
    border: none;
    cursor: pointer;
}

.theme-toggle .show-when-light { display: none; }
[data-theme="light"] .theme-toggle .show-when-light { display: inline; }
[data-theme="light"] .theme-toggle .show-when-dark { display: none; }

/* === Main === */
.main {
    min-height: 100vh;
    padding: var(--pad);
    background: var(--bg);
    overflow-y: auto;
}

.main:has(> .inbox-layout) {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-bottom: 0;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--gap);
}

.page-header:has(+ .inbox-layout) {
    flex-shrink: 0;
}

.page-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

.page-header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Header dropdowns — generic component. .actions-menu (mobile ⋮) is hidden
   on desktop; .groups-dropdown is hidden on mobile (its items move into ⋮). */
.navdrop {
    position: relative;
}

.actions-menu {
    display: none;
}

.navdrop-list {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 150;
    min-width: 180px;
    padding: 0.375rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.groups-dropdown .navdrop-list {
    left: 0;
    right: auto;
}

.navdrop.open .navdrop-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.navdrop-item {
    display: flex;
    align-items: center;
    justify-content: flex-start; /* overrides the global button centering */
    gap: 0.625rem;
    width: 100%;
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
    color: var(--text);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
}

.navdrop-item:hover {
    background: var(--bg-hover);
}

.navdrop-divider {
    height: 1px;
    margin: 4px 2px;
    background: var(--border);
}

.navdrop-item .item-check {
    margin-left: auto;
    color: var(--text-muted);
}

/* Per-device group row: plain text + folder icon, no pill, no arrow */
.device-group-drop .navdrop-list {
    left: 0;
    right: auto;
}

.device-group-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0;
    background: none;
    border: none;
    font: inherit;
    color: var(--text-secondary);
    cursor: pointer;
}

.device-group-trigger:hover {
    color: var(--text);
}

/* === Sections & Cards === */
section {
    margin-bottom: var(--gap);
}

.section-title {
    margin-bottom: 0.875rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.section-title a {
    color: inherit;
    text-decoration: none;
}
.section-title a:hover {
    color: var(--text);
}

.card,
.card-outline,
.stat-card {
    padding: 1.5rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.card {
    margin-bottom: 1rem;
}

.card:last-child {
    margin-bottom: 0;
}

.card-outline {
    background: transparent;
}

.card-outline .empty-state {
    text-align: left;
    padding: 0;
    margin: 0;
}

.card-danger {
    border-color: var(--danger);
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--gap);
}

/* === Stat Card === */
.stat-card {
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.stat-card h4 {
    margin-bottom: 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.stat-card .value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
    letter-spacing: -0.02em;
}

.stat-card .meta {
    margin-top: 0.375rem;
    font-size: 0.875rem;
    color: var(--text-muted);
    min-height: 1.25em;
    line-height: 1.25;
}

/* === Campaign Cards === */
.campaign-card {
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

.campaign-card:last-child {
    border-bottom: none;
}

.campaign-card-inner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

/* inline-flex + block svg: kills the inline baseline gap so the glyph
   centers on the name's midline (the lead flex centers the box). */
.campaign-icon {
    display: inline-flex;
    align-items: center;
    color: var(--text);
    flex-shrink: 0;
    margin-top: 2px;
}

.campaign-icon svg {
    display: block;
}

.campaign-icon-running  { color: var(--text); }
.campaign-icon-completed{ color: var(--ok); }
.campaign-icon-failed   { color: var(--danger); }
.campaign-icon-stopped  { color: var(--danger); }

.campaign-body {
    flex: 1;
    min-width: 0;
}

.campaign-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.campaign-name {
    font-weight: 600;
    color: var(--text);
    /* The flex chain must be bounded or long names overflow into the date:
       name truncates with ellipsis, the meta date never gets encroached. */
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.campaign-meta {
    color: var(--text-secondary);
    font-size: 0.8125rem;
    margin-top: 2px;
    flex: 0 0 auto;
    white-space: nowrap;
}

.campaign-progress {
    margin-top: 8px;
}

.campaign-progress progress {
    width: 100%;
    height: 4px;
    appearance: none;
    background: var(--border);
    border: none;
    border-radius: 999px;
}

.campaign-progress progress::-webkit-progress-bar {
    background: var(--border);
    border-radius: 999px;
}

.campaign-progress progress::-webkit-progress-value {
    background: var(--info);
    border-radius: 999px;
}

.campaign-progress-meta {
    display: flex;
    gap: 12px;
    margin-top: 4px;
    color: var(--text-secondary);
    font-size: 0.8125rem;
}

.campaign-stats {
    display: flex;
    gap: 16px;
    margin-top: 6px;
    color: var(--text-secondary);
    font-size: 0.8125rem;
}

.campaign-stats strong,
.campaign-progress-meta strong {
    color: var(--text);
    font-weight: 600;
}

/* Failure count: red when shown — the span renders only when > 0 (UI rule 4). */
.campaign-stats .stat-failed,
.campaign-stats .stat-failed strong,
.campaign-progress-meta .stat-failed,
.campaign-progress-meta .stat-failed strong {
    color: var(--danger);
}

.campaign-error {
    margin-top: 4px;
    color: var(--danger);
    font-size: 0.8125rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Sub-line annotation slot — one state annotation per row, same position and
   typography as the failure reason: stopped summary (red, terminated by
   intervention) / waiting (muted, the one allowed status word). */
.campaign-stopped-line,
.campaign-waiting-line {
    margin-top: 4px;
    font-size: 0.8125rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.campaign-stopped-line { color: var(--danger); }
.campaign-waiting-line { color: var(--text-muted); }

/* === Message Monitor (compact single-row) === */
/* Replace .monitor-row and children */

.monitor-row {
    display: grid;
    grid-template-columns: 24px 140px 20px 140px 1fr auto;
    gap: 8px;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.monitor-row:last-child {
    border-bottom: none;
}

.monitor-icon {
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
}

.monitor-sender-block,
.monitor-target-block {
    min-width: 0;
    overflow: hidden;
}

.monitor-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.monitor-name-meta {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.monitor-arrow {
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

.monitor-body-text {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 4px;
}

.monitor-time-block {
    text-align: right;
    min-width: 0;
}

.monitor-time {
    font-size: 12px;
    color: var(--text-muted);
}

.monitor-device {
    font-size: 11px;
    color: var(--text-secondary);
    /* The restored alias · glyph · number line renders on ONE line (owner
       ruling 2026-09-24) — the last track is auto (content-sized) and the
       line never wraps. */
    white-space: nowrap;
}

/* Clickable monitor rows reuse the Conversations whole-row anchor grammar
   verbatim (a.conv-preview-card): whole-row --bg-hover, no underline;
   draggable="false" on the tag + user-select: text keep the row text
   select/copy-able. Only anchor rows get the hover — plain rows (no
   conversation) never paint: a hover must never promise a click that does
   nothing. */
a.monitor-row.monitor-link {
    text-decoration: none;
    color: inherit;
    user-select: text;
    transition: background 0.1s ease;
}

a.monitor-row.monitor-link:hover {
    background: var(--bg-hover);
    text-decoration: none;
}

/* === Tables === */
.table-wrap {
    overflow-x: auto;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.table-wrap table {
    width: 100%;
    font-size: 0.9375rem;
    border-collapse: collapse;
}

.table-wrap th {
    padding: 0.875rem 1.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-align: left;
    background: transparent;
    border-bottom: 1px solid var(--border);
}

.table-wrap td {
    padding: 0.875rem 1.25rem;
    color: var(--text);
    border-bottom: 1px solid var(--border);
}

.table-wrap tr:last-child td {
    border-bottom: none;
}

.table-wrap tr:hover td {
    background: var(--bg-hover);
}

/* === Progress === */
progress {
    width: 100%;
    height: 6px;
    appearance: none;
    background: var(--border);
    border: none;
    border-radius: 999px;
}

progress::-webkit-progress-bar {
    background: var(--border);
    border-radius: 999px;
}

progress::-webkit-progress-value {
    background: var(--info);
    border-radius: 999px;
}

progress::-moz-progress-bar {
    background: var(--info);
    border-radius: 999px;
}

.progress-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* === Forms === */
input,
textarea,
select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
    color: var(--text);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: border-color 0.1s ease, box-shadow 0.1s ease;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--border-bright);
    box-shadow: 0 0 0 3px rgba(255,255,255,0.08);
}

label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
}

/* === Buttons === */
button,
input[type="submit"],
.btn-primary,
.btn-danger,
.btn-secondary,
.btn-text,
.btn-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: opacity 0.1s ease;
}

/* Toolbar-register modifier: matches .filter-search sizing (owner variant B) */
.btn-sm {
    padding: 0.375rem 0.9rem;
    font-size: 0.8125rem;
}

button:hover,
input[type="submit"]:hover,
.btn-primary:hover,
.btn-danger:hover {
    opacity: 0.9;
}

button,
input[type="submit"],
.btn-primary {
    color: var(--bg);
    background: var(--text);
    border: none;
}

button.secondary,
button.outline,
.btn-secondary {
    color: var(--text);
    background: transparent;
    border: 1px solid var(--border-bright);
    transition: all 0.1s ease;
}

button.secondary:hover,
button.outline:hover,
.btn-secondary:hover {
    background: var(--bg-hover);
    opacity: 1;
}

.btn-secondary {
    text-decoration: none;
}

.btn-danger {
    color: var(--danger);
    background: transparent;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

.btn-text {
    padding: 0.5rem 0.75rem;
    color: var(--text-secondary);
    background: none;
    border: none;
    transition: all 0.1s ease;
}

.btn-text:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.btn-pill {
    padding: 0.5rem 1rem;
    color: var(--text);
    background: transparent;
    border: 1px solid var(--border-bright);
    border-radius: 999px;
    transition: all 0.1s ease;
}

.btn-pill:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.btn-full {
    width: 100%;
}

/* === Details / Summary === */
details {
    overflow: hidden;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

summary {
    padding: 1rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text);
    list-style: none;
    cursor: pointer;
    user-select: none;
    transition: background 0.1s ease;
}

summary:hover {
    background: var(--bg-hover);
}

details > *:not(summary) {
    padding: 1.25rem;
    border-top: 1px solid var(--border);
}

/* === Links === */
a {
    color: var(--text);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Exception: dropdown rows are rows, not prose links — no hover underline. */
.dropdown-item:hover {
    text-decoration: none;
}

.action-link,
.action-link:visited {
    color: var(--text-secondary);
    text-decoration: underline;
    text-underline-offset: 0.15em;
}

.action-link:hover {
    color: var(--text);
}

/* === Status === */
.status-dot {
    font-size: 0.875rem;
}

.status-dot.online {
    color: var(--ok);
}

.status-dot.offline {
    color: var(--text-muted);
}

/* === Utilities === */
.text-muted {
    color: var(--text-muted);
}

.text-danger {
    color: var(--danger);
}

/* Status chips (2026-09-19): plain text on a low-saturation tint — the ONE
   honest-status treatment (Refresh status strip, per-slot scrape status,
   Set Profile modal). State, never action: no icons/glyphs, no borders, no
   animation. The mount guard keeps an empty per-slot mount invisible (the
   slot-actions flex gap would otherwise shift the icons). */
.chip {
    border-radius: var(--radius-sm);
    padding: 1px 8px;
}
.chip-info    { background: color-mix(in srgb, var(--info) 18%, transparent); }
.chip-ok      { background: color-mix(in srgb, var(--ok) 16%, transparent); }
.chip-warn    { background: color-mix(in srgb, var(--warn) 18%, transparent); }
.chip-danger  { background: color-mix(in srgb, var(--danger) 16%, transparent); }
.chip-mount:empty { display: none; }

.mb-0 {
    margin-bottom: 0 !important;
}

.empty-state {
    padding: 2rem 0;
    font-size: 0.875rem;
    color: var(--text-muted);
    text-align: center;
}

.form-inline {
    display: inline;
}

.input-inline {
    display: inline-block;
    width: auto;
}

.input-gap {
    margin-bottom: 0.5rem;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-weight: 400;
}

.form-check input {
    margin: 0;
}

/* === Login === */
.login-header {
    margin-bottom: 2rem;
    text-align: center;
}

.login-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    margin-bottom: 1rem;
    background: var(--bg-hover);
    border-radius: var(--radius-lg);
}

.login-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
}

.login-subtitle {
    margin: 0.5rem 0 0;
    font-size: 0.9375rem;
    color: var(--text-muted);
}

.login-error {
    margin-bottom: 1.25rem;
    font-size: 0.875rem;
    color: var(--danger);
    text-align: center;
}

/* === Mobile Nav Toggle (hidden on desktop; styled for the mobile header row) === */
.sidebar-backdrop {
    display: none;
}

.nav-toggle {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 300;
    width: 48px;
    height: 52px;
    align-items: center;
    justify-content: center;
    color: var(--text);
    background: transparent;
    border: none;
    cursor: pointer;
}

.nav-toggle svg {
    width: 28px;
    height: 28px;
}

/* === Modal === */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.modal-backdrop.open {
    display: flex;
}

.modal-card {
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    padding: 1.5rem;
    overflow-y: auto;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 48px rgba(0,0,0,0.6);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text);
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.modal-actions-left,
.modal-actions-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* === Modal Form Elements === */
.form-section-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-input {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 0.9375rem;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: border-color 0.1s ease;
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-input:focus {
    outline: none;
    border-color: var(--border-bright);
}

textarea.form-input {
    min-height: 120px;
    line-height: 1.5;
    resize: vertical;
}

.segmented {
    display: flex;
    gap: 0.25rem;
    padding: 0.25rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.segmented label {
    flex: 1;
    display: block;
    margin: 0;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: center;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.1s ease;
}

.segmented input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.segmented input:checked + label {
    color: var(--text);
    background: var(--bg-elevated);
    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.target-panel {
    display: none;
    animation: fadeIn 0.15s ease;
}

.target-panel.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.file-input-wrap {
    position: relative;
}

.file-input-wrap input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.file-input-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1rem;
    font-size: 0.9375rem;
    color: var(--text-muted);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.file-input-display .filename {
    color: var(--text);
}

/* === Sidebar Extras === */
.sidebar-spacer {
    margin-top: 1rem;
    margin-bottom: 0.25rem;
    list-style: none;
}

.sidebar-group-title {
    padding: 0.625rem 0.875rem;
    margin-bottom: 0.25rem;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    list-style: none;
}

.sidebar-sub-item a {
    display: block;
    padding: 0.5rem 0.875rem 0.5rem 1.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all 0.1s ease;
}

.sidebar-sub-item a:hover {
    color: var(--text);
    background: var(--bg-hover);
}


/* === Inbox Filters (Unified) === */
.inbox-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    height: auto;
}

#conversation-list {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow-y: auto;
}

#conversation-list .empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
}

/* Row 4's slide-down field spans the FULL row width (owner spec, both
   viewports). */
.inbox-search {
    padding: 0.5rem 1rem 0.75rem 0.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.inbox-search .form-input { width: 100%; }

.conversation-list-pane {
    width: 450px;
    min-width: 450px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--bg);
    min-height: 0;
    overflow: hidden;
    padding-bottom: 1rem;
}

.thread-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    min-height: 0;
    overflow: hidden;
}

.empty-thread {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Filter bar rows (owner spec — BOTH viewports): row 1 tabs, row 2 pills,
   row 3 campaigns dropdown + right-aligned search icon, row 4 slide-down
   search field. The bar is a column; .filter-tabs is layout-transparent
   so its children join the column flow with explicit order. Scoped to
   .inbox-filters: the devices page reuses .filter-tabs. */
.inbox-filters {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 0.75rem 1rem 0.75rem 0.25rem;
    border-bottom: none;
    gap: 0.75rem;
    flex-shrink: 0;
}

.filter-tabs {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.inbox-filters .filter-tabs { display: contents; }

/* Mobile adds horizontal scrolling (overflow-x: auto) to this wrapper. */
.filter-tabs-scroll {
    order: 1;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    min-width: 0;
}

/* Pills never shrink — the ROW wraps, never the pill internals. */
.filter-actions {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    order: 2;
    flex-wrap: wrap;
}

.filter-actions .toggle-btn {
    flex: 0 0 auto;
    white-space: nowrap;
}

.filter-actions .toggle-btn svg {
    flex: 0 0 auto;
}

/* Row 3: bounded dropdown plus the search icon, right-most. width:100% is
   required — a nested flex container at auto width resolves to max-content
   (616px of long campaign name) and overflows the viewport. */
.filter-tabs .dropdown-wrap {
    order: 3;
    flex: 0 0 auto;
    min-width: 0;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.search-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    margin-left: auto;
    padding: 0.375rem 0.5rem;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border);
    cursor: pointer;
}

.search-toggle:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.search-toggle.active {
    color: var(--text);
    background: var(--bg-active);
    border-color: var(--border-bright);
}

/* Row 4 (both viewports): slide-down search — zero-height until the icon
   toggles it, smooth transition, no layout jump, never persisted. */
.filter-search-row {
    display: block;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.2s ease;
}

.filter-search-row.open {
    max-height: 60px;
}

.filter-tab {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.5rem;
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    color: var(--text-secondary);
    text-decoration: none;
    background: transparent;
    border: 1px solid transparent;
    transition: all 0.1s ease;
}

.filter-tab:hover { color: var(--text); background: var(--bg-hover); }
.filter-tab.active { color: var(--text); background: var(--bg-active); }

.filter-tab svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    stroke-width: 1.5;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.filter-count {
    background: var(--text);
    color: var(--bg);
    font-size: 0.6875rem;
    font-weight: 600;
    padding: 0.125rem 0.375rem;
    border-radius: 999px;
    margin-left: 0.125rem;
}

/* Pill hides itself when the live OOB update empties it (count hits 0) */
.filter-count:empty {
    display: none;
}

.filter-actions {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.toggle-btn {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.5rem;
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border);
    text-decoration: none;
    transition: all 0.1s ease;
}

/* Active strength matches .filter-tab.active (--bg-active): a selected
   toggle must not read weaker than a selected tab. The border stays —
   toggles are outlined pills, tabs are fill-only; that grammar is intact. */
.toggle-btn.active {
    color: var(--text);
    background: var(--bg-active);
    border-color: var(--border-bright);
}

.toggle-btn svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
    stroke-width: 1.5;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.dropdown-wrap { position: relative; flex-shrink: 0; }

.dropdown-trigger {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    width: 180px;
    padding: 0.375rem 0.5rem;
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.1s ease;
}

.dropdown-trigger:hover { color: var(--text); background: var(--bg-hover); }

/* Conversations (owner ruling): the trigger is content-driven between
   180px and min(320px, row width) on desktop — typical campaign names
   show fully, very long names still ellipsize. Scoped to .filter-tabs:
   device-logs keeps the 180px fixed trigger; mobile overrides below. */
.filter-tabs .dropdown-trigger {
    width: auto;
    min-width: 180px;
    max-width: min(320px, 100%);
}

.dropdown-trigger span {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
}

.dropdown-trigger svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
    stroke-width: 1.5;
    fill: none;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 0.25rem);
    right: 0;
    width: 280px;
    max-height: 320px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    display: none;
    z-index: 100;
}

.dropdown-menu.open { display: block; }

/* Conversations row 3: the wrap spans the full row, so the menu anchors
   under the TRIGGER (left), not the row's right edge. */
.filter-tabs .dropdown-menu { left: 0; right: auto; }

.dropdown-search {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.dropdown-search input {
    width: 100%;
    padding: 0.5rem 0.625rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.8125rem;
}

.dropdown-list {
    max-height: 260px;
    overflow-y: auto;
}

.dropdown-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.625rem 0.75rem;
    color: var(--text);
    text-decoration: none;
    font-size: 0.8125rem;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s ease;
}

.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-item.active { background: var(--bg-active); }

.item-date { color: var(--text-muted); font-size: 0.75rem; flex: 0 0 auto; }

/* Long campaign names truncate like campaign rows (.campaign-name pattern):
   bounded, nowrap, ellipsis — the date is never encroached. */
.dropdown-item .item-name {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* === Conversation List — WhatsApp/Telegram style === */
.conv-row {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.75rem 1rem;
    position: relative;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s ease;
    /* Whole-row anchor: row text stays select/copy-able (with draggable=false
       on the tag); click-through and hover grammar unchanged. */
    user-select: text;
}

.conv-row:hover { background: var(--bg-hover); text-decoration: none; }
.conv-row.active {
    background: var(--bg-active);
    text-decoration: none;
}

.conv-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.conv-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.conv-top {
    display: flex;
    justify-content: space-between;
    /* center, not flex-start: the timestamp (smaller font) is vertically
       centered against the name, not top-aligned to it */
    align-items: center;
    gap: 0.5rem;
}

.conv-name {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-time {
    position: relative; /* anchor for the floating pin */
    font-size: 0.75rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* Pin floats directly above the timestamp's right edge, inside the row's
   12px top padding (1px clear of the divider). Absolutely positioned:
   zero layout impact, so pinned and unpinned rows keep the timestamp on
   the name row at the same x. Rendered only when pinned — nothing is
   reserved for unpinned rows. */
.conv-pin-above {
    position: absolute;
    top: -11px;
    right: 0;
    width: 12px;
    height: 12px;
    color: var(--text-muted);
}

.thread-action-btn.pinned {
    color: var(--text);
}

.conv-preview {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    display: flex;
    /* center: the unread badge (taller than the text) is vertically centered
       with the message line */
    align-items: center;
    gap: 0.375rem;
}

/* Ellipsis lives on the text item, not the flex container — overflow on a
   flex parent cannot clip its children correctly */
.conv-preview-text {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Unread badge wrapper: in-flow, pushed to the line's right edge. Empty
   wrapper collapses so no stray gap remains after the thread page's OOB
   swap clears the badge. */
.conv-preview > [id^="unread-"] {
    margin-left: auto;
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.conv-preview > [id^="unread-"]:empty {
    display: none;
}

.conv-unread {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 0.375rem;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--bg);
    background: var(--text);
    border-radius: 999px;
    flex-shrink: 0;
}

/* Invisible infinite-scroll trigger (X-feed pattern — no Load More button).
   Needs a minimum box so IntersectionObserver can reveal it; the spinner
   appears only while the next-page request is in flight. */
.conv-sentinel {
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.conv-sentinel.htmx-request::after {
    content: "";
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--border);
    border-top-color: var(--text-muted);
    animation: conv-spin 0.7s linear infinite;
}

@keyframes conv-spin {
    to { transform: rotate(360deg); }
}

/* === Thread Pane === */
.thread-pane-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.sender-bar {
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

.sender-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.25rem;
}

.sender-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: space-between;
}

.sender-row-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sender-info {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.sender-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
}

.sender-meta {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.sender-via {
    font-size: 0.75rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* Inactive thread status (number on no slot): no-SIM glyph + label, plus
   the optional chain link to the active persona thread. */
.sender-status {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.sender-status svg {
    display: block;
}

.sender-status .thread-link {
    display: flex;
    align-items: center;
    color: var(--text-secondary);
    margin-left: 0.625rem;  /* separate the action from the status label */
}

.sender-status .thread-link:hover {
    color: var(--text);
    text-decoration: none;
}

.thread-header {
    display: flex;
    align-items: flex-start;
    gap: 0.875rem;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

.thread-back-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin: -4px 0 -4px -6px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    flex-shrink: 0;
}

.thread-header-info {
    flex: 1;
    min-width: 0;
}

.thread-header-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.75rem;
}

.thread-target-name {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text);
}

.thread-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.thread-action-btn {
    padding: 0.375rem;
    color: var(--text-secondary);
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.1s ease;
    line-height: 0;
}

.thread-action-btn:hover { color: var(--text); }

.thread-target-meta {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.125rem;
}

.thread-target-phone {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: 0.125rem;
}

.thread-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-height: 0;
}

.msg-bubble {
    max-width: 70%;
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius-md);
    font-size: 0.9375rem;
    line-height: 1.4;
}

.msg-inbound {
    align-self: flex-start;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text);
}

.msg-outbound {
    align-self: flex-end;
    background: var(--text);
    color: var(--bg);
}

.msg-body { word-break: break-word; }

.msg-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0.25rem;
    font-size: 0.75rem;
}

.msg-outbound .msg-meta { color: var(--bg); }
.msg-inbound .msg-meta { color: var(--text-muted); }

.thread-input-bar {
    padding: 0.75rem 1.5rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

.thread-input-form {
    display: flex;
    gap: 0.75rem;
}

.thread-input {
    flex: 1;
    padding: 0.625rem 1rem;
    font-size: 0.9375rem;
    color: var(--text);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.thread-input:focus {
    outline: none;
    border-color: var(--border-bright);
}

/* Disabled composer (inactive thread): must READ disabled, not just be it. */
.thread-input:disabled,
.btn-primary:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.avatar-sm {
    width: 28px;
    height: 28px;
    font-size: 0.75rem;
}

/* === Dashboard Conversations Summary === */
.conv-summary-bar {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1rem;
    padding: 0.75rem 0;
}

.conv-stat {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex: 0 0 auto; /* left-grouped, fixed gaps — never spread across the card */
    font-size: 0.9375rem;
    color: var(--text-secondary);
    text-decoration: none;
}

.conv-stat:hover .conv-stat-value,
.conv-stat:hover .conv-stat-label {
    text-decoration: underline;
}

.conv-stat-icon {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

.conv-stat-icon.ok { color: var(--ok); }
.conv-stat-icon.danger { color: var(--danger); }

.conv-stat-text {
    display: flex;
    align-items: baseline;
    gap: 0.375rem;
}

.conv-stat-value {
    font-size: 0.9375rem; /* PRIMARY tier (decisions 0080) */
    font-weight: 600;
    color: var(--text);
}

.conv-stat-label {
    font-size: 0.8125rem;
}

a.conv-preview-card {
    text-decoration: none;
    color: inherit;
    /* Whole-row anchor: row text stays select/copy-able (with draggable=false
       on the tag); click-through and hover grammar unchanged. */
    user-select: text;
}

/* Row-level hover, same grammar as .conv-row:hover in the Conversations
   list — the whole row paints var(--bg-hover); no name underline. */
a.conv-preview-card:hover {
    background: var(--bg-hover);
    text-decoration: none;
}

.conv-preview-card {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 0;
    border-top: 1px solid var(--border);
    transition: background 0.1s ease;
}

.conv-preview-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.conv-preview-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* Name row: name left, relative timestamp pinned to the right end (same
   anatomy as the inbox list's .conv-top). */
.conv-preview-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.conv-preview-name {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-preview-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-preview-text {
    flex: 1;
    min-width: 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* SECONDARY tier (decisions 0080): the dashboard card's preview text sits at
   0.8125rem like every other preview/stats line. Scoped to the card — the
   shared rule above also reaches the inbox list's .conv-preview-text, which
   keeps its own size (other pages untouched). */
.conv-preview-card .conv-preview-text {
    font-size: 0.8125rem;
}

.conv-preview-time {
    flex-shrink: 0;
    font-size: 0.75rem;
    color: var(--text-muted);
}



/* ═════════════════════════════════════════════════════════════════════════════
   Device Bars — one joined bar per device: device column + 4 slot columns
   separated by hairline dividers, no gaps. Slots render fully online AND
   offline; the status dot is the sole reachability indicator (no dimming).
   ═════════════════════════════════════════════════════════════════════════════ */

.device-bar {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
    /* visible, not hidden: the per-device group menu must escape the bar.
       No child paints a background; the slot state strips round their own
       top corner below. */
    overflow: visible;
}

/* Device column: status dot, alias, model, group + label chips. */
.device-col {
    width: 230px;
    flex-shrink: 0;
    min-width: 0;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.device-col-top {
    display: flex;
    align-items: center;
    gap: 10px;
}

.device-delete { margin-left: auto; }

.device-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* 0151: the dot is the derived display state — Ready (green) / Not Ready
   (amber, reasons on hover) / Offline (grey). */
.device-status-dot.online { background: var(--ok); }
.device-status-dot.not-ready { background: var(--warn); }
.device-status-dot.offline { background: var(--text-muted); }

.device-alias {
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--text);
}

.device-sub {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* Missing-package annotation (agent-reported at identify): one amber line in
   each affected slot column — attention flag, not an error: some fleet phones
   legitimately carry only WA. Nothing renders when installed or never reported. */
.slot-missing {
    font-size: 0.8125rem;
    color: var(--warn);
}

/* Group + label chips: icon-led, gap-spaced, no · separators. */
.device-name {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 2px;
}

.device-name .device-group-trigger,
.device-name .device-label-trigger {
    font-size: 0.8125rem;
    font-weight: 400;
}

.device-group-drop {
    width: 150px;
    flex-shrink: 0;
    min-width: 0;
}

.device-group-drop .device-group-trigger {
    max-width: 100%;
}

.device-group-drop .device-group-trigger span,
.device-label-trigger span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.device-label-trigger {
    max-width: 220px;
    min-width: 0;
}

.btn-outline {
    padding: 6px 14px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.1s;
}

.btn-outline:hover { color: var(--text); border-color: var(--text-muted); }

.btn-danger-outline {
    padding: 6px 14px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--danger);
    background: transparent;
    border: 1px solid rgba(239,68,68,0.3);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.1s;
}

.btn-danger-outline:hover { background: rgba(239,68,68,0.1); }

/* ── Slot columns ── */

.slot-col {
    flex: 1;
    min-width: 0;
    border-left: 1px solid var(--border);
    padding: 12px 14px 10px;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Single top-edge state strip: green Idle / blue Engaging / none Empty.
   State color lives ONLY here — never a pill, never red. */
.slot-col::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 0;
    right: 0;
    height: 4px;
}

.slot-col.idle::before { background: var(--ok); }
.slot-col.engaging::before { background: var(--info); }
.slot-col:last-child::before { border-top-right-radius: var(--radius-lg); }

/* Head row: "WA 1 · <number>" with the lock toggle next to the number. */
.slot-col-head {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
}

.slot-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    flex-shrink: 0;
}

.slot-sep {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.slot-number {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

/* Lock toggle: open padlock muted outline (unlocked), closed padlock filled
   danger red (locked — a slot wearing a locked number cannot send). */
.lock-toggle {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    color: var(--text-muted);
}

.lock-toggle.locked { color: var(--danger); }

/* Send hold overlay on the slot column: an amber dashed frame inside the
   column edges — coexists with the state strip (::before) and the lock
   affordances; never replaces them. */
.slot-col.sendheld {
    outline: 1px dashed var(--warn);
    outline-offset: -1px;
}

.slot-id {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.slot-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.slot-avatar.empty {
    background: rgba(255,255,255,0.04);
    color: var(--text-muted);
}

.slot-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.slot-name {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text);
}

.slot-name.empty { color: var(--text-secondary); }

.slot-details {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.slot-details.empty { color: var(--text-muted); }

/* Locked-number note: muted text, no glyph. */
.slot-note {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
    min-width: 0;
}

.slot-note-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-btn {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
}

.icon-btn:hover { color: var(--text); background: var(--bg-hover); }

/* Pencil + refresh pinned to the column's bottom edge so all four columns
   align; rendered only when the device is online (phone-dependent). */
.slot-actions {
    margin-top: auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

.slot-actions button {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s;
}

.slot-actions button:hover {
    background: var(--bg-hover);
}

.slot-actions button svg {
    stroke: var(--text);
    width: 14px;
    height: 14px;
}

.slot-actions button:hover svg {
    stroke: var(--text-secondary);
}

.slot-scrape-form {
    display: inline-flex;
    margin: 0;
    padding: 0;
}

/* The app icon (owner ruling 2026-09-24 — the glyph ACCOMPANIES the
   registry label text wherever a human reads the app's identity): the
   registry glyph at 1em, middle-aligned with the text line, currentColor
   (the registry
   SVGs fill currentColor, so themes and text states inherit); tooltip/aria
   name the app. */
.app-icon { display: inline-flex; vertical-align: middle; }
.app-icon svg { width: 1em; height: 1em; display: block; }

/* ═══════════════════════════════════════════════════════════════════════════
   Responsive — Mobile (max-width: 768px)
   Everything in this block is mobile-only. No desktop rule above is
   overridden outside this media query, so desktop rendering is unchanged.
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

    /* --- App frame: single column; the page scrolls, not .main ---
       minmax(0, 1fr): a plain 1fr track has an 'auto' minimum, so long
       unbreakable content would force the track (and the whole page)
       wider than the viewport. The 0 minimum lets the track shrink. --- */
    .app-layout {
        grid-template-columns: minmax(0, 1fr);
        height: auto;
        overflow: visible;
    }

    .main {
        min-width: 0;
        min-height: 100vh;
        min-height: 100dvh;
        padding: 0 1rem 1.5rem;
        overflow-y: visible;
    }

    .main:has(> .inbox-layout) {
        height: auto;
        overflow: visible;
        padding-bottom: 0;
    }

    /* --- Off-canvas sidebar with backdrop --- */
    .sidebar {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: min(280px, 85vw);
        height: 100vh;
        height: 100dvh;
        z-index: 200;
        box-shadow: 4px 0 24px rgba(0,0,0,0.6);
        /* Clear the fixed nav toggle (52px tall) so the brand never
           slides underneath it while the drawer is open */
        padding-top: 60px;
    }

    .sidebar.open {
        display: flex;
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 150;
        background: rgba(0,0,0,0.6);
    }

    .sidebar-backdrop.open {
        display: block;
    }

    .nav-toggle {
        display: flex;
    }

    /* Toggle sits above the open drawer: make it opaque so the brand
       doesn't bleed through */
    body.sidebar-open .nav-toggle {
        background: var(--bg);
    }

    /* --- Page header: hamburger + title + actions on one sticky row --- */
    .page-header {
        position: sticky;
        top: 0;
        z-index: 100;
        flex-wrap: wrap;
        gap: 0.5rem;
        min-height: 52px;
        margin: 0 -1rem 1rem;
        padding: 0.375rem 1rem 0.375rem 48px; /* 48px reserved for the nav toggle */
        background: var(--bg);
    }

    .page-header h2 {
        font-size: 1.25rem;
        line-height: 1.3;
    }

    .page-header-actions {
        gap: 0.5rem;
    }

    .page-header-actions .btn-pill,
    .page-header-actions .btn-secondary,
    .page-header-actions .btn-danger,
    .page-header > .btn-secondary,
    .page-header > .btn-danger {
        padding: 0.4rem 0.75rem;
        font-size: 0.8125rem;
        white-space: nowrap;
    }

    /* Overflow menu replaces the pills on mobile — they can't fit.
       The Groups dropdown hides too; its items live in the ⋮ menu. */
    .page-header-actions > .btn-pill,
    .page-header-actions > .groups-dropdown {
        display: none;
    }

    .actions-menu {
        display: block;
    }

    /* --- Inputs at 16px: prevents iOS Safari auto-zoom on focus --- */
    input,
    textarea,
    select,
    .form-input,
    .thread-input {
        font-size: 16px;
    }

    /* --- Cards breathe less on small screens --- */
    .card,
    .card-outline,
    .stat-card {
        padding: 1rem;
    }

    /* --- Dashboard board: single column, ordered Attention → Conversations
           → Campaigns → Devices (DOM unchanged — CSS order only) --- */
    .dash-board {
        display: flex;
        flex-direction: column;
        gap: var(--gap);
    }

    .dash-board section {
        margin-bottom: 0;
    }

    .board-attention     { order: 1; }
    .board-conversations { order: 2; }
    .board-campaigns     { order: 3; }
    .board-devices       { order: 4; }

    /* --- Dashboard header-counts lines: on mobile the bar stacks vertically,
           one stat per line, icon + value + label anatomy unchanged at BASE
           sizes (the single no-wrap row overflowed phone widths) --- */
    .conv-summary-bar {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.5rem 0;
    }

    /* --- Campaign cards: meta rows wrap instead of overflow --- */
    .campaign-progress-meta,
    .campaign-stats {
        flex-wrap: wrap;
        gap: 0.25rem 0.75rem;
    }

    /* --- Message Monitor: pure restack, nothing truncated ---
       Line 1: icon | sender name + company · country
       Line 2: (indented) arrow | target name + company · country
       Line 3: message body, full width, wraps freely
       Line 4: device · slot (left) | time (right)              */
    .monitor-row {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-start;
        gap: 2px 8px;
    }

    .monitor-icon         { order: 1; flex: 0 0 20px; margin-top: 2px; }
    .monitor-sender-block { order: 2; flex: 1 1 0; min-width: 0; overflow: visible; }
    .monitor-arrow        { order: 3; margin: 2px 0 0 28px; }
    .monitor-target-block { order: 4; flex: 1 1 0; min-width: 0; overflow: visible; }

    .monitor-name,
    .monitor-name-meta {
        white-space: normal;
        overflow: visible;
    }

    .monitor-body-text {
        order: 5;
        flex: 1 0 100%;
        padding: 2px 0 0 28px;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .monitor-time-block {
        order: 6;
        flex: 1 0 calc(100% - 28px);
        margin-left: 28px;
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        text-align: left;
    }

    .monitor-device { order: 1; }
    .monitor-time   { order: 2; }

    /* --- Inbox: stacked panes, full-width list --- */
    .inbox-layout {
        flex-direction: column;
        height: auto;
    }

    .conversation-list-pane {
        width: 100%;
        min-width: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding-bottom: 0;
        overflow: visible;
    }

    #conversation-list {
        flex: none;
        overflow-y: visible;
    }

    /* --- Inbox filters: same 4-row structure as desktop; mobile adds only
           horizontal tab scroll (the dropdown stays a SIBLING of the scroll
           region, so the open menu is never clipped) and tighter padding. --- */
    .inbox-filters {
        gap: 0.5rem;
        padding: 0.5rem 0.75rem;
    }

    /* The slide-down field spans the row; its edges line up with the
       filter bar's padding. */
    .inbox-search {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .filter-tabs-scroll {
        overflow-x: auto;
        scrollbar-width: none;
    }

    /* The trigger fills row 3 up to the search icon; min-width:0 +
       max-width:100% + overflow:hidden bound the ellipsis chain (never
       width:100% of the 0%-basis wrap, which resolves to max-content).
       Scoped to match the base .filter-tabs rule's specificity. */
    .filter-tabs .dropdown-trigger {
        flex: 1 1 auto;
        min-width: 0;
        width: auto;
        max-width: 100%;
        overflow: hidden;
    }

    .dropdown-menu {
        /* 100svw, never raw vw: the small-viewport unit can never overflow
           under mobile browser chrome; identical to vw on desktop. */
        width: min(280px, calc(100svw - 2rem));
    }

    /* --- Thread: full-screen app view once a conversation loads (:has).
           The global top bar and hamburger hide — navigation out is the
           thread header's own back arrow (mobile-only .thread-back-btn),
           WhatsApp/Telegram style. Empty pane stays in flow under the
           list. Back button restores it. --- */
    .thread-pane {
        width: 100%;
        overflow: visible;
    }

    body:has(.thread-pane-inner) .page-header,
    body:has(.thread-pane-inner) .nav-toggle {
        display: none;
    }

    .thread-pane:has(.thread-pane-inner) {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 250;
        background: var(--bg);
        /* Nothing may escape the viewport: unbroken strings and wide rows
           otherwise push past the right edge and eat the gutter */
        overflow: hidden;
    }

    .thread-pane:has(.thread-pane-inner) .thread-pane-inner {
        height: 100%;
    }

    .thread-pane:has(.thread-pane-inner) .thread-messages {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }

    .msg-bubble {
        overflow-wrap: anywhere;
    }

    .thread-back-btn {
        display: inline-flex;
    }

    .thread-pane-inner {
        overflow: visible;
    }

    .sender-bar {
        padding: 0.625rem 1rem;
    }

    .thread-header {
        align-items: center;
        gap: 4px;
        padding: 0.5rem 0.75rem;
    }

    .thread-messages {
        padding: 1rem;
    }

    .msg-bubble {
        max-width: 85%;
    }

    .thread-input-bar {
        position: sticky;
        bottom: 0;
        z-index: 50;
        padding: 0.625rem 1rem calc(0.625rem + env(safe-area-inset-bottom, 0px));
    }

    .thread-input-form {
        align-items: center;
    }

    /* --- Device bars stack: device column on top, slot columns below ---
       The top-edge strip turns into a left state bar (the old slot-row
       grammar) so state stays visible in the stacked layout. */
    .device-bar {
        flex-direction: column;
    }

    .device-col {
        width: auto;
        border-bottom: 1px solid var(--border);
    }

    .slot-col {
        border-left: none;
        border-top: 1px solid var(--border);
    }

    .slot-col::before {
        top: 0;
        bottom: 0;
        left: 0;
        right: auto;
        width: 4px;
        height: auto;
    }

    .slot-col:last-child::before { border-top-right-radius: 0; }

    .slot-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.75rem;
    }

    /* --- Tables: scroll inside the wrap, cells keep their width --- */
    .table-wrap th,
    .table-wrap td {
        padding: 0.625rem 0.875rem;
        white-space: nowrap;
    }

    /* Raw tables outside .table-wrap (e.g. campaign preview slot test) */
    .table-scroll {
        overflow-x: auto;
    }

    .slot-test-table {
        min-width: 17.5rem;
    }

    /* --- Modal: centered, viewport-constrained, no horizontal overflow --- */
    .modal-backdrop {
        align-items: center;
        justify-content: center;
        padding: 1rem;
    }

    .modal-card {
        width: 100%;
        max-width: 100%;
        max-height: calc(100dvh - 2rem);
        padding: 1.25rem;
        overflow-x: hidden;
    }

    .modal-header {
        margin-bottom: 1rem;
    }

    .modal-actions {
        flex-wrap: wrap;
        row-gap: 0.5rem;
    }
}

/* === Devices page: filters, result bar, inline group assign, pager ===
   New components — shared by desktop and mobile. Status tabs reuse the
   conversations .filter-tabs/.filter-tab styles. */
.devices-filters {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    margin-bottom: 1rem;
}

.devices-filter-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.devices-filter-selects {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* The Number locked checkbox: a standalone filter dimension (intersects with
   the state dropdown), plain label — never a pill. The global `input` rule
   (width/padding/background) unpaints native checkboxes in WebKit/Firefox, so
   the control paints itself engine-independently: appearance:none + a 16px
   box, 1px --text border; :checked = filled accent + check mark. */
.filter-check {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
}

.filter-check input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    padding: 0;
    margin: 0;
    flex-shrink: 0;
    background: transparent;
    border: 1px solid var(--border); /* the filter row's own token (filter-select) */
    border-radius: 3px;
    cursor: pointer;
}

.filter-check input[type="checkbox"]:checked {
    background: var(--info) url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E") center / 11px no-repeat;
    border-color: var(--info);
}

.filter-select {
    padding: 0.375rem 0.5rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.showing-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.filter-search {
    width: 220px;
    max-width: 100%;
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.filter-search::placeholder {
    color: var(--text-muted);
}

/* Inline group assignment: a <select> dressed as meta text, not a button */
.device-group-form {
    /* hidden select's form: inline-level would add a phantom text line
       (~20px) under the group row — display:none still allows requestSubmit() */
    display: none;
}

/* Same phantom-item guard for the hidden label-post form (now lives in the
   line-1 flex/grid row, where an empty inline form would eat a gap slot) */
.device-label-form { display: none; }

.device-group-select {
    appearance: none;
    -webkit-appearance: none;
    padding: 0 14px 0 0;
    font-size: inherit;
    color: inherit;
    background: transparent url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 24 24' fill='none' stroke='%238f8f8f' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right center;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.device-group-select:hover {
    color: var(--text);
}

.device-group-select:focus-visible {
    outline: 1px solid var(--border-bright);
    outline-offset: 2px;
}

.device-group-select option {
    color: var(--text);
    background: var(--bg-elevated);
}

/* Photo avatars (slot rows, thread sender bar) — fall back to initials */
/* Avatars: initial letter always rendered underneath; the photo is an
   absolute overlay, so a broken/dead URL degrades to the initial cleanly
   (img carries onerror="this.remove()"). */
.avatar,
.slot-avatar {
    position: relative;
}

.avatar-img,
.slot-avatar img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

/* Pagination */
.pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1rem 0 0.25rem;
    font-size: 0.8125rem;
}

.pager-btn {
    padding: 0.25rem 0.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
}

.pager-btn:hover {
    color: var(--text);
    background: var(--bg-hover);
    text-decoration: none;
}

.pager-btn.disabled {
    color: var(--text-muted);
    opacity: 0.6;
    pointer-events: none;
}

.pager-info {
    color: var(--text-muted);
}

/* Set Profile modal + Manage Groups modal bits */
.modal-sub {
    margin: 0;
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.photo-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Set Profile modal two-column surface (2026-09-19 modal package): photo +
   preview widget beside the fields, wrapping to one stacked column when
   narrow — ONE rule, no media query, desktop and mobile. */
.profile-cols {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(13rem, 100%), 1fr));
    gap: 1rem;
    align-items: start;
}

.upload-btn {
    position: relative;
    overflow: hidden;
}

.upload-btn input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.manage-group-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.manage-group-rename {
    flex: 1;
    display: flex;
    gap: 0.5rem;
}

.manage-group-row .form-input {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
}

/* DNU manager modal: divider + fleet-wide list under the add form */
.dnu-modal-divider {
    border-top: 1px solid var(--border);
    margin: 1rem 0;
}

/* Campaign preview: summary divider + cancel link spacing */
.preview-divider {
    border-color: var(--border);
    margin: 1rem 0;
}

.preview-cancel {
    margin-top: 1rem;
}

/* Campaign preview truth: per-phone slot groups, per-row state, the
   exclusion summary line */
.preview-table {
    width: 100%;
}

.preview-row {
    display: grid;
    grid-template-columns: 2rem 10rem 1fr auto;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.5rem;
    font-size: 0.9375rem;
}

.preview-phone-header {
    padding: 0.625rem 0.5rem 0.25rem;
    font-size: 0.8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.preview-tick input {
    margin: 0;
    accent-color: var(--text);
}

.preview-state {
    color: var(--text-muted);
    white-space: nowrap;
}

.preview-state-ok {
    color: var(--ok);
}

.preview-exclusions-details {
    margin-top: 0.75rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.preview-exclusions-details summary {
    cursor: pointer;
}

.preview-exclusion-list {
    margin: 0.5rem 0 0;
    padding-left: 1.25rem;
}

.preview-exclusion-list li {
    padding: 0.125rem 0;
}

.preview-exclusion-slot {
    color: var(--text);
}

.preview-exclusion-reason {
    color: var(--text-muted);
}

.dnu-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.375rem 0;
}

.dnu-row-meta {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.dnu-list-footer {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
}

@media (max-width: 768px) {
    /* Campaign preview truth: narrower grid so the verdict stays on-screen */
    .preview-row {
        grid-template-columns: 1.5rem 5.5rem 1fr auto;
        gap: 0.375rem;
        font-size: 0.8125rem;
    }

    /* Devices filter bar: tighter on phones */
    .devices-filters {
        gap: 0.5rem;
        margin-bottom: 0.75rem;
    }

    .filter-search {
        width: auto;
        flex: 1 1 140px;
        min-width: 0;
        font-family: inherit; /* inputs don't inherit the app font by default */
        font-size: 16px; /* prevents iOS Safari auto-zoom on focus */
    }

    .filter-select {
        font-size: 0.75rem;
    }
}

/* Profile modal polish */
.avatar-lg {
    width: 56px;
    height: 56px;
    font-size: 1.375rem;
    flex-shrink: 0;
}

.upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
}

.form-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: -0.25rem 0 0.5rem;
}

.modal-body .form-section-label {
    margin-top: 0.75rem;
}

.modal-body .form-section-label:first-of-type {
    margin-top: 0;
}

/* === Dashboard — 2×2 board (min-width: 769px) ===
   Row 1: Attention | Devices; row 2: Conversations | Campaigns. Columns
   5fr/7fr. Devices and Campaigns are pinned to column 2. Empty-Attention
   state: row 1 collapses to Devices full board width, row 2 keeps the
   5fr/7fr split (dense auto-flow). Each row's pair stretches to a shared
   bottom edge (grid default). The page scrolls naturally — there is no
   viewport lock. */
@media (min-width: 769px) {
    .dash-board {
        display: grid;
        /* minmax(0, …) overrides grid items' min-width:auto, otherwise a
           card's min-content inflates its track */
        grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
        grid-auto-flow: dense;
        gap: var(--gap);
        align-items: stretch;
    }

    .dash-board section {
        margin-bottom: 0; /* the grid gap owns the spacing */
    }

    .board-devices,
    .board-campaigns {
        grid-column: 2;
    }

    /* Empty-Attention state: row 1 collapses to Devices full board width;
       row 2 stays Conversations | Campaigns at the 5fr/7fr split. */
    .board-attention:not(:has(section)) + .board-devices {
        grid-column: 1 / -1;
    }

    /* Stretch is per PAIR: the wrapper (grid item) flexes so the card inside
       shares the row's bottom edge with its neighbour. */
    .board-attention,
    .board-devices {
        display: flex;
        flex-direction: column;
        min-width: 0;
    }

    .board-attention > section,
    .board-devices > section {
        flex: 1;
    }
}

/* Attention / Devices wrappers poll every 5s; when the fragment renders no
   card (no items / no devices) the wrapper collapses — no empty shell, no
   phantom gap. Whitespace-only fragments still match: :has() counts elements,
   not text. */
.board-attention:not(:has(section)),
.board-devices:not(:has(section)) {
    display: none;
}

/* === Dashboard — Attention card ===
   Neutral card (same chrome as every other card — no warn tint on the chrome).
   One line per flag: device lines (never/stale) carry the phone glyph, stalled
   campaigns the running-clock glyph — icons amber (--warn) = attention flags
   (rule 12); alias/name semibold, truncates with ellipsis (long lines never
   orphan-wrap), then `· copy` (muted, nowrap). */
.attention-line {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    min-width: 0;
    padding: 0.5rem 0;
    font-size: 0.9375rem;
}

.attention-line svg {
    flex-shrink: 0;
    color: var(--warn);
}

.attention-alias {
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.attention-copy {
    flex-shrink: 0;
    font-size: 0.8125rem; /* SECONDARY tier (decisions 0080) — state annotation, like preview/stats text */
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Overflow footer: the card caps at ATTENTION_CAP lines; this links to the
   Devices page with the hidden count. Actions are grey (grammar rule 9). */
.attention-overflow {
    display: block;
    padding: 0.5rem 0 0.25rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    text-decoration: none;
}

.attention-overflow:hover {
    color: var(--text);
}

/* === Dashboard — Devices heatmap grid ===
   One 30px square per phone holding a 2×2 of slot squares (canonical
   partition: idle --ok / engaging --info / empty outlined; Number Lock is a
   --danger dot overlay, never a partition member). Online phone = solid
   green ring; offline = dashed grey ring + dimmed slots. */
.hm-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.hm-cell {
    width: 30px;
    height: 30px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    /* rows must be fr too: with auto rows the lock dot of a slot wearing a
       locked number counts as row content, that row stretches 10 → 12 and
       the squares turn rectangular */
    grid-template-rows: 1fr 1fr;
    gap: 2px;
    /* 30 − 2×1 border − 2×3 padding − 2 gap = 20 → two true 10px squares;
       even size puts the square's center on a pixel boundary so the 4px
       lock dot + 1px halo center exactly (padding 4 made 9px squares and
       the dot snapped off-centre) */
    padding: 3px;
    border: 1px solid var(--ok);
    border-radius: 4px;
}

.hm-cell.off {
    border-style: dashed;
    border-color: var(--text-muted); /* must read as dashed at 30px */
}

/* 0151: Not Ready — online but health-gate-unhealthy; amber border, solid. */
.hm-cell.nr {
    border-color: var(--warn);
}

.hm-cell.off .hm-slot {
    opacity: 0.45;
}

.hm-slot {
    border-radius: 1px;
}

.hm-slot.idle      { background: var(--ok); }
.hm-slot.engaging  { background: var(--info); }
/* Empty reads as an empty SQUARE in both themes — a flat fill sits too close
   to the card background */
.hm-slot.empty     { box-shadow: inset 0 0 0 1px var(--border-bright); }

/* Number Lock = a danger-red dot centered on the activity square — a hat,
   never a state. Never on .empty (no number, nothing to lock).
   Centering is grid place-items, not 50%+translate — exact at any square size. */
.hm-slot.locked:not(.empty) {
    display: grid;
    place-items: center;
}

/* The locked KEY swatch stays inline-block like its plain siblings —
   identical baseline, so top edges and the tuned vertical-align: -1px match
   exactly. inline-grid would change the swatch's baseline and drop it off
   the label's optical middle. The dot centers absolutely instead. */
.hm-key.locked {
    position: relative;
}

.hm-key.locked::after {
    position: absolute;
    inset: 0;
    margin: auto;
}

.hm-slot.locked:not(.empty)::after,
.hm-key.locked::after {
    content: "";
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--danger);
    /* halo: #111 in both themes — the ring, not the red, separates the dot
       from every state fill (decisions 0038; theme split superseded, 0042). */
    box-shadow: 0 0 0 1px #111;
}

/* Send hold = an amber DASHED outline on the activity square — a second
   overlay beside Number Lock's dot, never a state. Never on .empty (no
   number, nothing to hold). Both overlays render together when a number is
   locked AND held. */
.hm-slot.sendheld:not(.empty) {
    outline: 1px dashed var(--warn);
}

.hm-key.sendheld {
    border: 1px dashed var(--warn);
}

/* Warmup = a charging glyph (⚡) on the activity square — the third
   number-following overlay beside the lock dot and the hold outline, never
   a state. Never on .empty (no number, nothing to warm). Bottom-anchored
   via ::before so it composes with the lock's centered ::after dot — all
   three overlays render together on a locked AND held AND warming number. */
.hm-slot.warming:not(.empty) {
    display: grid;
    place-items: end center;
}

.hm-key.warming {
    position: relative;
}

.hm-key.warming::before {
    position: absolute;
    inset: 0;
    margin: auto;
    width: fit-content;
    height: fit-content;
}

.hm-slot.warming:not(.empty)::before,
.hm-key.warming::before {
    content: "⚡";
    font-size: 8px;
    line-height: 1;
    color: var(--warn);
    /* halo: #111 in both themes — the ring separates the glyph from every
       state fill (the lock dot's discipline). */
    text-shadow: 0 0 1px #111, 0 0 2px #111;
}

.hm-viewall {
    margin-top: 0.5rem;
    text-align: right;
    font-size: 0.8125rem;
}

.hm-legend {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.25rem 0;
    margin-top: 0.75rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

/* Three clearly separated groups — Devices | Slots | Number locked — with a
   vertical divider between them; mobile stacks them (see the ≤768px block).
   Gaps are tight so the three groups hold one row at desktop widths. */
.hm-legend-group + .hm-legend-group {
    border-left: 1px solid var(--border);
    padding-left: 0.625rem;
    margin-left: 0.625rem;
}

/* Legend items separated by a fixed gap, not " · " — phrase-joining dots
   stay only in the summary line. */
.hm-item + .hm-item {
    margin-left: 0.75rem;
}

.hm-key {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    vertical-align: -1px;
}

.hm-key.dev-ready     { border: 1px solid var(--ok); }
.hm-key.dev-not-ready { border: 1px solid var(--warn); }
.hm-key.dev-offline { border: 1px dashed var(--text-muted); }
.hm-key.idle        { background: var(--ok); }
.hm-key.engaging    { background: var(--info); }
.hm-key.empty       { box-shadow: inset 0 0 0 1px var(--border-bright); }

.hm-n {
    font-weight: 600;
    color: var(--text);
}

.hm-summary {
    margin-top: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 400;
    color: var(--text-muted);
}

@media (max-width: 768px) {
    /* Legend groups stack — Number locked on its own line, dividers off. */
    .hm-legend {
        flex-direction: column;
        align-items: flex-start;
    }
    .hm-legend-group + .hm-legend-group {
        border-left: none;
        padding-left: 0;
        margin-left: 0;
    }
}

/* === Dashboard — Campaigns card rows: ONE shared grid, true columns ===
   Scoped to the dashboard card — the campaigns LIST page shares the
   campaign-* classes and keeps its own layout. Rows use the conversations
   hairline anatomy (border-TOP per row) so the metrics line gets the same
   separator under it that the Conversations counts line has.

   The polled container owns the tracks: [lead minmax(0,1fr)] then one
   content-sized auto track per stat (Sent | Replies · % | Failed) plus the
   timestamp. Every row is a column-subgrid on those tracks, so a column is
   as wide as the widest row's content and the stats align down the card at
   ANY number magnitude — no fixed fractions, no hardcoded content widths.
   Failed is the LAST stat track: rows without failures render no span and
   their other stats stay in the shared columns (never shifted). */
.board-campaigns-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) repeat(3, auto) auto;
    column-gap: 1rem;
}

/* The header metrics line and the empty state are not rows — they span
   the full track set. */
.board-campaigns-grid > .conv-summary-bar,
.board-campaigns-grid > .empty-state {
    grid-column: 1 / -1;
}

.board-campaigns .campaign-card {
    border-bottom: none;
    border-top: 1px solid var(--border);
}

/* Rows are whole-row links to the campaign detail page — hover grammar
   identical to the conversation rows (whole-row --bg-hover, no underline);
   row text stays select/copy-able (draggable=false on the tag). The row is
   a subgrid on the container's tracks; every cell centers vertically, and
   on running rows lead/timestamp span the bar + stats lines. */
a.campaign-card-link {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: subgrid;
    align-items: center;
    row-gap: 4px;
    text-decoration: none;
    color: inherit;
    user-select: text;
    transition: background 0.1s ease;
}

a.campaign-card-link:hover {
    background: var(--bg-hover);
    text-decoration: none;
}

.board-campaigns .campaign-lead {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.board-campaigns .campaign-lead .campaign-icon {
    margin-top: 0;
}

.board-campaigns .campaign-name {
    font-size: 0.9375rem; /* PRIMARY tier, explicit (decisions 0080) — was inherited */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Running rows: the neutral bar spans the three stat tracks on line 1,
   the stats line sits beneath it in the SAME tracks. */
.board-campaigns .campaign-bar {
    grid-column: 2 / 5;
    width: 100%;
    height: 4px;
    appearance: none;
    background: var(--border);
    border: none;
    border-radius: 999px;
}

.board-campaigns .campaign-bar::-webkit-progress-bar {
    background: var(--border);
    border-radius: 999px;
}

.board-campaigns .campaign-bar::-webkit-progress-value {
    background: var(--info);
    border-radius: 999px;
}

.board-campaigns .campaign-card-running .campaign-lead,
.board-campaigns .campaign-card-running .campaign-time {
    grid-row: 1 / span 2;
}

/* Desktop: the stats wrapper generates no box — each stat is a no-wrap
   grid item pinned to its shared track. Tabular figures keep the digits
   uniform where the system font stack supports them. (Mobile gives the
   wrapper its own equal-thirds grid — see the media query below.) */
.board-campaigns .campaign-stats {
    display: contents;
}

.board-campaigns .campaign-stats > span {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.board-campaigns .stat-sent    { grid-column: 2; }
.board-campaigns .stat-replies { grid-column: 3; }
.board-campaigns .stat-failed  { grid-column: 4; }

.board-campaigns .campaign-time {
    grid-column: 5;
    grid-row: 1;
    font-size: 0.75rem; /* META tier (decisions 0080) — timestamps are 12px everywhere */
    color: var(--text-secondary);
    white-space: nowrap;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Mobile (≤768px): the owner-ruled two-row anatomy, STRUCTURAL alignment —
   no hardcoded px offsets. Row 1: the lead generates no box, so the icon,
   the name and the timestamp are three card-grid tracks — [icon auto]
   [name minmax(0,1fr), truncates] [timestamp auto, content-sized, NEVER
   truncates]; the name takes whatever remains. Row 2 (running rows: the
   bar full width on row 2, stats on row 3): the stats wrapper spans
   grid-column 2 / -1 — starting exactly under the name's first pixel BY
   CONSTRUCTION (same track, immune to icon/gap changes) — as an
   equal-thirds grid with the stats anchored Sent flush LEFT / Replies · %
   CENTERED / Failed flush RIGHT (under the timestamp's right edge); the
   anchor x-positions are fixed, so the stat columns align down the card
   across ALL rows and Failed's empty third never shifts anything. No-wrap
   tabular-nums stats, no-wrap timestamp — measured worst case (13px stats,
   DejaVu: Sent 91.6px, Replies 103.4px, Failed 69.0px, span 317px @343px
   content) clears with ≥15px; no overlap/overflow at 343px/360px.
   Desktop is untouched. */
@media (max-width: 768px) {
    .board-campaigns-grid {
        display: block;
    }

    .board-campaigns a.campaign-card-link {
        grid-template-columns: auto minmax(0, 1fr) auto;
        column-gap: 10px;
        row-gap: 8px;
    }

    .board-campaigns .campaign-lead {
        display: contents;
    }

    .board-campaigns .campaign-lead .campaign-icon {
        grid-column: 1;
        grid-row: 1;
    }

    .board-campaigns .campaign-name {
        grid-column: 2;
        grid-row: 1;
    }

    .board-campaigns .campaign-time {
        grid-column: 3;
        grid-row: 1;
    }

    .board-campaigns .campaign-bar {
        grid-column: 1 / -1;
        grid-row: 2;
    }

    .board-campaigns .campaign-stats {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        column-gap: 0.5rem;
        grid-column: 2 / -1;
        grid-row: 2;
        margin-top: 0;
    }

    .board-campaigns .campaign-card-running .campaign-stats {
        grid-row: 3;
    }

    .board-campaigns .campaign-stats > span {
        min-width: 0;
    }

    .board-campaigns .stat-sent    { grid-column: 1; justify-self: start; }
    .board-campaigns .stat-replies { grid-column: 2; justify-self: center; }
    .board-campaigns .stat-failed  { grid-column: 3; justify-self: end; }

    .board-campaigns .campaign-card-running .campaign-lead,
    .board-campaigns .campaign-card-running .campaign-time {
        grid-row: 1;
    }
}

/* === Devices — viewport-locked shell (desktop, tall-enough windows) ===
   Same anatomy as the dashboard: page header, fleet bar, filters and the
   pager are fixed chrome; only the phone grid scrolls. The lock releases
   on short windows (< 500px height) so nothing ever becomes unreachable. */
@media (min-width: 769px) and (min-height: 500px) {
    body.page-devices {
        overflow: hidden;
    }

    body.page-devices .main {
        height: 100dvh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    body.page-devices .main > * {
        flex-shrink: 0;
    }

    body.page-devices .main > section {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        margin-bottom: 0;
    }

    body.page-devices #device-grid {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        scrollbar-width: thin;
        scrollbar-color: var(--border) transparent;
    }
}

/* === Campaigns list (#9): dashboard row grammar — icons only, divider
   rows, no card backgrounds. Fixed stat grids keep numbers vertically
   aligned across rows; the Replies stat IS the inbox link. === */
.camp-toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}
.camp-tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.camp-tab {
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    text-decoration: none;
}
.camp-tab:hover { color: var(--text); background: var(--bg-hover); }
.camp-tab.on { background: var(--bg-active); color: var(--text); }
.camp-search { margin-left: auto; }

.camp-list { border-top: 1px solid var(--border); }
.camp-list .campaign-card { padding: 14px 4px; }
.camp-row { cursor: pointer; }
.camp-row:hover { background: var(--bg-hover); }

/* Finished rows: fixed 4-column stat grid */
.camp-list .campaign-stats {
    display: grid;
    grid-template-columns: 110px 110px 130px 130px;
    gap: 0;
}

/* Running rows: bar + solid red Stop pill inline at the bar's right end */
.camp-list .campaign-progress {
    display: flex;
    align-items: center;
    gap: 10px;
}
.camp-list .campaign-progress progress {
    flex: 1 1 auto;
    width: auto;
    min-width: 120px;
    margin: 0;
}
.camp-stop2 {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #dc2626;
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 5px 13px;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    flex-shrink: 0;
}
.camp-stop2:hover { filter: brightness(1.1); }

/* Running rows: fixed-grid live stats, label-over-value cells.
   Columns 1–3 match the finished-row grid (110/110/130) so Sent, the
   middle column, and Replies align vertically across all rows. */
.camp-runstats {
    display: grid;
    grid-template-columns: 110px 110px 130px 210px 1fr;
    gap: 0;
    margin-top: 8px;
    font-size: 0.8125rem;
    color: var(--text-muted);
}
.camp-runstat {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}
.camp-runstat-label {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.camp-runstat-value {
    color: var(--text);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.camp-replies { color: inherit; text-decoration: none; }
.camp-replies:hover { text-decoration: underline; }

/* Mobile-only white + for New Campaign (desktop pill hides on mobile) */
.camp-add-mobile { display: none; }

@media (max-width: 768px) {
    .camp-add-mobile { display: inline-flex; }
    .camp-search { margin-left: 0; width: 100%; }
    .camp-search .filter-search { width: 100%; }
    .camp-list .campaign-stats { grid-template-columns: 1fr 1fr; row-gap: 6px; }
    .camp-runstats { grid-template-columns: 1fr 1fr; row-gap: 6px; }
}

/* === Campaign run page (/campaigns/{cid}) — scoped .run-* classes.
   The stat strip IS the page header: first cell carries the campaign
   identity (icon + name, status · Started on line 2) and the Stop action.
   Other cells: label-over-value, divider-separated, padding-driven heights.
   Activity: divider row-list, state via border-left (no pills). === */
.run-kpis {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-elevated);
    padding: 0.5rem 0;
}
/* The 1.5rem spacer lives on the strip wrapper: strip → filters when no
   error card, error card → filters when there is one (card sits 12px under
   the strip). */
#run-strip { margin-bottom: 1.5rem; }
#run-strip .run-errors { margin-top: 12px; margin-bottom: 0; }
.run-kpi {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* top-aligned: label and value baselines
                                    lock across cells of unequal height */
    gap: 2px;
    padding: 0.375rem 1rem;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}
/* Title takes the remaining strip width; the SENT cell keeps the bar
   meaningful at 200px; every other stat sizes to its content. */
.run-kpi-title { flex: 1 1 auto; }
.run-kpi-sent { min-width: 200px; }
.run-kpi + .run-kpi { border-left: 1px solid var(--border); }
/* Fixed vertical rhythm — every stat cell has the same label/value/meta row
   geometry, so alignment holds by construction across fonts and content:
   1rem label row, 1.75rem value row (text and the SENT bar both center in
   it), meta row below. */
.run-kpi-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    height: 1rem;
    line-height: 1rem;
}
.run-kpi-value {
    display: flex;
    align-items: center;
    height: 1.75rem;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text);
}
.run-kpi-meta {
    height: 1.125rem;
    line-height: 1.125rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
}
.run-kpi-link:hover .run-kpi-value { text-decoration: underline; }

/* Breadcrumb above the strip — small/muted, chevron mirrors the row expander */
.run-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 8px;
    font-size: 0.8125rem;
    color: var(--text-muted);
    text-decoration: none;
}
.run-back:hover { color: var(--text); }

/* Identity cell — same fonts as the old page header (h2 + campaign-meta),
   top-aligned like every other cell so the name shares the label row */
.run-title-line {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
    min-width: 0;
}
.run-title-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.run-stop { margin-left: 8px; }

/* SENT while running: the value IS the bar — it fills the fixed 1.75rem
   value row, so its number centers exactly like the plain text values;
   sent count white inside the fill, total muted at the track's right end. */
.run-bar {
    display: flex;
    align-items: stretch;
    height: 1.75rem;
    background: var(--bg-hover);
    border-radius: 6px;
    overflow: hidden;
    font-size: 0.875rem;
    font-weight: 600;
}
.run-bar-fill {
    display: flex;
    align-items: center;
    background: var(--info);
    color: #fff;
    padding: 0 8px;
    border-radius: 6px 0 0 6px;
    min-width: fit-content;
    white-space: nowrap;
}
.run-bar-total {
    display: flex;
    align-items: center;
    margin-left: auto;
    padding: 0 8px;
    color: var(--text-muted);
    font-weight: 500;
}

/* Failure breakdown: one card, errors as bullets, full text (no truncation).
   Count is danger (rule 4); the bullet links to the failed view filtered by
   that error. */
.run-errors {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-elevated);
    padding: 0.625rem 1rem;
    margin-bottom: 12px;
}
.run-errors-list {
    margin: 0;
    padding-left: 1.25rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
}
.run-errors-list li { padding: 1px 0; }
.run-errors-list a { color: inherit; text-decoration: none; }
.run-errors-list a:hover { text-decoration: underline; }
.run-errors-list strong { color: var(--danger); font-weight: 600; }

.run-list { border-top: 1px solid var(--border); }

/* Activity rows: each row is a native <details> — the <summary> IS the row
   (Activity Monitor grammar minus the direction icon column), the message
   body expands below. hx-preserve keeps the open state across the 5s poll.
   No stripes: the border-left grammar is exclusive to slot/device state on
   Devices. No placeholders: missing info is simply absent. */
.run-item {
    /* Flat list, not cards — neutralize the generic details card chrome;
       the row separator is the only border. */
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    overflow: visible;
}
.run-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 4px 10px 12px;
    cursor: pointer;
    list-style: none;
    /* neutralize the generic summary styles — children carry their own */
    font-size: inherit;
    font-weight: 400;
    user-select: none;
}
.run-row:hover { background: transparent; }
.run-row::-webkit-details-marker { display: none; }
.run-chevron {
    flex: 0 0 12px;
    display: flex;
    color: var(--text-muted);
    transition: transform 0.15s ease;
}
.run-item[open] .run-chevron { transform: rotate(90deg); }
.run-status { flex: 0 0 14px; display: flex; }
.run-status.st-sent    { color: var(--ok); }
.run-status.st-failed  { color: var(--danger); }
.run-status.st-pending { color: var(--text-muted); }
.run-status.st-sending { color: var(--info); }
/* Color standard (decisions 0061): cancelled = terminated by intervention →
   danger, same glyph family as stopped one level down. */
.run-status.st-cancelled { color: var(--danger); }

/* Color standard tones (decisions 0061) — filter-chip counts.
   Meta/status TEXT is never colored (fix round 2 ruling). */
.cnt-ok     { color: var(--ok); }
.cnt-info   { color: var(--info); }
.cnt-danger { color: var(--danger); }
.cnt-muted  { color: var(--text-muted); }
.run-sender, .run-target { flex: 0 0 240px; min-width: 0; }
.run-arrow { flex: 0 0 auto; display: flex; color: var(--text-muted); }
.run-id-name, .run-id-meta {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.run-id-name { font-size: 13px; font-weight: 600; color: var(--text); }
.run-id-meta { font-size: 11px; color: var(--text-secondary); }
/* Target line 1: the name absorbs all truncation, the number never truncates */
.run-target-line { display: flex; align-items: baseline; gap: 6px; }
.run-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-num { flex-shrink: 0; font-size: 0.8125rem; font-weight: 400; color: var(--text-muted); }
.run-right { flex: 0 0 auto; min-width: 0; margin-left: auto; text-align: right; }
.run-time { font-size: 0.8125rem; color: var(--text-muted); white-space: nowrap; }
.run-slot {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Row reason (failed/cancelled): own flex lane right after the target column,
   left-aligned, vertically centered by the row's align-items: center. */
.run-error {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.75rem;
    color: var(--danger);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Expanded message body: indented past chevron+icon */
.run-msg {
    margin: 2px 4px 12px 50px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    white-space: pre-wrap;
    max-width: 640px;
}

@media (max-width: 768px) {
    /* Identity cell spans the strip's full width; 48px left padding clears
       the fixed nav toggle (there is no .page-header on this page) — the
       breadcrumb above the strip needs the same clearance. */
    /* Detail pages have no .page-header — the breadcrumb IS the top bar:
       one proper row beside the fixed nav toggle, full-width band, LOCKED on
       scroll with the exact page-title grammar (sticky, same z-ordering vs
       the fixed toggle), and the run strip clears it with normal spacing. */
    .run-back {
        position: sticky;
        top: 0;
        z-index: 100;
        display: flex;
        align-items: center;
        min-height: 52px;
        margin: 0 -1rem 1rem;
        padding: 0.375rem 1rem 0.375rem 48px; /* 48px reserved for the nav toggle */
        background: var(--bg);
    }
    .run-kpi-title {
        grid-column: 1 / -1;
        border-bottom: 1px solid var(--border);
        padding-left: 0.75rem; /* flush with the stat cells below — the
                                  breadcrumb owns hamburger clearance now */
    }

    /* Strip → 2×2 grid, same grammar as the dashboard mobile strip */
    .run-kpis { display: grid; grid-template-columns: 1fr 1fr; }
    .run-kpi:not(.run-kpi-title) { border-left: none; padding-left: 0.75rem; }
    .run-kpi:not(.run-kpi-title):nth-child(-n+3) { border-bottom: 1px solid var(--border); }

    /* Rows restack (two-line slot-row grammar): line 1 chevron | status icon |
       target identity; line 2 (indented) sender name; line 3 slot ··· time;
       failed rows add a full-width error line. flex-basis 100% forces each
       wrap (basis-0 items would all collapse onto line 1); padding indents.
       The whole summary stays the 44px toggle target. */
    .run-row { flex-wrap: wrap; gap: 2px 8px; }
    .run-chevron { order: 1; }
    .run-status { order: 2; }
    .run-target { order: 3; flex: 1 1 0; min-width: 0; }
    .run-target .run-id-meta { display: none; }
    .run-arrow { display: none; }
    .run-sender {
        order: 4;
        flex: 1 0 100%;
        min-width: 0;
        padding-left: 42px;
        box-sizing: border-box;
    }
    .run-sender .run-id-name { font-size: 0.8125rem; font-weight: 400; color: var(--text-muted); }
    .run-sender .run-id-meta { display: none; }
    .run-right {
        order: 5;
        flex: 1 0 100%;
        padding-left: 42px;
        box-sizing: border-box;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: baseline;
        gap: 2px 8px;
        text-align: left;
    }
    .run-slot { order: 1; }
    .run-time { order: 2; margin-left: auto; }
    /* The reason is a direct row child now: its own indented line between the
       sender line and the slot/time line on the stacked mobile layout. */
    .run-row > .run-error { order: 4; flex: 1 0 100%; padding-left: 42px; box-sizing: border-box; }
    .run-msg { margin: 4px 4px 10px 42px; }
}

/* Campaign-level failure reason — detail header, under the Started line,
   same danger-lane grammar as row reasons. */
.campaign-error-line {
    display: block;
    font-size: 0.75rem;
    color: var(--danger);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Viewport-locked shell, bottom pager (Devices grammar) */
@media (min-width: 769px) and (min-height: 500px) {
    body.page-campaigns {
        overflow: hidden;
    }
    body.page-campaigns .main {
        height: 100dvh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    body.page-campaigns .main > * {
        flex-shrink: 0;
    }
    body.page-campaigns .main > section.camp-shell {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        margin-bottom: 0;
    }
    body.page-campaigns #camp-list {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        scrollbar-width: thin;
        scrollbar-color: var(--border) transparent;
    }

    body.page-campaign-run {
        overflow: hidden;
    }
    body.page-campaign-run .main {
        height: 100dvh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    body.page-campaign-run .main > * {
        flex-shrink: 0;
    }
    body.page-campaign-run #run-live {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        scrollbar-width: thin;
        scrollbar-color: var(--border) transparent;
    }
}

/* === Agent Manager === */
.am-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: var(--gap);
    max-width: 760px;
}
.am-title { margin: 0 0 6px; font-size: 1rem; color: var(--text); }
.am-sub { margin: 0 0 14px; font-size: 0.875rem; color: var(--text-secondary); }
.am-note { font-size: 0.8125rem; color: var(--warn); margin: 0 0 10px; }
.am-note.ok { color: var(--ok); }
.am-warn { font-size: 0.8125rem; color: var(--warn); margin: 0 0 12px; }
.am-token {
    display: inline-block;
    margin-bottom: 12px;
    padding: 8px 12px;
    font-size: 0.9375rem;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.am-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.am-form .form-input { flex: 1; min-width: 200px; }
.am-form-vertical { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.am-form-row { display: flex; gap: 8px; width: 100%; }
.am-form-row .form-input { flex: 1; min-width: 0; }

/* APK upload: hint left, button right on one row; stacked full-width on mobile */
.am-apk-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    width: 100%;
}
.am-apk-row .form-hint { flex: 1; min-width: 0; }
.am-apk-row .btn-primary { flex-shrink: 0; }

/* Device label: shown once, in the meta row (the name line shows alias +
   model only). */


/* === Pile 2026-08-21: honest send status, slot stripes, dashboard rhythm === */

/* #14 — send-status icons in the thread (sent plane / queued clock /
   failed triangle). Icons sit next to the timestamp; the failed reason
   is hidden behind a click-to-slide-down detail, never shown inline. */
.msg-status { display: inline-flex; align-items: center; opacity: 0.75; }
.msg-status svg { display: block; }
.msg-status.st-queued { opacity: 0.55; }
.msg-status.st-failed { opacity: 1; color: var(--danger); cursor: pointer; }
/* The receipt plane's tick takeover (0468 + the 2026-09-27 display ruling):
   st-delivered keeps the base muted grey; st-read goes blue. A tick renders
   only with a filed receipt — never a default, never a hoped-for state. */
.msg-status.st-read { opacity: 1; color: var(--info); }
/* Gap 3: the phone-sent provenance glyph — muted, beside the timestamp. */
.msg-manual { display: inline-flex; align-items: center; opacity: 0.55; margin-right: 4px; }
.msg-manual svg { display: block; }

.msg-fail-detail {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    margin-top: 0;
    font-size: 0.75rem;
    line-height: 1.35;
    color: var(--danger);
    word-break: break-word;
    transition: max-height 0.18s ease, opacity 0.18s ease, margin-top 0.18s ease;
}
.msg-fail-detail.open {
    max-height: 8rem;
    opacity: 1;
    margin-top: 0.375rem;
}

/* Conversation list: red triangle prefix when the latest outbound failed. */
.conv-fail-ico {
    display: inline-flex;
    align-items: center;
    color: var(--danger);
    margin-right: 0.25rem;
    vertical-align: -1px;
}
.conv-fail-ico svg { display: block; }

/* #20 — dashboard rhythm: tighter card padding and consistent title gaps. */
.page-dashboard .card-outline { padding: 0.875rem 1.125rem; }
.page-dashboard .card-outline > :first-child { margin-top: 0; }
.page-dashboard .section-title { margin-bottom: 0.5rem; }

/* #18 — Agent Manager fleet token: full value in a display rectangle with
   a copy button; "Suggest a strong token" is a quiet text link that only
   fills the update field (nothing applies until Save). */
.amx-current {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 12px;
    padding: 6px 6px 6px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}
.amx-key {
    flex: 1;
    min-width: 0;
    font-size: 0.8125rem;
    color: var(--text);
    word-break: break-all;
    user-select: all;
}
/* Masked-by-default (click-to-reveal): bullets are not selectable, the real
   value never rides the selection clipboard. */
.amx-key.amx-masked { cursor: pointer; user-select: none; letter-spacing: 0.15em; }
.amx-copy { flex-shrink: 0; }
.amx-link {
    background: none;
    border: none;
    padding: 0;
    margin: 0 0 10px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    cursor: pointer;
}
.amx-link:hover { color: var(--text); text-decoration: underline; }

/* === Device bar mobile clearance === */
@media (max-width: 768px) {
    /* Chips row: group pinned to the 150px column, label truncates. */
    .device-name {
        display: grid;
        grid-template-columns: 150px minmax(0, 1fr);
        column-gap: 10px;
        row-gap: 4px;
        align-items: center;
    }
    .device-label-trigger { max-width: 140px; }
}

/* === Device Logs page (pull-based viewer) === */
.page-back {
    width: 32px;
    height: 32px;
    margin: -4px 0 -4px -6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    flex-shrink: 0;
}
.page-back:hover { background: var(--bg-hover); }

.dl-layout {
    display: flex;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.dl-rail {
    width: 280px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}

#dl-search, #tf-search {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 8px 11px;
    font-size: 0.875rem;
    margin: 0 2px 8px;
    outline: none;
}
#dl-search:focus, #tf-search:focus { border-color: var(--border-bright); }

/* Scope pills (Online / All — no counts) */
.dl-scope { display: flex; gap: 6px; padding: 0 2px 8px; }

/* Group filter — Conversations dropdown grammar, full rail width */
.dl-groupdd { margin: 0 0 6px; }
.dl-groupdd .dropdown-trigger { width: 100%; }
.dl-groupdd .dropdown-trigger svg:first-child { width: 15px; height: 15px; flex-shrink: 0; }
.dl-groupdd .dropdown-menu { left: 0; right: 0; width: auto; }
.dl-groupdd .dropdown-menu:not([hidden]) { display: block; }
.dl-groupdd .dropdown-item {
    width: 100%;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    gap: 8px;
}
.dl-groupdd .dropdown-item span:first-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dl-groupdd .dropdown-count {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 0.75rem;
    flex-shrink: 0;
}
.dl-chip {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px 9px;
    cursor: pointer;
    font-family: inherit;
}
.dl-chip.on { background: var(--bg-active); color: var(--text); border-color: transparent; }

.dl-sec {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 6px 8px 3px;
    font-weight: 600;
}

.dl-row {
    display: flex;
    align-items: flex-start; /* dot centers on line 1 via .dl-dot margin-top */
    justify-content: flex-start;
    gap: 9px;
    width: 100%;
    padding: 7px 10px;
    border: none;
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
}
.dl-row:hover { background: var(--bg-hover); }
.dl-row.sel { background: var(--bg-active); }

.dl-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; margin-top: 6px; }
.dl-dot.on { background: var(--ok); }
.dl-dot.nr { background: var(--warn); }  /* 0151: Not Ready (online, health-gate-unhealthy) */
.dl-dot.off { background: var(--border-bright); }

.dl-row-text { display: block; min-width: 0; flex: 1; }
.dl-row-l1, .dl-row-l2 {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dl-row-l1 { font-size: 0.875rem; }
.dl-row-l1 b { font-weight: 600; color: var(--text); }
.dl-row-l1 s {
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.8125rem;
}
.dl-row-l2 { font-size: 0.75rem; color: var(--text-muted); margin-top: 1px; }

.dl-more {
    margin: 6px 8px;
    padding: 6px;
    background: transparent;
    border: 1px dashed var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 0.8125rem;
    cursor: pointer;
    font-family: inherit;
}
.dl-more:hover { color: var(--text-secondary); border-color: var(--border-bright); }

.dl-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.dl-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9375rem;
    line-height: 1.7;
}

.dl-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.dl-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.dl-who { min-width: 0; }
.dl-alias { font-size: 0.9375rem; font-weight: 700; display: block; }
.dl-meta { font-size: 0.8125rem; color: var(--text-muted); display: block; }
.dl-live {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;
}
.dl-live input { accent-color: var(--ok); }

.dl-stream {
    flex: 1;
    overflow: auto;
    margin: 0;
    padding: 14px 18px;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 0.8125rem;
    line-height: 1.7;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
}

.dl-foot {
    border-top: 1px solid var(--border);
    padding: 8px 18px;
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

/* === Device Logs / Test Fleet — viewport-locked shell (desktop, tall
   enough windows). Same grammar as Devices/Campaigns: the page header is
   fixed chrome; only the panes scroll. The lock releases on short windows
   (< 500px height) so the page falls back to natural document scroll. */
@media (min-width: 769px) and (min-height: 500px) {
    body.page-device-logs,
    body.page-test-fleet {
        overflow: hidden;
    }

    body.page-device-logs .main,
    body.page-test-fleet .main {
        height: 100dvh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    body.page-device-logs .main > *,
    body.page-test-fleet .main > * {
        flex-shrink: 0;
    }

    body.page-device-logs .dl-layout,
    body.page-test-fleet .dl-layout {
        flex: 1;
        min-height: 0;
    }

    body.page-device-logs .dl-main,
    body.page-test-fleet .dl-main {
        min-height: 0;
    }

    body.page-device-logs .dl-stream {
        scrollbar-width: thin;
        scrollbar-color: var(--border) transparent;
    }
}

@media (max-width: 768px) {
    .dl-layout { flex-direction: column; border: none; border-radius: 0; }
    .dl-rail { width: 100%; border-right: none; }
    .dl-head { padding: 10px 12px; }
}

/* === Test Fleet — mobile stacked-fixed (owner ruling 2026-09-03 "Stacked
   fixed"): the picker rail keeps a fixed share of the viewport so a
   filtered list can never collapse it (the "N Devices" count stays visible
   as the empty state); both panels scroll independently and the page
   itself never scrolls. Scoped to body.page-test-fleet — Device Logs keeps
   the shared natural-scroll rules above. */
@media (max-width: 768px) {
    body.page-test-fleet { overflow: hidden; }
    body.page-test-fleet .main {
        height: 100dvh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    body.page-test-fleet .main > * { flex-shrink: 0; }
    body.page-test-fleet .dl-layout { flex: 1; min-height: 0; }
    body.page-test-fleet .dl-rail {
        flex: 0 0 42%;
        min-height: 0;
        border-bottom: 1px solid var(--border);
    }
    body.page-test-fleet .dl-main { flex: 1; min-height: 0; }
}

@media (max-width: 768px) {
    .am-apk-row { flex-direction: column; align-items: stretch; }
}

/* hidden must beat our flex displays */
.dl-view[hidden], .dl-more[hidden], .dl-sec[hidden], .dl-empty[hidden] { display: none; }

/* This header has back + title only — no space-between spreading */
.page-device-logs .page-header, .page-test-fleet .page-header { justify-content: flex-start; gap: 12px; }

/* === Devices view toggle (C7): desktop-only rows⇄stacked preference ===
   The attribute lives on documentElement — the grid poll swaps
   #device-grid-inner and can never touch it. Icon shows the target view. */
.view-toggle {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
}
.view-toggle:hover { color: var(--text); }
html[data-devices-view="rows"] .icon-to-rows,
html[data-devices-view="stacked"] .icon-to-stacked { display: none; }
@media (max-width: 768px) { .view-toggle { display: none; } }

/* Toggle + Showing text are one inline unit at the row's left edge (the bare
   text's old slot); space-between keeps the search pinned right. Mobile is
   untouched: the hidden toggle leaves only the text. */
.showing-unit { display: inline-flex; align-items: center; gap: 8px; }

/* Stacked layout on desktop when the preference says stacked — the same six
   rules the mobile media block applies, regated to the attribute. */
@media (min-width: 769px) {
    html[data-devices-view="stacked"] .device-bar { flex-direction: column; }
    html[data-devices-view="stacked"] .device-col { width: auto; border-bottom: 1px solid var(--border); }
    html[data-devices-view="stacked"] .slot-col { border-left: none; border-top: 1px solid var(--border); }
    html[data-devices-view="stacked"] .slot-col::before { top: 0; bottom: 0; left: 0; right: auto; width: 4px; height: auto; }
    html[data-devices-view="stacked"] .slot-col:last-child::before { border-top-right-radius: 0; }
    html[data-devices-view="stacked"] .slot-avatar { width: 32px; height: 32px; font-size: 0.75rem; }
}

/* === Live rows — reusable arrival/update signal for polled lists ===
   Contract lives in base.html (data-live-list container + data-live-key /
   data-live-ver rows). NEW rows: entrance slide+fade PLUS the tint wash.
   BUMPED rows (ver changed, key known): tint wash only — the reorder to
   top is the motion cue. Tint is a color-mix of var(--info), theme-safe in
   both themes; the wash ends on `to { background-color: transparent }`,
   which matches the base row background exactly (rows paint no background
   at rest). */
@keyframes live-row-in {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: none; }
}
@keyframes live-row-tint {
    from { background-color: color-mix(in srgb, var(--info) 22%, transparent); }
    to   { background-color: transparent; }
}
.live-row-enter { animation: live-row-in 0.25s ease-out, live-row-tint 1.8s ease-out; }
.live-row-bump  { animation: live-row-tint 1.8s ease-out; }

/* === Test Fleet page (Agent Manager → Test Fleet) — Device Logs idiom ===
   Two panes on the shared dl-layout shell: the rail is a stable device list
   (membership shows as the row's action state — circled "+" adds one, greyed
   checkmark = in the fleet), the main pane lists the fleet (members +
   orphans, live-count title, per-row meta column and circled "−").
   Rail width, viewport lock and header rules are the shared dl-* ones above. */

/* The rail's added state (owner ruling 2026-09-03): greyed checkmark,
   disabled, no hover paint. */
.icon-btn.added, .icon-btn.added:hover {
    color: var(--text-muted);
    background: transparent;
    cursor: default;
}

/* Fleet pane: rows scroll, the note stays pinned at the bottom. */
.tf-members {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Union row: dl-row paint, but a div — it hosts real controls (icon
   buttons), so it must not be a <button> itself. Rail rows pin their one
   action (membership state) to the right column. */
.tf-row {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    width: 100%;
    padding: 7px 10px;
    border-radius: 8px;
}
.tf-row:hover { background: var(--bg-hover); }
.tf-row .dl-dot { margin-top: 6px; }
.tf-row .icon-btn { flex-shrink: 0; margin-top: 2px; }
/* Remove icon in a tf-row: centered on the row middle too; the scoped rule
   zeroes the class's line-1 margin-top nudge for direct children only —
   .icon-btn elsewhere keeps its 2px offset (owner 2026-09-14). */
.tf-row > .icon-btn { align-self: center; margin-top: 0; }

/* Member rows only: the fleet pane caps the row width so the circled "−"
   aligns as a column; orphan rows share the same geometry. */
.tf-members .tf-row { max-width: 700px; gap: 16px; }
.tf-members .tf-row .dl-row-text { flex: 0 1 300px; }

/* === Test Fleet — Organism summary card (owner-ruled 2026-09-14; 0346 state
   word + rows; 0348 visual amendment, owner go on the final mock: icon +
   state word row with NO label, the dot vertically centered against the
   word and following the STATE, two-part label/value fact rows, Needs-you
   block with its own amber marker, ONE font scale across the whole card) ===
   The ONLY organism surface in the UI: read-only lines of finished
   display text (the no-guessing contract). Same chrome as the dashboard
   cards (card-outline padding + section-title rhythm); the status line
   carries the shared dl-dot. */
.tfo { padding: 0.875rem 1.125rem; margin-bottom: var(--gap); font-size: 0.9375rem; }
.tfo .section-title { margin-bottom: 0.25rem; }
.tfo-line {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    min-width: 0;
    padding: 0.25rem 0;
}
.tfo .dl-dot { margin-top: 0; }  /* icon vertically centered against the word (0348) */
/* The fact rows: labels aligned in a fixed first column, values in the
   second — the two-part arrangement of the owner mock. */
.tfo-facts {
    display: grid;
    grid-template-columns: max-content 1fr;
    column-gap: 0.625rem;
    row-gap: 0.25rem;
    padding: 0.25rem 0;
}
.tfo-flabel { color: var(--text-secondary); }
.tfo-needs-head { color: var(--text-secondary); }
.tfo-needs-item {
    padding: 0.125rem 0;
    color: var(--text-secondary);
}
.tfo-needs-item::before { content: "• "; }

/* Orphan (in selftest.json, no DB row): dashed border + muted pill — an
   inventory gap, not an error state. */
.tf-row.orphan { border: 1px dashed var(--border); }
.tf-pill {
    font-size: 0.6875rem;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 8px;
    margin-top: 2px;
    flex-shrink: 0;
}

.tf-note { font-size: 0.75rem; color: var(--text-muted); margin: 10px 12px; }
