/* ═══════════════════════════════════════════════════════════════════
   WhatsApp Business Portal — Professional UI
   ═══════════════════════════════════════════════════════════════════ */

:root {
    /* ── Brand ─────────────────────────────────────────────────── */
    --brand:        #10b981;
    --brand-hover:  #059669;
    --brand-dark:   #047857;
    --brand-light:  #ecfdf5;
    --brand-100:    #d1fae5;

    /* ── Neutrals ──────────────────────────────────────────────── */
    --gray-950: #030712;
    --gray-900: #111827;
    --gray-800: #1f2937;
    --gray-700: #374151;
    --gray-600: #4b5563;
    --gray-500: #6b7280;
    --gray-400: #9ca3af;
    --gray-300: #d1d5db;
    --gray-200: #e5e7eb;
    --gray-100: #f3f4f6;
    --gray-50:  #f9fafb;

    /* ── Semantic ──────────────────────────────────────────────── */
    --text:        #111827;
    --text-2:      #374151;
    --text-muted:  #6b7280;
    --text-light:  #9ca3af;
    --bg:          #f0f4f8;
    --surface:     #ffffff;
    --border:      #e5e7eb;
    --border-2:    #d1d5db;

    /* ── Status colors ─────────────────────────────────────────── */
    --red:      #ef4444;
    --red-50:   #fef2f2;
    --red-100:  #fee2e2;
    --red-800:  #991b1b;
    --yellow:   #f59e0b;
    --yel-50:   #fffbeb;
    --yel-100:  #fef3c7;
    --yel-800:  #854d0e;
    --blue:     #3b82f6;
    --blu-50:   #eff6ff;
    --blu-100:  #dbeafe;
    --blu-800:  #1e40af;
    --grn-50:   #f0fdf4;
    --grn-100:  #dcfce7;
    --grn-800:  #166534;

    /* ── Sidebar ───────────────────────────────────────────────── */
    --sb-bg:        #0f172a;
    --sb-surface:   #1e293b;
    --sb-text:      #94a3b8;
    --sb-hover-bg:  rgba(255,255,255,0.05);
    --sb-active-bg: rgba(16,185,129,0.14);
    --sb-active-tx: #34d399;
    --sb-border:    rgba(255,255,255,0.07);

    /* ── Shadows ───────────────────────────────────────────────── */
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow:    0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.04);
    --shadow-md: 0 10px 15px -3px rgba(0,0,0,0.07), 0 4px 6px -4px rgba(0,0,0,0.04);

    /* ── Radii ─────────────────────────────────────────────────── */
    --r-xs:   4px;
    --r-sm:   6px;
    --r:      8px;
    --r-md:   10px;
    --r-lg:   12px;
    --r-xl:   16px;
    --r-full: 9999px;

    /* Transition */
    --t: 150ms ease;
}

/* ── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-hover); text-decoration: none; transition: color var(--t); }
a:hover { color: var(--brand); text-decoration: underline; }

/* ── Auth pages ─────────────────────────────────────────────────── */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, #ecfdf5 0%, #f0f4f8 60%, #e0e7ff 100%);
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-md);
}
.auth-card h1 {
    margin-bottom: 6px;
    font-size: 24px;
    font-weight: 700;
    color: var(--gray-900);
}
.auth-card .sub  { color: var(--text-muted); font-size: 14px; margin-bottom: 28px; }
.auth-card .switch { margin-top: 20px; font-size: 14px; text-align: center; color: var(--text-muted); }

/* Brand logo in auth */
.auth-logo {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 24px;
    font-weight: 800;
    font-size: 20px;
    color: var(--brand-dark);
}
.auth-logo-icon {
    width: 36px; height: 36px; border-radius: 10px;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 18px;
}

/* ── App shell ──────────────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
    width: 240px;
    background: var(--sb-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 17px;
    color: #fff;
    padding: 20px 18px 16px;
    border-bottom: 1px solid var(--sb-border);
    letter-spacing: -0.01em;
}
.sidebar .brand-icon {
    width: 32px; height: 32px; border-radius: 8px;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; flex-shrink: 0;
}

.sidebar nav {
    flex: 1;
    padding: 10px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}
.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--sb-text);
    padding: 9px 12px;
    border-radius: var(--r);
    font-size: 13.5px;
    font-weight: 500;
    transition: background var(--t), color var(--t);
    text-decoration: none;
}
.sidebar nav a i { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }
.sidebar nav a:hover { background: var(--sb-hover-bg); color: #e2e8f0; text-decoration: none; }
.sidebar nav a.active {
    background: var(--sb-active-bg);
    color: var(--sb-active-tx);
    font-weight: 600;
}
.sidebar nav a.active i { color: var(--brand); }

.sidebar .nav-divider {
    margin: 12px 12px 4px;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #475569;
    font-weight: 700;
}
.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--sb-border);
}
.sidebar-footer .user-info {
    display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
}
.sidebar-footer .avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 13px; font-weight: 700; flex-shrink: 0;
}
.sidebar-footer .user-name {
    color: #e2e8f0;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-footer .user-role { color: #64748b; font-size: 11px; }
.logout-link {
    display: flex; align-items: center; gap: 6px;
    color: #f87171;
    font-size: 13px;
    transition: color var(--t);
}
.logout-link:hover { color: #fca5a5; text-decoration: none; }

/* ── Content area ───────────────────────────────────────────────── */
.content { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 28px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: var(--shadow-xs);
}
.topbar h1 {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    color: var(--gray-900);
}
.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--text-muted);
}

.page-body { padding: 24px 28px; }

/* ── Alerts / Flash ─────────────────────────────────────────────── */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--r);
    margin-bottom: 16px;
    font-size: 14px;
    border: 1px solid transparent;
}
.alert i { margin-top: 1px; flex-shrink: 0; }
.alert-success { background: var(--grn-100); color: var(--grn-800); border-color: #bbf7d0; }
.alert-error   { background: var(--red-100); color: var(--red-800); border-color: #fecaca; }
.alert-info    { background: var(--blu-100); color: var(--blu-800); border-color: #bfdbfe; }
.alert-warning { background: var(--yel-100); color: var(--yel-800); border-color: #fde68a; }

/* ── Forms ──────────────────────────────────────────────────────── */
label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--text-2);
}

input[type=text], input[type=email], input[type=password],
input[type=number], input[type=url], input[type=tel],
input[type=file], select, textarea {
    width: 100%;
    padding: 9px 13px;
    border: 1.5px solid var(--border-2);
    border-radius: var(--r);
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    transition: border-color var(--t), box-shadow var(--t);
    outline: none;
    margin-bottom: 16px;
}
input[type=text]:focus, input[type=email]:focus, input[type=password]:focus,
input[type=number]:focus, input[type=url]:focus, input[type=tel]:focus,
select:focus, textarea:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(16,185,129,0.12);
}
input[type=file] { padding: 6px 10px; }
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
select { cursor: pointer; }

.form-group { margin-bottom: 4px; }
.form-group > input, .form-group > select, .form-group > textarea { margin-bottom: 0; }

.form-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 18px;
}
.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0 14px;
}
@media (max-width: 640px) {
    .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
}

.req { color: var(--red); }
.field-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Checkboxes / radios */
input[type=checkbox], input[type=radio] {
    width: auto;
    margin: 0;
    accent-color: var(--brand);
    cursor: pointer;
}

/* ── Buttons ─────────────────────────────────────────────────────── */
button, .btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-hover) 100%);
    color: #fff;
    border: none;
    border-radius: var(--r);
    padding: 9px 18px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: opacity var(--t), box-shadow var(--t), transform var(--t);
    box-shadow: 0 1px 3px rgba(5,150,105,0.3);
    white-space: nowrap;
}
button:hover, .btn:hover {
    opacity: .92;
    box-shadow: 0 4px 10px rgba(5,150,105,0.35);
    text-decoration: none;
    color: #fff;
}
button:active, .btn:active { transform: translateY(1px); }
button:disabled, .btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn-secondary {
    background: var(--surface);
    color: var(--text-2);
    border: 1.5px solid var(--border-2);
    box-shadow: var(--shadow-xs);
}
.btn-secondary:hover { background: var(--gray-50); color: var(--text); box-shadow: var(--shadow-sm); }
.btn-danger { background: linear-gradient(135deg, #ef4444, #dc2626); box-shadow: 0 1px 3px rgba(220,38,38,0.3); }
.btn-danger:hover { box-shadow: 0 4px 10px rgba(220,38,38,0.35); }
.btn-sm { padding: 6px 13px; font-size: 13px; }
.btn-xs { padding: 4px 10px; font-size: 12px; border-radius: var(--r-sm); }
.btn-icon { padding: 8px; }

.connect-btn {
    font-size: 15px;
    padding: 12px 28px;
    box-shadow: 0 4px 14px rgba(5,150,105,0.35);
}

/* ── Stats cards ─────────────────────────────────────────────────── */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--t), transform var(--t);
}
.card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.card .label {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.card .label i { font-size: 14px; }
.card .value { font-size: 28px; font-weight: 800; color: var(--gray-900); line-height: 1.1; }
.card .trend { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* ── Panel ───────────────────────────────────────────────────────── */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 22px 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}
.panel h2 {
    font-size: 15px;
    font-weight: 700;
    color: var(--gray-900);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.panel h2 i { color: var(--brand); }
.panel h3 { font-size: 14px; font-weight: 700; color: var(--gray-800); margin: 0 0 12px; }

/* ── Tables ──────────────────────────────────────────────────────── */
.table-wrap {
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    overflow: hidden;
}
table { width: 100%; border-collapse: collapse; background: var(--surface); }
table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    background: var(--gray-50);
    border-bottom: 1px solid var(--border);
}
table td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
    color: var(--text);
    vertical-align: middle;
}
table tbody tr:last-child td { border-bottom: none; }
table tbody tr { transition: background var(--t); }
table tbody tr:hover { background: var(--gray-50); }

/* ── Badges ──────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--r-full);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-green  { background: var(--grn-100); color: var(--grn-800); }
.badge-yellow { background: var(--yel-100); color: var(--yel-800); }
.badge-red    { background: var(--red-100); color: var(--red-800); }
.badge-gray   { background: var(--gray-100); color: var(--gray-700); }
.badge-blue   { background: var(--blu-100); color: var(--blu-800); }

/* ── Utilities ───────────────────────────────────────────────────── */
.muted { color: var(--text-muted); font-size: 13px; }
.mt    { margin-top: 16px; }
.mt-2  { margin-top: 8px; }
.mb    { margin-bottom: 16px; }
.flex  { display: flex; gap: 10px; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.gap-6 { gap: 6px; }
code, pre {
    background: var(--gray-100);
    border-radius: var(--r-xs);
    padding: 2px 6px;
    font-size: 12.5px;
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
    color: var(--gray-800);
}
pre { padding: 14px; overflow-x: auto; border-radius: var(--r); border: 1px solid var(--border); }

/* ── Token reveal (API tokens) ──────────────────────────────────── */
.token-reveal {
    background: #0f172a;
    color: #4ade80;
    padding: 14px 18px;
    border-radius: var(--r);
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
    font-size: 13px;
    word-break: break-all;
    margin-bottom: 12px;
    border: 1px solid rgba(74,222,128,0.2);
}

/* ── Help / info boxes ──────────────────────────────────────────── */
.help-box {
    background: var(--blu-50);
    border: 1px solid #bfdbfe;
    border-radius: var(--r);
    padding: 12px 16px;
    font-size: 13px;
    margin-bottom: 16px;
    color: var(--blu-800);
}
details.help-box summary {
    cursor: pointer;
    font-weight: 700;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}
details.help-box summary::before { content: '▶'; font-size: 10px; }
details.help-box[open] summary::before { content: '▼'; }
.help-box ol { margin: 10px 0 4px 18px; line-height: 1.8; color: var(--blu-800); }

/* ── Tabs ────────────────────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 22px;
}
.tab-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    color: var(--text-muted);
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: -2px;
    box-shadow: none;
    transition: color var(--t), border-color var(--t);
}
.tab-btn:hover { background: var(--gray-50); color: var(--text); box-shadow: none; }
.tab-btn.active { color: var(--brand-hover); border-bottom-color: var(--brand-hover); background: none; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Template variable fields ────────────────────────────────────── */
.var-fields-wrapper { margin-bottom: 16px; }
.var-fields-heading { font-weight: 700; margin-bottom: 12px; font-size: 14px; color: var(--gray-800); }
.var-section { margin-bottom: 16px; }
.var-section-type {
    font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
    color: var(--text-muted); font-weight: 700; margin-bottom: 8px;
    display: flex; align-items: center; gap: 5px;
}
.var-preview-text {
    background: var(--gray-50);
    border: 1.5px solid var(--border);
    border-radius: var(--r);
    padding: 10px 14px;
    font-size: 13.5px;
    margin-bottom: 10px;
    line-height: 1.55;
    color: var(--text);
}
.var-placeholder {
    background: var(--yel-100);
    color: #92400e;
    border-radius: var(--r-xs);
    padding: 1px 5px;
    font-weight: 700;
    font-size: 12.5px;
}

/* ── Template picker cards ───────────────────────────────────────── */
.tpl-picker-card { cursor: pointer; }
.tpl-picker-card input[type=radio] { display: none; }
.tpl-picker-card-inner {
    border: 2px solid var(--border-2);
    border-radius: var(--r-lg);
    padding: 12px 16px;
    transition: border-color var(--t), background var(--t), box-shadow var(--t);
}
.tpl-picker-card:hover .tpl-picker-card-inner {
    border-color: var(--brand);
    background: var(--brand-light);
}
.tpl-picker-card input:checked + .tpl-picker-card-inner {
    border-color: var(--brand-hover);
    background: var(--brand-light);
    box-shadow: 0 0 0 3px rgba(16,185,129,0.12);
}

/* ── Chat shell ──────────────────────────────────────────────────── */
.chat-shell {
    display: flex;
    height: calc(100vh - 108px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.chat-list { width: 300px; border-right: 1px solid var(--border); overflow-y: auto; flex-shrink: 0; }
.chat-list-header {
    padding: 14px 16px;
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    background: var(--gray-50);
    position: sticky; top: 0; z-index: 1;
}
.chat-list a {
    display: block;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    transition: background var(--t);
    text-decoration: none;
}
.chat-list a:hover { background: var(--gray-50); text-decoration: none; }
.chat-list a.active { background: var(--brand-light); border-left: 3px solid var(--brand); }
.chat-list .name { font-weight: 600; font-size: 14px; color: var(--gray-900); }
.chat-list .preview { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.chat-thread { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.thread-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
    gap: 12px;
    box-shadow: var(--shadow-xs);
}
.thread-contact { font-weight: 700; font-size: 15px; }
.thread-phone   { font-size: 12px; color: var(--text-muted); }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    background: #e5ddd5 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Cpath d='M 0 30 L 15 0 L 45 0 L 60 30 L 45 60 L 15 60 Z' stroke='%23ccc' stroke-width='0.3' fill='none'/%3E%3C/svg%3E");
    display: flex;
    flex-direction: column;
}

.bubble {
    max-width: 68%;
    padding: 8px 12px 6px;
    border-radius: 12px;
    margin-bottom: 6px;
    font-size: 14px;
    line-height: 1.45;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    word-wrap: break-word;
}
.bubble.in  {
    background: #fff;
    border-bottom-left-radius: 3px;
    align-self: flex-start;
}
.bubble.out {
    background: #d9fdd3;
    border-bottom-right-radius: 3px;
    align-self: flex-end;
    margin-left: auto;
}
.bubble .meta {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 3px;
    text-align: right;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 3px;
}
.bubble-template {
    font-style: italic;
    opacity: .88;
    border-left: 3px solid var(--brand-hover);
    padding-left: 10px;
}
.bubble-template .bubble-tpl-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--brand-hover);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 3px;
}

.chat-input {
    display: flex;
    gap: 10px;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    background: #f0f2f5;
    align-items: flex-end;
    flex-shrink: 0;
}
.chat-input input {
    margin-bottom: 0;
    flex: 1;
    border-radius: var(--r-full);
    padding: 10px 16px;
    background: #fff;
    border-color: transparent;
    box-shadow: var(--shadow-xs);
}
.chat-input input:focus { border-color: var(--brand); }
.chat-input .send-btn {
    border-radius: var(--r-full);
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
}

.chat-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    flex-direction: column;
    gap: 12px;
    font-size: 15px;
}
.chat-empty i { font-size: 48px; opacity: .2; }

/* In-thread template panel */
.in-thread-panel {
    border-bottom: 2px solid var(--brand);
    background: linear-gradient(to bottom, var(--brand-light), #fff);
    flex-shrink: 0;
    animation: slideDown 0.2s ease;
}
.in-thread-panel-inner { padding: 14px 18px; }
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Notification dot */
.notif-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--red);
    display: inline-block;
    animation: pulse 1.5s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .4; }
}

/* ── Broadcast preview panel ─────────────────────────────────────── */
.broadcast-layout {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 20px;
    align-items: start;
}
@media (max-width: 900px) { .broadcast-layout { grid-template-columns: 1fr; } }

.phone-preview {
    background: #e5ddd5;
    border-radius: var(--r-xl);
    padding: 14px;
    min-height: 200px;
    position: relative;
}
.phone-preview-header {
    background: var(--brand-dark);
    color: #fff;
    padding: 10px 14px;
    border-radius: var(--r-md) var(--r-md) 0 0;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.phone-preview-body {
    background: #e5ddd5;
    padding: 12px;
    border-radius: 0 0 var(--r-md) var(--r-md);
    min-height: 120px;
}
.phone-preview .preview-bubble {
    background: #fff;
    padding: 10px 14px 8px;
    border-radius: 10px 10px 10px 3px;
    font-size: 13px;
    line-height: 1.5;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    max-width: 90%;
    white-space: pre-wrap;
}
.phone-preview .preview-bubble .preview-meta {
    font-size: 11px;
    color: #9ca3af;
    text-align: right;
    margin-top: 5px;
}
.phone-preview .preview-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100px;
    color: #94a3b8;
    font-size: 13px;
    font-style: italic;
}

/* ── Contacts scroll table ───────────────────────────────────────── */
.contacts-scroll {
    max-height: 380px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
}
.contacts-scroll table { margin: 0; }
.contacts-scroll table th { position: sticky; top: 0; z-index: 1; }

/* ── Quick replies pop-up ────────────────────────────────────────── */
.quick-reply-popup {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-md);
    max-height: 240px;
    overflow-y: auto;
    z-index: 50;
    margin-bottom: 6px;
}
.quick-reply-item {
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background var(--t);
}
.quick-reply-item:last-child { border-bottom: none; }
.quick-reply-item:hover { background: var(--brand-light); }
.qr-shortcut {
    font-size: 12px; font-weight: 700; color: var(--brand-hover);
    background: var(--brand-100);
    border-radius: var(--r-xs);
    padding: 1px 6px;
    margin-right: 8px;
}
.qr-message { font-size: 13px; color: var(--text-muted); }

/* ── Auto-reply toggle ───────────────────────────────────────────── */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px; height: 22px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--gray-300);
    border-radius: var(--r-full);
    transition: var(--t);
}
.toggle-slider:before {
    position: absolute;
    content: "";
    height: 16px; width: 16px;
    left: 3px; bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: var(--t);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-switch input:checked + .toggle-slider { background: var(--brand); }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(18px); }

/* ── Page section title ──────────────────────────────────────────── */
.section-title {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-muted);
    margin: 24px 0 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.section-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ── Chat search input ───────────────────────────────────────────── */
#conv-search:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(16,185,129,0.1);
    outline: none;
}
.chat-list-header {
    padding: 10px 14px;
    font-weight: 700;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    background: var(--gray-50);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ── New conversation fade-in ────────────────────────────────────── */
@keyframes fadeInConv {
    from { background: var(--brand-light); opacity: 0.5; }
    to   { background: transparent; opacity: 1; }
}
.conv-item { display: block; }

/* ── Status pill ─────────────────────────────────────────────────── */
.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
}
.status-dot {
    width: 7px; height: 7px; border-radius: 50%;
}
.status-dot.online  { background: var(--brand); }
.status-dot.offline { background: var(--gray-300); }
.status-dot.error   { background: var(--red); }

/* ── Chat page: full-height viewport layout ──────────────────────── */
.page-body-chat {
    padding: 8px 16px 0;
    height: calc(100vh - 60px);   /* 60px = topbar */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    gap: 0;
}
.page-body-chat > .alert { flex-shrink: 0; }
.page-body-chat > .panel { flex-shrink: 0; margin-bottom: 6px; }
.page-body-chat > .chat-shell {
    flex: 1;
    min-height: 0;   /* critical: allows flex child to shrink */
    height: auto;    /* override fixed calc() height */
    margin-bottom: 0;
}

/* Chat page controls bar (account selector + buttons) */
.chat-ctrl-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
    margin-bottom: 6px;
}
.chat-ctrl-bar .ctrl-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.chat-ctrl-bar .ctrl-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.chat-ctrl-bar .account-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Start new conversation panel */
#start-conversation-panel {
    flex-shrink: 0;
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}
.sc-grid {
    display: grid;
    grid-template-columns: 1fr 260px;
    gap: 18px;
    align-items: start;
}
@media (max-width: 900px) { .sc-grid { grid-template-columns: 1fr; } }

/* Phone contact lookup result */
.contact-lookup-found {
    background: var(--grn-100);
    color: var(--grn-800);
    border-radius: var(--r-sm);
    padding: 5px 10px;
    font-size: 12.5px;
    margin-top: 4px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.contact-lookup-new {
    background: var(--gray-100);
    color: var(--text-muted);
    border-radius: var(--r-sm);
    padding: 5px 10px;
    font-size: 12.5px;
    margin-top: 4px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Thread header: add to list dropdown */
#add-to-list-dropdown {
    position: fixed;
    z-index: 1000;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-md);
    min-width: 210px;
    padding: 8px;
}
.list-pick-btn {
    display: flex !important;
    align-items: center;
    gap: 7px;
    width: 100%;
    text-align: left;
    background: none !important;
    border: none !important;
    padding: 7px 10px !important;
    border-radius: var(--r-sm) !important;
    cursor: pointer;
    font-size: 13px;
    color: var(--text) !important;
    box-shadow: none !important;
    font-weight: 500 !important;
    transition: background var(--t);
}
.list-pick-btn:hover { background: var(--brand-light) !important; color: var(--brand-dark) !important; }

/* Broadcast: multi-list checkboxes */
.list-check-box {
    border: 1.5px solid var(--border-2);
    border-radius: var(--r);
    padding: 8px 10px;
    max-height: 180px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 4px;
}
.list-check-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 5px 6px;
    border-radius: var(--r-sm);
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 400;
    transition: background var(--t);
}
.list-check-item:hover { background: var(--gray-50); }
.list-check-item input[type=checkbox] { margin-bottom: 0; width: auto; }
.list-check-item .lci-name { font-weight: 600; font-size: 13.5px; color: var(--text); }
.list-check-item .lci-count { font-size: 12px; color: var(--text-muted); margin-left: 4px; }
