* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: Arial, sans-serif;
    background: #f5f7fb;
}

.hidden {
    display: none !important;
}

/* Floating bubble */
.chat-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #ffffff;
    width: 76px;
    height: 76px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(0,0,0,0.22);
    z-index: 9999;
    border: 2px solid #e6eefc;
    overflow: hidden;
}

.toggle-logo {
    width: 50px;
    height: 50px;
    object-fit: contain;
    display: block;
    border-radius: 50%;
}

/* Main widget */
.chat-container {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 360px;
    height: 520px;
    background: #ffffff;
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
    overflow: hidden;
    z-index: 9998;
    display: flex;
    flex-direction: column;
}

.chat-header {
    background: linear-gradient(135deg, #0d47a1, #1565c0);
    color: white;
    padding: 16px;
    flex-shrink: 0;
}

.chat-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.header-logo {
    width: 42px;
    height: 42px;
    object-fit: contain;
    background: #ffffff;
    border-radius: 50%;
    padding: 5px;
    border: 1px solid rgba(255,255,255,0.35);
    display: block;
    flex-shrink: 0;
}

.chat-header h2 {
    margin: 0;
    font-size: 17px;
}

.chat-header p {
    margin: 4px 0 0;
    font-size: 13px;
    opacity: 0.95;
}

.menu-btn {
    border: none;
    background: rgba(255,255,255,0.15);
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 18px;
}

.assistant-tabs {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

.assistant-tab {
    border: none;
    background: rgba(255,255,255,0.16);
    color: white;
    padding: 8px 14px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 13px;
}

.assistant-tab.active {
    background: white;
    color: #1565c0;
    font-weight: bold;
}

/* Panels */
.assistant-panel {
    flex: 1;
    min-height: 0;
}

/* Chat panel */
#chat-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-box {
    flex: 1;
    padding: 14px;
    overflow-y: auto;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.message {
    margin-bottom: 12px;
    padding: 10px 14px;
    border-radius: 12px;
    max-width: 82%;
    line-height: 1.45;
    font-size: 14px;
    word-wrap: break-word;
}

.bot-message {
    background: #eef3ff;
    color: #222;
    align-self: flex-start;
}

.user-message {
    background: #1565c0;
    color: white;
    align-self: flex-end;
}

.options-box {
    padding: 0 14px 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    background: #fff;
    flex-shrink: 0;
}

.option-btn {
    border: 1px solid #1565c0;
    background: white;
    color: #1565c0;
    border-radius: 20px;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 13px;
}

.option-btn:hover {
    background: #1565c0;
    color: white;
}

.chat-input-area {
    display: flex;
    gap: 10px;
    padding: 14px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
    flex-shrink: 0;
}

.chat-input-area input {
    flex: 1;
    padding: 12px;
    border: 1px solid #d0d7e2;
    border-radius: 10px;
    outline: none;
    font-size: 14px;
}

.chat-input-area button {
    padding: 12px 18px;
    border: none;
    border-radius: 10px;
    background: #1565c0;
    color: white;
    cursor: pointer;
    font-size: 14px;
}

/* Typing dots */
.typing-dots {
    display: flex;
    align-items: center;
    gap: 5px;
    min-height: 18px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #7a8699;
    display: inline-block;
    animation: typingBounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    40% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* Voice panel */
#voice-panel {
    height: 100%;
    overflow-y: auto;
    background: #fff;
}

.voice-body {
    padding: 16px;
}

.intro-box {
    background: #f7faff;
    border: 1px solid #e3edff;
    border-radius: 16px;
    padding: 14px;
    margin-bottom: 16px;
}

.intro-box h3 {
    margin: 0 0 8px;
    font-size: 17px;
}

.intro-box p {
    margin: 0;
    font-size: 14px;
    color: #475569;
    line-height: 1.5;
}

.status-wrap {
    text-align: center;
    margin-bottom: 16px;
}

.status-pill {
    display: inline-block;
    padding: 7px 14px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: bold;
    margin-bottom: 8px;
}

.status-pill.idle {
    background: #eef2ff;
    color: #3949ab;
}

.status-pill.listening {
    background: #e8f5e9;
    color: #2e7d32;
}

.status-pill.thinking {
    background: #fff8e1;
    color: #b26a00;
}

.status-pill.speaking {
    background: #e3f2fd;
    color: #1565c0;
}

.status-text {
    font-size: 14px;
    color: #475569;
}

.mic-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 18px;
}

.record-btn {
    width: 82px;
    height: 82px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #1565c0, #0d47a1);
    color: white;
    cursor: pointer;
    box-shadow: 0 12px 30px rgba(21, 101, 192, 0.28);
}

.record-btn.recording {
    animation: pulseRing 1.4s infinite;
}

.mic-icon {
    font-size: 28px;
}

.wave {
    display: flex;
    align-items: flex-end;
    gap: 5px;
    height: 30px;
    margin-top: 14px;
}

.wave span {
    width: 6px;
    border-radius: 999px;
    background: #1565c0;
    animation: waveBounce 1s infinite ease-in-out;
}

.wave span:nth-child(1) { height: 10px; animation-delay: 0s; }
.wave span:nth-child(2) { height: 18px; animation-delay: 0.15s; }
.wave span:nth-child(3) { height: 26px; animation-delay: 0.3s; }
.wave span:nth-child(4) { height: 18px; animation-delay: 0.45s; }
.wave span:nth-child(5) { height: 10px; animation-delay: 0.6s; }

.voice-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
}

.section-card,
.audio-wrap {
    background: #ffffff;
    border: 1px solid #e8edf5;
    border-radius: 16px;
    padding: 14px;
}

.section-title {
    font-size: 13px;
    font-weight: bold;
    color: #1565c0;
    margin-bottom: 8px;
}

.content-box {
    min-height: 70px;
    background: #f7faff;
    border-radius: 14px;
    padding: 12px;
    line-height: 1.6;
    font-size: 14px;
    color: #1f2937;
    white-space: pre-wrap;
}

#audio-player {
    width: 100%;
    margin-top: 8px;
}

@keyframes pulseRing {
    0% { box-shadow: 0 0 0 0 rgba(21, 101, 192, 0.4); }
    70% { box-shadow: 0 0 0 18px rgba(21, 101, 192, 0); }
    100% { box-shadow: 0 0 0 0 rgba(21, 101, 192, 0); }
}

@keyframes waveBounce {
    0%, 100% {
        transform: scaleY(0.7);
        opacity: 0.6;
    }
    50% {
        transform: scaleY(1.2);
        opacity: 1;
    }
}


@media (max-width: 768px) {
    .chat-container {
        right: 10px;
        left: 10px;
        bottom: 84px;
        width: auto;
        height: 78vh;
        max-height: 78vh;
        border-radius: 20px;
    }

    .chat-toggle {
        right: 14px;
        bottom: 14px;
        width: 76px;
        height: 76px;
    }

    .chat-header {
        padding: 14px;
    }

    .chat-header h2 {
        font-size: 16px;
    }

    .chat-header p {
        font-size: 12px;
    }

    .header-logo {
        width: 38px;
        height: 38px;
        padding: 4px;
    }

    .assistant-tabs {
        margin-top: 12px;
        gap: 6px;
    }

    .assistant-tab {
        padding: 7px 12px;
        font-size: 12px;
    }

    .chat-box {
        padding: 12px;
    }

    .message {
        font-size: 14px;
        max-width: 88%;
    }

    .options-box {
        padding: 0 12px 10px;
        gap: 8px;
    }

    .option-btn {
        font-size: 12px;
        padding: 8px 12px;
    }

    .chat-input-area {
        padding: 12px;
        gap: 8px;
    }

    .chat-input-area input {
        font-size: 14px;
        padding: 11px;
    }

    .chat-input-area button {
        padding: 11px 16px;
        font-size: 14px;
    }

    .voice-body {
        padding: 14px;
    }

    .intro-box {
        padding: 12px;
        margin-bottom: 14px;
    }

    .intro-box h3 {
        font-size: 16px;
    }

    .intro-box p {
        font-size: 14px;
    }

    .record-btn {
        width: 74px;
        height: 74px;
    }

    .mic-icon {
        font-size: 24px;
    }

    .content-box {
        min-height: 64px;
        font-size: 14px;
    }
}


.voice-top-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
}

.voice-reset-btn {
    border: 1px solid #1565c0;
    background: #ffffff;
    color: #1565c0;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 12px;
    cursor: pointer;
}

.voice-reset-btn:hover {
    background: #1565c0;
    color: #ffffff;
}


.voice-form-area {
    margin-top: 14px;
    background: #ffffff;
    border: 1px solid #e8edf5;
    border-radius: 16px;
    padding: 14px;
}

.voice-form-label {
    font-size: 13px;
    font-weight: bold;
    color: #1565c0;
    margin-bottom: 10px;
}

.voice-form-row {
    display: flex;
    gap: 10px;
}

.voice-text-input {
    flex: 1;
    padding: 12px;
    border: 1px solid #d0d7e2;
    border-radius: 10px;
    outline: none;
    font-size: 14px;
}

.voice-text-send {
    padding: 12px 16px;
    border: none;
    border-radius: 10px;
    background: #1565c0;
    color: white;
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
}

.voice-text-send:hover {
    background: #0d47a1;
}

@media (max-width: 768px) {
    .voice-form-row {
        flex-direction: column;
    }

    .voice-text-send {
        width: 100%;
    }
}



.chat-container,
.chat-box,
.chat-input-area,
.message,
.assistant-panel,
.voice-body,
.voice-grid,
.section-card,
.content-box {
    min-width: 0;
}

.chat-box {
    overflow-x: hidden;
}

.message {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.chat-input-area input,
.voice-text-input {
    min-width: 0;
}

@media (max-width: 768px) {
    html, body {
        overflow-x: hidden;
    }

    .chat-container {
        left: max(10px, env(safe-area-inset-left));
        right: max(10px, env(safe-area-inset-right));
        width: auto;
        height: calc(100dvh - 96px - env(safe-area-inset-bottom));
        max-height: calc(100dvh - 96px - env(safe-area-inset-bottom));
    }

    .chat-box {
        padding-bottom: 16px;
    }

    .chat-input-area {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }

    .voice-body {
        padding-bottom: calc(14px + env(safe-area-inset-bottom));
    }

    .message {
        max-width: 80%;
    }
}



#voice-panel .voice-grid {
    margin-top: 10px;
}

#voice-panel .section-card {
    padding: 12px;
}

#voice-panel .content-box {
    min-height: 56px;
}

#voice-panel .audio-wrap {
    margin-top: 12px;
}

#voice-panel .voice-form-area {
    margin-top: 12px;
}

#voice-panel .voice-form-label {
    line-height: 1.4;
}

#voice-panel .voice-text-send {
    min-height: 48px;
}

#voice-panel .section-card.hidden {
    display: none !important;
}

@media (max-width: 768px) {
    #voice-panel .intro-box {
        padding: 10px;
        margin-bottom: 12px;
    }

    #voice-panel .intro-box h3 {
        font-size: 15px;
        margin-bottom: 6px;
    }

    #voice-panel .intro-box p {
        font-size: 13px;
        line-height: 1.45;
    }

    #voice-panel .status-wrap {
        margin-bottom: 12px;
    }

    #voice-panel .mic-area {
        margin-bottom: 14px;
    }

    #voice-panel .record-btn {
        width: 70px;
        height: 70px;
    }

    #voice-panel .voice-form-area {
        padding: 12px;
    }

    #voice-panel .voice-form-label {
        font-size: 12px;
        margin-bottom: 8px;
    }

    #voice-panel .section-title {
        font-size: 12px;
    }

    #voice-panel .content-box {
        font-size: 13px;
        min-height: 52px;
        padding: 10px;
    }

    #voice-panel .audio-wrap {
        padding: 12px;
    }
}



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

.chat-container {
    overflow-x: hidden;
    max-width: 100%;
}

.chat-box,
#voice-panel,
.voice-body,
.voice-grid,
.section-card,
.content-box,
.options-box {
    overflow-x: hidden;
    max-width: 100%;
    min-width: 0;
}

.message {
    max-width: 100%;
    overflow-wrap: break-word;
    word-break: break-word;
}

.chat-input-area {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.chat-input-area input {
    min-width: 0;
    max-width: 100%;
}

.chat-input-area button {
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .chat-container {
        width: auto;
        max-width: calc(100vw - 20px);
        overflow-x: hidden;
    }

    .message {
        max-width: 85%;
    }
}


.voice-iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    background: #fff;
}

#voice-panel {
    height: 100%;
    min-height: 0;
    background: #fff;
    overflow: hidden;
}

/* .voice-iframe-wrapper {
    width: 100%;
    height: 100%;
    background: #fff;
    overflow: auto;
    padding: 0;
} */