/* ==========================================================================
   AI CHAT — Full-width Sidebar Layout
   Nihongo AI Coach
   ========================================================================== */

/* ===== Page Layout ===== */
.ai-chat-page {
    overflow: hidden;
}

.ai-chat-wrapper {
    display: flex;
    height: calc(100vh - 64px);
    margin-top: 0;
    background: var(--bg-main, #f6f8fc);
}

/* ===== Sidebar ===== */
.ai-sidebar {
    width: 280px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-card, #ffffff);
    border-right: 1px solid var(--border-soft, rgba(0, 0, 0, 0.06));
    overflow: hidden;
}

.ai-sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-soft, rgba(0, 0, 0, 0.06));
}

.ai-new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    border-radius: 12px;
    border: 1.5px dashed var(--border-medium, rgba(0, 0, 0, 0.12));
    background: transparent;
    color: var(--text-main, #0f172a);
    font-size: 0.9rem;
    font-weight: 700;
    font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
    cursor: pointer;
    transition: all 0.2s;
}
.ai-new-chat-btn:hover {
    background: var(--bg-card-hover, #f0fdf4);
    border-color: var(--accent-green, #059669);
    color: var(--accent-green, #059669);
}

.ai-sidebar-section {
    flex: 1;
    overflow-y: auto;
    padding: 12px 8px;
}
.ai-sidebar-section::-webkit-scrollbar { width: 4px; }
.ai-sidebar-section::-webkit-scrollbar-thumb { background: var(--border-soft, rgba(0,0,0,0.08)); border-radius: 4px; }

.ai-sidebar-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted, #94a3b8);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 4px 12px 8px;
}

.ai-sidebar-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ai-sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-soft, #334155);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ai-sidebar-item:hover {
    background: var(--bg-card-hover, #f1f5f9);
}
.ai-sidebar-item.active {
    background: var(--accent-green-bg, rgba(101, 199, 71, 0.12));
    color: var(--accent-green, #059669);
    border-left: 3px solid var(--accent-green, #059669);
    border-radius: 10px 6px 6px 10px;
    font-weight: 700;
}
.ai-sidebar-item.active .material-symbols-outlined {
    opacity: 1;
    color: var(--accent-green, #059669);
}
.ai-sidebar-item .material-symbols-outlined {
    font-size: 18px;
    flex-shrink: 0;
    opacity: 0.5;
}
.ai-sidebar-item-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-sidebar-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 32px 12px;
    color: var(--text-muted, #94a3b8);
}
.ai-sidebar-empty small {
    font-size: 0.78rem;
    font-weight: 600;
}

.ai-sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-soft, rgba(0, 0, 0, 0.06));
}

.ai-clear-all-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 8px 12px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--text-muted, #94a3b8);
    font-size: 0.82rem;
    font-weight: 600;
    font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
    cursor: pointer;
    transition: all 0.2s;
}
.ai-clear-all-btn:hover {
    background: var(--danger-bg, #fef2f2);
    color: var(--danger-text, #dc2626);
}

/* ===== Main Chat Area ===== */
.ai-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* Header */
.ai-main-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border-soft, rgba(0, 0, 0, 0.06));
    background: var(--bg-card, #ffffff);
    flex-shrink: 0;
}

.ai-sidebar-toggle {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--border-soft, rgba(0, 0, 0, 0.06));
    background: var(--bg-card, #ffffff);
    color: var(--text-main, #0f172a);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}
.ai-sidebar-toggle:hover {
    background: var(--bg-card-hover, #f1f5f9);
}

.ai-main-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.ai-main-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, #fce4ec, #f8bbd0);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.ai-main-header-info h6 {
    color: var(--text-main, #0f172a);
    font-size: 0.95rem;
}
.ai-status-text {
    color: var(--accent-green, #059669);
    font-size: 0.75rem;
    font-weight: 600;
}

.ai-main-header-actions {
    display: flex;
    gap: 8px;
}

.ai-action-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--border-soft, rgba(0, 0, 0, 0.06));
    background: var(--bg-card, #ffffff);
    color: var(--text-muted, #64748b);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}
.ai-action-btn:hover {
    background: var(--bg-card-hover, #f1f5f9);
    color: var(--text-main, #0f172a);
}

/* ===== Messages Area ===== */
.ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.ai-messages::-webkit-scrollbar { width: 5px; }
.ai-messages::-webkit-scrollbar-thumb { background: var(--border-medium, rgba(0,0,0,0.12)); border-radius: 4px; }

/* Welcome */
.ai-welcome {
    text-align: center;
    padding: 60px 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.ai-welcome-icon {
    font-size: 3.5rem;
    margin-bottom: 8px;
}

.ai-welcome h4 {
    color: var(--text-main, #0f172a);
    font-size: 1.6rem;
}

.ai-welcome-desc {
    color: var(--text-muted, #64748b);
    font-size: 1rem;
    max-width: 480px;
    line-height: 1.6;
}

.ai-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 28px;
    max-width: 520px;
}

.ai-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card, #ffffff);
    border: 1px solid var(--border-soft, rgba(0, 0, 0, 0.08));
    color: var(--text-main, #0f172a);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 10px 16px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
}
.ai-chip:hover {
    background: var(--bg-card-hover, #f0fdf4);
    border-color: var(--accent-green, #059669);
    color: var(--accent-green, #059669);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

/* ===== Message Bubbles ===== */
.ai-msg-wrapper {
    display: flex;
    gap: 10px;
    max-width: 75%;
    animation: fadeInUp 0.3s ease;
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.ai-msg-wrapper.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.ai-msg-wrapper.assistant {
    align-self: flex-start;
}

.ai-msg-avatar {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    flex-shrink: 0;
}
.ai-msg-wrapper.user .ai-msg-avatar {
    background: linear-gradient(135deg, #fce4ec, #f8bbd0);
}
.ai-msg-wrapper.assistant .ai-msg-avatar {
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
}

.ai-msg-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.92rem;
    line-height: 1.65;
    word-wrap: break-word;
}
.ai-msg-wrapper.user .ai-msg-bubble {
    background: linear-gradient(135deg, var(--v-accent, #10b981), var(--v-accent-dark, #059669));
    color: #ffffff;
    border-bottom-right-radius: 6px;
}
.ai-msg-wrapper.assistant .ai-msg-bubble {
    background: var(--bg-card, #ffffff);
    color: var(--text-main, #0f172a);
    border: 1px solid var(--border-soft, rgba(0, 0, 0, 0.06));
    border-bottom-left-radius: 6px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.ai-msg-bubble strong { font-weight: 700; }
.ai-msg-bubble code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Noto Sans JP', monospace;
    font-size: 0.88rem;
}
.ai-msg-wrapper.user .ai-msg-bubble code {
    background: rgba(255, 255, 255, 0.2);
}
.ai-msg-bubble ul, .ai-msg-bubble ol {
    padding-left: 20px;
    margin: 6px 0;
}
.ai-msg-bubble h4, .ai-msg-bubble h5 {
    font-weight: 700;
    margin-top: 8px;
    margin-bottom: 4px;
}

.ai-msg-time {
    font-size: 0.68rem;
    color: var(--text-muted, #94a3b8);
    margin-top: 4px;
}
.ai-msg-wrapper.user .ai-msg-time {
    text-align: right;
}

/* ===== Typing Indicator ===== */
.ai-typing {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 24px 12px;
}
.ai-typing-avatar {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
}
.ai-typing-bubble {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--bg-card, #ffffff);
    border: 1px solid var(--border-soft, rgba(0, 0, 0, 0.06));
    border-radius: 16px;
    border-bottom-left-radius: 6px;
}
.ai-typing-bubble small {
    color: var(--text-muted, #94a3b8);
    font-size: 0.78rem;
    font-weight: 600;
}
.ai-typing-dots {
    display: flex;
    gap: 4px;
}
.ai-typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted, #94a3b8);
    animation: typingBounce 1.4s infinite;
}
.ai-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* ===== Input Area (sticky bottom) ===== */
.ai-input-area {
    padding: 12px 24px 16px;
    border-top: 1px solid var(--border-soft, rgba(0, 0, 0, 0.06));
    background: var(--bg-card, #ffffff);
    flex-shrink: 0;
}

.ai-input-form {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-main, #f6f8fc);
    border: 1.5px solid var(--border-soft, rgba(0, 0, 0, 0.08));
    border-radius: 16px;
    padding: 8px 8px 8px 16px;
    transition: all 0.2s;
}
.ai-input-form:focus-within {
    border-color: var(--accent-green, #059669);
    box-shadow: 0 0 0 3px rgba(101, 199, 71, 0.1);
}

.ai-input {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-size: 0.92rem;
    font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
    background: transparent;
    max-height: 120px;
    padding: 4px 0;
    color: var(--text-main, #0f172a);
}
.ai-input:focus {
    outline: none !important;
    box-shadow: none !important;
    border: none !important;
}
.ai-input::placeholder {
    color: var(--text-muted, #94a3b8);
}

.ai-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, var(--accent-green, #059669), #22c55e);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}
.ai-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(101, 199, 71, 0.3);
}
.ai-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.ai-input-hint {
    text-align: center;
    margin-top: 8px;
}
.ai-input-hint small {
    color: var(--text-muted, #94a3b8);
    font-size: 0.72rem;
}

/* ===== Mobile Sidebar Overlay ===== */
.ai-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99;
}
.ai-sidebar-overlay.open {
    display: block;
}

/* ===== Responsive ===== */
@media (max-width: 991px) {
    .ai-chat-wrapper {
        height: calc(100vh - 64px);
    }
    .ai-sidebar {
        position: fixed;
        top: 72px;
        left: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.1);
    }
    .ai-sidebar.open {
        transform: translateX(0);
    }
    .ai-msg-wrapper {
        max-width: 85%;
    }
}

@media (max-width: 767px) {
    .ai-main-header {
        padding: 10px 16px;
    }
    .ai-messages {
        padding: 16px;
    }
    .ai-input-area {
        padding: 10px 16px 12px;
    }
    .ai-msg-wrapper {
        max-width: 90%;
    }
    .ai-welcome {
        padding: 40px 16px;
    }
    .ai-welcome h4 {
        font-size: 1.3rem;
    }
    .ai-chips {
        gap: 8px;
    }
    .ai-chip {
        padding: 8px 12px;
        font-size: 0.8rem;
    }
}

/* ══════════════════════════════════════════════════════════════════════════
   EXPLICIT LIGHT & DARK MODE OVERRIDES (AI CHAT)
   ══════════════════════════════════════════════════════════════════════════ */

/* ─── Light Mode ─── */
[data-theme="light"] .ai-chat-wrapper,
:root:not([data-theme="dark"]) .ai-chat-wrapper {
    background: #f8fafc !important;
}

[data-theme="light"] .ai-sidebar,
:root:not([data-theme="dark"]) .ai-sidebar {
    background: #ffffff !important;
    border-right-color: rgba(15, 23, 42, 0.08) !important;
}

[data-theme="light"] .ai-main-header,
:root:not([data-theme="dark"]) .ai-main-header {
    background: #ffffff !important;
    border-bottom-color: rgba(15, 23, 42, 0.08) !important;
}

[data-theme="light"] .ai-msg-wrapper.assistant .ai-msg-bubble,
:root:not([data-theme="dark"]) .ai-msg-wrapper.assistant .ai-msg-bubble {
    background: #ffffff !important;
    color: #0f172a !important;
    border: 1px solid rgba(15, 23, 42, 0.09) !important;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.03) !important;
}

[data-theme="light"] .ai-input-area,
:root:not([data-theme="dark"]) .ai-input-area {
    background: #ffffff !important;
    border-top-color: rgba(15, 23, 42, 0.08) !important;
}

[data-theme="light"] .ai-input-form,
:root:not([data-theme="dark"]) .ai-input-form {
    background: #f1f5f9 !important;
    border: 1.5px solid rgba(15, 23, 42, 0.1) !important;
}

[data-theme="light"] .ai-input-form:focus-within,
:root:not([data-theme="dark"]) .ai-input-form:focus-within {
    border-color: #10b981 !important;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15) !important;
}

[data-theme="light"] .ai-input,
:root:not([data-theme="dark"]) .ai-input {
    color: #0f172a !important;
}

/* ─── Dark Mode ─── */
[data-theme="dark"] .ai-chat-wrapper,
html.dark .ai-chat-wrapper {
    background: #0b0f17 !important;
}

[data-theme="dark"] .ai-sidebar,
html.dark .ai-sidebar {
    background: #111827 !important;
    border-right-color: rgba(255, 255, 255, 0.08) !important;
}

[data-theme="dark"] .ai-sidebar-item,
html.dark .ai-sidebar-item {
    color: #cbd5e1 !important;
}

[data-theme="dark"] .ai-sidebar-item:hover,
html.dark .ai-sidebar-item:hover {
    background: #1f2937 !important;
}

[data-theme="dark"] .ai-sidebar-item.active,
html.dark .ai-sidebar-item.active {
    background: rgba(16, 185, 129, 0.18) !important;
    color: #34d399 !important;
}

[data-theme="dark"] .ai-new-chat-btn,
html.dark .ai-new-chat-btn {
    background: #161d2b !important;
    border-color: rgba(255, 255, 255, 0.15) !important;
    color: #f8fafc !important;
}

[data-theme="dark"] .ai-new-chat-btn:hover,
html.dark .ai-new-chat-btn:hover {
    border-color: #10b981 !important;
    color: #34d399 !important;
}

[data-theme="dark"] .ai-main-header,
html.dark .ai-main-header {
    background: #111827 !important;
    border-bottom-color: rgba(255, 255, 255, 0.08) !important;
}

[data-theme="dark"] .ai-main-header h6,
html.dark .ai-main-header h6 {
    color: #f8fafc !important;
}

[data-theme="dark"] .ai-welcome h4,
html.dark .ai-welcome h4 {
    color: #f8fafc !important;
}

[data-theme="dark"] .ai-welcome-desc,
html.dark .ai-welcome-desc {
    color: #cbd5e1 !important;
}

[data-theme="dark"] .ai-chip,
html.dark .ai-chip {
    background: #161d2b !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
    color: #f8fafc !important;
}

[data-theme="dark"] .ai-chip:hover,
html.dark .ai-chip:hover {
    border-color: #10b981 !important;
    color: #34d399 !important;
    background: #1a2436 !important;
}

[data-theme="dark"] .ai-msg-wrapper.assistant .ai-msg-bubble,
html.dark .ai-msg-wrapper.assistant .ai-msg-bubble {
    background: #161d2b !important;
    color: #f8fafc !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25) !important;
}

[data-theme="dark"] .ai-typing-bubble,
html.dark .ai-typing-bubble {
    background: #161d2b !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

[data-theme="dark"] .ai-input-area,
html.dark .ai-input-area {
    background: #111827 !important;
    border-top-color: rgba(255, 255, 255, 0.08) !important;
}

[data-theme="dark"] .ai-input-form,
html.dark .ai-input-form {
    background: #161d2b !important;
    border: 1.5px solid rgba(255, 255, 255, 0.12) !important;
}

[data-theme="dark"] .ai-input-form:focus-within,
html.dark .ai-input-form:focus-within {
    border-color: #10b981 !important;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2) !important;
}

[data-theme="dark"] .ai-input,
html.dark .ai-input {
    color: #f8fafc !important;
}
