/* ═══════════════════════════════════════════════════════════
   AsysaChatIA — Dark Theme CSS
   Diseño fiel a las capturas del proyecto
   ═══════════════════════════════════════════════════════════ */

/* ── Reset & Variables ── */
:root {
    --bg-primary: #1a1d23;
    --bg-secondary: #22262e;
    --bg-card: #282c34;
    --bg-card-hover: #2e3340;
    --bg-input: #1e2128;
    --bg-sidebar: #1e2228;
    --bg-modal-overlay: rgba(0, 0, 0, 0.6);

    --border-color: #353a44;
    --border-input: #444b58;
    --border-focus: #4a9eff;

    --text-primary: #e4e6eb;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --text-label: #8b929e;

    --accent-green: #10b981;
    --accent-green-bg: rgba(16, 185, 129, 0.15);
    --accent-blue: #3b82f6;
    --accent-blue-bg: rgba(59, 130, 246, 0.15);
    --accent-yellow: #f59e0b;
    --accent-yellow-bg: rgba(245, 158, 11, 0.15);
    --accent-red: #ef4444;
    --accent-red-bg: rgba(239, 68, 68, 0.15);
    --accent-orange: #f97316;
    --accent-cyan: #06b6d4;

    --btn-primary: #3b82f6;
    --btn-primary-hover: #2563eb;
    --btn-danger: #ef4444;
    --btn-danger-hover: #dc2626;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.3);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;
    --radius-full: 50%;

    --transition: 0.2s ease;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

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

html {
    font-size: 14px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

/* ── Scrollbar personalizada ── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #444b58;
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: #5a6272;
}

/* ═══ LAYOUT ═══ */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    padding: 28px 48px;
    width: 100%;
    box-sizing: border-box;
}

/* ═══ HEADER DE PÁGINA ═══ */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 28px;
}

.page-header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.page-header-icon {
    width: 42px;
    height: 42px;
    background: var(--bg-card);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 1.3rem;
    border: 1px solid var(--border-color);
}

.page-header h1 {
    font-size: 1.55rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.page-header p {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.page-header-actions {
    display: flex;
    gap: 10px;
}

/* ═══ BOTONES ═══ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    font-family: inherit;
}

.btn-primary {
    background: var(--btn-primary);
    color: #fff;
    border-color: var(--btn-primary);
}
.btn-primary:hover {
    background: var(--btn-primary-hover);
    border-color: var(--btn-primary-hover);
}

.btn-outline {
    background: transparent;
    color: var(--text-primary);
    border-color: var(--border-color);
}
.btn-outline:hover {
    background: var(--bg-card);
    border-color: var(--border-input);
}

.btn-danger {
    background: var(--btn-danger);
    color: #fff;
}
.btn-danger:hover {
    background: var(--btn-danger-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    padding: 6px 10px;
}
.btn-ghost:hover {
    color: var(--text-primary);
    background: var(--bg-card);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.82rem;
}

.btn-icon {
    width: 34px;
    height: 34px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
}

/* ═══ CARDS ═══ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 22px;
    box-shadow: var(--shadow-card);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.card-header h2 {
    font-size: 1.05rem;
    font-weight: 600;
}

.card-header .icon {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* ═══ CONSUMO DEL DÍA ═══ */
.consumption-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 22px 26px;
    margin-bottom: 24px;
}

.consumption-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.consumption-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.consumption-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.consumption-header .icon {
    color: var(--text-secondary);
}

.consumption-badge {
    background: var(--accent-green-bg);
    color: var(--accent-green);
    padding: 3px 12px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
}

.progress-bar-container {
    width: 100%;
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 20px;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-green), #34d399);
    border-radius: 4px;
    transition: width 0.5s ease;
}

.consumption-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    text-align: center;
    margin-bottom: 10px;
}

.consumption-stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.consumption-stat-value.green { color: var(--accent-green); }
.consumption-stat-value.blue { color: var(--accent-blue); }
.consumption-stat-value.yellow { color: var(--accent-yellow); }

.consumption-stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.consumption-provider-info {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ═══ PROVIDERS GRID ═══ */
#providersContainer {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

/* ═══ PROVIDER CARD ═══ */
.provider-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 22px;
    transition: border-color 0.3s, box-shadow 0.3s;
    position: relative;
}

.provider-card.is-default {
    border: 2px solid var(--accent-blue);
    box-shadow: 0 0 18px rgba(59, 130, 246, 0.25), 0 0 4px rgba(59, 130, 246, 0.15);
}

.provider-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}

.provider-card-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.provider-card-avatar {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-full);
    background: #ffffff;
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.provider-card-name {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.provider-card-sub {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.badge-default {
    display: none;
}

.provider-star-btn {
    position: absolute;
    top: -8px;
    left: -8px;
    background: var(--bg-card);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
    padding: 0;
    transition: transform 0.2s, filter 0.2s;
}

.provider-star-btn:hover {
    transform: scale(1.2);
}

.provider-star-btn .material-symbols-rounded {
    font-size: 1.3rem;
    color: #4a5568;
    transition: color 0.2s;
}

.provider-star-btn:hover .material-symbols-rounded {
    color: #fbbf24;
}

.provider-card.is-default .provider-star-btn .material-symbols-rounded {
    color: #fbbf24;
    filter: drop-shadow(0 0 4px rgba(251, 191, 36, 0.5));
}

.badge-economic {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: #2d6a4f;
    color: #b7e4c7;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Toggle switch */
.toggle-switch {
    position: relative;
    width: 40px;
    height: 22px;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: #4a5568;
    border-radius: 11px;
    transition: var(--transition);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: var(--transition);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent-green);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(18px);
}

.provider-card-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 24px;
}

.provider-detail-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.provider-detail-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.provider-card-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--border-color);
}

.provider-edit-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
    background: none;
    border: none;
    font-family: inherit;
    transition: color var(--transition);
}
.provider-edit-btn:hover { color: var(--text-primary); }

.provider-delete-btn {
    color: var(--accent-red);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px;
    transition: opacity var(--transition);
}
.provider-delete-btn:hover { opacity: 0.7; }

/* ═══ ESTADÍSTICAS DE USO ═══ */
.stats-section {
    margin-top: 32px;
}

.stats-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.stats-header h2 {
    font-size: 1.15rem;
    font-weight: 600;
}

.stats-badges {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
}

.stat-badge {
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.stat-badge.green {
    background: var(--accent-green);
    color: #fff;
}
.stat-badge.blue {
    background: var(--accent-blue);
    color: #fff;
}
.stat-badge.yellow {
    background: var(--accent-yellow);
    color: #000;
}

/* ═══ TABLA ═══ */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.data-table thead th {
    text-align: left;
    padding: 12px 16px;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.82rem;
    border-bottom: 1px solid var(--border-color);
}

.data-table tbody td {
    padding: 12px 16px;
    color: var(--text-primary);
    border-bottom: 1px solid rgba(53, 58, 68, 0.4);
}

.data-table tbody tr:hover {
    background: var(--bg-card-hover);
}

.data-table .align-right {
    text-align: right;
}

/* ═══ GUÍA RÁPIDA ═══ */
.guide-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px 20px;
    margin-top: 24px;
    cursor: pointer;
    transition: background var(--transition);
}
.guide-bar:hover { background: var(--bg-card-hover); }

.guide-bar span {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.guide-bar .help-icon {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    border: 2px solid var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 700;
}

/* ═══ MODAL / DIALOG ═══ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-modal-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.25s ease;
}

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

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    width: 94%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 28px 32px;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px);
    transition: transform 0.25s ease;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.modal-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
}

.modal-header .edit-icon {
    color: var(--accent-blue);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    transition: color var(--transition);
}
.modal-close:hover { color: var(--text-primary); }

/* ═══ FORMULARIO ═══ */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 18px;
    overflow: visible;
}

.form-row.single {
    grid-template-columns: 1fr;
}

.form-row.four {
    grid-template-columns: repeat(4, 1fr);
}

.form-group {
    position: relative;
}

.form-group label {
    position: absolute;
    top: -8px;
    left: 12px;
    background: var(--bg-secondary);
    padding: 0 6px;
    font-size: 0.75rem;
    color: var(--text-label);
    z-index: 1;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color var(--transition);
    outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--border-focus);
}

.form-group select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%239ca3af' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.form-group textarea {
    resize: vertical;
    min-height: 90px;
}

.form-group .hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.form-group input[type="number"] {
    -moz-appearance: textfield;
}

.form-checkbox-row {
    display: flex;
    align-items: center;
    gap: 28px;
    margin: 18px 0;
}

.form-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.88rem;
    color: var(--text-primary);
}

.form-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: 2px solid var(--border-input);
    background: var(--bg-input);
    appearance: none;
    cursor: pointer;
    position: relative;
    transition: all var(--transition);
}

.form-checkbox input[type="checkbox"]:checked {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
}

.form-checkbox input[type="checkbox"].green-check:checked {
    background: var(--accent-green);
    border-color: var(--accent-green);
}

.form-checkbox input[type="checkbox"]::after {
    content: '';
    position: absolute;
    display: none;
    left: 5px;
    top: 1px;
    width: 5px;
    height: 10px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.form-checkbox input[type="checkbox"]:checked::after {
    display: block;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.btn-cancel {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    padding: 10px 20px;
    font-weight: 500;
    font-family: inherit;
    transition: color var(--transition);
}
.btn-cancel:hover { color: var(--text-primary); }

.btn-save {
    background: var(--accent-blue);
    color: #fff;
    border: none;
    padding: 10px 24px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background var(--transition);
}
.btn-save:hover { background: var(--btn-primary-hover); }

/* ═══ CHAT LAYOUT ═══ */
.chat-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Nav sidebar inside chat layout — solo desktop (>768px) */
@media (min-width: 769px) {
    .chat-nav-sidebar {
        position: relative !important;
        height: 100vh;
        width: 200px !important;
        min-width: 200px !important;
        max-width: 200px !important;
        left: auto !important;
        top: auto !important;
        z-index: auto !important;
        transform: none !important;
        overflow-y: auto;
        overflow-x: hidden;
    }
}

/* ── Chat Sidebar ── */
.chat-sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.chat-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border-color);
}

.chat-sidebar-header h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.05rem;
    font-weight: 600;
}

.chat-sidebar-header h2 .icon {
    font-size: 1.2rem;
}

.new-chat-btn {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all var(--transition);
}
.new-chat-btn:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

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

.chat-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    cursor: pointer;
    transition: background var(--transition);
    border-left: 3px solid transparent;
}

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

.chat-list-item.active {
    background: var(--bg-card);
    border-left-color: var(--accent-blue);
}

.chat-item-info {
    flex: 1;
    min-width: 0;
}

.chat-item-title {
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-meta {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 2px;
    display: flex;
    gap: 8px;
}

.chat-item-actions {
    opacity: 0;
    transition: opacity var(--transition);
}

.chat-list-item:hover .chat-item-actions {
    opacity: 1;
}

.chat-item-menu-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    font-size: 1.1rem;
    line-height: 1;
}
.chat-item-menu-btn:hover { color: var(--text-primary); }

/* ── Archived Section ── */
.chat-archived-section {
    border-top: 1px solid var(--border-color);
}

.archived-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 18px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition);
    font-family: inherit;
}
.archived-toggle:hover {
    background: var(--bg-card);
}

.archived-count {
    background: var(--bg-input);
    padding: 1px 7px;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
}

.archived-chevron {
    margin-left: auto;
}

.chat-archived-list {
    max-height: 200px;
    overflow-y: auto;
}

.chat-archived-list .chat-list-item {
    opacity: 0.7;
}
.chat-archived-list .chat-list-item:hover {
    opacity: 1;
}

/* ── Session Context Menu ── */
.session-context-menu {
    position: fixed;
    z-index: 500;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    min-width: 170px;
    padding: 4px;
    overflow: hidden;
}

.session-context-menu button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 14px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background var(--transition), color var(--transition);
    font-family: inherit;
}

.session-context-menu button:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.session-context-menu button.danger {
    color: var(--accent-red);
}
.session-context-menu button.danger:hover {
    background: var(--accent-red-bg);
    color: var(--accent-red);
}

.session-context-menu button .material-symbols-rounded {
    font-size: 1.1rem;
}

/* ── Chat Sidebar Footer (Consumo) ── */
.chat-sidebar-footer {
    padding: 14px 18px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-sidebar);
}

.sidebar-consumption-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.sidebar-consumption-header span {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.sidebar-consumption-header strong {
    font-size: 0.82rem;
    color: var(--text-primary);
}

.sidebar-progress-bar {
    width: 100%;
    height: 5px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 6px;
}

.sidebar-progress-fill {
    height: 100%;
    background: var(--accent-green);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.sidebar-consumption-details {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.sidebar-consumption-detail {
    display: flex;
    flex-direction: column;
}

/* ── Chat Main Area ── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--bg-primary);
    position: relative;
}

/* ── Drag & drop de archivos (compartido por todos los chats) ── */
.chat-attach-overlay-element {
    position: absolute;
    inset: 12px;
    z-index: 50;
    border: 3px dashed var(--accent-blue, #6366f1);
    border-radius: 14px;
    background: rgba(99, 102, 241, 0.12);
    display: none;
    pointer-events: none;
    animation: chat-drag-pulse 1.4s ease-in-out infinite;
}
.chat-attach-overlay-element.active { display: block; }
.chat-attach-overlay-element::before {
    content: '📎  Suelta el archivo para adjuntarlo al chat';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 14px 22px;
    background: var(--bg-secondary);
    border: 1px solid var(--accent-blue, #6366f1);
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent-blue, #6366f1);
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
}
@keyframes chat-drag-pulse {
    0%, 100% { background: rgba(99, 102, 241, 0.10); }
    50% { background: rgba(99, 102, 241, 0.20); }
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-header-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.85rem;
}

.chat-header-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chat-header-model {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.chat-header-settings {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}
.chat-header-settings:hover {
    color: var(--text-primary);
    background: var(--bg-card);
}

/* ── Chat Model Selector ── */
.chat-model-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}
.chat-model-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    white-space: nowrap;
}
.chat-model-selector select {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 5px 10px;
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    min-width: 160px;
    outline: none;
    transition: border-color var(--transition);
}
.chat-model-selector select:focus {
    border-color: var(--accent-blue);
}
.chat-model-selector select option {
    background: var(--bg-card);
    color: var(--text-primary);
}

/* ── Chat Messages Area ── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
}

/* ── Welcome Screen ── */
.chat-welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    text-align: center;
}

.chat-welcome-icon {
    width: 72px;
    height: 72px;
    border-radius: var(--radius-full);
    background: var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    font-size: 2rem;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.chat-welcome h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.chat-welcome p {
    font-size: 0.92rem;
    color: var(--text-muted);
    margin-bottom: 32px;
}

.chat-suggestions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    max-width: 620px;
    width: 100%;
}

.chat-suggestion-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px 18px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    text-align: left;
    transition: all var(--transition);
}

.chat-suggestion-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-input);
}

.chat-suggestion-icon {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.chat-suggestion-text h4 {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 3px;
}

.chat-suggestion-text p {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 0;
}

/* ── Mensajes de chat ── */
.message {
    max-width: 80%;
    margin-bottom: 16px;
    animation: fadeIn 0.3s ease;
}

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

.message-user {
    align-self: flex-end;
}

.message-assistant {
    align-self: flex-start;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

.message-user .message-bubble {
    background: var(--accent-blue);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message-assistant .message-bubble {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
    text-align: right;
}

.message-assistant .message-time {
    text-align: left;
}

/* ── Export Toolbar ── */
/* ── File Download Card (IA-generated files) ── */
.file-download-card {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 12px 0 4px;
    padding: 14px 18px;
    background: var(--bg-tertiary, rgba(255,255,255,0.04));
    border: 1px solid color-mix(in srgb, var(--file-color, #6c757d) 40%, transparent);
    border-left: 4px solid var(--file-color, #6c757d);
    border-radius: var(--radius-md, 10px);
    transition: border-color 0.2s, box-shadow 0.2s;
}
.file-download-card:hover {
    border-color: var(--file-color, #6c757d);
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}
.file-card-icon {
    font-size: 28px;
    line-height: 1;
    flex-shrink: 0;
}
.file-card-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}
.file-card-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.file-card-format {
    font-size: 0.7rem;
    color: var(--file-color, var(--text-muted));
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.file-card-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 0.8rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm, 6px);
    background: var(--file-color, #6c757d);
    color: #fff;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}
.file-card-btn:hover {
    filter: brightness(1.15);
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    transform: translateY(-1px);
}
.file-card-btn:active {
    transform: translateY(0);
}

@media (max-width: 480px) {
    .file-download-card {
        gap: 10px;
        padding: 10px 12px;
    }
    .file-card-btn {
        padding: 6px 12px;
        font-size: 0.75rem;
    }
}

/* ── Mermaid Diagrams ── */
.mermaid-container {
    margin: 14px 0 8px;
    border-radius: var(--radius-md, 10px);
    background: #ffffff;
    border: 1px solid var(--border-color);
    overflow: hidden;
}
.mermaid-diagram {
    padding: 20px;
    display: flex;
    justify-content: center;
    overflow-x: auto;
}
.mermaid-diagram svg {
    max-width: 100%;
    height: auto;
}
.mermaid-actions {
    display: flex;
    gap: 8px;
    padding: 8px 14px;
    background: var(--bg-tertiary, rgba(255,255,255,0.04));
    border-top: 1px solid var(--border-color);
    justify-content: flex-end;
}
.mermaid-download-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm, 6px);
    background: var(--bg-card, #282c34);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}
.mermaid-download-btn:hover {
    background: var(--accent-blue);
    color: #fff;
    border-color: var(--accent-blue);
}
.mermaid-error {
    padding: 12px;
    background: var(--bg-input, #1e2128);
    border-radius: var(--radius-sm, 6px);
    overflow-x: auto;
}
.mermaid-error-msg {
    padding: 8px 12px;
    color: var(--accent-yellow);
    font-size: 0.8rem;
}

/* ── Chat Input Bar ── */
.chat-input-container {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

/* ── Archivo adjunto: preview ── */
.chat-file-preview {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    margin-bottom: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    color: var(--text-secondary);
}
.chat-file-preview img {
    width: 48px; height: 48px;
    object-fit: cover;
    border-radius: 6px;
}
.chat-file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-file-remove {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; padding: 2px; border-radius: 4px; display: flex;
}
.chat-file-remove:hover { color: var(--text-primary); background: var(--bg-card); }

/* ── Archivo adjunto: botón clip ── */
.chat-attach-btn {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; padding: 4px; display: flex; align-items: center;
    border-radius: 4px; transition: color .15s;
}
.chat-attach-btn:hover { color: var(--text-primary); }

/* ── Chip de archivo en mensajes ── */
.chat-file-chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 8px; margin-bottom: 6px;
    background: rgba(99,102,241,0.1); border-radius: 6px;
    font-size: 0.78rem; color: var(--accent-blue);
}
.chat-file-chip .material-symbols-rounded { font-size: .85rem; }
.chat-file-chip-img { flex-direction: column; align-items: flex-start; padding: 6px; }
.chat-file-chip-img img { max-width: 180px; max-height: 120px; border-radius: 6px; object-fit: cover; }
.chat-file-chip-img span { font-size: 0.72rem; color: var(--text-muted); margin-top: 4px; word-break: break-all; }

.chat-input-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: var(--radius-md);
    padding: 4px 4px 4px 16px;
}

.chat-input-bar .input-icon {
    color: var(--text-muted);
    font-size: 1rem;
}

.chat-input-bar input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    font-family: inherit;
    padding: 10px 0;
}

.chat-input-bar input::placeholder {
    color: var(--text-muted);
}

.chat-send-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.chat-send-btn:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

.chat-send-btn.active {
    color: var(--accent-blue);
}

.chat-disclaimer {
    text-align: center;
    font-size: 0.72rem;
    color: var(--accent-orange);
    margin-top: 8px;
}

/* ═══ RESPONSIVE — Mobile-first overrides ═══ */

/* Hamburger button (hidden on desktop) */
.mobile-menu-btn,
.mobile-chat-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: background var(--transition), color var(--transition);
    flex-shrink: 0;
}
.mobile-menu-btn:hover,
.mobile-chat-toggle:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}
.mobile-menu-btn .material-symbols-rounded,
.mobile-chat-toggle .material-symbols-rounded {
    font-size: 1.5rem;
}

/* Sidebar overlay backdrop */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 9998;
    opacity: 0;
    transition: opacity 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}
.sidebar-overlay.open {
    display: block;
    opacity: 1;
}

/* Lock body scroll when sidebar is open on mobile */
body.sidebar-open {
    overflow: hidden !important;
    touch-action: none;
    -webkit-overflow-scrolling: auto;
}

/* ─── Tablet ≤1024px ─── */
@media (max-width: 1024px) {
    .db-layout {
        grid-template-columns: 280px 1fr;
    }
    .detail-info-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .chat-nav-sidebar {
        width: 180px;
        min-width: 180px;
    }
}

/* ─── Mobile ≤768px ─── */
@media (max-width: 768px) {
    /* Show hamburger buttons */
    .mobile-menu-btn,
    .mobile-chat-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Sidebar becomes slide-over overlay */
    .sidebar,
    .chat-nav-sidebar {
        position: fixed !important;
        left: 0 !important;
        top: 0 !important;
        width: 260px !important;
        min-width: 260px !important;
        max-width: 260px !important;
        height: 100% !important;
        height: 100dvh !important;
        z-index: 9999 !important;
        transform: translateX(-105%) !important;
        -webkit-transform: translateX(-105%) !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        box-shadow: none;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
        overscroll-behavior-x: none;
        will-change: transform;
        background: var(--bg-sidebar, #1e2228) !important;
        display: flex !important;
        flex-direction: column !important;
    }
    .sidebar.open,
    .chat-nav-sidebar.open {
        transform: translateX(0) !important;
        -webkit-transform: translateX(0) !important;
        box-shadow: 4px 0 25px rgba(0, 0, 0, 0.5);
    }

    /* Remove sidebar margin for main content */
    body:has(.sidebar) .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }

    /* Main content full width */
    .main-content {
        padding: 16px;
        width: 100%;
    }

    /* Page header stacks vertically */
    .page-header {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 12px;
        padding: 14px 16px;
        align-items: center;
    }
    .page-header-left,
    .header-left {
        flex: 1;
        min-width: 0;
    }
    .page-header-left h1,
    .header-left h1 {
        font-size: 1.15rem;
    }
    .page-header-left p,
    .header-subtitle {
        font-size: 0.78rem;
        display: none;
    }
    .page-header-actions,
    .header-actions {
        flex-shrink: 0;
    }
    .page-header-actions .btn,
    .header-actions .btn {
        font-size: 0.78rem;
        padding: 8px 12px;
    }

    /* Consumption card */
    .consumption-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    /* Provider cards grid single column on mobile */
    #providersContainer {
        grid-template-columns: 1fr;
    }

    /* Provider cards */
    .provider-card-details {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Forms */
    .form-row {
        grid-template-columns: 1fr;
    }
    .form-row.four {
        grid-template-columns: 1fr 1fr;
    }

    /* Modal fullscreen mobile */
    .modal {
        width: 95%;
        max-width: 95%;
        max-height: 90vh;
        margin: 5vh auto;
    }

    /* Chat layout */
    .chat-layout {
        flex-direction: column;
        position: relative;
    }

    /* Chat sidebar hidden by default, slides from right */
    .chat-sidebar {
        position: fixed;
        right: 0;
        top: 0;
        height: 100vh;
        width: 280px;
        min-width: 280px;
        z-index: 150;
        transform: translateX(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: none;
    }
    .chat-sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    /* Chat main takes full width */
    .chat-main {
        width: 100%;
        height: 100vh;
    }

    /* Chat header adjustments */
    .chat-header {
        padding: 10px 12px;
        gap: 8px;
    }
    .chat-header-title {
        font-size: 0.88rem;
    }
    .chat-header-model {
        font-size: 0.7rem;
    }
    .chat-model-selector {
        display: none;
    }

    /* Chat suggestions 2-column on small screens */
    .chat-suggestions {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .chat-suggestion-card {
        padding: 12px;
    }
    .chat-suggestion-text h4 {
        font-size: 0.8rem;
    }
    .chat-suggestion-text p {
        font-size: 0.72rem;
    }

    /* Chat input adjustments */
    .chat-input-bar {
        padding: 8px 10px;
    }
    .chat-input-bar input {
        font-size: 0.88rem;
    }
    .chat-send-btn {
        padding: 8px 14px;
        font-size: 0.78rem;
    }

    /* Message bubbles */
    .message-bubble {
        max-width: 90%;
    }

    /* Database page */
    .db-layout {
        grid-template-columns: 1fr;
        height: auto;
    }
    .db-connections-panel {
        max-height: 300px;
    }
    .detail-info-grid {
        grid-template-columns: 1fr;
    }

    /* Users table */
    .users-table-container {
        overflow-x: auto;
    }

    /* Stats table */
    .stats-section {
        overflow-x: auto;
    }
    .data-table {
        min-width: 400px;
    }

    /* Quota info bar */
    .quota-info-bar {
        flex-direction: column;
        text-align: center;
        font-size: 0.8rem;
    }
}

/* ─── Small phones ≤480px ─── */
@media (max-width: 480px) {
    .main-content {
        padding: 10px;
    }

    /* Stack page header vertically */
    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .page-header > .mobile-menu-btn {
        align-self: flex-start;
    }
    .page-header-left p,
    .header-subtitle {
        display: none;
    }
    .page-header-actions,
    .header-actions {
        width: 100%;
    }
    .page-header-actions .btn,
    .header-actions .btn {
        width: 100%;
        justify-content: center;
    }

    /* Consumption stats single column */
    .consumption-stats {
        grid-template-columns: 1fr 1fr;
    }

    /* Provider card details single column */
    .provider-card-details {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .provider-card-actions {
        flex-direction: column;
        gap: 6px;
    }
    .provider-card-actions .provider-edit-btn,
    .provider-card-actions .provider-delete-btn {
        width: 100%;
        justify-content: center;
    }

    /* Form four-column becomes single on very small */
    .form-row.four {
        grid-template-columns: 1fr;
    }

    /* Chat suggestions single column */
    .chat-suggestions {
        grid-template-columns: 1fr;
    }

    /* Chat send button: icon only */
    .chat-send-btn {
        padding: 8px 10px;
        font-size: 0;
    }
    .chat-send-btn .material-symbols-rounded {
        font-size: 1.1rem !important;
        margin: 0;
    }

    /* Chat welcome */
    .chat-welcome h2 {
        font-size: 1.2rem;
    }
    .chat-welcome p {
        font-size: 0.82rem;
    }

    /* Sidebar overlay slide-over narrower */
    .sidebar.open,
    .chat-nav-sidebar.open {
        width: 240px !important;
        min-width: 240px !important;
        max-width: 240px !important;
        transform: translateX(0) !important;
        -webkit-transform: translateX(0) !important;
    }

    /* Chat header: hide settings links */
    .chat-header-settings {
        display: none;
    }

    /* Modal */
    .modal {
        width: 100%;
        max-width: 100%;
        max-height: 100vh;
        margin: 0;
        border-radius: 0;
    }

    /* User modal */
    .user-modal {
        max-width: 100%;
    }
    .form-row:has(.flex-1),
    .form-row:has(.flex-2) {
        flex-direction: column;
    }

    /* Guide bar */
    .guide-bar {
        font-size: 0.82rem;
        padding: 10px 14px;
    }
}

/* ═══ UTILIDADES ═══ */
.hidden { display: none !important; }
.text-green { color: var(--accent-green); }
.text-blue { color: var(--accent-blue); }
.text-yellow { color: var(--accent-yellow); }
.text-red { color: var(--accent-red); }
.text-muted { color: var(--text-muted); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }

/* Typing indicator */
#typingIndicator {
    max-width: fit-content !important;
}

#typingIndicator .message-bubble {
    display: inline-flex;
    padding: 8px 14px !important;
    line-height: 1;
    white-space: nowrap;
}

.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0;
    flex-wrap: wrap;
}

/* ── Fase chat-step: ícono parpadeante + label de paso actual ── */
.typing-indicator .typing-ai-icon {
    color: var(--accent-blue, #6366f1);
    font-size: 1.05rem;
    animation: chat-typing-pulse 1.5s ease-in-out infinite;
    line-height: 1;
}
.typing-indicator .typing-step {
    color: var(--text-primary);
    font-size: 0.88rem;
    font-weight: 500;
}
@keyframes chat-typing-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.45; transform: scale(0.92); }
}

/* ── Clases compartidas para los typing indicators de BI/Reports/Prediction ── */
.chat-typing-icon {
    color: var(--accent-blue, #6366f1);
    font-size: 1.05rem;
    line-height: 1;
    animation: chat-typing-pulse 1.5s ease-in-out infinite;
    flex-shrink: 0;
}
.chat-typing-step {
    color: var(--text-primary);
    font-size: 0.82rem;
    font-weight: 500;
    /* Mantener la frase en una sola línea; truncar con ellipsis si llega a ser muy larga. */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1 1 auto;
}

/* Los tres puntos animados van adentro de .typing-dots para no chocar con
   el resto de hijos directos del indicador. */
.typing-indicator .typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.typing-indicator .typing-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing 1.2s infinite;
}
.typing-indicator .typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator .typing-dots span:nth-child(3) { animation-delay: 0.4s; }

.typing-indicator .typing-elapsed {
    margin-left: 4px;
    font-size: 0.72rem;
    color: var(--text-muted);
    opacity: 0.7;
    align-self: center;
    font-variant-numeric: tabular-nums;
}

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* Markdown tables in chat */
.message-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 0.85rem;
}

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

.message-bubble table th {
    background: var(--bg-input);
    font-weight: 600;
}

.message-bubble code {
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.85em;
}

.message-bubble pre {
    background: var(--bg-input);
    padding: 12px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 8px 0;
}

.message-bubble pre code {
    background: transparent;
    padding: 0;
}

/* ═══════════════════════════════════════
   DATABASE ADMIN PAGE
   ═══════════════════════════════════════ */

/* Layout */
.db-layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 20px;
    height: calc(100vh - 140px);
    min-height: 0;
}

.db-connections-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.db-connections-panel .panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.db-connections-panel .panel-header h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

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

/* Connection card */
.connection-card {
    display: flex;
    flex-direction: column;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s;
    border: 1px solid transparent;
    margin-bottom: 4px;
}

.connection-card:hover {
    background: var(--bg-hover);
}

.connection-card.selected {
    background: rgba(59, 130, 246, 0.08);
    border-color: var(--accent);
}

.connection-card.active-conn {
    border-left: 3px solid var(--success);
}

.conn-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.conn-engine-badge {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #fff;
    font-size: 18px;
}

.conn-card-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
}

.conn-card-icon.status-ok {
    background: rgba(16, 185, 129, 0.12);
    color: var(--success);
}

.conn-card-icon.status-error {
    background: rgba(239, 68, 68, 0.12);
    color: var(--danger);
}

.conn-card-icon.status-unknown {
    background: rgba(148, 163, 184, 0.12);
    color: var(--text-secondary);
}

.conn-card-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.conn-card-info strong {
    font-size: 13px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conn-card-sub {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conn-card-engine {
    font-size: 10px;
    color: var(--text-muted, var(--text-secondary));
    font-weight: 500;
    opacity: 0.7;
}

.conn-card-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}

.active-badge {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 2px 6px;
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
    border-radius: 4px;
    flex-shrink: 0;
}

/* Detail panel */
.db-detail-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.detail-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-secondary);
    padding: 40px;
    text-align: center;
}

.detail-empty .material-symbols-rounded {
    font-size: 56px;
    opacity: 0.25;
}

.detail-empty h3 {
    color: var(--text-primary);
    margin: 0;
}

.detail-empty p {
    max-width: 380px;
    line-height: 1.5;
    font-size: 13px;
}

.detail-content {
    padding: 24px;
}

.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.detail-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.detail-title h2 {
    margin: 0;
    font-size: 20px;
    color: var(--text-primary);
}

.status-pill {
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.pill-active {
    background: rgba(16, 185, 129, 0.12);
    color: var(--success);
}

.pill-inactive {
    background: rgba(148, 163, 184, 0.12);
    color: var(--text-secondary);
}

.detail-actions {
    display: flex;
    gap: 6px;
}

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.btn-icon:hover {
    color: var(--text-primary);
    border-color: var(--accent);
}

.btn-danger-icon:hover {
    color: var(--danger);
    border-color: var(--danger);
    background: rgba(239, 68, 68, 0.08);
}

/* Info grid */
.detail-info-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.info-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px;
    background: var(--bg-main);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.info-card .material-symbols-rounded {
    color: var(--accent);
    font-size: 20px;
    margin-top: 2px;
}

.info-card label {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.info-card span:not(.material-symbols-rounded) {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
}

/* Test result banner */
.test-result-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    font-size: 13px;
}

.test-result-banner.success {
    background: rgba(16, 185, 129, 0.08);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: var(--success);
}

.test-result-banner.error {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--danger);
}

.test-result-banner.testing {
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: var(--accent);
}

.test-result-banner p {
    margin: 0;
    flex: 1;
    word-break: break-word;
}

/* Tabs */
.detail-tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 16px;
}

.tab-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s;
}

.tab-btn:hover {
    color: var(--text-primary);
}

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

.tab-btn .material-symbols-rounded {
    font-size: 18px;
}

.tab-panel {
    display: none;
}

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

.tab-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    gap: 12px;
}

.tab-desc {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
    flex: 1;
}

/* Table entries */
.table-entries {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.table-entry {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-main);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.entry-icon {
    font-size: 18px;
}

.entry-icon.allowed {
    color: var(--success);
}

.entry-icon.blocked {
    color: var(--danger);
}

.entry-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.entry-info strong {
    font-size: 13px;
    color: var(--text-primary);
}

.entry-desc {
    font-size: 11px;
    color: var(--text-secondary);
}

.empty-msg {
    font-size: 13px;
    color: var(--text-secondary);
    font-style: italic;
    padding: 8px 0;
}

.btn-xs {
    width: 28px;
    height: 28px;
    padding: 0;
    font-size: 16px;
}

.btn-xs .material-symbols-rounded {
    font-size: 16px;
}

/* Explorer */
.explorer-content {
    max-height: calc(100vh - 520px);
    overflow-y: auto;
}

.explorer-table {
    width: 100%;
    font-size: 12px;
}

.explorer-table th {
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 1;
}

.explorer-table code {
    font-size: 11px;
    padding: 2px 6px;
    background: var(--bg-input);
    border-radius: 4px;
    color: var(--accent);
}

.explorer-count {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 10px;
    text-align: right;
}

/* ═══ DICCIONARIO DE DATOS ═══ */

.dictionary-entries {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.dict-table-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: visible;
    transition: border-color var(--transition);
}

.dict-table-card:hover {
    border-color: var(--accent-blue);
}

.dict-table-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    cursor: pointer;
    user-select: none;
    transition: background var(--transition);
}

.dict-table-header:hover {
    background: var(--bg-hover);
}

.dict-table-header .dict-icon {
    color: var(--accent-blue);
    font-size: 1.2rem;
}

.dict-table-header .dict-name {
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--text-primary);
    flex: 1;
}

.dict-table-header .dict-name code {
    color: var(--accent);
    font-size: 0.8rem;
    margin-right: 8px;
}

.dict-table-header .dict-desc-preview {
    font-size: 0.78rem;
    color: var(--text-secondary);
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dict-table-header .dict-col-count {
    font-size: 0.72rem;
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: 2px 8px;
    border-radius: 10px;
}

.dict-table-header .dict-chevron {
    color: var(--text-muted);
    font-size: 1.1rem;
    transition: transform 0.2s ease;
}

.dict-table-card.expanded .dict-chevron {
    transform: rotate(180deg);
}

.dict-table-header .dict-remove-btn {
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: color var(--transition), background var(--transition);
}

.dict-table-header .dict-remove-btn:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

.dict-edit-name-btn {
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    transition: color var(--transition), background var(--transition);
    opacity: 0;
    margin-left: 4px;
}
.dict-edit-name-btn .material-symbols-rounded { font-size: 14px; }
.dict-table-header:hover .dict-edit-name-btn { opacity: 1; }
.dict-edit-name-btn:hover {
    color: var(--accent);
    background: rgba(99, 102, 241, 0.1);
}

.col-name-input {
    font-family: 'SFMono-Regular', 'Consolas', monospace;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--accent);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 2px 4px;
    width: 100%;
    min-width: 0;
    transition: border-color var(--transition), background var(--transition);
}
.col-name-input:hover { border-color: var(--border-color); }
.col-name-input:focus {
    border-color: var(--accent);
    background: var(--bg-primary);
    outline: none;
}

.dict-table-body {
    display: none;
    padding: 0 16px 16px 16px;
    border-top: 1px solid var(--border-color);
}

.dict-table-card.expanded .dict-table-body {
    display: block;
}

.dict-table-desc {
    margin: 12px 0;
}

.dict-table-desc label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: block;
    margin-bottom: 6px;
}

.dict-table-desc textarea {
    width: 100%;
    min-height: 50px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.82rem;
    resize: vertical;
    transition: border-color var(--transition);
}

.dict-table-desc textarea:focus {
    border-color: var(--accent-blue);
    outline: none;
}

.dict-columns-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 14px 0 8px 0;
    gap: 8px;
}

.dict-columns-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.dict-columns-header h4 {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.dict-columns-header .btn {
    font-size: 0.72rem;
}

.dict-column-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 480px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
}
.dict-column-list::-webkit-scrollbar {
    width: 6px;
}
.dict-column-list::-webkit-scrollbar-track {
    background: transparent;
}
.dict-column-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}
.dict-column-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.dict-column-row {
    display: grid;
    grid-template-columns: 220px 1fr 1fr auto;
    gap: 8px;
    align-items: start;
    padding: 8px 10px;
    background: var(--bg-secondary);
    border-radius: 6px;
    border: 1px solid transparent;
    transition: border-color var(--transition);
}

.dict-column-row:hover {
    border-color: var(--border-color);
}

.dict-column-row .col-name {
    font-family: 'SFMono-Regular', 'Consolas', monospace;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--accent);
    padding-top: 6px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

.dict-column-row .col-name .pk-badge {
    font-size: 0.6rem;
    color: var(--accent-yellow);
    font-weight: 700;
    background: rgba(234, 179, 8, 0.15);
    padding: 1px 4px;
    border-radius: 3px;
}

.dict-column-row .col-name .col-type {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-weight: 400;
}

.dict-column-row input,
.dict-column-row textarea {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 5px 8px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.78rem;
    transition: border-color var(--transition);
}

.dict-column-row input:focus,
.dict-column-row textarea:focus {
    border-color: var(--accent-blue);
    outline: none;
}

.dict-column-row input::placeholder,
.dict-column-row textarea::placeholder {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.dict-column-row textarea {
    min-height: 32px;
    resize: vertical;
}

.dict-column-row .col-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    margin-top: 2px;
    transition: color var(--transition);
}

.dict-column-row .col-remove:hover {
    color: var(--danger);
}

.dict-scan-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 0.78rem !important;
    padding: 5px 12px !important;
}
.dict-scan-btn .material-symbols-rounded {
    font-size: 1rem;
}

.dict-hidden-hint {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--text-muted);
    padding: 8px 12px;
    margin: 4px 0 0;
    background: rgba(99, 102, 241, 0.05);
    border: 1px dashed var(--border-color);
    border-radius: 6px;
    cursor: pointer;
}
.dict-hidden-hint:hover { color: var(--accent-blue); }

/* ── Diccionario asistido por IA: insignias, chips y controles ── */
.dict-badge {
    font-size: 0.62rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
    letter-spacing: 0.02em;
}
.dict-badge-ia {
    color: #a855f7;
    background: rgba(168, 85, 247, 0.15);
}
.dict-badge-ok {
    color: #22c55e;
    background: rgba(34, 197, 94, 0.15);
}
.dict-badge-vista {
    color: #06b6d4;
    background: rgba(6, 182, 212, 0.15);
}
.dict-chip {
    font-size: 0.65rem;
    color: var(--text-muted);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 2px 7px;
    border-radius: 10px;
    white-space: nowrap;
}
.dict-chip-mod {
    color: var(--accent-blue);
    border-color: var(--accent-blue);
}
.dict-table-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.dict-check {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
}
.dict-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 8px;
}
.dict-meta-grid label {
    display: block;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 3px;
}
.dict-meta-grid input {
    width: 100%;
    padding: 6px 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.82rem;
}
.col-desc-cell { display: flex; flex-direction: column; gap: 3px; }
.col-sample {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-style: italic;
    padding-left: 2px;
    word-break: break-word;
}
.col-sensible-toggle {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 0.62rem;
    color: var(--text-muted);
    cursor: pointer;
}
.col-sensible-toggle input { width: auto; }
.dict-column-sensible {
    border-left: 2px solid #f43f5e;
}
.dict-coverage {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 8px;
    font-size: 0.72rem;
    background: rgba(99, 102, 241, 0.08);
    border-radius: 10px;
    color: var(--text-muted);
}
.dict-coverage strong { color: var(--accent-blue); font-weight: 700; }

/* ── Diccionario: layout apilado para que la descripción y la cobertura tengan ancho completo ── */
#tab-dictionary .tab-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
}
#tab-dictionary .tab-toolbar .tab-desc { flex: 0 1 auto; }
#tab-dictionary .tab-toolbar-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
}

/* ── Banner persistente del task de IA (visible aunque el modal esté cerrado o tras recargar) ── */
.ai-task-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    margin-bottom: 12px;
    background: rgba(99, 102, 241, 0.10);
    border: 1px solid rgba(99, 102, 241, 0.30);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 0.85rem;
}
.ai-task-banner-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.ai-task-banner-icon {
    color: var(--accent-blue);
    animation: ai-task-pulse 1.6s ease-in-out infinite;
    font-size: 1.05rem;
}
.ai-task-banner-text { flex: 1; min-width: 0; }
.ai-task-banner-text strong { color: var(--accent-blue); font-weight: 700; }
.ai-task-banner-text .ai-task-current {
    display: block;
    color: var(--text-muted);
    font-size: 0.78rem;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ai-task-banner-progress {
    width: 160px;
    height: 6px;
    background: rgba(99, 102, 241, 0.15);
    border-radius: 3px;
    overflow: hidden;
    flex-shrink: 0;
}
.ai-task-banner-progress-fill {
    height: 100%;
    background: var(--accent-blue);
    width: 0%;
    transition: width 0.5s ease;
}
.ai-task-banner-actions { display: flex; gap: 6px; flex-shrink: 0; }
@keyframes ai-task-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.45; }
}

/* ── Fase 1.2: barra de progreso del job de IA ── */
.ai-progress-bar {
    width: 100%;
    height: 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 7px;
    overflow: hidden;
    margin: 12px 0 8px;
}
.ai-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #6366f1, #a855f7);
    transition: width 0.6s ease;
    border-radius: 7px;
    box-shadow: 0 0 8px rgba(168, 85, 247, 0.4);
}
.ai-progress-current {
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 0.82rem;
    color: var(--accent-blue);
    margin: 4px 0;
    min-height: 18px;
}
.ai-progress-stats {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 6px;
}
.ai-progress-stats strong { color: var(--text-primary); }

/* ── Fase 1.1: multi-select de esquemas en wizard de conexión ── */
.schemas-multiselect {
    margin-top: 6px;
    padding: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    min-height: 56px;
}
.schemas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 6px;
}
.schema-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.82rem;
    cursor: pointer;
    transition: border-color var(--transition);
}
.schema-item:hover { border-color: var(--accent-blue); }
.schema-item input[type="checkbox"] { margin: 0; }
.schemas-placeholder {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-style: italic;
}
.schemas-hint {
    margin: 8px 0 0;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    color: var(--text-muted);
}
.dict-hidden-hint strong {
    color: var(--accent-blue);
}

.dict-column-pk {
    border-left: 2px solid var(--accent-yellow, #eab308);
}
.dict-scan-btn.scanning {
    pointer-events: none;
    opacity: 0.7;
}

.tab-toolbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.text-right {
    text-align: right;
}

/* DB Modal / Wizard Modal */
.db-modal,
.wizard-modal {
    max-width: 780px;
    width: 95vw;
}

.wizard-modal .modal-body,
.db-modal .modal-body {
    max-height: calc(100vh - 240px);
    overflow-y: auto;
    padding-top: 14px;
}

.form-section-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 14px 0 6px;
    border-top: 1px solid var(--border-color);
    margin-top: 8px;
}

.form-section-title .material-symbols-rounded {
    font-size: 16px;
}

/* Quick test banner in modal */
.test-quick-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 12px;
    margin-top: 12px;
}

.test-quick-banner.success {
    background: rgba(16, 185, 129, 0.08);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: var(--success);
}

.test-quick-banner.error {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--danger);
}

.test-quick-banner.testing {
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: var(--accent);
}

.modal-footer-right {
    display: flex;
    gap: 8px;
}

/* Loading spinner */
.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 40px;
    color: var(--text-secondary);
    font-size: 13px;
}

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

.spin {
    animation: spin 1s linear infinite;
}

.btn-success-flash {
    background: var(--success) !important;
    border-color: var(--success) !important;
    color: #fff !important;
    transition: background 0.3s, border-color 0.3s;
}

/* Empty state small */
.empty-state.small {
    padding: 30px;
}

.empty-state.small .material-symbols-rounded {
    font-size: 36px;
}

.empty-state.small p {
    font-size: 12px;
}

.empty-state.error {
    color: var(--danger);
}


/* ═══════════════════════════════════════════════
   SIDEBAR NAV  (database.html, users.html)
   ═══════════════════════════════════════════════ */
.sidebar {
    width: 240px;
    min-width: 240px;
    max-width: 240px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    overflow: hidden;
}

body:has(.sidebar) .main-content {
    margin-left: 240px;
    width: calc(100% - 240px);
}

/* En chat-layout el sidebar NO es fixed, así que no necesita margin/width override */
.chat-layout .main-content {
    margin-left: 0;
    width: auto;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.logo .material-symbols-rounded {
    font-size: 1.5rem;
    color: var(--accent-blue);
}

.logo-text {
    letter-spacing: -0.3px;
}

.company-logo {
    max-width: 32px;
    max-height: 32px;
    object-fit: contain;
    border-radius: 4px;
}

/* ── Light theme overrides ── */
.theme-light input,
.theme-light select,
.theme-light textarea {
    color-scheme: light;
}

.theme-light .sidebar {
    box-shadow: 1px 0 0 var(--border-color);
}

.theme-light .nav-item:hover {
    background: rgba(0, 0, 0, 0.04);
}

.theme-light .modal {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.88rem;
    font-weight: 500;
    text-decoration: none;
    transition: all var(--transition);
}

.nav-item:hover {
    background: var(--bg-card);
    color: var(--text-primary);
    text-decoration: none;
}

.nav-item.active {
    background: var(--accent-blue-bg);
    color: var(--accent-blue);
}

.nav-item .material-symbols-rounded {
    font-size: 1.2rem;
}

.sidebar-footer {
    padding: 14px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.powered-by {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 0 2px;
    margin-top: 4px;
    border-top: 1px solid var(--border-color);
    opacity: 0.5;
    transition: opacity 0.2s;
    overflow: hidden;
}

.powered-by:hover {
    opacity: 0.8;
}

.powered-by span {
    font-size: 0.68rem;
    color: var(--text-muted);
    letter-spacing: 0.3px;
    text-transform: uppercase;
    flex-shrink: 0;
}

.powered-by-logo {
    height: 14px;
    width: auto;
    max-width: 60px;
    object-fit: contain;
    filter: grayscale(100%) brightness(1.5);
    transition: filter 0.2s;
}

.powered-by:hover .powered-by-logo {
    filter: grayscale(0%) brightness(1);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.82rem;
    padding: 4px 6px;
}

.user-info .material-symbols-rounded {
    font-size: 1.3rem;
    color: var(--accent-blue);
}

.version-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 0.78rem;
}

.version-badge .material-symbols-rounded {
    font-size: 1rem;
}


/* ═══════════════════════════════════════════════
   LOGIN PAGE
   ═══════════════════════════════════════════════ */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: color-mix(in srgb, var(--bg-primary) 70%, #3a3f4a 30%);
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 40px 36px 32px;
    box-shadow: var(--shadow-lg);
}

.login-logo {
    text-align: center;
    margin-bottom: 8px;
}

.login-logo-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 4px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--accent-blue), #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-logo-icon .material-symbols-rounded {
    font-size: 2rem;
    color: #fff;
}

.login-logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.login-logo p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.login-field {
    margin-bottom: 20px;
}

.login-field label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-label);
    margin-bottom: 8px;
}

.login-field label .material-symbols-rounded {
    font-size: 1rem;
}

.login-field input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.92rem;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition);
}

.login-field input:focus {
    border-color: var(--border-focus);
}

.password-wrapper {
    position: relative;
}

.password-wrapper input {
    padding-right: 44px;
}

.password-toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    font-size: 1.1rem;
    transition: color var(--transition);
}

.password-toggle:hover {
    color: var(--text-primary);
}

.login-error {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--accent-red-bg);
    color: var(--accent-red);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 16px;
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.login-error .material-symbols-rounded {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.login-btn {
    width: 100%;
    padding: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    justify-content: center;
    margin-top: 8px;
}

.login-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 24px;
    padding-top: 18px;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.78rem;
}

.login-footer .material-symbols-rounded {
    font-size: 0.9rem;
}

/* Login: Company Logo */
.login-company-logo {
    width: 144px;
    height: 144px;
    object-fit: contain;
    border-radius: 8px;
}

.login-logo-icon.has-company-logo {
    background: transparent;
    width: auto;
    height: auto;
    min-width: 144px;
    min-height: 144px;
}

/* Login: Page Footer */
.login-body {
    flex-direction: column;
}

.login-page-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    padding: 14px 20px;
    color: var(--text-muted);
    font-size: 0.76rem;
    letter-spacing: 0.02em;
    line-height: 1.6;
    background: linear-gradient(to top, var(--bg-primary) 60%, transparent);
}

.login-page-footer strong {
    color: var(--text-secondary);
    font-weight: 600;
}

.login-page-footer-legal {
    margin-top: 2px;
    opacity: 0.7;
    font-size: 0.7rem;
}


/* ═══════════════════════════════════════════════
   USERS PAGE
   ═══════════════════════════════════════════════ */

/* Header overrides */
.header-left h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-left h1 .material-symbols-rounded {
    font-size: 1.6rem;
    color: var(--accent-blue);
}

.header-subtitle {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.header-actions {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

/* Quota info bar */
.quota-info-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--accent-blue-bg);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: var(--radius-md);
    padding: 12px 18px;
    margin-bottom: 20px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.quota-info-bar .material-symbols-rounded {
    color: var(--accent-blue);
    font-size: 1.2rem;
    flex-shrink: 0;
}

.quota-info-bar strong {
    color: var(--accent-blue);
}

/* Users table container */
.users-table-container {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.users-table {
    min-width: 900px;
}

.users-table thead th {
    background: var(--bg-secondary);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.user-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-input);
    color: var(--text-secondary);
    font-size: 1.1rem;
    border: 1px solid var(--border-color);
}

.user-avatar.admin-avatar {
    background: var(--accent-blue-bg);
    color: var(--accent-blue);
    border-color: rgba(59, 130, 246, 0.3);
}

.role-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.role-badge.admin {
    background: var(--accent-blue-bg);
    color: var(--accent-blue);
}

.role-badge.usuario {
    background: rgba(156, 163, 175, 0.1);
    color: var(--text-secondary);
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    margin-right: 4px;
}

.status-dot.active {
    background: var(--accent-green);
    box-shadow: 0 0 4px rgba(16, 185, 129, 0.4);
}

.status-dot.inactive {
    background: var(--text-muted);
}

.action-buttons {
    display: flex;
    gap: 6px;
}

.empty-td {
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
    padding: 32px 16px !important;
}

/* User modal overrides */
.user-modal {
    max-width: 620px;
}

.flex-1 { flex: 1; }
.flex-2 { flex: 2; }

.form-row:has(.flex-1),
.form-row:has(.flex-2) {
    display: flex;
}

.quota-note {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 14px;
    line-height: 1.5;
}

.quota-note strong {
    color: var(--accent-blue);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.88rem;
    color: var(--text-primary);
}

.toggle-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-green);
    cursor: pointer;
}

.seed-toggle {
    flex-wrap: wrap;
}
.toggle-hint {
    width: 100%;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: 26px;
    margin-top: -4px;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    transition: color var(--transition);
}
.btn-close:hover {
    color: var(--text-primary);
}

/* ═══════════════════════════════════════════════════
   WIZARD — Multi-engine Data Source Connection
   ═══════════════════════════════════════════════════ */

/* ── Wizard Header ── */
.wizard-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 20px 24px 0;
}

.wizard-title-area h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.wizard-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 4px 0 0;
}

/* ── Step Progress Bar ── */
.wizard-steps-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 16px 24px 8px;
}

.wizard-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 70px;
    transition: all 0.3s;
}

.wizard-step span {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
    transition: color 0.3s;
}

.wizard-step-circle {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    border: 2px solid var(--border-color);
    color: var(--text-secondary);
    background: var(--bg-primary);
    transition: all 0.3s;
}

.wizard-step.active .wizard-step-circle {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
}

.wizard-step.active span {
    color: var(--accent);
    font-weight: 600;
}

.wizard-step.completed .wizard-step-circle {
    border-color: var(--success);
    background: var(--success);
    color: #fff;
}

.wizard-step.completed span {
    color: var(--success);
}

.wizard-step-line {
    flex: 1;
    height: 2px;
    background: var(--border-color);
    margin: 0 8px;
    margin-bottom: 18px;
    transition: background 0.3s;
    max-width: 80px;
}

.wizard-step-line.completed {
    background: var(--success);
}

/* ── Wizard Panels ── */
.wizard-panel {
    display: none;
    padding: 16px 24px;
    max-height: calc(100vh - 320px);
    overflow-y: auto;
}

.wizard-panel.active {
    display: block;
    animation: wizardFadeIn 0.25s ease;
}

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

/* ── Engine Selection Grid ── */
.engine-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    padding: 8px 0;
}

.engine-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 18px 12px 14px;
    border-radius: var(--radius-lg);
    border: 2px solid var(--border-color);
    background: var(--bg-primary);
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.engine-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.02), transparent);
    pointer-events: none;
}

.engine-card:hover {
    border-color: rgba(59, 130, 246, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.engine-card.selected {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.06);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1), 0 4px 16px rgba(0, 0, 0, 0.1);
}

.engine-card.selected::after {
    content: '✓';
    position: absolute;
    top: 6px;
    right: 8px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.engine-logo {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
}

.engine-logo svg {
    width: 100%;
    height: 100%;
}

.engine-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
}

.engine-desc {
    font-size: 10.5px;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.3;
}

/* ── Wizard Form (Step 2) ── */
.wizard-selected-engine {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    border-radius: var(--radius-md);
    background: rgba(59, 130, 246, 0.06);
    border: 1px solid rgba(59, 130, 246, 0.15);
    margin-bottom: 16px;
}

.selected-engine-info {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--accent);
    font-size: 14px;
}

.selected-engine-info .material-symbols-rounded {
    font-size: 20px;
}

.wizard-form {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.btn-xs {
    font-size: 11px;
    padding: 4px 10px;
    gap: 4px;
}

.btn-xs .material-symbols-rounded {
    font-size: 14px;
}

.form-hint {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    display: block;
}

/* ── Test Connection (Step 3) ── */
.wizard-test-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 16px 0 8px;
    min-height: 240px;
}

.test-summary-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    width: 100%;
    max-width: 480px;
}

.test-summary-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 22px;
    flex-shrink: 0;
    background: var(--accent);
}

.test-summary-info h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.test-summary-info p {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 2px 0 0;
}

.btn-test-connection {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 32px;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, var(--accent), #2563eb);
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 12px rgba(59, 130, 246, 0.3);
}

.btn-test-connection:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.4);
}

.btn-test-connection .material-symbols-rounded {
    font-size: 20px;
}

.test-state {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
    padding: 16px 0;
}

.test-state p {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
    max-width: 420px;
    word-break: break-word;
}

.test-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: wizardSpin 0.8s linear infinite;
}

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

.test-state.test-success .material-symbols-rounded {
    font-size: 48px;
    color: var(--success);
}

.test-state.test-success h3 {
    margin: 0;
    color: var(--success);
    font-size: 16px;
}

.test-state.test-error .material-symbols-rounded {
    font-size: 48px;
    color: var(--danger);
}

.test-state.test-error h3 {
    margin: 0;
    color: var(--danger);
    font-size: 16px;
}

.test-version {
    font-size: 11px;
    color: var(--text-secondary);
    background: var(--bg-hover);
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    margin-top: 4px;
    font-family: 'Courier New', monospace;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Wizard Footer ── */
.wizard-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 24px;
    border-top: 1px solid var(--border-color);
}

.wizard-footer-spacer {
    flex: 1;
}

/* ── Success Modal ── */
.success-modal {
    max-width: 400px;
    width: 90vw;
    text-align: center;
    border-radius: var(--radius-xl, 16px);
}

.success-modal-content {
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.success-icon-ring {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: rgba(16, 185, 129, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: successPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.success-icon-ring .material-symbols-rounded {
    font-size: 40px;
    color: var(--success);
}

@keyframes successPop {
    0% { transform: scale(0); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.success-modal h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.success-modal p {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.5;
}

#successModal {
    z-index: 10001;
}

#successModal .modal {
    animation: successModalIn 0.3s ease;
}

@keyframes successModalIn {
    from { opacity: 0; transform: scale(0.9) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Security Warning Modal ── */
#securityWarningModal {
    z-index: 10002;
}

.security-warning-modal {
    max-width: 600px;
    width: 92vw;
    border-radius: var(--radius-xl, 16px);
    overflow: hidden;
}

.security-warning-content {
    padding: 32px 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.security-warning-icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: rgba(245, 158, 11, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: successPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.security-warning-icon .material-symbols-rounded {
    font-size: 40px;
    color: #f59e0b;
}

.security-warning-modal h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.security-warning-modal p {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.6;
    text-align: center;
}

.security-recommendation {
    width: 100%;
    margin-top: 4px;
}

.security-rec-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.security-rec-header .material-symbols-rounded {
    font-size: 18px;
    color: #f59e0b;
}

.security-code-block {
    position: relative;
    background: #0d1117;
    border: 1px solid var(--border-subtle, #30363d);
    border-radius: 8px;
    overflow: hidden;
    max-height: 280px;
    overflow-y: auto;
}

.security-code-block pre {
    margin: 0;
    padding: 16px;
    overflow-x: auto;
}

.security-code-block code {
    font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 11.5px;
    line-height: 1.6;
    color: #e6edf3;
    white-space: pre;
}

.btn-copy-script {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 6px;
    padding: 4px 8px;
    cursor: pointer;
    color: #8b949e;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    transition: all 0.15s;
    z-index: 2;
}

.btn-copy-script:hover {
    background: rgba(255,255,255,0.14);
    color: #e6edf3;
}

.btn-copy-script .material-symbols-rounded {
    font-size: 16px;
}

.security-note {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: 11px !important;
    color: var(--text-muted) !important;
    text-align: left !important;
    margin-top: 10px !important;
    padding: 10px 12px;
    background: rgba(245, 158, 11, 0.06);
    border-radius: 8px;
    border: 1px solid rgba(245, 158, 11, 0.15);
}

.security-note .material-symbols-rounded {
    font-size: 16px;
    color: #f59e0b;
    flex-shrink: 0;
    margin-top: 1px;
}

/* ── Responsive wizard ── */
@media (max-width: 640px) {
    .engine-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .engine-card {
        padding: 14px 8px 10px;
    }

    .engine-logo {
        width: 40px;
        height: 40px;
    }

    .wizard-steps-bar {
        padding: 12px 16px 4px;
    }

    .wizard-panel {
        padding: 12px 16px;
    }

    .wizard-footer {
        padding: 12px 16px;
    }

    .wizard-header {
        padding: 16px 16px 0;
    }

    .test-summary-card {
        max-width: 100%;
    }
}

@media (max-width: 420px) {
    .engine-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ══════════════════════════════════════════════════════════
   BOTONES DE ACCIÓN INLINE (Auditoría)
   ══════════════════════════════════════════════════════════ */
.btn-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 0.82rem;
    font-weight: 500;
    border-radius: 8px;
    border: 1px solid var(--accent);
    background: transparent;
    color: var(--accent);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn-action:hover {
    background: var(--accent);
    color: #fff;
}
.btn-action-sm {
    padding: 5px 12px;
    font-size: 0.78rem;
}
.btn-action:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.btn-danger-outline {
    border-color: #ef4444;
    color: #ef4444;
}
.btn-danger-outline:hover {
    background: #ef4444;
    color: #fff;
}
.btn-icon-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: color 0.2s, background 0.2s;
}
.btn-icon-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

/* Audit modal uses display:flex directly */
#auditModalOverlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    align-items: center;
    justify-content: center;
    z-index: 1100;
}
#auditModalOverlay > .modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
#auditModalOverlay .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}
#auditModalOverlay .modal-header h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.05rem;
    font-weight: 600;
    margin: 0;
}
.stats-header-actions .btn-action {
    flex-shrink: 0;
}

/* ═══════════════════════════════════════════════
   WIZARD — Configurar Motor de IA
   ═══════════════════════════════════════════════ */
.wizard-modal {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 760px;
    max-width: 96vw;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 80px rgba(0,0,0,0.6);
    animation: wizardIn 0.25s ease;
}
@keyframes wizardIn {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
.wizard-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 24px; border-bottom: 1px solid var(--border-color);
}
.wizard-header h2 { font-size: 1.15rem; font-weight: 600; }
.wizard-steps {
    display: flex; align-items: center; justify-content: center;
    padding: 16px 32px; gap: 0;
    background: var(--bg-secondary); border-bottom: 1px solid var(--border-color);
}
.wiz-step {
    display: flex; align-items: center; gap: 8px;
    color: var(--text-muted); font-size: 0.82rem;
    transition: color 0.3s; cursor: default; white-space: nowrap;
}
.wiz-step.active { color: var(--accent-blue); font-weight: 500; }
.wiz-step.completed { color: var(--accent-green); cursor: pointer; }
.wiz-step-num {
    width: 30px; height: 30px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.82rem; font-weight: 600;
    background: var(--bg-input); border: 2px solid var(--border-color);
    transition: all 0.3s;
}
.wiz-step.active .wiz-step-num {
    background: var(--accent-blue); border-color: var(--accent-blue); color: #fff;
    box-shadow: 0 0 12px rgba(59,130,246,0.35);
}
.wiz-step.completed .wiz-step-num {
    background: var(--accent-green); border-color: var(--accent-green); color: #fff;
}
.wiz-step-line {
    flex: 1; height: 2px; background: var(--border-color);
    margin: 0 10px; max-width: 50px; transition: background 0.3s;
}
.wiz-step-line.done { background: var(--accent-green); }
.wizard-body {
    flex: 1; overflow-y: auto; padding: 28px; min-height: 320px;
}
.wiz-step-intro { margin-bottom: 8px; }
.wiz-step-intro h3 { font-size: 1.08rem; font-weight: 600; margin-bottom: 4px; }
.wiz-step-intro p { color: var(--text-secondary); font-size: 0.85rem; }
.wizard-footer {
    display: flex; align-items: center; padding: 16px 24px;
    border-top: 1px solid var(--border-color); gap: 8px;
}
.wiz-btn {
    padding: 10px 20px; border-radius: var(--radius-sm);
    font-size: 0.85rem; font-weight: 600; border: none;
    cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
    transition: all 0.2s; font-family: inherit;
}
.wiz-btn .material-symbols-rounded { font-size: 1rem; }
.wiz-btn-back { background: transparent; color: var(--text-secondary); }
.wiz-btn-back:hover { color: var(--text-primary); }
.wiz-btn-cancel { background: transparent; color: var(--text-muted); }
.wiz-btn-cancel:hover { color: var(--text-secondary); }
.wiz-btn-next { background: var(--btn-primary); color: #fff; }
.wiz-btn-next:hover { background: var(--btn-primary-hover); }
.wiz-btn-next:disabled { opacity: 0.4; cursor: not-allowed; }
.wiz-btn-test {
    background: transparent; color: var(--text-secondary); border: 1px solid var(--border-color);
    padding: 6px 14px; border-radius: var(--radius-sm); font-size: 0.82rem;
    cursor: pointer; display: inline-flex; align-items: center; gap: 5px; transition: all 0.2s;
}
.wiz-btn-test:hover { border-color: var(--accent-blue); color: var(--accent-blue); }
.wiz-btn-test:disabled { opacity: 0.5; cursor: not-allowed; }
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 1s linear infinite; }
/* Provider cards — step 1 */
.provider-select-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 20px;
}
.prov-card {
    background: var(--bg-input); border: 2px solid var(--border-color);
    border-radius: var(--radius-md); padding: 22px 16px;
    text-align: center; cursor: pointer; transition: all 0.2s;
}
.prov-card:hover { border-color: var(--accent-blue); background: var(--bg-card-hover); transform: translateY(-2px); }
.prov-card.selected { border-color: var(--accent-blue); background: var(--accent-blue-bg); }
.prov-icon {
    width: 52px; height: 52px; border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 12px; font-size: 1.6rem;
}
.prov-name { font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; }
.prov-desc { font-size: 0.75rem; color: var(--text-secondary); line-height: 1.4; }
/* Model cards — step 2 & 3 */
.model-select-grid { display: grid; gap: 10px; margin-top: 16px; }
.model-card {
    background: var(--bg-input); border: 2px solid var(--border-color);
    border-radius: var(--radius-md); padding: 14px 18px;
    cursor: pointer; transition: all 0.2s;
    display: flex; align-items: center; gap: 16px;
}
.model-card:hover { border-color: var(--accent-blue); background: var(--bg-card-hover); }
.model-card.selected { border-color: var(--accent-blue); background: var(--accent-blue-bg); }
.model-card-info { flex: 1; min-width: 0; }
.model-card-name {
    font-weight: 600; font-size: 0.9rem;
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.model-card-desc { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; }
.model-card-meta {
    font-size: 0.72rem; color: var(--text-muted);
    background: var(--bg-secondary); padding: 4px 10px; border-radius: 20px; white-space: nowrap;
}
.model-card-pricing { text-align: right; font-size: 0.82rem; white-space: nowrap; min-width: 105px; }
.price-row { display: flex; justify-content: space-between; gap: 8px; }
.price-value { color: var(--text-primary); font-weight: 500; }
.price-value.free { color: var(--accent-green); font-weight: 600; font-size: 0.92rem; }
.price-label { font-size: 0.7rem; color: var(--text-muted); }
.model-badge {
    font-size: 0.62rem; padding: 2px 8px; border-radius: 20px;
    font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px;
}
.model-badge.recommended { background: var(--accent-blue-bg); color: var(--accent-blue); }
.model-badge.budget { background: var(--accent-green-bg); color: var(--accent-green); }
.model-badge.premium { background: var(--accent-yellow-bg); color: var(--accent-yellow); }
/* Hybrid mode — step 3 */
.hybrid-hero { text-align: center; padding: 8px 0 12px; }
.hybrid-hero h3 { margin-top: 8px; }
.hybrid-options { display: flex; gap: 12px; margin-top: 8px; }
.hybrid-card {
    flex: 1; background: var(--bg-input); border: 2px solid var(--border-color);
    border-radius: var(--radius-md); padding: 16px 20px;
    cursor: pointer; transition: all 0.2s;
    display: flex; align-items: center; gap: 14px;
}
.hybrid-card:hover { border-color: var(--accent-blue); }
.hybrid-card.selected { border-color: var(--accent-blue); background: var(--accent-blue-bg); }
.hybrid-card-icon {
    width: 40px; height: 40px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.hybrid-card strong { display: block; margin-bottom: 2px; font-size: 0.9rem; }
.hybrid-card p { font-size: 0.78rem; color: var(--text-secondary); margin: 0; }
.hybrid-radio { margin-left: auto; flex-shrink: 0; }
/* Config form — step 4 */
.wiz-summary {
    display: flex; gap: 16px; flex-wrap: wrap;
    background: var(--bg-secondary); border-radius: var(--radius-sm);
    padding: 12px 16px; margin: 16px 0;
}
.wiz-summary-item { display: flex; gap: 6px; font-size: 0.85rem; }
.wiz-summary-label { color: var(--text-muted); }
.wiz-summary-value { font-weight: 600; color: var(--accent-blue); }
.wiz-form-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 8px;
}
.wiz-form-group.span-2 { grid-column: span 2; }
.wiz-label {
    font-size: 0.82rem; color: var(--text-label); font-weight: 500;
    margin-bottom: 6px; display: block;
}
.wiz-input, .wiz-textarea {
    width: 100%; padding: 10px 14px; background: var(--bg-input);
    border: 1px solid var(--border-input); border-radius: var(--radius-sm);
    color: var(--text-primary); font-size: 0.88rem; font-family: inherit;
    transition: border-color 0.2s;
}
.wiz-input:focus, .wiz-textarea:focus { border-color: var(--border-focus); outline: none; }
.wiz-textarea { min-height: 80px; resize: vertical; }
.wiz-hint { font-size: 0.73rem; color: var(--text-muted); margin-top: 4px; }
.wiz-check-row {
    display: flex; gap: 24px; margin-top: 16px; padding-top: 16px;
    border-top: 1px solid var(--border-color);
}
.wiz-check {
    display: flex; align-items: center; gap: 6px;
    font-size: 0.88rem; cursor: pointer;
}
.wiz-check input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent-blue); }
.wiz-link-btn {
    background: none; border: none; color: var(--accent-blue); cursor: pointer;
    font-size: 0.82rem; display: inline-flex; align-items: center; gap: 4px;
    font-family: inherit; padding: 0;
}
.wiz-link-btn:hover { text-decoration: underline; }
@media (max-width: 640px) {
    .provider-select-grid { grid-template-columns: repeat(2, 1fr); }
    .wiz-form-grid { grid-template-columns: 1fr; }
    .wiz-form-group.span-2 { grid-column: span 1; }
    .hybrid-options { flex-direction: column; }
    .wizard-steps { padding: 12px 16px; }
    .wiz-step span:not(.material-symbols-rounded) { display: none; }
    .wizard-body { padding: 20px 16px; }
}
/* SVG logos inside provider elements */
.prov-icon svg, .provider-card-avatar svg {
    display: block;
}

/* ── Info tooltip icon ── */
.wiz-info-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 18px; height: 18px; border-radius: 50%;
    background: var(--accent-blue-bg); color: var(--accent-blue);
    cursor: pointer; margin-left: 4px; vertical-align: middle;
    transition: all 0.2s; flex-shrink: 0;
}
.wiz-info-icon .material-symbols-rounded { font-size: 14px; }
.wiz-info-icon:hover { background: var(--accent-blue); color: #fff; transform: scale(1.1); }

/* ── Info Modal (field explanation) ── */
.info-modal-overlay {
    display: none; position: fixed; inset: 0; z-index: 2100;
    background: rgba(0,0,0,.55); backdrop-filter: blur(4px);
    align-items: center; justify-content: center;
}
.info-modal-overlay.active { display: flex; }
.info-modal {
    background: var(--bg-card); border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    width: 440px; max-width: 92vw; max-height: 80vh;
    box-shadow: 0 20px 60px rgba(0,0,0,.4);
    overflow: hidden; animation: modalSlideIn 0.25s ease;
}
.info-modal-header {
    display: flex; align-items: center; gap: 10px;
    padding: 16px 20px; border-bottom: 1px solid var(--border-color);
}
.info-modal-header h4 { margin: 0; font-size: 1rem; flex: 1; }
.info-modal-body {
    padding: 20px; font-size: 0.88rem; line-height: 1.65;
    color: var(--text-secondary); overflow-y: auto; max-height: 60vh;
}
.info-modal-body strong { color: var(--text-primary); }
.info-modal-body .info-example {
    background: var(--bg-secondary); border-radius: var(--radius-sm);
    padding: 10px 14px; margin: 10px 0; font-size: 0.82rem;
    border-left: 3px solid var(--accent-blue);
}
.info-modal-body .info-tip {
    background: rgba(16,185,129,.08); border-radius: var(--radius-sm);
    padding: 10px 14px; margin: 10px 0; font-size: 0.82rem;
    border-left: 3px solid var(--accent-green);
    color: var(--accent-green);
}

/* ── Tutorial Wizard ── */
.tutorial-overlay {
    display: none; position: fixed; inset: 0; z-index: 2200;
    background: rgba(0,0,0,.6); backdrop-filter: blur(5px);
    align-items: center; justify-content: center;
}
.tutorial-overlay.active { display: flex; }
.tutorial-box {
    background: var(--bg-card); border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    width: 560px; max-width: 94vw; max-height: 88vh;
    box-shadow: 0 24px 64px rgba(0,0,0,.45);
    overflow: hidden; animation: modalSlideIn 0.3s ease;
    display: flex; flex-direction: column;
}
.tutorial-header {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 24px; border-bottom: 1px solid var(--border-color);
}
.tutorial-header h3 { margin: 0; font-size: 1.05rem; flex: 1; }
.tutorial-progress {
    display: flex; gap: 4px; padding: 0 24px; margin-top: 12px;
}
.tutorial-progress-dot {
    height: 4px; flex: 1; border-radius: 2px;
    background: var(--border-color); transition: background 0.3s;
}
.tutorial-progress-dot.active { background: var(--accent-blue); }
.tutorial-progress-dot.done { background: var(--accent-green); }
.tutorial-body {
    padding: 24px; flex: 1; overflow-y: auto;
}
.tutorial-body h4 { margin: 0 0 8px; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.tutorial-body p { color: var(--text-secondary); font-size: 0.88rem; line-height: 1.6; margin: 0 0 12px; }
.tutorial-body .tut-card {
    background: var(--bg-secondary); border-radius: var(--radius-sm);
    padding: 14px 16px; margin: 12px 0;
}
.tutorial-body .tut-option {
    background: var(--bg-input); border: 2px solid var(--border-color);
    border-radius: var(--radius-sm); padding: 12px 16px; margin: 6px 0;
    cursor: pointer; transition: all 0.2s; display: flex; align-items: center; gap: 12px;
}
.tutorial-body .tut-option:hover { border-color: var(--accent-blue); background: var(--bg-card-hover); }
.tutorial-body .tut-option.selected { border-color: var(--accent-blue); background: var(--accent-blue-bg); }
.tutorial-body .tut-option-icon {
    width: 36px; height: 36px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.tutorial-body .tut-option strong { display: block; font-size: 0.88rem; }
.tutorial-body .tut-option span.tut-desc { font-size: 0.78rem; color: var(--text-secondary); }
.tutorial-footer {
    display: flex; align-items: center; padding: 14px 24px;
    border-top: 1px solid var(--border-color); gap: 8px;
}
.tutorial-footer .tut-step-label {
    font-size: 0.78rem; color: var(--text-muted); margin-right: auto;
}

/* ═══════════════════════════════════════════════════════
   SISTEMA DE ACTUALIZACIONES — Badge + Panel
   ═══════════════════════════════════════════════════════ */

/* ── Badge en sidebar header ── */
.update-badge {
    position: relative;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    color: var(--accent-orange);
    transition: all 0.2s;
    animation: updatePulse 2s ease-in-out infinite;
    margin-left: auto;
}
.update-badge:hover {
    background: var(--accent-yellow-bg);
    color: var(--accent-yellow);
}
.update-badge .material-symbols-rounded {
    font-size: 1.3rem;
}
.update-badge::after {
    content: '';
    position: absolute;
    top: 2px; right: 2px;
    width: 8px; height: 8px;
    background: var(--accent-red);
    border-radius: 50%;
    border: 2px solid var(--bg-sidebar);
}

@keyframes updatePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ── Overlay ── */
.update-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: var(--bg-modal-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.update-overlay.open {
    opacity: 1;
}

/* ── Panel ── */
.update-panel {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    transform: translateY(20px);
    transition: transform 0.2s ease;
}
.update-overlay.open .update-panel {
    transform: translateY(0);
}

.update-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border-color);
}

.update-panel-body {
    padding: 20px 22px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ── Version cards ── */
.update-version-cards {
    display: flex;
    gap: 12px;
}
.update-ver-card {
    flex: 1;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    text-align: center;
    border: 1px solid var(--border-color);
}
.update-ver-card.update-ver-new {
    border-color: var(--accent-green);
    background: var(--accent-green-bg);
}
.update-ver-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.update-ver-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
}
.update-ver-new .update-ver-value {
    color: var(--accent-green);
}

/* ── Status banners ── */
.update-status-banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
}
.update-status-available {
    background: var(--accent-yellow-bg);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: var(--accent-yellow);
}
.update-status-available .material-symbols-rounded { color: var(--accent-yellow); }

.update-status-ok {
    background: var(--accent-green-bg);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: var(--accent-green);
}
.update-status-ok .material-symbols-rounded { color: var(--accent-green); }

.update-status-error {
    background: var(--accent-red-bg);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--accent-red);
}
.update-status-error .material-symbols-rounded { color: var(--accent-red); }

/* ── Sections ── */
.update-section {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}
.update-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-secondary);
}
.update-section-title .material-symbols-rounded {
    font-size: 1.1rem;
}

.update-release-notes {
    padding: 14px;
    font-size: 0.84rem;
    line-height: 1.7;
    color: var(--text-secondary);
    white-space: pre-wrap;
    max-height: 200px;
    overflow-y: auto;
}

/* ── Progress bar ── */
.update-progress-bar {
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    margin: 12px 14px 0;
}
.update-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-cyan));
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* ── Actions ── */
.update-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* ── History items ── */
.update-history-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.84rem;
}
.update-history-item:last-child { border-bottom: none; }
.update-history-item .material-symbols-rounded { color: var(--accent-green); }
.update-history-item.failed .material-symbols-rounded { color: var(--accent-red); }

/* ── Mobile responsive ── */
@media (max-width: 600px) {
    .update-panel {
        width: 96%;
        max-height: 90vh;
        border-radius: var(--radius-md);
    }
    .update-version-cards {
        flex-direction: column;
    }
}

/* ═══════════════════════════════════════════════════════════
   HISTORIAL DE CAMBIOS IA — DRAWER (BI + Reports)
   ═══════════════════════════════════════════════════════════ */

.history-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 420px;
    max-width: 95vw;
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    z-index: 1100;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.4);
}
.history-drawer.open {
    transform: translateX(0);
}

.history-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-card);
}
.history-drawer-title {
    display: flex;
    align-items: center;
    gap: 12px;
}
.history-drawer-title > .material-symbols-rounded {
    font-size: 28px;
    color: var(--accent-blue);
    background: var(--accent-blue-bg);
    padding: 8px;
    border-radius: var(--radius-md);
}
.history-drawer-title h3 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}
.history-drawer-subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
    display: block;
    margin-top: 1px;
}

.history-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

/* ── Empty / Loading states ── */
.history-empty, .history-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 20px;
    text-align: center;
    gap: 10px;
}
.history-empty .material-symbols-rounded,
.history-loading .material-symbols-rounded {
    font-size: 48px;
    color: var(--text-muted);
    opacity: 0.5;
}
.history-empty p, .history-loading p {
    color: var(--text-secondary);
    font-size: 0.92rem;
    margin: 0;
}
.history-empty-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    max-width: 260px;
    line-height: 1.4;
}

/* ── Timeline ── */
.history-timeline {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.history-entry {
    display: flex;
    gap: 14px;
    position: relative;
    padding-bottom: 4px;
    animation: historyEntryIn 0.3s ease both;
}
.history-entry:last-child .history-entry-line::after {
    display: none;
}

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

.history-entry-line {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 36px;
    flex-shrink: 0;
    position: relative;
}
.history-entry-line::after {
    content: '';
    position: absolute;
    top: 36px;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    bottom: 0;
    background: var(--border-color);
}

.history-entry-dot {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    transition: all 0.2s;
}
.history-entry-dot .material-symbols-rounded {
    font-size: 18px;
    color: var(--text-secondary);
}

/* Dot colors by origin */
.history-entry-dot.ai_edit,
.history-entry-dot.ai_generate {
    border-color: #8b5cf6;
    background: rgba(139, 92, 246, 0.15);
}
.history-entry-dot.ai_edit .material-symbols-rounded,
.history-entry-dot.ai_generate .material-symbols-rounded {
    color: #a78bfa;
}
.history-entry-dot.ai_chat {
    border-color: var(--accent-blue);
    background: var(--accent-blue-bg);
}
.history-entry-dot.ai_chat .material-symbols-rounded {
    color: var(--accent-blue);
}
.history-entry-dot.manual {
    border-color: var(--accent-green);
    background: var(--accent-green-bg);
}
.history-entry-dot.manual .material-symbols-rounded {
    color: var(--accent-green);
}
.history-entry-dot.restore {
    border-color: var(--accent-yellow);
    background: var(--accent-yellow-bg);
}
.history-entry-dot.restore .material-symbols-rounded {
    color: var(--accent-yellow);
}

/* Pinned glow */
.history-entry.pinned .history-entry-dot {
    border-color: var(--accent-yellow) !important;
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.3);
}

.history-entry-content {
    flex: 1;
    min-width: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    margin-bottom: 10px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.history-entry-content:hover {
    border-color: var(--border-focus);
    box-shadow: 0 2px 12px rgba(74, 158, 255, 0.1);
}
.history-entry.pinned .history-entry-content {
    border-color: rgba(245, 158, 11, 0.35);
    background: rgba(245, 158, 11, 0.04);
}

.history-entry-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}
.history-entry-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent-blue);
    background: var(--accent-blue-bg);
    padding: 2px 8px;
    border-radius: 20px;
}
.history-entry.pinned .history-entry-label {
    color: var(--accent-yellow);
    background: var(--accent-yellow-bg);
}
.history-entry-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.history-entry-desc {
    font-size: 0.88rem;
    color: var(--text-primary);
    line-height: 1.4;
    margin-bottom: 4px;
}

.history-entry-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.78rem;
    color: var(--accent-yellow);
    background: var(--accent-yellow-bg);
    padding: 3px 10px;
    border-radius: 16px;
    margin-bottom: 6px;
    font-weight: 500;
}
.history-entry-tag .material-symbols-rounded {
    font-size: 14px;
}

.history-entry-prompt {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--text-muted);
    background: var(--bg-input);
    border-left: 3px solid var(--border-color);
    padding: 6px 10px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    margin-bottom: 8px;
    line-height: 1.4;
    font-style: italic;
}
.history-entry-prompt .material-symbols-rounded {
    font-size: 14px;
    margin-top: 2px;
    flex-shrink: 0;
    color: var(--text-muted);
}

.history-entry-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}
.history-entry-content:hover .history-entry-actions {
    opacity: 1;
}

.history-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.history-btn .material-symbols-rounded {
    font-size: 16px;
}

.history-btn.restore {
    color: var(--accent-blue);
    border-color: rgba(59, 130, 246, 0.3);
}
.history-btn.restore:hover {
    background: var(--accent-blue-bg);
    border-color: var(--accent-blue);
}

.history-btn.pin {
    padding: 4px 8px;
}
.history-btn.pin:hover {
    color: var(--accent-yellow);
    border-color: var(--accent-yellow);
    background: var(--accent-yellow-bg);
}
.history-btn.pin.pinned {
    color: var(--accent-yellow);
    background: var(--accent-yellow-bg);
    border-color: var(--accent-yellow);
}

.history-btn.delete {
    padding: 4px 8px;
    margin-left: auto;
}
.history-btn.delete:hover {
    color: var(--accent-red);
    border-color: var(--accent-red);
    background: var(--accent-red-bg);
}

/* ── Toast notification ── */
.bi-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 2000;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.9rem;
    color: var(--text-primary);
    max-width: 450px;
}
.bi-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.bi-toast.success { border-color: var(--accent-green); }
.bi-toast.success .material-symbols-rounded { color: var(--accent-green); }
.bi-toast.error { border-color: var(--accent-red); }
.bi-toast.error .material-symbols-rounded { color: var(--accent-red); }
.bi-toast.info .material-symbols-rounded { color: var(--accent-blue); }

/* ── Responsive ── */
@media (max-width: 600px) {
    .history-drawer {
        width: 100vw;
        max-width: 100vw;
    }
}

/* ══════════════════════════════════════════
   CLARIFICATION CHIPS & RECOVERY NOTICES
   ══════════════════════════════════════════ */

.clarification-chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 8px 16px;
    margin: 4px 0 12px 0;
    animation: fadeInUp 0.3s ease;
}

.chips-label {
    font-size: 0.75rem;
    color: var(--text-secondary, #888);
    margin-right: 4px;
    font-weight: 500;
}

.clarification-chip {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--primary, #6366f1);
    background: transparent;
    color: var(--primary, #6366f1);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    white-space: nowrap;
}

.clarification-chip:hover {
    background: var(--primary, #6366f1);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.clarification-chip:active {
    transform: translateY(0);
}

.recovery-notice {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    margin: 4px 0 8px 0;
    font-size: 0.72rem;
    color: var(--text-secondary, #888);
    background: var(--bg-card, rgba(255,255,255,0.03));
    border-radius: 8px;
    border-left: 3px solid var(--accent, #f59e0b);
    animation: fadeInUp 0.3s ease;
}

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

/* Botón de compactación en el header del chat */
.compact-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--border, #333);
    background: transparent;
    color: var(--text-secondary, #888);
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.compact-btn:hover {
    background: var(--primary, #6366f1);
    color: #fff;
    border-color: var(--primary, #6366f1);
}
