/* --- CORE & RESET --- */
:root {
    /* Default theme is night - can be overridden by imported theme files */
    --bg-core: #09090b;
    --bg-panel: #18181b;
    --bg-input: #27272a;
    --gold-dark: #B8860B;
    --gold-main: #FFD700;
    --gold-light: #FFEC8B;
    --accent: var(--gold-main);
    --accent-light: var(--gold-light);
    --accent-bright: var(--gold-dark);
    --grad-main: linear-gradient(135deg, var(--gold-light), var(--gold-main), var(--gold-dark));
    --grad-accent: linear-gradient(135deg, var(--gold-light), var(--gold-main));
    --grad-highlight: linear-gradient(135deg, var(--gold-main), var(--gold-dark));
    --text-main: #f4f4f5;
    --text-dim: #a1a1aa;
    --text-light: #d4d4d8;
    --border-light: rgba(255, 255, 255, 0.08);
    --border-medium: rgba(255, 255, 255, 0.15);
    --border-dark: rgba(255, 255, 255, 0.25);
    --shadow-light: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-medium: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-heavy: 0 10px 15px rgba(0, 0, 0, 0.5);
    --success: var(--gold-main);
    --warning: var(--gold-dark);
    --error: var(--gold-dark);
    --code-bg: #101012;
    --code-text: #e5e7eb;
    --inline-code-bg: rgba(255, 215, 0, 0.1);
    --inline-code-text: var(--gold-main);
    --hover-light: rgba(255, 255, 255, 0.1);
    --hover-medium: rgba(255, 255, 255, 0.2);
    --hover-dark: rgba(255, 255, 255, 0.3);

    --font-sans: 'Poppins', 'Montserrat', system-ui, -apple-system, sans-serif;
    --font-mono: 'Fira Code', monospace;

    /* Reducción de tamaño global del 10% */
    --header-height: 48px;
    /* 54px -> 48px */
    --header-padding-x: 12px;
    /* 14px -> 12px */
    --icon-btn-size: 29px;
    /* 32px -> 29px */
    --icon-btn-svg-size: 16px;
    /* 18px -> 16px */
    --sep-height: 16px;
    /* 18px -> 16px */
    --logo-font-size: 1rem;
    /* 1.1rem -> 1rem */

    --input-area-padding: 0;
    /* 8px -> 0 */
    --input-wrapper-padding-y: 2px;
    --input-wrapper-padding-x: 4px;
    --input-wrapper-border-radius: 18px;
    --textarea-height: 20px;
    --textarea-font-size: 14px;
    --act-btn-size: 28px;
    --act-btn-svg-size: 15px;
    --send-btn-size: 32px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--font-sans);
    -webkit-tap-highlight-color: transparent;
}

/* Scrollbar invisible pero funcional */
* {
    scrollbar-width: none;
}

*::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

body {
    background-color: var(--bg-core);
    color: var(--text-main);
    height: 100vh;
    height: 100dvh;
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    cursor: default;
    user-select: none;
    touch-action: pan-x pan-y;
    overscroll-behavior: none;
}

/* Habilitar selección de texto donde importa */
.bubble,
.code-head,
pre code,
textarea,
input {
    user-select: text;
    cursor: text;
}

button {
    cursor: pointer;
}

/* --- HEADER --- */
header {
    height: var(--header-height);
    padding: 0 var(--header-padding-x);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
    z-index: 50;
}

.icon-btn:hover {
    background: var(--hover-light);
}

.logo {
    font-weight: 800;
    font-size: var(--logo-font-size);
    background: var(--grad-main);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 8px;
}

.controls-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    width: var(--icon-btn-size);
    height: var(--icon-btn-size);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    position: relative;
}

.icon-btn:hover {
    background: var(--hover-light);
    color: var(--text-main);
}

.icon-btn.active {
    color: var(--accent);
}

.icon-btn svg,
.icon-btn .icon-mask {
    width: var(--icon-btn-svg-size);
    height: var(--icon-btn-svg-size);
}

.icon-mask {
    background-color: currentColor;
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    display: inline-block;
}

.badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--accent);
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

/* --- CHAT AREA --- */
#chat-box {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.msg {
    display: flex;
    gap: 0;
    opacity: 0;
    animation: fadeUp 0.3s forwards;
    max-width: 100%;
    margin: 0;
    padding: 12px 0;
    /* Espacio vertical para el separador */
    border: none;
    border-bottom: 1px solid rgb(125, 125, 125);
    /* Separador horizontal */
}

.msg.user {
    flex-direction: row-reverse;
}

/* Hide avatars */
.avatar {
    display: none;
}

.bubble-col {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 90%;
    min-width: 0;
}

.msg.user .bubble-col {
    align-items: flex-end;
}

.msg.ai .bubble {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    margin: 0;
}

.msg.user .bubble {
    border: none;
    margin: 0;
    padding: 0;
}

/* Edit button for user messages */
.edit-msg-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 0.8rem;
    transition: all 0.2s ease;
    opacity: 0.5;
    color: var(--accent-light);
    margin-left: 6px;
}

.msg:hover .edit-msg-btn {
    opacity: 1;
}

.msg.user:hover .edit-msg-btn {
    opacity: 1;
}

.edit-msg-btn:hover {
    background: var(--hover-light);
    color: var(--accent);
}

/* Message editing input */
.msg-edit-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-medium);
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text-main);
    font-size: 0.9rem;
    line-height: 1.6;
    resize: vertical;
    min-height: 60px;
    margin-bottom: 4px;
}

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

.edit-actions button {
    padding: 4px 8px;
    border: 1px solid var(--border-medium);
    background: var(--bg-panel);
    color: var(--text-main);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.edit-actions button:hover {
    background: var(--hover-light);
}

.bubble {
    padding: 0;
    border-radius: 0;
    font-size: 0.9rem;
    line-height: 1.6;
    overflow-wrap: break-word;
    position: relative;
    margin: 0;
    border: none;
}

.msg.ai .bubble {
    background: transparent;
    color: var(--text-main);
    padding: 0;
    margin: 0;
    border: none;
}

.msg.user .bubble {
    background: transparent;
    color: var(--text-main);
    border-radius: 0;
    margin: 0;
    padding: 0;
    border: none;
}

/* --- FORMATTING --- */
.bubble h1,
.bubble h2,
.bubble h3 {
    font-weight: 700;
    margin-top: 0.8em;
    color: var(--text-main);
    line-height: 1.2;
}

.bubble h1 {
    font-size: 1.2em;
    background: var(--grad-main);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: inline-block;
}

.bubble p {
    margin-bottom: 0.6em;
}

.bubble p:last-child {
    margin-bottom: 0;
}

.bubble pre {
    background: var(--code-bg);
    border: 1px solid var(--border-medium);
    border-radius: 8px;
    margin: 10px 0;
    overflow-x: auto;
}

.bubble pre code {
    padding: 12px;
    background: transparent;
    display: block;
    font-family: var(--font-mono);
    font-size: 0.8em;
}

.bubble :not(pre)>code {
    background: var(--inline-code-bg);
    color: var(--inline-code-text);
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: var(--font-mono);
}

.file-attachment-chip {
    margin-top: 5px;
    font-size: 0.8em;
    background: var(--bg-panel);
    color: var(--text-main);
    padding: 4px 8px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border-medium);
}

.chat-img {
    max-width: 100%;
    border-radius: 8px;
    margin-top: 8px;
    border: 1px solid var(--border-medium);
}

.code-head {
    display: flex;
    justify-content: space-between;
    background: var(--bg-panel);
    padding: 6px 12px;
    font-size: 0.7rem;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border-medium);
}

.copy-btn {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 0.7rem;
}

.search-step {
    border: 1px solid var(--border-medium);
    background: var(--bg-panel);
    border-radius: 8px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 5px;
    animation: pulse 2s infinite;
    width: fit-content;
}

.meta {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 4px;
    opacity: 0;
    animation: fadeIn 1s forwards;
}

.delete-msg-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.delete-msg-btn:hover {
    background: var(--hover-light);
    color: var(--error);
}

/* API Keys Input Styling */
#new-key-name,
#new-key-val {
    background: var(--bg-input) !important;
    color: var(--text-main) !important;
    border: 1px solid var(--border-light) !important;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.9rem;
    width: 100%;
    margin-bottom: 8px;
}

#new-key-name:focus,
#new-key-val:focus {
    outline: none;
    border-color: var(--accent) !important;
}

#new-key-name::placeholder,
#new-key-val::placeholder {
    color: var(--text-dim);
}

.tok {
    font-size: 0.6rem;
    color: var(--text-dim);
    font-family: var(--font-mono);
}

.timestamp {
    font-size: 0.6rem;
    color: var(--text-dim);
    font-family: var(--font-mono);
    margin-left: 4px;
    white-space: nowrap;
}

.tts-btn {
    background: none;
    border: none;
    outline: none;
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    padding: 2px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.tts-btn:hover {
    color: var(--text-main);
    background: var(--hover-light);
}

.tts-btn.active {
    color: var(--accent);
    animation: pulse 1.5s infinite;
    background: var(--hover-light);
}

.copy-msg-btn {
    background: none;
    border: none;
    outline: none;
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    margin-left: 8px;
}

.copy-msg-btn:hover {
    color: var(--text-main);
}

.reload-msg-btn {
    background: none;
    border: none;
    outline: none;
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    margin-left: 8px;
}

.reload-msg-btn:hover {
    color: var(--text-main);
}

/* --- INPUT AREA --- */
/* Extracted to components/input-area.css */

/* --- MODALS (Estilo Base PC) --- */
/* Extracted to components/modals-extended.css */

/* --- MOBILE OPTIMIZATION (CORREGIDO) --- */
@media (max-width: 768px) {
    header {
        padding: 0 12px;
    }

    #chat-box {
        padding: 15px 12px;
    }

    .bubble-col {
        max-width: 100%;
    }

    .avatar {
        display: none;
    }

    .msg {
        gap: 0;
    }

    .bubble {
        padding: 12px;
        border-radius: 16px;
        font-size: 1rem;
    }

    .msg.user .bubble {
        border-bottom-right-radius: 4px;
    }

    .msg.ai .bubble {
        padding-left: 0;
    }

    .modal-overlay {
        padding: 16px;
    }

    .modal {
        max-height: 85vh;
        max-width: calc(100vw - 32px);
        width: calc(100vw - 32px);
    }

    /* Specific handling for portrait orientation */
    @media (orientation: portrait) {
        .modal {
            max-height: 80vh;
            max-width: 95vw;
            width: 95vw;
        }
    }

    /* Specific handling for landscape orientation */
    @media (orientation: landscape) {
        .modal {
            max-height: 90vh;
            max-width: 700px;
            width: 90vw;
        }
    }

    #confirm-modal .modal {
        width: 100%;
        max-width: 320px;
    }

    .input-area {
        padding: 8px;
    }

    .act-btn {
        width: 36px;
        height: 36px;
    }

    .send-btn {
        width: 32px;
        height: 32px;
    }
}

/* Additional responsive handling for modals on different screen sizes */
@media (max-height: 600px) {
    .modal {
        max-height: 95vh;
    }
}

@media (min-width: 769px) {
    .modal {
        max-width: 500px;
    }
}

/* --- CONVERSATION MODAL --- */
/* Extracted to components/conversation-modal.css */

/* --- SIDEBAR --- */
#sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 99;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

#sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100%;
    background: var(--bg-panel);
    border-right: 1px solid var(--border-light);
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-heavy);
}

#sidebar.active {
    transform: translateX(0);
}

.sidebar-header {
    height: var(--header-height);
    padding: 0 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-light);
    background: rgba(9, 9, 11, 0.5);
}

.sidebar-nav {
    flex: 1;
    padding: 20px 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    border-radius: 12px;
    color: var(--text-dim);
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s;
    cursor: pointer;
}

.sidebar-item:hover {
    background: var(--hover-light);
    color: var(--text-main);
    transform: translateX(4px);
}

.sidebar-item svg,
.sidebar-item .icon-mask {
    width: 20px;
    height: 20px;
    min-width: 20px;
    min-height: 20px;
    stroke-width: 2;
}

.sidebar-avatar .icon-mask {
    width: 24px;
    height: 24px;
}

.sidebar-item.danger {
    color: #ff4444;
    margin-top: auto;
}

.sidebar-item.danger span {
    line-height: 0.4;
    /* 40% height reduction */
    display: inline-block;
}

.sidebar-item.danger:hover {
    background-color: rgba(255, 68, 68, 0.1);
}

.sidebar-footer {
    padding: 12px 15px;
    border-top: 1px solid var(--border-light);
}

.sidebar-section-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    margin: 15px 0 5px 10px;
    font-weight: 700;
    opacity: 0.6;
}

/* Animations */
@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}