/* --- 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: 'Inter', 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: 24px;
}

* {
    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;
}

/* 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: rgba(9, 9, 11, 0.98);
    /* This should use theme var but keeping for now to maintain transparency */
    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 {
    width: var(--icon-btn-svg-size);
    height: var(--icon-btn-svg-size);
}

.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: 8px;
    opacity: 0;
    animation: fadeUp 0.3s forwards;
    max-width: 100%;
}

.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;
}

/* 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: 10px 16px;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.6;
    overflow-wrap: break-word;
    position: relative;
    margin-left: 0.5rem;
}

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

.msg.user .bubble {
    background: var(--bg-input);
    color: var(--text-main);
    border-bottom-right-radius: 2px;
    margin-left: 0.5rem;
}

/* --- 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);
}

.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 --- */
.input-area {
    padding: var(--input-area-padding);
    background: var(--bg-core);
    border-top: 1px solid var(--border-light);
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    flex-shrink: 0;
    position: relative;
    z-index: 40;
}

#preview-box {
    display: none;
    gap: 8px;
    padding: 6px 0;
    margin: 0 0 6px 0;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    scrollbar-width: thin;
    scrollbar-color: var(--accent) transparent;
}

#preview-box::-webkit-scrollbar {
    height: 3px;
    display: block;
}

#preview-box::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 3px;
}

.file-preview-item {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 4px 8px;
    margin-right: 8px;
    flex-shrink: 0;
    height: 40px;
}

.file-preview-item img {
    height: 32px;
    width: auto;
    border-radius: 4px;
    margin-right: 6px;
}

.file-preview-item .file-icon {
    font-size: 1.2rem;
    margin-right: 6px;
}

.file-preview-item .file-name {
    font-size: 0.8rem;
    color: var(--text-main);
    max-width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-preview-item .remove-file {
    background: rgba(0, 0, 0, 0.2);
    border: none;
    color: var(--text-main);
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-left: 6px;
    font-size: 12px;
    line-height: 1;
}

.file-preview-item .remove-file:hover {
    background: var(--gold-dark);
    color: white;
}

.file-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px 4px 4px;
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.file-chip:hover {
    background: var(--hover-light);
    border-color: var(--border-medium);
}

.file-chip-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    flex-shrink: 0;
}

.file-chip-icon svg {
    width: 16px;
    height: 16px;
}

.file-chip-name {
    font-size: 0.7rem;
    color: var(--text-main);
    max-width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-chip-remove {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    font-size: 0.9rem;
    line-height: 1;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.file-chip-remove:hover {
    background: var(--gold-dark);
    color: var(--text-main);
}

.file-chip .processing {
    font-size: 0.7rem;
    animation: pulse 1.5s infinite;
}

.input-wrapper {
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--input-wrapper-border-radius);
    padding: var(--input-wrapper-padding-y) var(--input-wrapper-padding-x);
    display: flex;
    align-items: center;
    gap: 0;
    /* Sin espacio entre elementos */
    transition: 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
}

textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-main);
    resize: none;
    max-height: 150px;
    outline: none;
    font-size: var(--textarea-font-size);
    height: var(--textarea-height);
    line-height: 1.5;
    padding: 0 4px;
    /* Pequeño padding para que el texto no toque los botones */
}

.act-btn {
    width: var(--act-btn-size);
    height: var(--act-btn-size);
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-dim);
    background: transparent;
    transition: 0.2s;
    flex-shrink: 0;
    margin: 0;
    /* Sin margen */
}

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

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

.act-btn svg {
    width: var(--act-btn-svg-size);
    height: var(--act-btn-svg-size);
}

.send-btn {
    background: transparent;
    color: var(--gold-main);
    width: var(--send-btn-size);
    height: var(--send-btn-size);
    position: relative;
    overflow: hidden;
    border: 2px solid var(--gold-main);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.send-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(255, 215, 0, 0.1) 0%, transparent 70%);
    transform: translate(-50%, -50%) scale(0);
    transition: transform 0.6s ease-out;
    border-radius: 50%;
}

.send-btn:hover {
    background: var(--hover-light);
    color: var(--gold-light);
    transform: scale(1.1) rotate(5deg);
}

.send-btn:hover::before {
    transform: translate(-50%, -50%) scale(2);
}

.send-btn:active {
    transform: scale(0.95) rotate(-5deg);
    background: var(--hover-medium);
}

.send-btn:active::before {
    transform: translate(-50%, -50%) scale(0);
}

/* Animación de pulso dorado cuando hay texto */
.send-btn.has-content {
    animation: golden-pulse 2s ease-in-out infinite;
}

@keyframes golden-pulse {

    0%,
    100% {
        border-color: var(--gold-main);
        box-shadow: 0 0 5px rgba(255, 215, 0, 0.3);
    }

    50% {
        border-color: var(--gold-light);
        box-shadow: 0 0 15px rgba(255, 215, 0, 0.6);
    }
}

.send-btn svg {
    position: relative;
    z-index: 2;
    filter: drop-shadow(0 0 1px rgba(255, 215, 0, 0.5));
    font-weight: 700;
}

/* --- MODALS (Estilo Base PC) --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    /* Keeping this for overlay effect */
    backdrop-filter: blur(5px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 20px;
}

.modal {
    background: var(--bg-panel);
    width: 100%;
    max-width: 500px;
    border-radius: 16px;
    border: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    height: auto;
    box-shadow: var(--shadow-heavy);
    overflow: hidden;
}

.modal-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-panel);
}

.modal-title {
    font-weight: 600;
    color: var(--text-main);
    font-size: 0.9rem;
}

.close-icon {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0 5px;
    line-height: 1;
}

.close-icon:hover {
    color: var(--text-main);
}

.tabs-nav {
    display: flex;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-panel);
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-dim);
    padding: 12px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.8rem;
    transition: 0.2s;
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: var(--hover-light);
}

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

.modal-body {
    padding: 18px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    flex: 1;
}

.tab-content {
    display: none;
    animation: fadeIn 0.2s;
}

.tab-content.active {
    display: block;
}

/* Inputs de Modal */
.field label {
    font-size: 0.65rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.field input,
.field textarea {
    width: 100%;
    padding: 10px;
    font-size: 0.9rem;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    color: var(--text-main);
    outline: none;
}

.field input:focus,
.field textarea:focus {
    border-color: var(--accent);
}

.field textarea {
    min-height: 100px;
}

.key-list {
    gap: 6px;
    max-height: 160px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 2px 0;
}

.list-row {
    padding: 8px 12px;
    font-size: 0.85rem;
    background: var(--bg-input);
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.list-row span {
    color: var(--text-main);
}

.row-del {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 1rem;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.row-del:hover {
    background: var(--hover-light);
    color: var(--accent);
}

.btn-primary {
    padding: 10px;
    font-size: 0.9rem;
    background: var(--bg-input);
    color: var(--gold-main);
    border: 1px solid var(--border-medium);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
    transition: all 0.2s ease;
}

.btn-primary:hover {
    background: var(--hover-light);
    border-color: var(--gold-main);
    transform: translateY(-1px);
}

.btn-secondary {
    padding: 10px;
    font-size: 0.9rem;
    background: var(--bg-input);
    color: var(--text-main);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    cursor: pointer;
}

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

.btn-danger {
    padding: 8px 14px;
    font-size: 0.9rem;
    background: var(--error);
    color: var(--text-main);
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

.btn-danger:hover {
    opacity: 0.9;
}

/* Info Modal */
#info-modal .modal {
    max-width: 320px;
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
}

#info-modal .modal-header {
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-light);
}

#info-modal .modal-title {
    color: var(--text-main);
    font-weight: 600;
}

#info-modal p {
    color: var(--text-main);
    margin: 0;
    text-align: center;
}

/* Info modal type styles */
.modal.error {
    border-color: var(--error);
}

.modal.success {
    border-color: var(--success);
}

.modal.warning {
    border-color: var(--warning);
}

.modal.info {
    border-color: var(--accent);
}

#confirm-modal h3 {
    font-size: 1rem;
    color: var(--text-main);
}

#confirm-modal p {
    color: var(--text-dim);
}

@media (max-width: 768px) {
    #confirm-modal .modal {
        width: calc(100vw - 40px);
        max-width: 320px;
    }
}

/* Specific handling for portrait orientation */
@media (max-width: 768px) and (orientation: portrait) {
    #confirm-modal .modal {
        width: 90vw;
        max-width: 320px;
    }
}

/* Historial Items */
.session-list {
    gap: 5px;
    display: flex;
    flex-direction: column;
}

.session-item {
    padding: 12px;
    background: var(--bg-input);
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    border: 1px solid transparent;
}

.session-item:hover {
    background: var(--hover-light);
    border-color: var(--border-light);
}

.session-item.active {
    border-color: var(--accent);
    background: var(--hover-light);
}

.session-meta {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.session-title {
    font-size: 0.85rem;
    color: var(--text-main);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-date {
    font-size: 0.65rem;
    color: var(--text-dim);
    margin-top: 4px;
}

.row-del {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.row-del:hover {
    background: var(--hover-light);
    color: var(--accent);
}

/* Toasts */
/* Toasts (Mini Modales Flotantes) */
#toasts {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    /* Clicks pass through container */
    width: auto;
    max-width: 90%;
    align-items: center;
}

.toast {
    padding: 10px 20px;
    font-size: 0.85rem;
    background: var(--bg-panel);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-light);
    color: var(--text-main);
    border-radius: 50px;
    /* Pill shape */
    box-shadow: var(--shadow-medium);
    pointer-events: auto;
    /* Enable clicks on toast */
    animation: toastSlideDown 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.toast.error {
    border-color: var(--error);
    color: var(--error);
    background: var(--bg-panel);
}

.toast.success {
    border-color: var(--success);
    color: var(--success);
    background: var(--bg-panel);
}

.toast.info {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--bg-panel);
}

.toast.warning {
    border-color: var(--warning);
    color: var(--warning);
    background: var(--bg-panel);
}

@keyframes toastSlideDown {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.9);
    }

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

@keyframes toastSlideUp {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }

    to {
        opacity: 0;
        transform: translateY(-20px) scale(0.9);
    }
}

/* --- 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 --- */
.conversation-modal {
    max-width: 100vw;
    width: 100vw;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    background: var(--bg-core);
}

@media (max-width: 768px) {
    .conversation-modal {
        max-width: 100vw;
        width: 100vw;
        max-height: 100vh;
        height: 100vh;
    }
}

.conversation-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 30px 18px;
}

/* Estado de conversación */
.conversation-state {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.state-icon {
    font-size: 2.5rem;
    animation: pulse 2s infinite;
}

.state-text {
    font-size: 0.9rem;
    color: var(--text-dim);
    font-weight: 500;
}

/* Botón principal de conversación */
.conversation-btn {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: var(--grad-main);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(255, 215, 0, 0.3);
    /* Using gold color for the shadow */
}

.conversation-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 30px rgba(255, 215, 0, 0.5);
    /* Using gold color for the shadow */
}

.conversation-btn:active {
    transform: scale(0.95);
}

.conversation-btn.active {
    animation: pulse-btn 1.5s infinite;
    background: var(--grad-accent);
}

.conversation-btn.processing {
    background: var(--grad-highlight);
    animation: rotate 2s linear infinite;
}

.conversation-btn.speaking {
    background: var(--grad-main);
    animation: pulse-btn 1s infinite;
}

.mic-icon {
    width: 40px;
    height: 40px;
    color: var(--text-main);
}

/* Visualizador de audio */
.audio-visualizer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 40px;
    opacity: 0;
    transition: opacity 0.3s;
}

.audio-visualizer.active {
    opacity: 1;
}

.audio-bar {
    width: 4px;
    height: 8px;
    background: var(--accent);
    border-radius: 2px;
    animation: audio-wave 0.8s ease-in-out infinite;
}

.audio-bar:nth-child(1) {
    animation-delay: 0s;
}

.audio-bar:nth-child(2) {
    animation-delay: 0.1s;
}

.audio-bar:nth-child(3) {
    animation-delay: 0.2s;
}

.audio-bar:nth-child(4) {
    animation-delay: 0.3s;
}

.audio-bar:nth-child(5) {
    animation-delay: 0.4s;
}

/* Log de conversación */
.conversation-log {
    width: 100%;
    max-height: 300px;
    overflow-y: auto;
    background: var(--bg-input);
    border-radius: 12px;
    padding: 12px;
    font-size: 0.85rem;
    line-height: 1.6;
}

.log-placeholder {
    text-align: center;
    color: var(--text-dim);
    padding: 20px;
    font-style: italic;
}

.log-entry {
    margin-bottom: 12px;
    padding: 8px 12px;
    border-radius: 8px;
    animation: fadeIn 0.3s;
}

.log-entry.user {
    background: var(--hover-light);
    border-left: 3px solid var(--accent);
}

.log-entry.ai {
    background: rgba(255, 236, 139, 0.05);
    /* Gold tint */
    border-left: 3px solid var(--accent-light);
}

.log-entry-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 4px;
    font-weight: 600;
}

.log-entry-text {
    color: var(--text-main);
}

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

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

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

@keyframes pulse {
    0% {
        opacity: 0.7;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.7;
    }
}

@keyframes pulse-btn {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

@keyframes audio-wave {

    0%,
    100% {
        height: 8px;
    }

    50% {
        height: 32px;
    }
}
/* Auth UI Styles */
.auth-container {
    padding: 10px;
    overflow-y: auto;
    max-height: 100%;
    display: flex;
    flex-direction: column;
}

.auth-tabs {
    display: flex;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0; /* Evitar que las pestañas se encojan */
}

.auth-tab {
    flex: 1;
    padding: 10px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 500;
}

.auth-tab.active {
    color: var(--color-gold);
    border-bottom: 2px solid var(--color-gold);
}

.auth-form .field {
    margin-bottom: 15px;
}

.auth-form label {
    display: block;
    margin-bottom: 5px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.auth-form input {
    width: 100%;
    padding: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    color: var(--text-main);
}

.auth-message {
    margin-top: 15px;
    padding: 10px;
    border-radius: 6px;
    font-size: 0.9rem;
    text-align: center;
}

.auth-message.error {
    background: rgba(255, 107, 107, 0.1);
    color: #ff6b6b;
    border: 1px solid rgba(255, 107, 107, 0.2);
}

.auth-message.success {
    background: rgba(74, 222, 128, 0.1);
    color: #4ade80;
    border: 1px solid rgba(74, 222, 128, 0.2);
}

.auth-message.info {
    background: rgba(59, 130, 246, 0.1);
    color: #60a5fa;
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-light);
}

.profile-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--bg-panel);
    border: 2px solid var(--color-gold);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-placeholder {
    font-size: 24px;
    font-weight: bold;
    color: var(--color-gold);
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
}

.badge.free { background: #71717a; color: white; }
.badge.premium { background: var(--color-gold); color: black; }
.badge.admin { background: #ef4444; color: white; }

.full-width {
    width: 100%;
}

/* Profile Actions */
.profile-avatar-wrapper {
    position: relative;
    cursor: pointer;
}

.avatar-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
    font-size: 24px;
}

.profile-avatar-wrapper:hover .avatar-overlay {
    opacity: 1;
}

.profile-name-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.icon-btn-small {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    opacity: 0.7;
}

.icon-btn-small:hover {
    opacity: 1;
}

.profile-actions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
}

.action-card {
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-main);
}

.action-card:hover {
    background: var(--bg-panel);
    border-color: var(--color-gold);
}

.action-card .icon {
    font-size: 24px;
}

.action-card .label {
    font-size: 0.9rem;
    font-weight: 500;
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Password Form Animation */
#password-form {
    overflow: hidden;
    transition: max-height 0.3s ease-out, opacity 0.3s ease-out, padding 0.3s ease;
    max-height: 0;
    opacity: 0;
    padding: 0 15px; /* Padding horizontal fijo, vertical animado */
    margin-top: 0;
    border: none;
}

#password-form.visible {
    max-height: 400px; /* Altura suficiente */
    opacity: 1;
    padding: 15px;
    margin-top: 15px;
    border: 1px solid var(--border-light);
}

/* --- 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 {
    width: 20px;
    height: 20px;
    stroke-width: 2;
}

.sidebar-item.danger {
    color: #ef4444;
}

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

.sidebar-footer {
    padding: 20px 15px;
    border-top: 1px solid var(--border-light);
    background: rgba(9, 9, 11, 0.3);
}

.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;
}
