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

#btn-talk {
    min-height: 56px;
    font-size: 15px;
    font-weight: 600;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}
#btn-talk.on {
    background: var(--success);
    border-color: var(--success);
    color: white;
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.25);
    transform: scale(0.98);
}

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

.chat { 
    flex: 1; 
    overflow-y: auto; 
    padding: 20px; 
    display: flex;
    flex-direction: column;
    gap: 8px;
    /* NEW: Ensure scrollbar works smoothly */
    min-height: 0; 
}
.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); }
    #btn-talk { flex: 1 1 100%; }
}