/* ==========================================================================
   Beacon — design tokens + components.
   Every color / surface / border / shadow flows through CSS custom properties
   so light + dark themes stay 1:1. NEVER hard-code a hex outside :root.
   ========================================================================== */

:root {
    /* Brand */
    --brand-1: #6366f1;        /* indigo-500 */
    --brand-2: #8b5cf6;        /* violet-500 */
    --brand-grad: linear-gradient(135deg, var(--brand-1) 0%, var(--brand-2) 100%);

    /* Neutrals — light */
    --bg:           #f6f7fb;
    --surface:      #ffffff;
    --surface-2:    #f3f4f9;
    --surface-3:    #e9ebf3;
    --border:       #e3e6ee;
    --border-strong:#cdd1dd;
    --text:         #0f172a;     /* slate-900 */
    --text-2:       #334155;     /* slate-700 */
    --text-muted:   #64748b;     /* slate-500 */
    --text-on-accent: #ffffff;

    /* Accent (interactive) */
    --accent:        #6366f1;
    --accent-hover:  #4f46e5;
    --accent-soft:   #eef0ff;
    --accent-ring:   rgba(99, 102, 241, .25);

    /* Status colors */
    --success:       #10b981;
    --success-bg:    #d1fae5;
    --success-text:  #065f46;
    --danger:        #ef4444;
    --danger-bg:     #fee2e2;
    --danger-text:   #991b1b;
    --warning:       #f59e0b;
    --warning-bg:    #fef3c7;
    --warning-text:  #92400e;
    --info-bg:       #dbeafe;
    --info-text:     #1e40af;

    /* Inbound/outbound bubble surfaces */
    --bubble-in-bg:  #ffffff;
    --bubble-in-fg:  var(--text);
    --bubble-out-bg: var(--brand-grad);
    --bubble-out-fg: #ffffff;

    /* Shadow + radius + motion */
    --shadow-sm: 0 1px 2px rgba(15,23,42,.04);
    --shadow:    0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
    --shadow-md: 0 4px 14px -2px rgba(15,23,42,.10);
    --shadow-lg: 0 12px 32px -8px rgba(15,23,42,.18);
    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius:    12px;
    --radius-lg: 16px;
    --radius-pill: 999px;
    --ease: cubic-bezier(.2,.6,.2,1);
    --dur-fast: 120ms;
    --dur:      180ms;
}

html[data-theme="dark"] {
    --bg:           #0a0f1f;
    --surface:      #121829;
    --surface-2:    #182039;
    --surface-3:    #1f2748;
    --border:       #232c4a;
    --border-strong:#2e3a63;
    --text:         #e6eaf2;
    --text-2:       #c0c8d9;
    --text-muted:   #8b94aa;

    --accent:        #818cf8;
    --accent-hover:  #a5b1ff;
    --accent-soft:   #1c2347;
    --accent-ring:   rgba(129, 140, 248, .30);

    --success-bg:    #064e3b;
    --success-text:  #6ee7b7;
    --danger-bg:     #4c1d1d;
    --danger-text:   #fecaca;
    --warning-bg:    #4b2e0d;
    --warning-text:  #fcd34d;
    --info-bg:       #1e3a8a;
    --info-text:     #bfdbfe;

    --bubble-in-bg:  var(--surface-2);
    --bubble-in-fg:  var(--text);

    --shadow-sm: 0 1px 2px rgba(0,0,0,.45);
    --shadow:    0 1px 3px rgba(0,0,0,.5);
    --shadow-md: 0 4px 14px -2px rgba(0,0,0,.55);
    --shadow-lg: 0 12px 32px -8px rgba(0,0,0,.7);
}

/* ----- Reset + base ------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0;
    min-height: 100%;
    overflow-x: hidden;   /* last-resort: anything overflowing horizontally is clipped, not scrolled */
}
body {
    font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
.hidden { display: none !important; }
.center { text-align: center; }

/* ----- App shell ---------------------------------------------------------- */
.app {
    max-width: 1280px;
    margin: 0 auto;
    padding: 20px;
    display: grid;
    gap: 16px;
    min-width: 0;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* ----- Top bar ------------------------------------------------------------ */
.bar {
    position: sticky; top: 0; z-index: 50;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 16px;
    padding: 12px 18px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo-dot {
    width: 14px; height: 14px; border-radius: 5px;
    background: var(--brand-grad);
    box-shadow: 0 0 14px 1px color-mix(in srgb, var(--brand-1) 45%, transparent);
    flex-shrink: 0;
}
.bar h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.015em;
    background: var(--brand-grad);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.subtitle {
    color: var(--text-muted);
    font-size: 12px;
    margin-left: 4px;
    white-space: nowrap;
}

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

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

/* ----- Status pill -------------------------------------------------------- */
.status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px 6px 10px;
    border-radius: var(--radius-pill);
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--border);
    max-width: 260px;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.status::before {
    content: "";
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}
.status.connected {
    background: var(--success-bg);
    color: var(--success-text);
    border-color: color-mix(in srgb, var(--success) 30%, transparent);
}
.status.connected::before {
    background: var(--success);
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 60%, transparent);
    animation: pulse-dot 2s var(--ease) infinite;
}
.status.error {
    background: var(--danger-bg);
    color: var(--danger-text);
    border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}
.status.error::before { background: var(--danger); }
@keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 55%, transparent); }
    50%      { box-shadow: 0 0 0 7px transparent; }
}

/* ----- Pill controls (device chip, session picker) ----------------------- */
.device-chip {
    display: inline-flex; align-items: center; gap: 6px;
    height: 32px;
    padding: 0 12px;
    border-radius: var(--radius-pill);
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    max-width: 200px;
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.device-chip:hover { background: var(--surface-3); border-color: var(--border-strong); }
.device-chip .ic { width: 13px; height: 13px; opacity: .6; flex-shrink: 0; }
.device-chip > span {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    max-width: 140px;
}

.session-picker {
    display: inline-flex; align-items: center; gap: 8px;
    height: 32px;
    padding: 0 6px 0 12px;
    border-radius: var(--radius-pill);
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 12px;
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.session-picker:hover { background: var(--surface-3); border-color: var(--border-strong); }
.session-picker:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}
.session-picker .field-label {
    color: var(--text-muted);
    font-size: 11px;
    letter-spacing: .04em;
    text-transform: uppercase;
    margin: 0;
}
.session-picker select {
    height: auto;
    border: 0;
    background-color: transparent;
    color: var(--text);
    font: inherit;
    font-size: 12px;
    max-width: 180px;
    padding: 4px 22px 4px 4px;
    background-position: right 4px center;
    background-size: 14px 14px;
    cursor: pointer;
}
.session-picker select:hover, .session-picker select:focus { box-shadow: none; }

/* ----- Buttons ------------------------------------------------------------ */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 8px;
    height: 40px;
    padding: 0 18px;
    min-width: 100px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-weight: 500;
    font-size: 13.5px;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
                color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease),
                box-shadow var(--dur) var(--ease);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:not(:disabled):hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:not(:disabled):active { transform: translateY(1px); }

.btn.primary {
    background: var(--brand-grad);
    color: var(--text-on-accent);
    border-color: transparent;
    box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--brand-1) 55%, transparent);
}
/* Re-declare background here so the base `.btn:not(:disabled):hover` rule
   doesn't override the gradient and turn the button into a white-on-white block. */
.btn.primary:not(:disabled):hover {
    background: var(--brand-grad);
    border-color: transparent;
    filter: brightness(1.08);
    box-shadow: 0 10px 22px -6px color-mix(in srgb, var(--brand-1) 60%, transparent);
}
.btn.primary:not(:disabled):active { filter: brightness(.96); }

.btn.danger {
    background: var(--danger);
    color: var(--text-on-accent);
    border-color: transparent;
}
.btn.danger:not(:disabled):hover {
    background: color-mix(in srgb, var(--danger) 88%, black);
    border-color: transparent;
    color: var(--text-on-accent);
}

/* Compose-row action buttons: same fixed min-width so swapping
   label text (Intercept↔Release, Mute↔Unmute) doesn't reflow the row. */
.actions .btn { min-width: 104px; }
.actions .btn[data-flex="auto"] { min-width: 0; }
.actions { flex-wrap: wrap; }

/* Icon-only buttons */
.icon-btn {
    width: 40px; height: 40px;
    padding: 0;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    display: inline-grid;
    place-items: center;
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
                border-color var(--dur-fast) var(--ease);
    min-width: 0;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.icon-btn.danger:hover { color: var(--danger); }

/* ----- Icons -------------------------------------------------------------- */
.ic {
    width: 16px; height: 16px;
    fill: none; stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round; stroke-linejoin: round;
    flex-shrink: 0;
}
.icon-btn .ic { width: 18px; height: 18px; }

/* ----- Fields ------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
}
input[type="text"], select, textarea {
    height: 40px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease),
                background var(--dur-fast) var(--ease);
    width: 100%;
}
textarea {
    height: auto; padding: 12px 14px;
    min-height: 72px;
    resize: vertical;
    line-height: 1.5;
}
input[type="text"]:hover, select:hover, textarea:hover {
    border-color: var(--border-strong);
    background: var(--surface);
}
input[type="text"]:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-ring);
}
input[type="text"]::placeholder, textarea::placeholder {
    color: var(--text-muted);
    opacity: .7;
}

/* ----- Custom <select> ---------------------------------------------------
   Native chrome stripped; one stable chevron via background-image. We do NOT
   swap the chevron on hover/focus — that produced a visible flicker. The
   border + focus ring carry the interactive feedback instead.
   --------------------------------------------------------------------- */
select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding-right: 38px;
    font-weight: 500;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px 16px;
    text-overflow: ellipsis;
}
select::-ms-expand { display: none; }

html[data-theme="dark"] select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b94aa' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

/* OS-rendered option list — most styling is browser-locked, but colours
   propagate in Chrome/Edge when set here. Safari ignores; that's fine. */
option {
    background: var(--surface);
    color: var(--text);
    padding: 8px 12px;
    font-weight: 400;
}
option:checked, option:hover { background: var(--accent-soft); color: var(--accent); }
option[disabled] { color: var(--text-muted); }

/* ----- Composer ----------------------------------------------------------- */
.composer { padding: 16px 18px; }
.composer-row {
    display: grid;
    grid-template-columns: minmax(180px, 1.2fr) minmax(160px, 1fr) auto;
    gap: 14px;
    align-items: end;
}
.actions {
    display: flex; gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
}
.hint-bar {
    margin-top: 12px;
    padding: 10px 12px;
    background: var(--warning-bg);
    color: var(--warning-text);
    border-left: 3px solid var(--warning);
    border-radius: var(--radius-xs);
    font-size: 13px;
    line-height: 1.5;
}
.audio-row {
    display: flex; gap: 16px;
    margin-top: 12px;
    flex-wrap: wrap;
}
.field-inline {
    display: flex; align-items: center; gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}
.field-inline select {
    height: 30px;
    padding: 0 28px 0 10px;
    font-size: 12px;
    background-position: right 8px center;
    background-size: 14px 14px;
    min-width: 140px;
}

/* ----- Chat layout -------------------------------------------------------- */
.chat {
    display: grid;
    grid-template-columns: 300px 1fr;
    min-height: 540px;
    overflow: hidden;
}
.conversations {
    padding: 16px;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    background: var(--surface);
    max-height: 720px;
}
.conversations h2, .call-log h2 {
    margin: 0 0 12px;
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 600;
}
.conversations ul, .call-log ul { list-style: none; margin: 0; padding: 0; }
.conversations li {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-bottom: 4px;
    border: 1px solid transparent;
    transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.conversations li:hover { background: var(--surface-2); }
.conversations li.active {
    background: var(--accent-soft);
    border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}
.conv-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; min-width: 0; }
.conv-pair {
    font-weight: 500; font-size: 13px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    color: var(--text);
}
.conv-last {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-left: 36px;
}
.avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(15,23,42,.18);
}

/* ----- Messages thread ---------------------------------------------------- */
.messages {
    display: flex;
    flex-direction: column;
    padding: 16px;
    min-height: 100%;
    gap: 12px;
    min-width: 0;
}
.msg-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 4px;
    min-height: 28px;
    color: var(--text-muted);
    font-size: 12px;
}
.msg-list {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    max-height: 480px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.msg {
    padding: 9px 13px;
    border-radius: 14px;
    max-width: 72%;
    word-wrap: break-word;
    line-height: 1.45;
    box-shadow: var(--shadow-sm);
    font-size: 13.5px;
}
.msg.in {
    background: var(--bubble-in-bg);
    color: var(--bubble-in-fg);
    border: 1px solid var(--border);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.msg.out {
    background: var(--bubble-out-bg);
    color: var(--bubble-out-fg);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.msg .meta {
    font-size: 10px;
    opacity: .75;
    margin-bottom: 4px;
    font-variant-numeric: tabular-nums;
}
.msg .media { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.msg .media a {
    display: inline-block; padding: 4px 8px;
    background: rgba(255,255,255,.22); border-radius: 4px;
    font-size: 12px; color: inherit; text-decoration: none;
}
.msg.in .media a {
    background: var(--surface-3);
    color: var(--accent);
}
.msg img {
    max-width: 240px;
    max-height: 240px;
    border-radius: 8px;
    display: block;
    cursor: zoom-in;
}
.msg .status {
    font-size: 10px;
    opacity: .85;
    margin-top: 5px;
    display: inline-flex;
    gap: 4px;
    align-items: center;
}
.msg .status .ic { width: 12px; height: 12px; stroke-width: 2.5; }
.msg.out .status.delivered { color: #d1fae5; }
.msg.out .status.failed, .msg.out .status.undelivered { color: #fecaca; }

/* ----- Send form ---------------------------------------------------------- */
.send-form { display: flex; flex-direction: column; gap: 10px; }
.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.dropzone.drag {
    border-color: var(--accent);
    background: var(--accent-soft);
}
.dropzone-inner {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 16px;
    color: var(--text-muted);
    font-size: 13px;
}
.dz-icon { width: 24px; height: 24px; color: var(--text-muted); flex-shrink: 0; }
.dropzone.drag .dz-icon { color: var(--accent); }
.dz-link {
    color: var(--accent);
    text-decoration: underline;
    cursor: pointer;
}
.file-preview {
    list-style: none;
    margin: 0;
    padding: 0 14px 12px;
    display: flex; flex-wrap: wrap; gap: 8px;
}
.file-preview:empty { display: none; }
.file-chip {
    display: flex; align-items: center; gap: 6px;
    padding: 5px 9px 5px 5px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    font-size: 12px;
    color: var(--text);
}
.file-chip img {
    width: 28px; height: 28px;
    object-fit: cover;
    border-radius: 50%;
}
.file-chip .placeholder-icon {
    width: 28px; height: 28px;
    display: grid; place-items: center;
    background: var(--surface-2); border-radius: 50%;
    color: var(--text-muted);
}
.file-chip .name {
    max-width: 160px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-chip .size { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.file-chip .remove {
    cursor: pointer; border: 0; background: transparent;
    padding: 0; width: 22px; height: 22px;
    border-radius: 50%;
    color: var(--text-muted);
    display: inline-grid; place-items: center;
}
.file-chip .remove:hover { color: var(--danger); background: var(--surface-2); }
.send-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: end;     /* button anchors at bottom edge of growing textarea */
}
/* Send button sits at the bottom-right of the textarea and keeps its
   designed height — earlier `height: auto + align-self: stretch` made it
   into a tall awkward bar with no visible padding. */
.send-row button {
    height: 44px;
    min-width: 120px;
    padding: 0 24px;
    font-size: 14px;
}
.send-row button .ic { width: 18px; height: 18px; }

/* ----- Call log ----------------------------------------------------------- */
.call-log { padding: 16px 18px; position: relative; }
.call-log li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: 100px 1fr auto auto;
    gap: 12px;
    font-size: 13px;
    align-items: center;
    color: var(--text);
}
.call-log li:last-child { border-bottom: 0; }
.call-log .kind {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: .04em;
    padding: 4px 8px;
    border-radius: var(--radius-xs);
    text-align: center;
    background: var(--surface-2);
    color: var(--text-2);
}
.call-log .kind.incoming { background: var(--info-bg);    color: var(--info-text); }
.call-log .kind.outgoing { background: var(--success-bg); color: var(--success-text); }
.call-log .kind.error    { background: var(--danger-bg);  color: var(--danger-text); }
.call-log .kind.answered { background: var(--warning-bg); color: var(--warning-text); }
.call-log .kind.ended    { background: var(--surface-3);  color: var(--text-muted); }
.call-log .sid {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 11px;
    color: var(--text-muted);
}

/* ----- Misc --------------------------------------------------------------- */
.hint { color: var(--text-muted); font-style: italic; font-size: 13px; }
.empty {
    text-align: center;
    color: var(--text-muted);
    padding: 28px 12px;
}
.empty-icon {
    width: 32px; height: 32px;
    margin: 0 auto 8px;
    color: var(--accent);
    opacity: .65;
}
.empty-icon svg { width: 100%; height: 100%; }
.empty-sub { font-size: 12px; opacity: .85; margin-top: 4px; }

.timer {
    margin-left: 6px;
    font-variant-numeric: tabular-nums;
    background: rgba(255,255,255,.18);
    padding: 1px 6px;
    border-radius: var(--radius-xs);
    font-size: 12px;
}

/* ----- DTMF keypad overlay ------------------------------------------------ */
.keypad-overlay {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.55);
    display: grid; place-items: center;
    z-index: 100;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.keypad {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    width: min(320px, 92vw);
    box-shadow: var(--shadow-lg);
}
.keypad-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 12px;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
}
.keypad-display {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 14px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 18px;
    color: var(--text);
    text-align: right;
    min-height: 24px;
    word-break: break-all;
}
.keypad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.key {
    height: 56px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 22px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
    font-family: inherit;
}
.key:hover { background: var(--surface-2); }
.key:active { transform: scale(.96); background: var(--accent); color: var(--text-on-accent); border-color: transparent; }

/* ----- Webhook drawer ----------------------------------------------------- */
.webhook-drawer {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: min(620px, 95vw);
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    z-index: 90;
    display: flex; flex-direction: column;
    transform: translateX(0);
    transition: transform var(--dur) var(--ease);
}
.webhook-drawer.hidden {
    transform: translateX(100%);
    display: flex !important;
    pointer-events: none;
}
.drawer-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}
.drawer-head h2 { margin: 0; font-size: 14px; font-weight: 600; }
.webhook-list {
    list-style: none; margin: 0; padding: 14px;
    overflow-y: auto; flex: 1;
}
.webhook-list li {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    background: var(--surface-2);
    font-size: 12px;
    color: var(--text);
}
.webhook-list .wh-head {
    display: flex; justify-content: space-between;
    margin-bottom: 6px;
    font-weight: 600;
}
.webhook-list .wh-path { color: var(--accent); }
.webhook-list pre {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    padding: 8px;
    margin: 4px 0;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 11px;
    max-height: 180px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-2);
}

/* ----- Toasts ------------------------------------------------------------- */
.toast-host {
    position: fixed; bottom: 20px; right: 20px;
    display: flex; flex-direction: column; gap: 8px;
    z-index: 9998;
    pointer-events: none;
}
.toast {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 11px 14px;
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    min-width: 260px; max-width: 380px;
    opacity: 0; transform: translateY(8px);
    transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
    pointer-events: auto;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-warning { border-left-color: var(--warning); }
.toast-error   { border-left-color: var(--danger); }
.toast-info    { border-left-color: var(--accent); }

/* ----- Modal -------------------------------------------------------------- */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}
.modal-backdrop.hidden { display: none; }
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 24px;
    width: min(440px, 92vw);
}
.modal h2 { margin: 0 0 8px; font-size: 16px; color: var(--text); }
.modal-hint { margin: 0 0 16px; color: var(--text-muted); font-size: 13px; }
.modal input[type="text"] { width: 100%; }
.modal-actions {
    display: flex; gap: 8px; justify-content: flex-end;
    margin-top: 16px;
}

/* ----- Clean-logs split --------------------------------------------------- */
.cleanlogs-split { position: relative; display: inline-flex; }
.cleanlogs-split > .btn {
    height: 32px;
    padding: 0 12px;
    font-size: 12px;
    min-width: 0;
}
.cleanlogs-split > #cleanlogs-current {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}
.cleanlogs-split > #cleanlogs-menu-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    padding: 0;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-left: 0;
}
.cleanlogs-menu {
    position: absolute; top: calc(100% + 6px); right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: 4px;
    display: flex; flex-direction: column;
    min-width: 200px;
    max-width: calc(100vw - 28px);
    z-index: 100;
}
.cleanlogs-menu.hidden { display: none; }
.cleanlogs-menu button {
    background: transparent; border: 0; color: var(--text);
    text-align: left; padding: 8px 10px;
    font: inherit; font-size: 13px;
    border-radius: var(--radius-xs); cursor: pointer;
}
.cleanlogs-menu button:hover:not(:disabled) { background: var(--surface-2); }
.cleanlogs-menu button:disabled { color: var(--text-muted); cursor: not-allowed; }

/* ----- Protected number style in From dropdown ---------------------------- */
.from-protected { color: var(--text-muted); }

/* ----- Focus rings -------------------------------------------------------- */
:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-ring);
    border-radius: var(--radius-sm);
}

/* ============================================================================
   Responsive — tablet ≤980, phone ≤640
   ========================================================================== */

@media (max-width: 980px) {
    .app { padding: 14px; gap: 12px; }
    .bar {
        grid-template-columns: 1fr auto;
        gap: 10px;
    }
    .bar-mid {
        grid-column: 1 / -1;
        order: 3;
        flex-wrap: wrap;
        justify-content: flex-start;
    }
    .subtitle { display: none; }
    .composer-row {
        grid-template-columns: 1fr 1fr;
    }
    .actions {
        grid-column: 1 / -1;
        justify-content: flex-start;
        flex-wrap: wrap;
    }
    .chat { grid-template-columns: 240px 1fr; }
    .status { max-width: 200px; }
}

@media (max-width: 640px) {
    .app { padding: 10px; gap: 10px; }
    .bar { padding: 10px 12px; border-radius: var(--radius-sm); }
    .bar h1 { font-size: 16px; }
    .composer { padding: 14px; }
    .composer-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    .actions { gap: 6px; }
    .actions .btn { min-width: 0; flex: 1 1 calc(50% - 6px); padding: 0 12px; }
    .actions .btn span:not(.timer) { font-size: 12px; }
    .chat { grid-template-columns: 1fr; }
    .conversations {
        border-right: 0;
        border-bottom: 1px solid var(--border);
        max-height: 200px;
    }
    .msg-list { max-height: 380px; }
    .send-row { grid-template-columns: 1fr; gap: 8px; }
    .send-row button { width: 100%; min-width: 0; }
    .call-log { padding: 14px; }
    .call-log li {
        grid-template-columns: auto 1fr;
        grid-template-rows: auto auto;
        row-gap: 4px;
    }
    .call-log li .kind { grid-row: 1; grid-column: 1; }
    .call-log li > *:not(.kind):not(.sid) { grid-row: 1; grid-column: 2; }
    .call-log .sid { grid-row: 2; grid-column: 1 / -1; }
    .toast-host { left: 10px; right: 10px; bottom: 10px; }
    .toast { min-width: 0; max-width: none; }
    .device-chip { max-width: 100%; }
    .device-chip > span { max-width: 100px; }
    .session-picker { max-width: 100%; }
    .session-picker select { max-width: 130px; }
    .status { max-width: 100%; }

    /* Cleanlogs menu must stay inside the viewport. Anchor to the left edge
       of its trigger (not the right) and clamp width to the visible area. */
    .cleanlogs-menu {
        right: auto;
        left: 0;
        min-width: 0;
        width: max-content;
        max-width: calc(100vw - 28px);
    }
}

/* Reduce motion for users who request it */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
    }
}

/* Conv-list: media-only message preview ("N attachment(s)") */
.conv-last-media {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-style: italic;
}
.conv-last-media .ic { width: 13px; height: 13px; opacity: .75; }
