/* ============================================================
   Serficon IA — Estilos principales
   ============================================================ */

:root {
    /* Colores base - tema oscuro profesional */
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-sidebar: #12122b;
    --bg-input: #1e1e3a;
    --bg-hover: rgba(255,255,255,0.05);
    --bg-active: rgba(255,255,255,0.08);

    /* Texto */
    --text-primary: #e8e8f0;
    --text-secondary: #a0a0bc;
    --text-muted: #6b6b88;
    --text-accent: #64b5f6;

    /* Acentos */
    --accent: #4fc3f7;
    --accent-hover: #81d4fa;
    --accent-dim: rgba(79,195,247,0.15);
    --success: #66bb6a;
    --warning: #ffa726;
    --danger: #ef5350;

    /* Bordes */
    --border: rgba(255,255,255,0.08);
    --border-hover: rgba(255,255,255,0.15);

    /* Sombras */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);

    /* Layout */
    --sidebar-width: 280px;
    --header-height: 56px;
    --input-height: auto;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;

    /* Tipografía */
    --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* Transiciones */
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

button {
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

input, textarea, select {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    background: none;
    border: none;
    outline: none;
}

/* ── Scrollbar personalizado ────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ── Layout principal ───────────────────────────────────────── */
#app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Login ──────────────────────────────────────────────────── */
#login-view {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    width: 100%;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 50%, var(--bg-tertiary) 100%);
}

.login-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 48px 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.login-card h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.login-card p {
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-size: 14px;
}

.login-card .logo {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 24px;
    letter-spacing: -0.5px;
    text-align: center;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    transition: border-color var(--transition);
}

.form-group input:focus {
    border-color: var(--accent);
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: #0d1b2a;
    font-weight: 600;
    border-radius: var(--radius-sm);
    transition: background var(--transition), transform 0.1s;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.login-error {
    background: rgba(239,83,80,0.1);
    border: 1px solid rgba(239,83,80,0.3);
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius-xs);
    font-size: 13px;
    margin-bottom: 16px;
    display: none;
}

/* ── Sidebar ────────────────────────────────────────────────── */
#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition);
    z-index: 100;
}

.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.sidebar-close-btn {
    display: none;
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    padding: 8px 12px;
    color: var(--text-muted);
    font-size: 16px;
    border-radius: var(--radius-xs);
}
.sidebar-close-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.sidebar-header .logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.3px;
}

#btn-new-chat {
    display: flex;
    align-items: center;
    gap: 8px;
    width: calc(100% - 32px);
    margin: 12px 16px;
    padding: 10px 14px;
    background: var(--accent-dim);
    border: 1px solid rgba(79,195,247,0.2);
    border-radius: var(--radius-sm);
    color: var(--accent);
    font-weight: 500;
    font-size: 14px;
    transition: all var(--transition);
}

#btn-new-chat:hover {
    background: rgba(79,195,247,0.25);
    border-color: rgba(79,195,247,0.4);
}

#btn-new-chat svg { width: 18px; height: 18px; }

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: background var(--transition);
    margin-bottom: 2px;
}

.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-active); }

.chat-item-title {
    flex: 1;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item.active .chat-item-title { color: var(--text-primary); }

.chat-item-date {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

.chat-item-delete {
    opacity: 0;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 4px;
    transition: all var(--transition);
}

.chat-item:hover .chat-item-delete { opacity: 1; }
.chat-item-delete:hover { color: var(--danger); background: rgba(239,83,80,0.1); }

/* Sidebar footer */
.sidebar-footer {
    padding: 10px 16px;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.sidebar-footer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-footer-row strong {
    font-size: 13px;
    color: var(--text-primary);
}

.sidebar-settings-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    color: var(--text-secondary);
    font-size: 14px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    width: 100%;
    text-align: left;
    background: var(--bg-hover);
}
.sidebar-settings-btn:hover { background: var(--accent-dim); color: var(--accent); }
.sidebar-settings-btn svg { flex-shrink: 0; }

#btn-logout {
    font-size: 13px;
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: var(--radius-xs);
    transition: all var(--transition);
}
#btn-logout:hover { color: var(--danger); background: rgba(239,83,80,0.1); }

/* ── Main area ──────────────────────────────────────────────── */
#main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-width: 0;
}

/* Header */
#chat-header {
    height: var(--header-height);
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--bg-primary);
}

#btn-toggle-sidebar {
    display: none;
    padding: 8px;
    color: var(--text-secondary);
    border-radius: var(--radius-xs);
}
#btn-toggle-sidebar:hover { background: var(--bg-hover); }

#chat-title {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Model selector */
#model-select {
    padding: 6px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: border-color var(--transition);
    min-width: 180px;
}

#model-select:hover { border-color: var(--border-hover); }
#model-select:focus { border-color: var(--accent); }
#model-select option { background: var(--bg-secondary); color: var(--text-primary); }

/* Token usage badge */
.usage-badge {
    font-size: 11px;
    color: var(--text-muted);
    padding: 4px 10px;
    background: var(--bg-input);
    border-radius: 20px;
    white-space: nowrap;
}

/* ── Messages area ──────────────────────────────────────────── */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
}

.messages-container {
    max-width: 780px;
    margin: 0 auto;
    padding: 0 24px;
}

/* Welcome screen */
.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    text-align: center;
    padding: 40px;
}

.welcome h2 {
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.welcome p {
    color: var(--text-secondary);
    max-width: 460px;
    margin-bottom: 32px;
}

.welcome-suggestions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    max-width: 520px;
    width: 100%;
}

.suggestion-card {
    padding: 14px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-align: left;
    font-size: 13px;
    color: var(--text-secondary);
    transition: all var(--transition);
    cursor: pointer;
}

.suggestion-card:hover {
    border-color: var(--accent);
    background: var(--accent-dim);
    color: var(--text-primary);
}

/* Message bubbles */
.message {
    display: flex;
    gap: 14px;
    margin-bottom: 24px;
    animation: fadeIn 0.3s ease;
}

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

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
    margin-top: 2px;
}

.message.user .message-avatar {
    background: var(--accent-dim);
    color: var(--accent);
}

.message.assistant .message-avatar {
    background: rgba(102,187,106,0.15);
    color: var(--success);
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.message-role {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.message-model {
    font-size: 11px;
    color: var(--text-muted);
    padding: 1px 8px;
    background: var(--bg-input);
    border-radius: 10px;
}

.message-body {
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
}

/* Markdown styles in messages */
.message-body p { margin-bottom: 12px; }
.message-body p:last-child { margin-bottom: 0; }

.message-body h1, .message-body h2, .message-body h3 {
    margin: 20px 0 8px;
    font-weight: 600;
    color: var(--text-primary);
}
.message-body h1 { font-size: 20px; }
.message-body h2 { font-size: 17px; }
.message-body h3 { font-size: 15px; }

.message-body ul, .message-body ol {
    padding-left: 24px;
    margin-bottom: 12px;
}

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

.message-body strong { font-weight: 600; color: var(--text-primary); }
.message-body em { font-style: italic; }

.message-body a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.message-body blockquote {
    border-left: 3px solid var(--accent);
    padding: 8px 16px;
    margin: 12px 0;
    color: var(--text-secondary);
    background: var(--bg-input);
    border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
}

.message-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 14px;
}

.message-body th, .message-body td {
    padding: 8px 12px;
    text-align: left;
    border: 1px solid var(--border);
}

.message-body th {
    background: var(--bg-input);
    font-weight: 600;
    font-size: 13px;
}

/* Code blocks */
.message-body code {
    font-family: var(--font-mono);
    font-size: 13px;
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--accent);
}

.message-body pre {
    background: #0d1117;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    overflow-x: auto;
    margin: 12px 0;
    position: relative;
}

.message-body pre code {
    background: none;
    padding: 0;
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.5;
}

.code-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 10px;
    font-size: 11px;
    background: rgba(255,255,255,0.08);
    color: var(--text-muted);
    border-radius: 4px;
    transition: all var(--transition);
}
.code-copy-btn:hover { background: rgba(255,255,255,0.15); color: var(--text-primary); }

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1); }
}

/* ── Input area ─────────────────────────────────────────────── */
#input-area {
    padding: 16px 24px 24px;
    background: var(--bg-primary);
}

.input-container {
    max-width: 780px;
    margin: 0 auto;
    position: relative;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    transition: border-color var(--transition);
    gap: 8px;
}

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

/* File upload zone */
.input-wrapper.drag-over {
    border-color: var(--accent);
    background: var(--accent-dim);
}

#message-input {
    flex: 1;
    resize: none;
    min-height: 24px;
    max-height: 200px;
    padding: 6px 4px;
    line-height: 1.5;
    color: var(--text-primary);
    background: transparent;
}

#message-input::placeholder { color: var(--text-muted); }

.input-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    padding-bottom: 2px;
}

.input-btn {
    padding: 8px;
    border-radius: var(--radius-xs);
    color: var(--text-muted);
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-btn:hover { background: var(--bg-hover); color: var(--text-secondary); }

#btn-send {
    background: var(--accent);
    color: #0d1b2a;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

#btn-send:hover { background: var(--accent-hover); }
#btn-send:disabled { opacity: 0.3; cursor: not-allowed; }
#btn-send svg { width: 18px; height: 18px; }

/* Attached files preview */
.attachments-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 0 0;
}

.attachment-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--accent-dim);
    border: 1px solid rgba(79,195,247,0.2);
    border-radius: 20px;
    font-size: 12px;
    color: var(--accent);
}

.attachment-chip .remove {
    cursor: pointer;
    opacity: 0.6;
    transition: opacity var(--transition);
}
.attachment-chip .remove:hover { opacity: 1; }

/* Footer info */
.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-muted);
}

/* ── Stop button ────────────────────────────────────────────── */
#btn-stop {
    display: none;
    margin: 0 auto 12px;
    padding: 8px 20px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 13px;
    transition: all var(--transition);
}
#btn-stop:hover { border-color: var(--danger); color: var(--danger); }

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — TABLET (≤1024px)
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
    #chat-header { gap: 8px; padding: 0 12px; }
    #chat-title { font-size: 14px; }
    #prompt-select { max-width: 140px; font-size: 12px; }
    #model-select { min-width: 140px; font-size: 12px; }
    .usage-badge { font-size: 10px; padding: 3px 8px; }
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — MÓVIL (≤768px)
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

    /* ── Sidebar ──────────────────────────────────────────── */
    #sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 82vw;
        max-width: 340px;
        height: 100%;
        height: 100dvh;
        transform: translateX(-100%);
        box-shadow: 8px 0 30px rgba(0,0,0,0.4);
        z-index: 100;
    }
    #sidebar.open { transform: translateX(0); }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.55);
        z-index: 99;
        -webkit-backdrop-filter: blur(3px);
        backdrop-filter: blur(3px);
    }
    #sidebar.open ~ .sidebar-overlay { display: block; }

    #btn-toggle-sidebar { display: flex; padding: 10px; }

    .sidebar-header { padding: 20px 16px; }
    .sidebar-header .logo img { height: 52px !important; }
    .sidebar-close-btn { display: block; }

    .sidebar-footer {
        padding: 12px 16px;
        padding-bottom: max(16px, calc(12px + env(safe-area-inset-bottom)));
    }
    .sidebar-settings-btn { padding: 14px 16px; font-size: 14px; }

    .chat-item { padding: 14px 12px; }
    .chat-item-delete { opacity: 1; padding: 8px; }

    #btn-new-chat { padding: 14px 16px; font-size: 14px; }

    /* ── Header ───────────────────────────────────────────── */
    #chat-header {
        height: auto;
        padding: 10px 12px;
        flex-wrap: wrap;
        gap: 8px;
        position: sticky;
        top: 0;
        z-index: 10;
    }

    /* Fila 1: hamburguesa + título + tokens */
    #btn-toggle-sidebar { order: 0; }
    #chat-title {
        order: 1;
        flex: 1;
        min-width: 0;
        font-size: 14px;
        font-weight: 600;
    }
    .usage-badge {
        order: 2;
        font-size: 9px;
        padding: 3px 8px;
    }

    /* Fila 2: prompt + modelo + export - ancho completo */
    #prompt-select {
        order: 3;
        flex: 1;
        min-width: 0;
        max-width: none;
        font-size: 13px;
        padding: 9px 10px;
        border-radius: 8px;
    }
    #model-select {
        order: 4;
        flex: 1;
        min-width: 0;
        font-size: 13px;
        padding: 9px 10px;
        border-radius: 8px;
    }
    .export-menu { order: 5; }
    .export-dropdown { right: 0; left: auto; }

    /* ── Welcome ──────────────────────────────────────────── */
    .welcome {
        padding: 40px 24px;
        min-height: 50vh;
    }
    .welcome img { height: 80px !important; }
    .welcome h2 {
        font-size: 22px;
        padding: 0 8px;
    }
    .welcome p {
        font-size: 14px;
        padding: 0 8px;
    }

    /* ── Mensajes ─────────────────────────────────────────── */
    .messages-container { padding: 0 16px; }

    .message {
        gap: 10px;
        margin-bottom: 20px;
    }
    .message-avatar {
        width: 30px;
        height: 30px;
        font-size: 12px;
        flex-shrink: 0;
    }
    .message-body {
        font-size: 14.5px;
        line-height: 1.65;
        overflow-wrap: break-word;
        word-break: break-word;
    }
    .message-body pre {
        font-size: 12px;
        padding: 12px;
        margin-left: 0;
        margin-right: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .message-body table {
        font-size: 12px;
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: calc(100vw - 80px);
    }
    .message-model {
        font-size: 10px;
        padding: 2px 6px;
    }

    /* ── Input area ───────────────────────────────────────── */
    #input-area {
        padding: 8px 12px;
        padding-bottom: max(12px, calc(8px + env(safe-area-inset-bottom)));
    }
    .input-wrapper {
        padding: 6px 10px;
        border-radius: 14px;
    }
    #message-input {
        font-size: 16px;
        padding: 8px 4px;
        min-height: 22px;
    }
    .input-btn { padding: 10px; }
    #btn-send {
        padding: 10px 14px;
        border-radius: 12px;
    }
    #btn-send svg { width: 18px; height: 18px; }
    .input-footer { font-size: 10px; margin-top: 4px; }

    /* ── Stop button ──────────────────────────────────────── */
    #btn-stop {
        font-size: 12px;
        padding: 8px 16px;
        border-radius: 16px;
    }

    /* ── Login ────────────────────────────────────────────── */
    #login-view { padding: 16px; }
    .login-card {
        padding: 32px 24px;
        border-radius: 16px;
    }
    .login-card .logo img { height: 80px !important; }
    .login-card h1 { font-size: 20px; }
    .login-card p { font-size: 13px; margin-bottom: 24px; }
    .form-group input {
        padding: 14px 16px;
        font-size: 16px;
        border-radius: 10px;
    }
    .btn-primary {
        padding: 14px;
        font-size: 16px;
        border-radius: 10px;
    }

    /* ── Indicadores ──────────────────────────────────────── */
    .thinking-indicator, .search-indicator, .search-done, .thinking-done {
        font-size: 12px;
        padding: 8px 12px;
        border-radius: 8px;
    }
    .search-sources { gap: 4px; }
    .search-source-link { font-size: 10px; max-width: 160px; }

    /* ── Retry siempre visible ────────────────────────────── */
    .btn-retry { opacity: 1 !important; }

    /* ── Attachment chips ─────────────────────────────────── */
    .attachment-chip {
        font-size: 12px;
        padding: 6px 10px;
    }
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — MÓVIL PEQUEÑO (≤400px)
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 400px) {
    #chat-title { font-size: 12px; }
    .usage-badge { display: none; }

    .message-avatar { width: 26px; height: 26px; font-size: 11px; }
    .message-body { font-size: 13.5px; }

    .welcome { padding: 32px 16px; }
    .welcome img { height: 64px !important; }
    .welcome h2 { font-size: 19px; }
    .welcome p { font-size: 13px; }

    .login-card { padding: 24px 20px; }
    .login-card .logo img { height: 64px !important; }
}

/* ══════════════════════════════════════════════════════════════
   SAFE AREA — iPhone notch / barra inferior
   ══════════════════════════════════════════════════════════════ */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    #sidebar { padding-top: env(safe-area-inset-top); }
    #login-view {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ══════════════════════════════════════════════════════════════
   STANDALONE MODE (PWA en pantalla de inicio)
   ══════════════════════════════════════════════════════════════ */
@media (display-mode: standalone) {
    body {
        overscroll-behavior: none;
        -webkit-user-select: none;
        user-select: auto;
    }
    html, body {
        overflow: hidden;
        height: 100%;
    }
    .message-body {
        -webkit-user-select: text;
        user-select: text;
    }
    #chat-header {
        padding-top: max(10px, env(safe-area-inset-top));
    }
    #input-area {
        padding-bottom: max(12px, calc(8px + env(safe-area-inset-bottom)));
    }
    #sidebar {
        padding-top: max(12px, env(safe-area-inset-top));
        height: 100dvh;
    }
}

/* ── Loading spinner ────────────────────────────────────────── */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── File input (oculto, se dispara por JS) ─────────────────── */
#file-input {
    display: none !important;
}

/* ── Hidden utility ─────────────────────────────────────────── */
.hidden { display: none !important; }
