/* === 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: 2rem;
}

.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;
}

.campaign-icon {
    color: var(--text);
    flex-shrink: 0;
    margin-top: 2px;
}

.campaign-icon-running  { color: var(--text); }
.campaign-icon-completed{ color: var(--ok); }
.campaign-icon-failed   { color: var(--warn); }
.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);
}

.campaign-meta {
    color: var(--text-secondary);
    font-size: 0.8125rem;
    margin-top: 2px;
}

.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 {
    color: var(--text);
    font-weight: 600;
}

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

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

.monitor-row {
    display: grid;
    grid-template-columns: 24px 140px 20px 140px 1fr 80px;
    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);
}

/* === 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);
}

/* === Badges === */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25em 0.75em;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.4;
    letter-spacing: 0.02em;
    border-radius: 999px;
}

.badge-yellow {
    color: #fbbf24;
    background: rgba(245,158,11,0.15);
}

.badge-green {
    color: #4ade80;
    background: rgba(34,197,94,0.15);
}

.badge-red {
    color: #f87171;
    background: rgba(239,68,68,0.15);
}

.badge-gray {
    color: var(--text-secondary);
    background: rgba(102,102,102,0.2);
}

.badge-blue {
    color: #60a5fa;
    background: rgba(59,130,246,0.15);
}

/* === 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-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;
}

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;
}

.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);
}

.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: 26px;
    height: 26px;
}

/* === 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);
}

.phone-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.phone-chip {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.1s ease;
}

.phone-chip input {
    margin: 0;
    accent-color: var(--text);
}

.phone-chip:has(input:checked) {
    color: var(--text);
    background: var(--bg-active);
    border-color: var(--border-bright);
}

/* === 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;
}

.inbox-search {
    /* left edge lines up with the filter-tab icon above
       (0.25rem filters padding + 0.5rem tab padding) */
    padding: 0.5rem 1rem 0.75rem 0.75rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.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;
}

.inbox-filters {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem 0.75rem 0.25rem;
    border-bottom: none;
    gap: 0.75rem;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.filter-tabs {
    display: flex;
    align-items: center; /* campaign dropdown shares this row */
    gap: 0.375rem;
}

.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); }

.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; }

.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; }

/* === Dashboard stat strip ===
   (The old .topbar-slim header pattern is gone — every page uses
   .page-header now, so title size/spacing/hamburger clearance are uniform.) */
.stat-strip {
    display: flex;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-elevated);
    padding: 0.5rem 0;
}

.stat-cell {
    flex: 1;
    display: flex;
    align-items: baseline;
    justify-content: flex-start;
    gap: 0.45rem;
    white-space: nowrap;
    padding-left: 1rem;
}

.stat-cell + .stat-cell {
    border-left: 1px solid var(--border);
}

.stat-cell-label {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.stat-cell-value {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--text);
}

.stat-cell-meta {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 0.2rem;
}

/* === 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;
}

.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;
}

.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);
}

.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: 1;
    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-text {
    display: flex;
    align-items: baseline;
    gap: 0.375rem;
}

.conv-stat-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

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

a.conv-preview-card {
    text-decoration: none;
    color: inherit;
}

a.conv-preview-card:hover .conv-preview-name {
    text-decoration: underline;
}

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

.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;
}

.conv-preview-top {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    flex-wrap: wrap;
}

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

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

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



/* ═════════════════════════════════════════════════════════════════════════════
   Fleet Bar
   ═════════════════════════════════════════════════════════════════════════════ */

.fleet-bar {
    display: flex;
    align-items: baseline; /* dot-stats sit on the big number's baseline */
    gap: 12px;
    padding: 12px 20px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.fleet-block {
    display: flex;
    align-items: baseline;
    gap: 6px;
    flex-shrink: 0;
}

.fleet-big {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
    letter-spacing: -0.02em;
}

.fleet-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
}

.fleet-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    flex-shrink: 0;
    align-self: center; /* stay optically centered while siblings baseline-align */
    margin: 0 8px;      /* cluster separation > intra-cluster gap */
}

/* The dot is taken out of flow so the stat's first in-flow item is its text —
   only then does the stat export a real text baseline to the bar. */
.fleet-stat {
    position: relative;
    padding-left: 10px; /* 5px dot + 5px gap — same spacing as before */
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text);
    flex-shrink: 0;
}

.fleet-stat .dot {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 5px;
    height: 5px;
    border-radius: 50%;
}

.fleet-stat .dot.green { background: var(--ok); }
.fleet-stat .dot.yellow { background: var(--warn); }
.fleet-stat .dot.red { background: var(--danger); }
.fleet-stat .dot.gray { background: var(--text-muted); }

/* ═════════════════════════════════════════════════════════════════════════════
   Device Cards
   ═════════════════════════════════════════════════════════════════════════════ */

.device-card {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
    /* visible, not hidden: the per-device group menu must escape the card.
       No child paints a background, so nothing needs corner clipping —
       except the last row's 3px state bar, rounded below. */
    overflow: visible;
}

.device-card > .slot-row:last-child::before {
    border-bottom-left-radius: var(--radius-lg);
}

/* Offline dimming targets content, never .device-header-actions —
   grey = action (always full opacity), color = state. */
.device-card.offline .device-header-left,
.device-card.offline .slot-row {
    opacity: 0.5;
}

.device-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.device-header-left {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

/* optically center the 10px dot on the alias line (line-height ≈ 25px) */
.device-header-left .device-status-dot {
    margin-top: 8px;
}

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

.device-status-dot.online { background: var(--ok); }
.device-status-dot.offline { background: var(--text-muted); }

/* Header text: line 1 = alias + group + label (icon-led, gap-spaced, no
   · separators); line 2 = model · last seen. Group is a fixed 150px column
   so the label icon starts at the same x on every card. */
.device-head-text { min-width: 0; flex: 1; }

.device-name {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text);
}

.device-alias { flex-shrink: 0; }

.device-sub {
    font-size: 0.8125rem;
    color: var(--text-muted);
    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;
}

.device-header-actions {
    display: flex;
    gap: 8px;
}

.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 Rows
   ═════════════════════════════════════════════════════════════════════════════ */

.slot-row {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    position: relative;
}

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

.slot-row::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
}

.slot-row.ready::before { background: var(--ok); }
.slot-row.engaging::before { background: var(--warn); }
.slot-row.dnu::before { background: var(--danger); }
.slot-row.empty::before { background: transparent; }

.slot-label {
    width: 48px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
    flex-shrink: 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); }

.slot-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    flex-shrink: 0;
}

/* No state dots: the slot-row border-left already carries state color.
   The badge shows the WhatsApp number; Do Not Use prefixes a red icon+label;
   only Empty keeps a text-only badge. */
.slot-badge.empty {
    color: var(--text-muted);
}

.dnu-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--danger);
    min-width: 0;
    flex-shrink: 0;
}

.dnu-icon {
    flex-shrink: 0;
}

.dnu-note {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Remove-from-Do-Not-Use: ban icon with a tick badge — "banned, click to lift" */
.ban-tick {
    position: relative;
    display: inline-flex;
}

.ban-tick-check {
    position: absolute;
    right: -4px;
    bottom: -3px;
}
.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); }

.slot-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.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;
}

/* ═══════════════════════════════════════════════════════════════════════════
   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);
        border-bottom: 1px solid var(--border);
    }

    .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 stat strip: 2×2 grid, same look as the old stat bar --- */
    .stat-strip {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem 1rem;
        padding: 0.75rem 0;
        border: none;
        border-bottom: 1px solid var(--border);
        border-radius: 0;
        background: transparent;
    }

    .stat-cell {
        flex-direction: column;
        align-items: flex-start;
        justify-content: flex-start;
        gap: 2px;
        white-space: normal;
        padding-left: 0; /* base rule's desktop indent must not leak to mobile */
    }

    .stat-cell + .stat-cell {
        border-left: none;
    }

    .stat-cell-label {
        font-size: 0.75rem;
    }

    .stat-cell-value {
        font-size: 1.125rem;
    }

    /* --- Dashboard conversation summary: one stat per line --- */
    .conv-summary-bar {
        flex-wrap: wrap;
        gap: 0.625rem 1.25rem;
    }

    .conv-stat {
        flex-basis: 100%;
    }

    /* --- 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: tabs row on top (scrolls), actions row below;
           campaign dropdown takes the remaining width of the actions row --- */
    .inbox-filters {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
        padding: 0.5rem 0.75rem;
    }

    .inbox-search {
        padding-left: 1.25rem;
    }

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

    .filter-actions {
        width: 100%;
    }

    .filter-actions .dropdown-wrap {
        flex: 1;
        min-width: 0;
    }

    .dropdown-trigger {
        width: 100%;
        max-width: 100%;
    }

    .dropdown-menu {
        width: min(280px, calc(100vw - 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;
    }

    /* --- Devices fleet bar: 4 stacked lines ---
       1: "5 Phones"   2: its dot-stats
       3: "12 WhatsApp Accounts"   4: its dot-stats
       DOM: 1 block, 2-3 stats, 4 divider, 5 block, 6-8 stats --- */
    .fleet-bar {
        gap: 0.375rem 0.75rem;
        padding: 0.75rem 1rem;
    }

    .fleet-bar > :nth-child(1) { order: 1; flex-basis: 100%; }
    .fleet-bar > :nth-child(2),
    .fleet-bar > :nth-child(3) { order: 2; }

    .fleet-bar::before {
        content: '';
        order: 3;
        flex-basis: 100%;
        height: 0;
    }

    .fleet-bar > :nth-child(5) { order: 4; flex-basis: 100%; }
    .fleet-bar > :nth-child(n+6) { order: 5; }

    .fleet-divider {
        display: none;
    }

    .fleet-big   { font-size: 1.25rem; }
    .fleet-label { font-size: 0.8125rem; }
    .fleet-stat  { font-size: 0.75rem; padding-left: 9px; } /* 5px dot + 4px gap, as before */

    /* Header: actions (disconnect/delete) stay pinned right on row 1;
       the left block shrinks and wraps internally instead. */
    .device-header {
        flex-wrap: nowrap;
        align-items: flex-start;
        gap: 0.5rem;
        padding: 0.75rem 1rem;
    }

    .device-header-left {
        flex: 1 1 auto;
        min-width: 0;
        flex-wrap: wrap;
        row-gap: 2px;
    }

    .device-header-actions {
        flex-shrink: 0;
    }

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

    /* --- Slot rows: two lines, all info kept ---
       Line 1: label | avatar | name + number · company · country
       Line 2: status (dot + text) at the left edge, actions right --- */
    .slot-row {
        flex-wrap: wrap;
        gap: 6px 10px;
        padding: 0.75rem 1rem;
    }

    .slot-label {
        width: 40px;
        min-width: 0;
        font-size: 0.75rem;
    }

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

    .slot-body {
        flex: 1 1 calc(100% - 92px);
    }

    .slot-badge {
        order: 5;
        /* number + action icons form one right-aligned group (mirrors desktop);
           auto margin pushes the group to the row's right edge */
        margin-left: auto;
    }

    /* Do Not Use tag: own line below the number row, same avatar alignment */
    .dnu-tag {
        order: 7;
        margin-left: 50px;
        max-width: calc(100% - 50px);
    }

    .dnu-tag .dnu-note {
        max-width: 260px;
    }

    .slot-actions {
        order: 6;
        /* free space is already absorbed by the badge's auto margin —
           a second auto margin would split it and center the group */
        margin-left: 0;
    }

    /* --- 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;
}

.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;
}

.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-row .form-input {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
}

@media (max-width: 768px) {
    /* 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 — desktop layout (min-width: 769px) ===
   Two-column workspace: actionable panels left (30%), live monitor
   right (70%). Mobile keeps the stacked layout untouched. */
@media (min-width: 769px) {
    .dash-shell {
        display: flex;
        flex-direction: column;
        gap: var(--gap);
    }

    .dash-grid {
        display: grid;
        /* minmax(0, …) overrides grid items' min-width:auto, otherwise the
           left column's min-content (campaign cards) inflates the 3fr track */
        grid-template-columns: minmax(0, 3fr) minmax(0, 7fr);
        gap: var(--gap);
        align-items: start;
    }

    .dash-grid section {
        margin-bottom: 0; /* shell/grid gaps own the spacing */
    }

    .dash-col-left {
        display: flex;
        flex-direction: column;
        gap: var(--gap);
    }

    /* Conversations panel: tighter rhythm; summary stats shrink and each
       label stays on ONE line. Three stats can't fit the 30% column on one
       row, so whole stats wrap (never mid-label) instead of overflowing
       into a horizontal scrollbar */
    .conv-summary-bar {
        padding: 0.25rem 0 0.5rem;
        margin-bottom: 0.5rem;
        gap: 0.375rem 0.875rem;
        flex-wrap: wrap;
    }

    .conv-stat {
        flex: 0 0 auto;
        white-space: nowrap;
        gap: 0.4rem;
    }

    .conv-stat-icon {
        width: 15px;
        height: 15px;
    }

    .conv-stat-value {
        font-size: 0.875rem;
    }

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

    .conv-preview-card {
        padding: 0.75rem 0 0.25rem;
    }
}

/* === Dashboard — viewport-locked app shell (desktop, tall-enough windows) ===
   Gmail / trading-terminal anatomy: the page never scrolls; the top bar and
   stat strip are fixed chrome, the grid fills the remaining viewport, and
   only the panels scroll internally. The lock releases on short windows
   (< 500px height) so nothing ever becomes unreachable. */
@media (min-width: 769px) and (min-height: 500px) {
    body.page-dashboard {
        overflow: hidden;
    }

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

    .dash-shell {
        flex: 1;
        min-height: 0;
    }

    .dash-shell > .page-header,
    .dash-shell > .dash-stats {
        flex-shrink: 0;
    }

    .dash-grid {
        flex: 1;
        min-height: 0;
        overflow: hidden;
        align-items: stretch;
        grid-template-rows: minmax(0, 1fr); /* columns fill the grid's height */
    }

    /* Left column: Conversations natural (scrolls internally only if it
       overflows), Recent Campaigns docks to fill the rest — its bottom
       edge always equals the Message Monitor's bottom edge. */
    .dash-col-left {
        min-height: 0;
        overflow: hidden;
    }

    .dash-col-left > section:first-child {
        flex: 0 1 auto;
        min-height: 0;
        overflow-y: auto;
    }

    .dash-col-left > section:last-child {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    .dash-col-left > section:last-child .card-outline {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    .dash-col-left > section:last-child .card-outline > [hx-get] {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }

    /* Right column: the monitor card fills the grid row; only the feed
       scrolls. Newest rows are on top, so the live tail is always visible. */
    .dash-col-right {
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    .dash-col-right > section {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    .dash-col-right .card-outline {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    #dash-monitor {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }

    /* Thin themed scrollbars on the internal scrollports */
    .dash-col-left > section:first-child,
    .dash-col-left > section:last-child .card-outline > [hx-get],
    #dash-monitor {
        scrollbar-width: thin;
        scrollbar-color: var(--border) transparent;
    }
}

/* === 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;
    }
}

/* Monitor: one-shot amber fade for newly arrived rows. The .is-new class is
   added by the dashboard's seen-set script only for signatures never seen
   before, and removed on animationend — rows never re-glow on later polls. */
.monitor-row.is-new {
    margin: 0 -0.5rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    border-radius: var(--radius-lg);
    animation: monitor-arrive 2s ease-out 1;
}

@keyframes monitor-arrive {
    0%   { background-color: rgba(245, 158, 11, 0.14); }
    100% { background-color: 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 (bold numbers, muted labels).
   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-runstats strong { color: var(--text); font-weight: 600; }
.camp-runstats-fail,
.camp-runstats-pace {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.camp-replies { color: inherit; text-decoration: none; }
.camp-replies strong { color: var(--text); font-weight: 600; }
.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; }
}

/* 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;
    }
}

@media (prefers-reduced-motion: reduce) {
    .monitor-row.is-new {
        animation: none;
    }
}

/* === 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; }

.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; }

/* #15 — slot states are independent properties: Do Not Use (red) and
   Engaging (amber) can coexist on one slot → a double stripe. */
.slot-row.dnu.engaging::before {
    width: 6px;
    background: linear-gradient(90deg, var(--danger) 50%, var(--warn) 50%);
}

/* #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; }



/* #22 — dashboard stat strip: left-packed cells instead of stretched. */
.page-dashboard .stat-cell {
    flex: 0 0 auto;
    padding-right: 1.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;
}
.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; }

/* === Pile 2026-08-22: device card mobile clearance === */
@media (max-width: 768px) {
    /* Long model strings wrap BEFORE reaching the header actions — the
       trash icon always keeps its breathing room. */
    .device-header { gap: 12px; }
    .device-header-left { min-width: 0; }
    .device-header-left > div { min-width: 0; }
    /* Mobile: 3 lines — alias / group+label / model·last seen.
       Grid is deterministic: alias spans both columns, group pinned to the
       150px column, label truncates in the remainder. */
    .device-name {
        display: grid;
        grid-template-columns: 150px minmax(0, 1fr);
        column-gap: 10px;
        row-gap: 4px;
        align-items: center;
    }
    .device-alias { grid-column: 1 / -1; overflow-wrap: anywhere; }
    .device-header-actions { padding-left: 4px; flex-shrink: 0; }
    /* Group column stays the fixed 150px; label truncates */
    .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;
    min-height: 420px;
    height: calc(100dvh - 220px);
}

.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 {
    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 { 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.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;
}
.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;
}

.dl-back-picker { display: none; }

@media (max-width: 768px) {
    .dl-layout { height: calc(100dvh - 140px); border: none; border-radius: 0; }
    .dl-rail { width: 100%; border-right: none; }
    .dl-main { display: none; }
    .dl-layout.viewing .dl-rail { display: none; }
    .dl-layout.viewing .dl-main { display: flex; }
    .dl-back-picker { display: inline-flex; }
    .dl-head { padding: 10px 12px; }
}

@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] { display: none; }

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