/* ===================================================
   AI Chat Layout & Component Overrides (V5.2)
   All styles specific to /ai-chat.html
   =================================================== */

/* --- Full-Height Layout -------------------------------- */
body {
    overflow: hidden;
}

.app {
    display: flex;
    height: calc(100vh - 64px);
    overflow: hidden;
    position: relative;
}

/* --- Chat History Sidebar ------------------------------ */
.chat-sidebar {
    width: 260px;
    background: #111113;
    border-right: 1px solid #27272a;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

/* --- Main Chat Area ------------------------------------ */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #09090b;
    min-width: 0;
    overflow: hidden;
}

/* Toolbar */
.toolbar {
    background: #111113;
    border-bottom: 1px solid #27272a;
    padding: 0 16px;
    height: 52px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.toolbar-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
}

.toolbar-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.history-btn {
    background: transparent;
    border: none;
    font-size: 18px;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    color: var(--text-muted);
}

.history-btn:hover {
    background: #27272a;
    color: var(--text);
}

/* Messages Area */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    padding-bottom: 16px;
    scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 5px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: #3f3f46; border-radius: 4px; }

.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-track { background: transparent; }
.chat-list::-webkit-scrollbar-thumb { background: #27272a; border-radius: 4px; }

/* Message Animations */
@keyframes slideUpFade {
    0% { opacity: 0; transform: translateY(12px); }
    100% { opacity: 1; transform: translateY(0); }
}

.message {
    animation: slideUpFade 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-muted);
    gap: 12px;
    padding: 40px 20px;
}

.empty-state h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.empty-state p {
    font-size: 14px;
    margin: 0;
    max-width: 300px;
    line-height: 1.6;
}

/* --- Input Capsule (Bottom Bar) ------------------------ */
.input-area {
    padding: 12px 16px 16px;
    background: #09090b;
    border-top: 1px solid #18181b;
    flex-shrink: 0;
}

.input-capsule {
    max-width: 900px;
    margin: 0 auto;
    background: #18181b;
    border: 1px solid #3f3f46;
    border-radius: 20px;
    overflow: visible;
    transition: border-color 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.input-capsule:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(211, 84, 0, 0.15);
}

.input-actions-bar {
    display: flex;
    gap: 2px;
    padding: 8px 10px 4px;
    border-bottom: 1px solid #27272a;
}

.capsule-action-btn {
    background: transparent;
    border: 1px solid #3f3f46;
    color: #a1a1aa;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), border-color 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), color 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    white-space: nowrap;
}

.capsule-action-btn:hover {
    background: #27272a;
    border-color: #52525b;
    color: white;
}

.capsule-action-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* Custom Tooltip */
.capsule-action-btn { position: relative; }

.action-tooltip {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background: #27272a;
    color: #e4e4e7;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.4;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 100;
    border: 1px solid #3f3f46;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    font-weight: 500;
}

.action-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 5px;
    border-style: solid;
    border-color: #3f3f46 transparent transparent transparent;
}

.action-tooltip::before {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 4px;
    border-style: solid;
    border-color: #27272a transparent transparent transparent;
    z-index: 1;
    margin-top: -1px;
}

@media (hover: hover) {
    .capsule-action-btn:hover .action-tooltip {
        opacity: 1;
        visibility: visible;
        transform: translateX(-50%) translateY(0);
    }
}

.capsule-action-btn .action-tooltip.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* Edge safety for long texts */
.action-tooltip.long-text {
    white-space: normal;
    width: 220px;
    text-align: center;
}

#btnThinking .action-tooltip {
    left: -30px;
    transform: translateY(4px);
}
#btnThinking:hover .action-tooltip, 
#btnThinking .action-tooltip.show {
    transform: translateY(0);
}
#btnThinking .action-tooltip::after,
#btnThinking .action-tooltip::before {
    left: 45px;
    transform: none;
}

/* Rightmost button safety */
#btnSite .action-tooltip {
    left: auto;
    right: -10px;
    transform: translateY(4px);
}
#btnSite:hover .action-tooltip, 
#btnSite .action-tooltip.show {
    transform: translateY(0);
}
#btnSite .action-tooltip::after,
#btnSite .action-tooltip::before {
    left: auto;
    right: 20px;
    transform: none;
}

.input-main {
    display: flex;
    align-items: flex-end;
    padding: 8px 12px;
    gap: 8px;
}

#messageInput {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 180px;
    min-height: 24px;
    padding: 0;
    font-family: inherit;
}

#messageInput::placeholder {
    color: #52525b;
}

.send-btn-pill {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    line-height: 1;
}

.send-btn-pill:hover {
    background: var(--primary-dark, #b84700);
    transform: scale(1.05);
}

.send-btn-pill:disabled {
    background: #3f3f46;
    color: #71717a;
    cursor: not-allowed;
    transform: none;
}

/* --- Mobile Responsiveness ----------------------------- */
@media (max-width: 900px) {
    .app {
        height: calc(100svh - 60px);
    }

    .chat-sidebar {
        position: fixed;
        right: 0;
        top: 0;
        height: 100vh;
        width: 280px;
        z-index: 2000;
        transform: translateX(100%);
        box-shadow: 0 0 40px rgba(0,0,0,0.9);
    }

    .chat-sidebar.open {
        transform: translateX(0);
    }

    #chatOverlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.7);
        backdrop-filter: blur(4px);
        z-index: 1999;
        display: none;
    }

    #chatOverlay.show {
        display: block;
    }

    .messages {
        padding: 16px 12px;
    }

    .input-area {
        padding: 8px 10px 12px;
    }

    .desktop-only {
        display: none;
    }
}
