/* ═══════════════════════════════════════════════════════
   AI Yingying — Front-End Panel Styles
   Calm, light, minimal with one accent color.
   ═══════════════════════════════════════════════════════ */

:root {
    --aiy-accent: #6C63FF;
    --aiy-accent-light: #8B85FF;
    --aiy-accent-bg: rgba(108, 99, 255, 0.08);
    --aiy-bg: #FFFFFF;
    --aiy-bg-subtle: #F8F9FC;
    --aiy-text: #1A1A2E;
    --aiy-text-secondary: #6B7280;
    --aiy-border: #E5E7EB;
    --aiy-border-light: #F3F4F6;
    --aiy-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    --aiy-shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.12);
    --aiy-radius: 16px;
    --aiy-radius-sm: 10px;
    --aiy-transition: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    --aiy-panel-width: 24%;
    --aiy-panel-top: 32px;
    --aiy-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, sans-serif;
    --aiy-btn-size: 56px;
}

/* ─── Floating Button ───────────────────────────────── */
.aiy-float-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    width: var(--aiy-btn-size);
    height: var(--aiy-btn-size);
    border-radius: 50%;
    background: linear-gradient(135deg, var(--aiy-accent), var(--aiy-accent-light));
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: var(--aiy-shadow-lg), 0 0 0 0 rgba(108, 99, 255, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    animation: aiy-pulse 2.5s ease-in-out infinite;
}

.aiy-float-btn:hover {
    transform: scale(1.08);
    box-shadow: var(--aiy-shadow-lg), 0 0 0 8px rgba(108, 99, 255, 0.15);
}

.aiy-float-btn.aiy-no-pulse {
    animation: none;
}

.aiy-float-btn.aiy-hidden {
    display: none;
}

@keyframes aiy-pulse {

    0%,
    100% {
        box-shadow: var(--aiy-shadow-lg), 0 0 0 0 rgba(108, 99, 255, 0.4);
    }

    50% {
        box-shadow: var(--aiy-shadow-lg), 0 0 0 12px rgba(108, 99, 255, 0);
    }
}

/* ─── Panel ─────────────────────────────────────────── */
.aiy-panel {
    position: fixed;
    top: var(--aiy-panel-top, 32px);
    right: 0;
    bottom: 0;
    width: var(--aiy-panel-width);
    max-width: 440px;
    min-width: 300px;
    z-index: 99998;
    background: var(--aiy-bg);
    box-shadow: -4px 0 40px rgba(0, 0, 0, 0.1);
    transform: translateX(100%);
    transition: transform var(--aiy-transition);
    display: flex;
    flex-direction: column;
    font-family: var(--aiy-font);
    color: var(--aiy-text);
    font-size: 14px;
    line-height: 1.4;
}

.aiy-panel.aiy-open {
    transform: translateX(0);
}

.aiy-panel-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Content shift (desktop) */
body.aiy-panel-active {
    transition: margin-right var(--aiy-transition);
}

body.aiy-panel-active:not(.aiy-mobile) {
    margin-right: var(--aiy-panel-width);
}

/* ─── Panel Header ──────────────────────────────────── */
.aiy-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--aiy-border-light);
    background: var(--aiy-bg);
    flex-shrink: 0;
}

.aiy-panel-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.aiy-avatar {
    font-size: 28px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--aiy-accent-bg);
    border-radius: 12px;
}

.aiy-panel-title h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--aiy-text);
    line-height: 1.2;
}

.aiy-subtitle {
    font-size: 12px;
    color: var(--aiy-text-secondary);
}

.aiy-header-actions {
    display: flex;
    gap: 6px;
}

.aiy-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--aiy-border);
    background: var(--aiy-bg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--aiy-text-secondary);
    transition: all 0.2s ease;
}

.aiy-icon-btn:hover {
    background: var(--aiy-bg-subtle);
    color: var(--aiy-accent);
    border-color: var(--aiy-accent);
}

/* ─── Mode Selector ─────────────────────────────────── */
.aiy-mode-selector {
    display: flex;
    gap: 4px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--aiy-border-light);
    overflow-x: auto;
    flex-shrink: 0;
    background: var(--aiy-bg-subtle);
}

.aiy-mode-btn {
    flex: 1;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--aiy-text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
    font-family: var(--aiy-font);
}

.aiy-mode-btn:hover {
    background: var(--aiy-bg);
    color: var(--aiy-text);
}

.aiy-mode-btn.active {
    background: var(--aiy-bg);
    color: var(--aiy-accent);
    border-color: var(--aiy-accent);
    box-shadow: 0 1px 4px rgba(108, 99, 255, 0.15);
    font-weight: 600;
}

.aiy-mode-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ─── Chat Area ─────────────────────────────────────── */
.aiy-chat {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scroll-behavior: smooth;
}

.aiy-chat::-webkit-scrollbar {
    width: 5px;
}

.aiy-chat::-webkit-scrollbar-track {
    background: transparent;
}

.aiy-chat::-webkit-scrollbar-thumb {
    background: var(--aiy-border);
    border-radius: 3px;
}

/* ─── Messages ──────────────────────────────────────── */
.aiy-message {
    max-width: 92%;
    animation: aiy-fadeIn 0.3s ease;
}

.aiy-message-user {
    align-self: flex-end;
}

.aiy-message-ai {
    align-self: flex-start;
}

.aiy-message-content {
    padding: 10px 14px;
    border-radius: var(--aiy-radius-sm);
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
}

.aiy-message-user .aiy-message-content {
    background: linear-gradient(135deg, var(--aiy-accent), var(--aiy-accent-light));
    color: #fff;
    border-bottom-right-radius: 4px;
}

.aiy-message-ai .aiy-message-content {
    background: var(--aiy-bg-subtle);
    color: var(--aiy-text);
    border: 1px solid var(--aiy-border-light);
    border-bottom-left-radius: 4px;
}

.aiy-message-content * {
    margin: 0 !important;
    padding: 0 !important;
}

.aiy-message-content {
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.aiy-message-content p:empty {
    display: none !important;
}

.aiy-message-content strong {
    color: var(--aiy-accent);
    font-weight: 600;
}

.aiy-message-content ul,
.aiy-message-content ol {
    padding-left: 16px !important;
    list-style-position: outside;
}

.aiy-message-content li {
    line-height: 1.4;
}

.aiy-message-content li>p {
    display: contents;
}

.aiy-message-content br,
.aiy-message-content br+br {
    display: none !important;
}

.aiy-message-content h1,
.aiy-message-content h2,
.aiy-message-content h3,
.aiy-message-content h4 {
    line-height: 1.3;
    font-size: 0.95em;
}

.aiy-message-content a {
    color: var(--aiy-accent);
    text-decoration: none;
    border-bottom: 1px solid rgba(108, 99, 255, 0.3);
    transition: border-color 0.2s;
}

.aiy-message-content a:hover {
    border-bottom-color: var(--aiy-accent);
}

.aiy-message-content ul {
    margin: 6px 0;
    padding-left: 18px;
}

.aiy-message-content li {
    margin-bottom: 4px;
}

.aiy-tip {
    font-size: 12px;
    color: var(--aiy-text-secondary);
}

/* Thumbs feedback */
.aiy-feedback {
    display: none;
    gap: 6px;
    margin-top: 8px;
}

.aiy-thumb-btn {
    padding: 3px 8px;
    border-radius: 6px;
    border: 1px solid var(--aiy-border);
    background: var(--aiy-bg);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.aiy-thumb-btn:hover {
    background: var(--aiy-accent-bg);
    border-color: var(--aiy-accent);
}

.aiy-thumb-btn.active {
    background: var(--aiy-accent-bg);
    border-color: var(--aiy-accent);
}

/* TTS Play button per message */
.aiy-tts-play-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: none;
    background: transparent;
    color: var(--aiy-text-secondary);
    cursor: pointer;
    margin-top: 4px;
    opacity: 0.4;
    transition: opacity 0.2s, color 0.2s;
}

.aiy-tts-play-btn:hover {
    opacity: 1;
    color: var(--aiy-accent);
}

/* Loading indicator */
.aiy-loading {
    display: flex;
    gap: 6px;
    padding: 12px 16px;
}

.aiy-loading-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--aiy-accent);
    opacity: 0.3;
    animation: aiy-bounce 1.2s infinite;
}

.aiy-loading-dot:nth-child(2) {
    animation-delay: 0.15s;
}

.aiy-loading-dot:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes aiy-bounce {

    0%,
    80%,
    100% {
        transform: translateY(0);
        opacity: 0.3;
    }

    40% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

@keyframes aiy-fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── Transcript Preview ────────────────────────────── */
.aiy-transcript-preview {
    padding: 10px 16px;
    background: var(--aiy-accent-bg);
    border-top: 1px solid var(--aiy-border-light);
    flex-shrink: 0;
}

.aiy-transcript-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--aiy-accent);
    margin-bottom: 4px;
}

.aiy-transcript-text {
    width: 100%;
    border: 1px solid var(--aiy-border);
    border-radius: 8px;
    padding: 8px;
    font-size: 13px;
    font-family: var(--aiy-font);
    resize: none;
    background: var(--aiy-bg);
}

.aiy-transcript-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    justify-content: flex-end;
}

.aiy-btn-sm {
    padding: 5px 14px;
    border-radius: 6px;
    border: 1px solid var(--aiy-border);
    background: var(--aiy-bg);
    font-size: 12px;
    cursor: pointer;
    font-family: var(--aiy-font);
    transition: all 0.2s;
}

.aiy-btn-sm:hover {
    background: var(--aiy-bg-subtle);
}

.aiy-btn-primary {
    background: var(--aiy-accent);
    color: #fff;
    border-color: var(--aiy-accent);
}

.aiy-btn-primary:hover {
    background: var(--aiy-accent-light);
}

/* ─── Input Bar ─────────────────────────────────────── */

.aiy-consent-notice {
    margin-top: 12px !important;
    padding: 12px !important;
    line-height: 1.6 !important;
}

.aiy-consent-notice p {
    margin-bottom: 10px !important;
}

.aiy-consent-notice div[style*="display: flex"] {
    margin-top: 8px !important;
}

#aiy-survey-email-status {
    margin-top: 8px !important;
}

.aiy-input-bar {
    padding: 12px 16px;
    border-top: 1px solid var(--aiy-border-light);
    background: var(--aiy-bg);
    flex-shrink: 0;
}

.aiy-input-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    background: var(--aiy-bg-subtle);
    border: 1px solid var(--aiy-border);
    border-radius: 14px;
    padding: 6px 6px 6px 14px;
    transition: border-color 0.2s;
}

.aiy-input-row:focus-within {
    border-color: var(--aiy-accent);
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.1);
}

.aiy-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    font-family: var(--aiy-font);
    resize: none;
    min-height: 24px;
    max-height: 120px;
    line-height: 1.5;
    color: var(--aiy-text);
    outline: none;
}

.aiy-input::placeholder {
    color: var(--aiy-text-secondary);
}

.aiy-mic-btn,
.aiy-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.aiy-mic-btn {
    background: var(--aiy-bg);
    color: var(--aiy-text-secondary);
    border: 1px solid var(--aiy-border);
}

.aiy-mic-btn:hover {
    background: var(--aiy-accent-bg);
    color: var(--aiy-accent);
}

.aiy-mic-btn.aiy-recording {
    background: #EF4444;
    color: #fff;
    border-color: #EF4444;
    animation: aiy-mic-pulse 1s ease infinite;
}

@keyframes aiy-mic-pulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }

    50% {
        box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
    }
}

.aiy-send-btn {
    background: var(--aiy-accent);
    color: #fff;
}

.aiy-send-btn:hover {
    background: var(--aiy-accent-light);
    transform: scale(1.05);
}

.aiy-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ─── Disclosure Footer ─────────────────────────────── */
.aiy-disclosure {
    padding: 6px 16px;
    font-size: 10px;
    color: var(--aiy-text-secondary);
    text-align: center;
    border-top: 1px solid var(--aiy-border-light);
    background: var(--aiy-bg-subtle);
    flex-shrink: 0;
}

/* ─── Diagnostics ───────────────────────────────────── */
.aiy-diagnostics {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 400px;
    max-height: 250px;
    overflow-y: auto;
    background: #1a1a2e;
    color: #00ff88;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 11px;
    padding: 10px;
    z-index: 100000;
    border-top-right-radius: 8px;
}

.aiy-diagnostics h4 {
    margin: 0 0 6px;
    color: #fff;
}

/* ─── Mobile ────────────────────────────────────────── */
@media (max-width: 768px) {
    .aiy-panel {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
    }

    body.aiy-panel-active {
        overflow: hidden;
    }

    .aiy-float-btn {
        bottom: 16px;
        right: 16px;
        width: 50px;
        height: 50px;
    }

    .aiy-mode-selector {
        padding: 6px 10px;
    }

    .aiy-mode-btn {
        font-size: 11px;
        padding: 5px 8px;
    }
}

/* ─── Print (hide panel) ────────────────────────────── */
@media print {

    .aiy-float-btn,
    .aiy-panel,
    .aiy-diagnostics {
        display: none !important;
    }

    body.aiy-panel-active {
        margin-right: 0 !important;
    }
}