* { box-sizing: border-box; }

:root {
    --bg: #e9eaec; /* Light gray outer background to make the white app pop */
    --panel: #ffffff; /* Crisp white for the main app background */
    --panel2: #f0f2f5; /* Soft gray for inputs and assistant bubbles */
    --text: #1c1e21; /* Dark text for readability */
    --muted: #65676b; /* Medium gray for labels and timestamps */
    --border: #ccd0d5; /* Light subtle borders */
    --accent: #ff6699; /* Your vibrant pink */
    --accent-hover: #ff4d88;
    --danger: #ef4444;
    --success: #22c55e;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px; 
}

/* --- Centered App Container --- */
.app-wrapper {
    width: 100%;
    max-width: 1100px;
    height: 100%;
    max-height: 850px;
    display: grid;
    grid-template-rows: auto 1fr auto;
    border-radius: 12px;
    overflow: hidden;
    /* Softer shadow for light mode */
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
    border: 1px solid var(--border);
    background: var(--border); 
}

/* Thinking animation */
.thinking-bubble {
    opacity: 0.7;
    font-style: italic;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { opacity: 0.4; }
    50% { opacity: 0.8; }
    100% { opacity: 0.4; }
}

/* ===== Top bar ===== */
.topbar {
    padding: 12px 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.topbar h1 { margin: 0; font-size: 16px; font-weight: 600; color: var(--text); }
.status { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
    background: var(--panel2);
    border: 1px solid var(--border);
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    color: var(--muted);
}
.pill.on { color: var(--success); border-color: var(--success); background: #f0fdf4; }
.pill.err { color: var(--danger); border-color: var(--danger); background: #fef2f2; }

/* ===== Layout grid ===== */
.grid {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1px;
    overflow: hidden;
}
.panel {
    background: var(--panel);
    padding: 20px;
    overflow-y: auto;
}
.panel h2 {
    margin: 0 0 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
}
.panel label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 12px;
    font-weight: 500;
}
.panel input, .panel pre {
    width: 100%;
    background: var(--panel2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 13px;
    margin-top: 6px;
    font-family: inherit;
    outline: none;
    transition: all 0.2s;
}
.panel input:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px rgba(255, 102, 153, 0.15); }
.panel pre {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    white-space: pre-wrap;
    max-height: 140px;
    overflow: auto;
    margin: 0 0 10px;
}
hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* --- Beautiful Language Selector --- */
.lang-label {
    display: flex;
    flex-direction: column;
    margin-bottom: 20px;
    font-family: inherit;
}

.lang-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
    margin-bottom: 8px;
    font-weight: 500;
}

.beautiful-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    width: 100%;
    padding: 10px 40px 10px 12px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text);
    background-color: var(--panel2);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    
    /* Updated SVG Arrow color to match dark text (%2365676b = #65676b) */
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%2365676b%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 12px top 50%;
    background-size: 12px auto;
}

.beautiful-select:focus {
    outline: none;
    border-color: var(--accent);
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(255, 102, 153, 0.15); 
}

/* ===== Buttons ===== */
.btn-row { display: flex; gap: 8px; }
button {
    background: var(--panel2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    flex: 1;
    transition: all 0.15s;
    font-family: inherit;
    font-weight: 500;
}
button:hover:not(:disabled) { border-color: var(--accent); background: #fff; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: white; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.danger:hover:not(:disabled) { background: var(--danger); color: white; border-color: var(--danger); }

.mic-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin: 10px 0;
    background: var(--panel2);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 12px;
    color: var(--muted);
    transition: border-color 0.15s ease, color 0.15s ease;
}
.mic-indicator .dot {
    flex: 0 0 auto;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
    transition: background 0.15s ease;
}
.mic-indicator.speaking {
    color: var(--text);
    border-color: var(--success);
}
.mic-indicator.speaking .dot {
    background: var(--success);
    animation: pulse-dot 1.1s infinite;
}
@keyframes pulse-dot {
    0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
    70%  { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* ===== Chat (Boxy Messenger Style) ===== */
/* ===== Chat (Boxy Messenger Style) ===== */
.chat-panel { 
    display: flex; 
    flex-direction: column; 
    background: var(--panel);
    /* NEW: Force the panel to stay within the grid bounds */
    min-height: 0; 
    overflow: hidden; 
}

.command-activity {
    flex: 0 0 auto;
    margin: 14px 20px 0;
    padding: 12px;
    max-height: 245px;
    overflow: auto;
    border: 1px solid #f59e0b;
    border-radius: 8px;
    background: #fffbeb;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
}
.command-activity[hidden] { display: none; }
.command-activity-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}
.command-activity-heading h2 {
    margin: 0;
    color: #92400e;
    font-size: 11px;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.command-live-badge {
    padding: 2px 7px;
    border-radius: 999px;
    background: #f59e0b;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
}
.command-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.command-entry {
    padding: 9px 10px;
    border: 1px solid #fcd34d;
    border-radius: 6px;
    background: #fff;
}
.command-entry.latest {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(255, 102, 153, .14);
    animation: command-arrival .65s ease-out;
}
.command-name {
    display: inline-block;
    margin-bottom: 6px;
    color: #9f1239;
    font: 700 12px ui-monospace, SFMono-Regular, Consolas, monospace;
}
.command-payload {
    margin: 0;
    color: #3f3f46;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font: 11px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace;
}
@keyframes command-arrival {
    0% { transform: translateY(-5px); opacity: .35; background: #fef3c7; }
    100% { transform: translateY(0); opacity: 1; background: #fff; }
}

.chat { 
    flex: 1; 
    overflow-y: auto; 
    padding: 20px; 
    display: flex;
    flex-direction: column;
    gap: 8px;
    /* NEW: Ensure scrollbar works smoothly */
    min-height: 0; 
}
.response-latency {
    display: block;
    margin-top: 6px;
    color: #71717a;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}
.bubble {
    max-width: 75%;
    padding: 10px 16px;
    border-radius: 8px; 
    font-size: 14.5px;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
    width: fit-content;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.bubble.user {
    align-self: flex-end;
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 2px; 
}
.bubble.assistant {
    align-self: flex-start;
    background: var(--panel2);
    border: 1px solid var(--border);
    color: var(--text);
    border-bottom-left-radius: 2px; 
}

/* Chat Input */
.chat-input { 
    display: flex; 
    gap: 10px; 
    padding: 15px 20px; 
    background: var(--panel); 
    border-top: 1px solid var(--border); 
}
.chat-input input { 
    flex: 1; 
    border-radius: 6px; 
    padding: 12px 16px;
    background: var(--panel2);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
}
.chat-input input:focus {
    border-color: var(--accent);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(255, 102, 153, 0.15);
}
.chat-input button { 
    flex: 0 0 auto; 
    padding: 0 24px;
    font-weight: 600;
}

/* ===== Logs ===== */
.logs {
    background: #f8f9fa; /* Slightly off-white for distinction */
    border-top: 1px solid var(--border);
    padding: 12px 20px;
    max-height: 140px;
    overflow: auto;
}
.logs h2 { margin: 0 0 6px; font-size: 10px; text-transform: uppercase; color: var(--muted); }
.logs pre { margin: 0; font-family: ui-monospace, monospace; font-size: 11px; color: var(--muted); white-space: pre-wrap; }

/* ===== Mobile: Reverts to full screen ===== */
@media (max-width: 760px) {
    body {
        padding: 0;
        display: block;
        height: auto;
        min-height: 100vh;
    }
    .app-wrapper {
        border-radius: 0;
        max-height: none;
        border: none;
        box-shadow: none;
        display: flex;
        flex-direction: column;
        min-height: 100vh;
    }
    .topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 10px 16px;
    }
    .grid {
        display: flex;
        flex-direction: column;
        flex: 1;
        overflow: visible;
    }
    .panel {
        padding: 16px;
        overflow-y: visible;
        max-height: none;
    }
    .panel + .panel { border-top: 1px solid var(--border); }
    
    button {
        padding: 10px 12px;
        font-size: 14px;
        min-height: 44px;
    }
    .panel input, .beautiful-select {
        font-size: 16px;
        min-height: 44px;
    }

    .chat-panel { flex: 1; min-height: 50vh; }
    .chat { min-height: 240px; }
    .bubble { max-width: 88%; font-size: 14px; }
    .chat-input { position: sticky; bottom: 0; background: var(--panel); z-index: 10; }

    .logs { max-height: 110px; }
}

@media (max-width: 380px) {
    .btn-row { flex-wrap: wrap; }
    .btn-row > button { flex: 1 1 calc(50% - 4px); }
}
/* ===== Dynamic visual VAD demo controls ===== */
.help-text {
    color: var(--muted);
    display: block;
    margin: 10px 0;
    font-size: 11px;
    line-height: 1.45;
}

.vad-diagnostics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin: 10px 0;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--panel2);
}
.vad-diagnostics > div {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.vad-diagnostics span {
    color: var(--muted);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: .07em;
}
.vad-diagnostics strong {
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
    font-weight: 600;
}
.vad-diagnostics.fallback {
    border-color: #f59e0b;
    background: #fffbeb;
}

.camera-card {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    margin: 10px 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #111827;
}
.camera-card video {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    transform: scaleX(-1);
}
.camera-placeholder {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 18px;
    color: #cbd5e1;
    text-align: center;
    font-size: 11px;
    background: #111827;
}
.camera-placeholder.hidden { display: none; }

#remote-audio {
    width: 100%;
    height: 34px;
    margin-top: 8px;
}

.payment-card {
    align-self: stretch;
    margin: 8px 0;
    padding: 14px;
    border: 2px solid #2563eb;
    border-radius: 10px;
    background: #eff6ff;
    color: #1e3a8a;
    line-height: 1.5;
}
.payment-card strong,
.payment-card small { display: block; }

.image-message {
    align-self: stretch;
    display: grid;
    gap: 8px;
    margin: 8px 0;
}
.image-message img {
    display: block;
    width: 100%;
    max-height: 520px;
    object-fit: contain;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
}

@media (max-width: 760px) {
    .vad-diagnostics { grid-template-columns: repeat(3, 1fr); }
}

/* Live assistant reply while it is being spoken */
/* No typing cursor: replies are shown in full at once. */

.msg.draft > div {
    color: var(--muted);
    opacity: 0.75;
}

@keyframes stream-caret {
    50% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .msg.streaming > div::after { animation: none; }
}

/* Lisa avatar card (top of the session panel) */
.avatar-card { display: flex; flex-direction: column; gap: 8px; }
.avatar-frame {
    position: relative;
    aspect-ratio: 3 / 4;
    background: radial-gradient(ellipse at 50% 40%, #ffffff, var(--panel2) 75%);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
#avatar { position: absolute; inset: 0; width: 100%; height: 100%; }
/* Self-hosted AVTR-1 frames are 1280x720 with the person centred and padded
   at the sides, so fill the frame (cover) and zoom towards the face.
   --avtr1-zoom / --avtr1-focus-y tune the crop; overflow is clipped by the frame. */
.avatar-frame--selfhosted { --avtr1-zoom: 1; --avtr1-focus-y: 30%; }
#avatar canvas.avtr1-canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scale(var(--avtr1-zoom, 1));
    transform-origin: 50% var(--avtr1-focus-y, 50%);
}
/* LAM avatar: the avatar's bottom edge is blurry, so fade it out (mask) and
   optionally crop it (taller box, overflow hidden by the frame). avatar-lam.js
   sets the variables from config.lam_avatar_frame. The frame colour matches
   the avatar's background so the fade has no visible edge. */
.avatar-frame--lam { background: var(--lam-frame-bg, #ffffff); }
.avatar-frame--lam #avatar {
    bottom: auto;
    height: var(--lam-avatar-height, 100%);
    -webkit-mask-image: linear-gradient(to bottom, #000 var(--lam-fade-from, 70%), transparent var(--lam-fade-to, 100%));
            mask-image: linear-gradient(to bottom, #000 var(--lam-fade-from, 70%), transparent var(--lam-fade-to, 100%));
}
.avatar-frame--lam.avatar-frame--no-fade #avatar { -webkit-mask-image: none; mask-image: none; }
/* Round "bubble" avatar (lam_avatar_frame.shape = "circle"): a square frame
   with fully rounded corners; the zoomed-in camera keeps mainly the face. */
.avatar-frame--lam.avatar-frame--circle {
    width: min(100%, var(--lam-circle-size, 260px));
    height: auto;
    aspect-ratio: 1 / 1;
    margin: 0 auto;
    border-radius: 50%;
}
#avatar-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    pointer-events: none;
    color: var(--muted);
    font-size: 12px;
}
#avatar-placeholder[hidden] { display: none; }
.avatar-orb {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: radial-gradient(circle at 35% 30%, #ffffff, rgba(255, 102, 153, 0.25));
}
.avatar-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    font-weight: 600;
}
.avatar-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 6px;
    border-radius: 50%;
    background: var(--accent);
}
#avatar-state { color: var(--muted); font-weight: 500; }
#btn-avatar { width: 100%; }
.avatar-choice-label { margin-bottom: 0; }

/* Wider session panel: avatar, session fields and mic controls fit without scrolling */
.session-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.session-fields .lang-label { margin-bottom: 14px; min-width: 0; }
@media (min-width: 761px) {
    .app-wrapper { max-width: 1400px; }
    .grid { grid-template-columns: 360px 1fr; }
    .avatar-frame { aspect-ratio: auto; height: 240px; }
    .avatar-frame--selfhosted { height: 320px; }
    .avatar-frame--lam { height: 320px; }
    .panel hr { margin: 14px 0; }
}

/* ===== Avatar lip-sync test layout =====
   The avatar fills the left half of the window so every lip movement is
   easy to follow; session controls and the chat share the right half. */
body:has(.grid--avatar-test) { padding: 0; }
.app-wrapper:has(.grid--avatar-test) {
    max-width: none;
    max-height: none;
    height: 100vh;
    border-radius: 0;
    border: none;
}
.topbar-note { margin-left: 8px; font-size: 11px; font-weight: 500; color: var(--muted); text-transform: none; }

.grid.grid--avatar-test {
    grid-template-columns: 1fr 1fr;
    min-height: 0;
}
.avatar-stage {
    background: var(--panel);
    padding: 16px;
    min-height: 0;
    display: flex;
}
.avatar-stage .avatar-card { flex: 1; min-height: 0; }
/* The frame takes every pixel left over by the name, picker and buttons.
   The circle bubble (lam_avatar_frame.shape) is a kiosk look; here the
   avatar is shown large and rectangular. */
.avatar-stage .avatar-frame,
.avatar-stage .avatar-frame--lam,
.avatar-stage .avatar-frame--lam.avatar-frame--circle {
    flex: 1;
    width: 100%;
    height: auto;
    min-height: 0;
    aspect-ratio: auto;
    margin: 0;
    border-radius: 12px;
}
.avatar-stage #btn-avatar { width: auto; }
.avatar-stage .avatar-card > .avatar-status,
.avatar-stage .avatar-card > label,
.avatar-stage .avatar-card > button,
.avatar-stage .avatar-zoom { flex: none; }
.avatar-zoom {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 12px;
    color: var(--muted);
}
.avatar-zoom label { display: flex; align-items: center; gap: 6px; margin: 0; }
.avatar-zoom input[type="range"] { width: 140px; accent-color: var(--accent); }
.avatar-zoom output { font-family: ui-monospace, Consolas, monospace; min-width: 34px; }
.avatar-zoom #avatar-zoom-reset { width: auto; flex: none; padding: 6px 14px; }
.avatar-stage .avatar-choice-label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
}

.side-column {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 1px;
    min-height: 0;
    background: var(--border);
}
.side-column .panel { max-height: 42vh; }
.app-wrapper:has(.grid--avatar-test) .logs { max-height: 90px; }

@media (max-width: 760px) {
    .grid.grid--avatar-test { display: flex; flex-direction: column; }
    .avatar-stage { height: 60vh; flex: none; }
    .side-column .panel { max-height: none; }
}
