/* ==========================================================================
   X2 Communications — portal theme
   Tokens lifted from x2comms.co.uk so the portal reads as the same product.
   ========================================================================== */

:root {
    --primary: #2563eb;
    --primary-soft: #eff6ff;
    --primary-dark: #1d4ed8;
    --accent: #38bdf8;

    --dark: #0f172a;
    --text: #334155;
    --text-light: #94a3b8;
    --white: #ffffff;
    --bg: #f8fafc;
    --line: #e8edf5;

    --ok: #10b981;
    --ok-soft: #ecfdf5;
    --warn: #f59e0b;
    --warn-soft: #fffbeb;
    --danger: #ef4444;
    --danger-soft: #fef2f2;

    --radius: 24px;
    --radius-md: 16px;
    --radius-sm: 10px;
    --btn-radius: 50px;

    --shadow: 0 10px 40px -10px rgba(0, 0, 0, .08);
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, .05);
    --shadow-lg: 0 24px 60px -20px rgba(15, 23, 42, .22);

    --sidebar-w: 264px;
    --header-h: 72px;
}

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

html, body { width: 100%; overflow-x: hidden; }

body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; transition: color .2s ease; }
ul, ol { list-style: none; }
img, svg { max-width: 100%; display: block; }

h1, h2, h3, h4 { color: var(--dark); font-weight: 700; line-height: 1.25; }
h1 { font-size: 1.7rem; letter-spacing: -.02em; }
h2 { font-size: 1.25rem; letter-spacing: -.01em; }
h3 { font-size: 1.02rem; }

code, pre, .mono {
    font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    font-size: .84em;
}

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 6px;
}

/* ---------------------------------------------------------------- layout -- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--white);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 900;
    transition: transform .28s cubic-bezier(.4, 0, .2, 1);
}

.sidebar-brand {
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 0 22px;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.brand-logo {
    height: 30px; width: auto; display: block; flex-shrink: 0;
}

.brand-text { font-weight: 700; color: var(--dark); font-size: .95rem; letter-spacing: -.01em; }
.brand-text small { display: block; font-weight: 500; font-size: .68rem; color: var(--text-light); letter-spacing: .04em; text-transform: uppercase; }

.nav { flex: 1; overflow-y: auto; padding: 18px 14px; }
.nav-label {
    font-size: .68rem; font-weight: 700; letter-spacing: .09em;
    text-transform: uppercase; color: var(--text-light);
    padding: 0 12px; margin: 20px 0 8px;
}
.nav-label:first-child { margin-top: 0; }

.nav a {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; border-radius: 12px;
    font-size: .9rem; font-weight: 500; color: var(--text);
    margin-bottom: 2px;
    transition: background .18s ease, color .18s ease;
}
.nav a:hover { background: var(--primary-soft); color: var(--primary-dark); }
.nav a.active { background: var(--primary); color: #fff; font-weight: 600; box-shadow: 0 4px 12px rgba(37, 99, 235, .22); }
.nav a.active svg { opacity: 1; }
.nav a svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .65; }

.sidebar-foot { border-top: 1px solid var(--line); padding: 14px; flex-shrink: 0; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px; }
.user-chip:hover { background: var(--bg); }

/* Sign out is a labelled control, not a bare icon — an unlabelled glyph in the
   corner of a white sidebar is effectively invisible. */
.signout {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    margin-top: 8px; padding: 9px 12px;
    border: 1px solid var(--line); border-radius: 12px;
    font-size: .85rem; font-weight: 600; color: var(--text);
    background: var(--white);
    transition: background .18s, color .18s, border-color .18s;
}
.signout:hover {
    background: var(--danger-soft); color: var(--danger); border-color: #fecaca;
}
.signout svg { flex-shrink: 0; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--primary-soft); color: var(--primary-dark);
    display: grid; place-items: center;
    font-weight: 700; font-size: .76rem; flex-shrink: 0;
}
.user-meta { min-width: 0; flex: 1; }
.user-meta strong { display: block; font-size: .84rem; color: var(--dark); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta span { display: block; font-size: .72rem; color: var(--text-light); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: var(--header-h);
    background: rgba(255, 255, 255, .88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: 16px;
    padding: 0 28px;
    position: sticky; top: 0; z-index: 800;
}
.topbar h1 { font-size: 1.12rem; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.content { padding: 28px; flex: 1; max-width: 1400px; width: 100%; }

.mobile-toggle {
    display: none; background: none; border: none; cursor: pointer;
    color: var(--dark); padding: 8px; border-radius: 10px;
}
.mobile-toggle svg { width: 22px; height: 22px; }
.mobile-toggle:hover { background: var(--primary-soft); }
.scrim {
    display: none; position: fixed; inset: 0;
    background: rgba(15, 23, 42, .45); z-index: 890;
    backdrop-filter: blur(2px);
}
.scrim.open { display: block; }

/* ----------------------------------------------------------------- cards -- */

.card {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-pad { padding: 24px; }
.card-head {
    padding: 20px 24px;
    border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.card-head h2, .card-head h3 { margin: 0; }
.card-head .spacer { margin-left: auto; }
.card-sub { font-size: .85rem; color: var(--text-light); margin-top: 3px; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }

/* ----------------------------------------------------------------- stats -- */

.stat { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius-md); padding: 20px 22px; }
.stat-label { font-size: .74rem; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--text-light); }
.stat-value { font-size: 1.85rem; font-weight: 800; color: var(--dark); line-height: 1.1; margin-top: 7px; letter-spacing: -.02em; }
.stat-note { font-size: .8rem; color: var(--text-light); margin-top: 3px; }

/* --------------------------------------------------------------- buttons -- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 11px 22px;
    background: var(--primary); color: #fff;
    border: 1px solid transparent; border-radius: var(--btn-radius);
    font-family: inherit; font-weight: 600; font-size: .88rem;
    cursor: pointer; white-space: nowrap;
    box-shadow: 0 4px 12px rgba(37, 99, 235, .2);
    transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}
.btn:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 8px 20px rgba(37, 99, 235, .3); }
.btn:active { transform: translateY(0); }
.btn svg { width: 16px; height: 16px; }

.btn-ghost { background: var(--white); color: var(--text); border-color: var(--line); box-shadow: none; }
.btn-ghost:hover { background: var(--primary-soft); color: var(--primary-dark); border-color: #cfe0fb; box-shadow: none; }

.btn-danger { background: var(--danger); box-shadow: 0 4px 12px rgba(239, 68, 68, .2); }
.btn-danger:hover { background: #dc2626; box-shadow: 0 8px 20px rgba(239, 68, 68, .3); }

.btn-sm { padding: 7px 15px; font-size: .8rem; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-block { width: 100%; }
.btn[disabled], .btn.is-loading { opacity: .62; pointer-events: none; }

.btn-icon {
    padding: 8px; border-radius: 10px; background: transparent;
    border: 1px solid transparent;
    /* Not --text-light: on a white sidebar that is nearly invisible. */
    color: var(--text);
    cursor: pointer; display: inline-grid; place-items: center;
    transition: background .18s, color .18s;
}
.btn-icon svg { width: 17px; height: 17px; }
.btn-icon:hover { background: var(--primary-soft); color: var(--primary-dark); }
.btn-icon:focus-visible { background: var(--primary-soft); color: var(--primary-dark); }
.btn-icon-danger:hover { background: #fef2f2; color: #b91c1c; }
.btn-icon-danger:focus-visible { background: #fef2f2; color: #b91c1c; }

/* ----------------------------------------------------------------- forms -- */

label, .label {
    display: block; font-size: .86rem; font-weight: 600;
    color: var(--dark); margin-bottom: 7px;
}
.hint { font-size: .79rem; color: var(--text-light); font-weight: 400; margin-top: 5px; line-height: 1.5; }

input[type=text], input[type=email], input[type=password], input[type=url],
input[type=number], input[type=tel], input[type=search], select, textarea {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: var(--primary-soft);
    font-family: inherit; font-size: .92rem; color: var(--dark);
    transition: background .18s, box-shadow .18s;
}
input:focus, select:focus, textarea:focus {
    outline: none; background: var(--white);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
    border-color: #cfe0fb;
}
input::placeholder, textarea::placeholder { color: #a9bad3; }
textarea { resize: vertical; min-height: 110px; line-height: 1.65; }
select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23667' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 40px;
}

.field { margin-bottom: 18px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; }

/* Switch */
.switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; margin-bottom: 16px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
    width: 42px; height: 24px; border-radius: 999px; background: #d6e0ee;
    position: relative; flex-shrink: 0; margin-top: 2px;
    transition: background .2s ease;
}
.switch-track::after {
    content: ''; position: absolute; top: 3px; left: 3px;
    width: 18px; height: 18px; border-radius: 50%; background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
    transition: transform .2s cubic-bezier(.4, 0, .2, 1);
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px rgba(37, 99, 235, .25); }
.switch-text { min-width: 0; }
.switch-text strong { display: block; font-size: .88rem; color: var(--dark); font-weight: 600; }
.switch-text span { display: block; font-size: .79rem; color: var(--text-light); line-height: 1.5; }

/* Range */
.range-row { display: flex; align-items: center; gap: 14px; }
input[type=range] {
    -webkit-appearance: none; appearance: none;
    flex: 1; height: 6px; border-radius: 999px;
    background: #dbe6f5; outline: none; padding: 0;
}
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--primary); cursor: pointer;
    border: 3px solid #fff; box-shadow: 0 2px 6px rgba(37, 99, 235, .4);
}
input[type=range]::-moz-range-thumb {
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--primary); cursor: pointer;
    border: 3px solid #fff; box-shadow: 0 2px 6px rgba(37, 99, 235, .4);
}
.range-value {
    min-width: 52px; text-align: center;
    font-weight: 700; font-size: .84rem; color: var(--primary-dark);
    background: var(--primary-soft); border-radius: 8px; padding: 4px 8px;
}

/* Choice cards (radio grids) */
.choice-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; width: 0; height: 0; }
.choice-body {
    display: block; padding: 15px 17px; cursor: pointer;
    border: 1.5px solid var(--line); border-radius: var(--radius-md);
    background: var(--white); height: 100%;
    transition: border-color .18s, background .18s, box-shadow .18s;
}
.choice-body:hover { border-color: #bcd4f8; background: #fbfdff; }
.choice input:checked + .choice-body {
    border-color: var(--primary); background: var(--primary-soft);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
}
.choice input:focus-visible + .choice-body { box-shadow: 0 0 0 3px rgba(37, 99, 235, .25); }
.choice-body strong { display: block; font-size: .9rem; color: var(--dark); margin-bottom: 3px; }
.choice-body span { display: block; font-size: .79rem; color: var(--text-light); line-height: 1.5; }
.choice-tag {
    display: inline-block; margin-top: 8px;
    font-size: .67rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
    color: var(--ok); background: var(--ok-soft); padding: 3px 8px; border-radius: 6px;
}

/* ------------------------------------------------------------------ tabs -- */

.tabs {
    display: flex; gap: 4px; overflow-x: auto;
    border-bottom: 1px solid var(--line);
    padding: 0 4px; scrollbar-width: thin;
}
.tabs::-webkit-scrollbar { height: 3px; }
.tabs::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
.tab {
    padding: 13px 15px; font-size: .87rem; font-weight: 600;
    color: var(--text-light); white-space: nowrap; cursor: pointer;
    border: none; background: none; font-family: inherit;
    border-bottom: 2.5px solid transparent; margin-bottom: -1px;
    transition: color .18s, border-color .18s;
}
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.tab-select { display: none; }

/* ---------------------------------------------------------------- tables -- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
thead th {
    text-align: left; padding: 12px 16px;
    font-size: .72rem; font-weight: 700; letter-spacing: .06em;
    text-transform: uppercase; color: var(--text-light);
    border-bottom: 1px solid var(--line); white-space: nowrap;
}
tbody td { padding: 14px 16px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .15s; }
tbody tr:hover { background: #fbfdff; }

/* ----------------------------------------------------------------- pills -- */

.pill {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 11px; border-radius: 999px;
    font-size: .74rem; font-weight: 600;
    background: var(--primary-soft); color: var(--primary-dark);
    white-space: nowrap;
}
.pill-ok { background: var(--ok-soft); color: #047857; }
.pill-warn { background: var(--warn-soft); color: #b45309; }
.pill-danger { background: var(--danger-soft); color: #b91c1c; }
.pill-muted { background: #f1f5f9; color: var(--text-light); }
.pill svg { width: 13px; height: 13px; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.dot-live { background: var(--ok); box-shadow: 0 0 0 0 rgba(16, 185, 129, .6); animation: pulse 2s infinite; }
@keyframes pulse {
    0%   { box-shadow: 0 0 0 0 rgba(16, 185, 129, .55); }
    70%  { box-shadow: 0 0 0 7px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* --------------------------------------------------------------- toasts --- */

.toasts {
    position: fixed; top: 18px; right: 18px; z-index: 2000;
    display: flex; flex-direction: column; gap: 10px;
    max-width: min(400px, calc(100vw - 36px));
}
.toast {
    display: flex; align-items: flex-start; gap: 11px;
    background: var(--white); border: 1px solid var(--line);
    border-left: 3px solid var(--primary);
    border-radius: var(--radius-sm); padding: 13px 16px;
    box-shadow: var(--shadow-lg); font-size: .88rem;
    animation: slide-in .3s cubic-bezier(.4, 0, .2, 1);
}
.toast.out { animation: slide-out .25s ease forwards; }
.toast-success { border-left-color: var(--ok); }
.toast-error { border-left-color: var(--danger); }
.toast-info { border-left-color: var(--accent); }
.toast-close { margin-left: auto; background: none; border: none; cursor: pointer; color: var(--text-light); padding: 0 2px; font-size: 1.1rem; line-height: 1; }
@keyframes slide-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes slide-out { to { opacity: 0; transform: translateX(24px); } }

.alert {
    padding: 13px 17px; border-radius: var(--radius-md);
    font-size: .87rem; margin-bottom: 16px;
    border: 1px solid transparent;
}
.alert-error { background: var(--danger-soft); color: #b91c1c; border-color: #fecaca; }
.alert-success { background: var(--ok-soft); color: #047857; border-color: #a7f3d0; }
.alert-info { background: var(--primary-soft); color: var(--primary-dark); border-color: #bfdbfe; }
.alert-warn { background: var(--warn-soft); color: #b45309; border-color: #fde68a; }

/* ---------------------------------------------------------------- modal --- */

.modal-backdrop {
    position: fixed; inset: 0; z-index: 2100;
    background: rgba(15, 23, 42, .5);
    backdrop-filter: blur(3px);
    display: none; place-items: center; padding: 20px;
}
.modal-backdrop.open { display: grid; animation: fade .18s ease; }
.modal {
    background: var(--white); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); max-width: 440px; width: 100%;
    padding: 28px; animation: pop .22s cubic-bezier(.4, 0, .2, 1);
}
@keyframes pop { from { opacity: 0; transform: scale(.95) translateY(8px); } to { opacity: 1; transform: none; } }
.modal h3 { margin-bottom: 8px; }
.modal p { font-size: .9rem; color: var(--text); margin-bottom: 22px; line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ----------------------------------------------------------- empty state -- */

.empty { text-align: center; padding: 56px 24px; }
.empty-icon {
    width: 56px; height: 56px; margin: 0 auto 16px;
    border-radius: 16px; background: var(--primary-soft); color: var(--primary);
    display: grid; place-items: center;
}
.empty-icon svg { width: 26px; height: 26px; }
.empty h3 { margin-bottom: 7px; }
.empty p { font-size: .89rem; color: var(--text-light); max-width: 400px; margin: 0 auto 20px; line-height: 1.6; }

/* ------------------------------------------------------------- assistant -- */

.assistant-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); }

.assistant-card {
    background: var(--white); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 22px;
    display: flex; flex-direction: column; gap: 13px;
    transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.assistant-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: #d5e3fa; }
.assistant-card.flash-update { animation: highlight 1.6s ease; }
@keyframes highlight {
    0%   { background: #fffbeb; border-color: var(--warn); }
    100% { background: var(--white); border-color: var(--line); }
}

.assistant-head { display: flex; align-items: flex-start; gap: 12px; }
.assistant-avatar {
    width: 42px; height: 42px; border-radius: 13px; flex-shrink: 0;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .88rem;
}
.assistant-name { font-size: 1rem; font-weight: 700; color: var(--dark); line-height: 1.3; }
.assistant-desc {
    font-size: .84rem; color: var(--text-light); line-height: 1.55;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.assistant-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.assistant-foot {
    display: flex; align-items: center; gap: 8px;
    padding-top: 13px; border-top: 1px solid var(--line); margin-top: auto;
}

/* Voice picker — searchable dropdown */
.voice-combo { position: relative; }
.voice-trigger {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 12px 14px; background: var(--primary-soft);
    border: 1.5px solid var(--line); border-radius: var(--radius-md);
    cursor: pointer; text-align: left; font: inherit; color: var(--text);
    transition: border-color .16s, box-shadow .16s;
}
.voice-trigger:hover { border-color: #bcd4f8; }
.voice-trigger[aria-expanded="true"] {
    border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.voice-trigger-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.voice-trigger-main strong { font-size: .9rem; color: var(--dark); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.voice-trigger-play { flex-shrink: 0; }
.voice-caret { flex-shrink: 0; color: var(--text-light); transition: transform .18s; }
.voice-trigger[aria-expanded="true"] .voice-caret { transform: rotate(180deg); }

.voice-panel {
    position: absolute; z-index: 60; left: 0; right: 0; margin-top: 8px;
    background: var(--white); border: 1px solid var(--line);
    border-radius: var(--radius-md); box-shadow: var(--shadow);
    padding: 14px; max-height: 460px; display: flex; flex-direction: column;
}
.voice-panel-head { flex-shrink: 0; }
.voice-panel .voice-filters { margin-top: 10px; margin-bottom: 8px; }
.voice-panel .voice-list { max-height: 260px; margin-top: 4px; }

.voice-list { overflow-y: auto; display: grid; gap: 8px; padding-right: 4px; }
.voice-item {
    display: flex; align-items: center; gap: 12px; padding: 11px 14px;
    border: 1.5px solid var(--line); border-radius: var(--radius-sm);
    cursor: pointer; background: var(--white);
    transition: border-color .16s, background .16s;
}
.voice-item:hover { border-color: #bcd4f8; background: #fbfdff; }
.voice-item.selected { border-color: var(--primary); background: var(--primary-soft); }
.voice-check { flex-shrink: 0; color: var(--primary); opacity: 0; }
.voice-item.selected .voice-check { opacity: 1; }
.voice-testbar { display: flex; align-items: center; gap: 10px; margin: 10px 0 6px; flex-wrap: wrap; }
.voice-testbar input { margin: 0; flex: 1; min-width: 220px; font-size: .82rem; }
/* Play button while Telnyx synthesises the sample */
.voice-preview.is-loading, .voice-trigger-play.is-loading { position: relative; color: transparent; pointer-events: none; }
.voice-preview.is-loading::after, .voice-trigger-play.is-loading::after {
    content: ""; position: absolute; inset: 0; margin: auto; width: 13px; height: 13px;
    border: 2px solid var(--primary); border-right-color: transparent;
    border-radius: 50%; animation: spin .6s linear infinite;
}

/* Key/value editor for dynamic variables */
.kv-row { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 10px; margin-bottom: 10px; align-items: center; }
.kv-row input { margin: 0; }

/* Guided tool-parameter builder */
.param-row, .param-head {
    display: grid; grid-template-columns: 1.1fr .9fr 1.6fr .9fr auto;
    gap: 10px; align-items: center; margin-bottom: 8px;
}
.param-row input, .param-row select { margin: 0; }
.param-head {
    margin-bottom: 6px; font-size: .68rem; font-weight: 600; letter-spacing: .05em;
    text-transform: uppercase; color: var(--text-light);
}
.param-head span:last-child { width: 34px; }
@media (max-width: 720px) {
    .param-head { display: none; }
    .param-row { grid-template-columns: 1fr 1fr; }
    .param-row input:first-child, .param-row input:nth-child(3) { grid-column: 1 / -1; }
}

/* Live (portal-provided) dynamic variables */
.pill-live {
    display: inline-block; font-size: .6rem; font-weight: 700; letter-spacing: .08em;
    text-transform: uppercase; vertical-align: middle; margin-left: 6px;
    padding: 2px 8px; border-radius: 999px;
    background: var(--primary-soft); color: var(--primary-dark);
}
.live-var-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.live-var {
    border: 1px solid var(--line); border-radius: var(--radius-sm);
    background: var(--primary-soft); padding: 12px 14px;
}
.live-var-name { display: inline-block; font-size: .82rem; font-weight: 600; color: var(--primary-dark); }
.live-var-desc { display: block; font-size: .74rem; color: var(--text-light); line-height: 1.45; margin-top: 4px; }
.live-var-sample { display: block; font-size: .74rem; color: var(--text); margin-top: 6px; }
@media (max-width: 640px) { .live-var-grid { grid-template-columns: 1fr; } }

/* Chat playground */
.chat-log {
    display: flex; flex-direction: column; gap: 12px;
    padding: 18px; background: var(--bg);
    border-radius: var(--radius-md); min-height: 220px;
    max-height: 420px; overflow-y: auto;
}
.chat-msg { max-width: 82%; padding: 11px 15px; border-radius: 16px; font-size: .88rem; line-height: 1.55; }
.chat-user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 5px; }
.chat-bot { align-self: flex-start; background: var(--white); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.chat-typing { align-self: flex-start; color: var(--text-light); font-size: .84rem; font-style: italic; }
.chat-time { display: block; margin-top: 5px; font-size: .66rem; opacity: .55; }

/* Inline tool call / result inside the transcript */
.tool-event {
    align-self: center; width: 100%; max-width: 82%;
    border: 1px dashed #cbd5e1; border-radius: var(--radius-sm);
    background: #f8fafc;
}
.tool-event > summary {
    cursor: pointer; padding: 8px 12px; font-size: .78rem; color: var(--text);
    display: flex; align-items: center; gap: 6px; list-style: none;
}
.tool-event > summary::-webkit-details-marker { display: none; }
.tool-event > summary code { font-size: .76rem; color: var(--primary-dark); }
.tool-body {
    margin: 0; padding: 10px 12px; border-top: 1px solid var(--line);
    font-size: .74rem; white-space: pre-wrap; word-break: break-word;
    max-height: 260px; overflow: auto;
}

/* Collapsible detail sections (Details / Insights) */
details.section { padding: 0; overflow: hidden; }
details.section > .section-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; cursor: pointer; list-style: none;
}
details.section > .section-head::-webkit-details-marker { display: none; }
details.section > .section-head h3 { margin: 0; }
.section-chevron { color: var(--text-light); transform: rotate(-90deg); transition: transform .18s; display: inline-flex; }
details.section[open] > .section-head .section-chevron { transform: rotate(90deg); }
details.section > .section-head + .card-pad { padding-top: 0; }

.row-link { cursor: pointer; }
.row-link:hover { background: var(--primary-soft); }

/* Native dialog modal (client transfer) */
dialog.modal {
    border: none; border-radius: var(--radius-md); padding: 24px;
    width: min(440px, 92vw); box-shadow: var(--shadow); color: var(--text);
}
dialog.modal::backdrop { background: rgba(15, 23, 42, .5); backdrop-filter: blur(2px); }

/* Client folder cards (the assistants landing) */
.folder-grid {
    display: grid; gap: 14px;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.folder-card {
    display: flex; align-items: center; gap: 14px; padding: 18px 18px;
    background: var(--white); border: 1px solid var(--line);
    border-radius: var(--radius-md); text-decoration: none; color: inherit;
    box-shadow: var(--shadow-sm); transition: border-color .16s, box-shadow .16s, transform .16s;
}
.folder-card:hover {
    border-color: #bcd4f8; box-shadow: var(--shadow); transform: translateY(-1px);
}
.folder-card-icon {
    flex-shrink: 0; width: 44px; height: 44px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    background: var(--primary-soft); color: var(--primary-dark);
}
.folder-card-muted .folder-card-icon { background: #f1f5f9; color: var(--text-light); }
.folder-card-name { font-weight: 700; font-size: .98rem; color: var(--dark); }
.folder-card-caret { flex-shrink: 0; color: var(--text-light); }

/* Client rows (folders) */
.client-row {
    display: flex; align-items: center; gap: 10px; padding: 8px 12px;
    border: 1px solid var(--line); border-radius: var(--radius-sm);
    background: var(--white); text-decoration: none; color: inherit;
    transition: border-color .16s, background .16s;
}
a.client-row:hover, .client-row:hover { border-color: #bcd4f8; background: #fbfdff; }
.client-row-main {
    display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0;
    text-decoration: none; color: inherit; padding: 3px 2px;
}
.client-icon {
    flex-shrink: 0; width: 34px; height: 34px; border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    background: var(--primary-soft); color: var(--primary-dark);
}

.kv-table { width: 100%; }
.kv-table td { padding: 5px 0; vertical-align: top; }
.kv-table td:first-child { width: 38%; white-space: nowrap; padding-right: 12px; }

/* Telnyx variable chips — a substituted {{variable}} shown in previews */
.var-chip {
    display: inline; padding: 1px 6px; border-radius: 6px;
    background: var(--primary-soft); color: var(--primary-dark);
    font-weight: 600; box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}
.var-chip-empty {
    background: var(--warn-soft); color: #b45309;
    font-style: italic;
}

/* Widget preview */
.widget-preview {
    border-radius: var(--radius-md); padding: 22px; min-height: 250px;
    display: flex; flex-direction: column; justify-content: flex-end;
    background: linear-gradient(135deg, #eef4ff, #f8fafc);
    border: 1px solid var(--line);
}
.widget-preview[data-theme=dark] { background: linear-gradient(135deg, #1e293b, #0f172a); }
.widget-bubble {
    background: var(--white); border-radius: 18px; padding: 16px;
    box-shadow: var(--shadow); max-width: 290px; align-self: flex-end;
}
.widget-preview[data-theme=dark] .widget-bubble { background: #1e293b; color: #e2e8f0; }

/* Live indicator */
.live-badge {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: .74rem; font-weight: 600; color: var(--text-light);
    padding: 5px 11px; border-radius: 999px; background: #f1f5f9;
}
.live-badge.on { color: #047857; background: var(--ok-soft); }

/* Search */
.search-box { position: relative; }
.search-box svg {
    position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
    width: 16px; height: 16px; color: var(--text-light); pointer-events: none;
}
.search-box input { padding-left: 40px; }
.voice-clear {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    border: none; background: none; cursor: pointer; font-size: 1.2rem; line-height: 1;
    color: var(--text-light); padding: 4px 8px; border-radius: 8px;
}
.voice-clear:hover { background: var(--primary-soft); color: var(--primary-dark); }
.voice-empty {
    padding: 22px 16px; text-align: center; font-size: .86rem; color: var(--text-light);
}
.linklike {
    border: none; background: none; padding: 0; cursor: pointer;
    color: var(--primary); font: inherit; text-decoration: underline;
}

/* Improve-with-AI controls */
.enhance-controls { display: flex; align-items: center; gap: 8px; }
.enhance-prompt {
    margin: 0; width: 260px; max-width: 46vw; font-size: .8rem;
    padding: 8px 12px;
}
@media (max-width: 640px) {
    .enhance-controls { flex-direction: column; align-items: stretch; width: 100%; }
    .enhance-prompt { width: 100%; max-width: none; }
}

/* Diff */
.diff { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.diff-pane { border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden; }
.diff-head { padding: 9px 14px; font-size: .76rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; background: var(--bg); border-bottom: 1px solid var(--line); color: var(--text-light); }
.diff-body { padding: 14px; font-size: .84rem; line-height: 1.65; white-space: pre-wrap; max-height: 320px; overflow-y: auto; }
.diff-new .diff-head { background: var(--ok-soft); color: #047857; }

/* Code block */
.code-block {
    background: var(--dark); color: #e2e8f0;
    border-radius: var(--radius-md); padding: 16px;
    overflow-x: auto; font-size: .8rem; line-height: 1.6;
}

/* Skeleton */
.skeleton {
    background: linear-gradient(90deg, #eef2f7 25%, #f8fafc 50%, #eef2f7 75%);
    background-size: 200% 100%; animation: shimmer 1.4s infinite;
    border-radius: 8px; color: transparent;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* Auth pages */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 55%, #f0f9ff 100%); }
.auth-card { width: 100%; max-width: 430px; background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 38px; }
.auth-brand { display: flex; align-items: center; gap: 11px; justify-content: center; margin-bottom: 26px; }
.auth-card h1 { font-size: 1.4rem; text-align: center; margin-bottom: 6px; }
.auth-card .sub { text-align: center; font-size: .89rem; color: var(--text-light); margin-bottom: 26px; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 46px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; color: var(--text-light); padding: 8px; border-radius: 8px; }
.pw-toggle:hover { color: var(--primary); }

/* Utilities */
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-end { margin-left: auto; }
.muted { color: var(--text-light); }
.small { font-size: .82rem; }
.tiny { font-size: .75rem; }
.strong { font-weight: 600; color: var(--dark); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.hidden { display: none !important; }
.divider { height: 1px; background: var(--line); margin: 22px 0; }

/* Inline notice / disclaimer box */
.notice {
    border: 1px solid var(--line); border-radius: var(--radius-sm);
    padding: 11px 14px; font-size: .8rem; line-height: 1.5; color: var(--text);
}
.notice-cost { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.sticky-actions {
    position: sticky; bottom: 0; z-index: 10;
    background: rgba(255, 255, 255, .94); backdrop-filter: blur(8px);
    border-top: 1px solid var(--line);
    padding: 14px 24px; margin: 24px -24px -24px;
    border-radius: 0 0 var(--radius) var(--radius);
    display: flex; gap: 10px; align-items: center;
}

/* ----------------------------------------------------------- responsive -- */

@media (max-width: 1024px) {
    .diff { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    .sidebar.open { transform: none; }
    .main { margin-left: 0; }
    .mobile-toggle { display: inline-grid; place-items: center; }
    .content { padding: 20px 16px; }
    .topbar { padding: 0 16px; }
}

@media (max-width: 680px) {
    h1 { font-size: 1.4rem; }
    .card-pad, .card-head { padding: 18px; }
    .assistant-grid { grid-template-columns: 1fr; }
    .kv-row { grid-template-columns: 1fr; }
    .field-row { grid-template-columns: 1fr; }
    .tabs { display: none; }
    .tab-select { display: block; margin: 16px 0; }
    .sticky-actions { margin: 20px -18px -18px; padding: 12px 18px; flex-wrap: wrap; }
    .toasts { top: auto; bottom: 16px; left: 16px; right: 16px; max-width: none; }
    .modal { padding: 22px; }
    .chat-msg { max-width: 90%; }
}

@media print {
    .sidebar, .topbar, .toasts, .sticky-actions { display: none !important; }
    .main { margin-left: 0; }
}

/* ==========================================================================
   Tools, voice filters and analysis
   ========================================================================== */

/* Preview of what a caller actually hears, with variables substituted. */
.preview-box {
    padding: 11px 14px; border-radius: var(--radius-sm);
    background: var(--primary-soft); border: 1px solid #dbeafe;
    font-size: .88rem; line-height: 1.6; color: var(--dark);
}
.preview-label {
    display: block; font-size: .68rem; font-weight: 700; letter-spacing: .07em;
    text-transform: uppercase; color: var(--primary-dark); margin-bottom: 4px;
}

/* Voice filter chips */
.voice-filters { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.filter-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.filter-label {
    font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
    color: var(--text-light); min-width: 68px;
}
.chip {
    padding: 5px 12px; border-radius: 999px; cursor: pointer;
    border: 1px solid var(--line); background: var(--white);
    font-family: inherit; font-size: .8rem; font-weight: 600; color: var(--text);
    transition: background .16s, color .16s, border-color .16s;
}
.chip:hover { border-color: #bcd4f8; background: var(--primary-soft); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip-count { opacity: .6; font-weight: 500; }

/* Tool rows */
.tool-row {
    display: flex; align-items: center; gap: 12px;
    padding: 13px 15px; border: 1px solid var(--line);
    border-radius: var(--radius-md); background: var(--white);
}
.tool-icon {
    width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0;
    background: var(--primary-soft); color: var(--primary-dark);
    display: grid; place-items: center;
}

/* Combo box for attaching an existing tool */
.combo { position: relative; }
.combo-list {
    margin-top: 8px; border: 1px solid var(--line); border-radius: var(--radius-md);
    max-height: 300px; overflow-y: auto; background: var(--white);
    box-shadow: var(--shadow-sm);
}
.combo-item {
    display: flex; align-items: center; gap: 12px; width: 100%;
    padding: 11px 14px; border: none; border-bottom: 1px solid #f1f5f9;
    background: none; cursor: pointer; font-family: inherit; text-align: left;
    transition: background .14s;
}
.combo-item:last-child { border-bottom: none; }
.combo-item:hover { background: var(--primary-soft); }
.combo-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.combo-main strong { font-size: .88rem; color: var(--dark); }
.combo-add {
    font-size: .76rem; font-weight: 700; color: var(--primary);
    padding: 4px 11px; border-radius: 999px; background: var(--primary-soft);
    flex-shrink: 0;
}
.combo-empty { padding: 16px; font-size: .85rem; color: var(--text-light); text-align: center; }

/* Slide-over drawer for the tool builder */
.drawer-backdrop {
    position: fixed; inset: 0; z-index: 2050;
    background: rgba(15, 23, 42, .5); backdrop-filter: blur(3px);
    display: none; justify-content: flex-end;
}
.drawer-backdrop.open { display: flex; animation: fade .18s ease; }
.drawer {
    width: min(680px, 100%); background: var(--white);
    display: flex; flex-direction: column;
    box-shadow: var(--shadow-lg); animation: slide-over .26s cubic-bezier(.4, 0, .2, 1);
}
@keyframes slide-over { from { transform: translateX(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer-head {
    display: flex; align-items: center; gap: 12px;
    padding: 18px 22px; border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.drawer-head h3 { margin: 0; }
.drawer-body { padding: 22px; overflow-y: auto; flex: 1; }
.drawer-foot {
    display: flex; align-items: center; gap: 10px;
    padding: 16px 22px; border-top: 1px solid var(--line);
    background: var(--bg); flex-shrink: 0;
}

/* Builder / JSON segmented control */
.seg { display: inline-flex; background: var(--bg); border-radius: 999px; padding: 3px; gap: 2px; }
.seg-btn {
    padding: 6px 15px; border-radius: 999px; border: none; cursor: pointer;
    background: none; font-family: inherit; font-size: .82rem; font-weight: 600;
    color: var(--text-light); transition: background .16s, color .16s;
}
.seg-btn.active { background: var(--white); color: var(--dark); box-shadow: var(--shadow-sm); }

/* Analysis */
.spark { display: flex; align-items: flex-end; gap: 4px; height: 90px; }
.spark-bar { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.spark-bar span {
    width: 100%; min-height: 3px; border-radius: 4px 4px 0 0;
    background: linear-gradient(180deg, var(--accent), var(--primary));
    transition: opacity .16s;
}
.spark-bar:hover span { opacity: .75; }

.call-row {
    display: flex; align-items: center; gap: 11px; width: 100%;
    padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
    background: var(--white); cursor: pointer; font-family: inherit;
    transition: border-color .16s, background .16s;
}
.call-row:hover { border-color: #bcd4f8; background: #fbfdff; }
.call-row.active { border-color: var(--primary); background: var(--primary-soft); }
.call-dot {
    width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
    background: var(--text-light);
}
.call-dot.ok { background: var(--ok); }

@media (max-width: 680px) {
    .drawer { width: 100%; }
    .filter-label { min-width: 100%; }
}

/* Impersonation bar — shown to an admin testing as a reseller. Amber so it
   reads as a temporary, elevated state distinct from the normal chrome. */
.impersonate-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 20px;
    background: var(--warn);
    color: #3b2600;
    font-size: .9rem;
}
.impersonate-msg {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.impersonate-msg strong { font-weight: 700; }
.impersonate-exit {
    background: #3b2600;
    color: #fff;
    border: none;
}
.impersonate-exit:hover { background: #000; }
