:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --dark: #0f172a;
    --darker: #0b1120;
    --light: #f8fafc;
    --white: #ffffff;
    --gray: #94a3b8;
    --text-dark: #1e293b;
    --text-light: #f1f5f9;
    --radius: 16px;
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
    background-color: var(--dark);
    color: var(--text-light);
    overflow-x: hidden;
}

.bg-light { background-color: var(--light); color: var(--text-dark); }
.bg-dark { background-color: var(--dark); color: var(--text-light); }

.screen {
    display: none;
    min-height: 100vh;
    width: 100%;
    flex-direction: column;
}

.screen.active {
    display: flex;
}

.hidden {
    display: none !important;
}

/* =========================================================================
   PANTALLA 1: SPLASH
   ========================================================================= */
#screen-splash {
    justify-content: center;
    align-items: center;
    text-align: center;
    background: linear-gradient(135deg, var(--dark), var(--darker));
}

.splash-content {
    animation: fadeIn 0.8s ease;
}

.logo-icon {
    font-size: 80px;
    margin-bottom: 20px;
}

#screen-splash h1 { font-size: 2.5rem; margin-bottom: 10px; font-weight: 700; }
#screen-splash p { color: var(--gray); font-size: 1.1rem; margin-bottom: 40px; line-height: 1.5; }

.loading-bar {
    width: 220px;
    height: 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
    overflow: hidden;
    margin: 0 auto;
}
.loading-bar .fill {
    height: 100%;
    width: 0%;
    background: var(--primary);
    animation: load 2.2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes load {
    to { width: 100%; }
}

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

/* =========================================================================
   PANTALLA 2: LOGIN & REGISTRO
   ========================================================================= */
#screen-login {
    justify-content: center;
    align-items: center;
    padding: 20px;
    background: linear-gradient(135deg, #0b1120 0%, #1e1b4b 100%);
}

.login-container {
    background: var(--white);
    padding: 35px 30px;
    border-radius: var(--radius);
    width: 100%;
    max-width: 420px;
    color: var(--text-dark);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.25);
    animation: fadeIn 0.4s ease;
}

.logo-small {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 20px;
}
.logo-small.dark { color: var(--primary); }

.login-container h2 { margin-bottom: 6px; font-size: 1.5rem; font-weight: 700; }
.login-container p { color: #64748b; margin-bottom: 20px; font-size: 0.95rem; line-height: 1.4; }

/* Alert Box */
.alert-box {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 18px;
    font-size: 0.9rem;
    line-height: 1.4;
    animation: fadeIn 0.3s ease;
}
.alert-error {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}
.alert-success {
    background-color: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.88rem;
    font-weight: 600;
    color: #334155;
}
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid #cbd5e1;
    border-radius: 10px;
    font-size: 0.98rem;
    outline: none;
    transition: all 0.25s ease;
    background-color: #fff;
    color: #0f172a;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { 
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.row { display: flex; gap: 15px; }
.half { flex: 1; }

.btn-primary {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: var(--white);
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px -1px rgba(99, 102, 241, 0.2);
}
.btn-primary:hover { 
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 8px -1px rgba(99, 102, 241, 0.3);
}
.btn-primary:active { transform: translateY(0); }

.toggle-auth { text-align: center; margin-top: 22px; font-size: 0.92rem; color: #64748b; }
.toggle-auth a { color: var(--primary); text-decoration: none; font-weight: 600; }
.toggle-auth a:hover { text-decoration: underline; }

/* =========================================================================
   PANTALLA 3: DASHBOARD & CHAT PRINCIPAL
   ========================================================================= */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--white);
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar.transparent { 
    background: rgba(15, 23, 42, 0.85); 
    backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(255,255,255,0.08); 
    color: var(--white); 
}
.topbar.transparent .btn-back { color: var(--white); }

.user-profile-badge {
    display: flex;
    align-items: center;
    gap: 12px;
}
.user-profile-badge span {
    font-weight: 600;
    font-size: 0.95rem;
    color: #334155;
}
.btn-logout {
    background: #f1f5f9;
    border: none;
    padding: 7px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #ef4444;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-logout:hover { background: #fee2e2; }

.btn-back {
    background: none; 
    border: none; 
    font-size: 0.95rem; 
    color: var(--primary); 
    font-weight: 600; 
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
}

.dashboard-content {
    padding: 24px 20px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}
.dashboard-content h2 { font-size: 1.85rem; margin-bottom: 4px; font-weight: 700; }
.dashboard-content > p { color: #64748b; margin-bottom: 24px; font-size: 1rem; }

/* Chat Principal */
.chat-container {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 28px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid #e2e8f0;
}
.chat-header {
    padding: 12px 18px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.88rem;
    font-weight: 600;
    color: #475569;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.badge-status {
    background: #dcfce7;
    color: #166534;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 0.75rem;
}
.chat-messages {
    padding: 20px;
    height: 280px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: #fdfdfd;
}
.message {
    padding: 12px 16px;
    border-radius: 14px;
    max-width: 85%;
    font-size: 0.95rem;
    line-height: 1.45;
}
.ai-message {
    background: #f1f5f9;
    align-self: flex-start;
    border: 1px solid #e2e8f0;
    color: var(--text-dark);
}
.user-message {
    background: var(--primary);
    color: var(--white);
    align-self: flex-end;
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.2);
}
.chat-input-area {
    display: flex;
    padding: 12px 16px;
    background: var(--white);
    border-top: 1px solid #e2e8f0;
}
.chat-input-area input {
    flex: 1;
    padding: 11px 16px;
    border: 1.5px solid #cbd5e1;
    border-radius: 24px;
    outline: none;
    margin-right: 10px;
    font-size: 0.95rem;
}
.chat-input-area input:focus { border-color: var(--primary); }
.chat-input-area button {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 24px;
    padding: 0 22px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}
.chat-input-area button:hover { background: var(--primary-hover); }

/* Acciones Principales */
.action-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}
.action-card {
    padding: 24px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: var(--shadow);
}
.action-card:hover { transform: translateY(-4px); box-shadow: 0 12px 20px -3px rgba(0,0,0,0.12); }
.action-card.primary { background: linear-gradient(135deg, #6366f1, #4f46e5); color: white; }
.action-card.secondary { background: #e0e7ff; color: #3730a3; border: 1px solid #c7d2fe; }
.action-card .icon { font-size: 28px; margin-bottom: 12px; }
.action-card h3 { font-size: 1.2rem; margin-bottom: 6px; font-weight: 700; }
.action-card p { font-size: 0.88rem; opacity: 0.9; line-height: 1.4; }

@media (max-width: 600px) {
    .action-grid { grid-template-columns: 1fr; }
}

/* =========================================================================
   PANTALLA 4: FORMULARIO Y LOADER
   ========================================================================= */
.form-container { 
    padding: 24px 20px; 
    max-width: 640px; 
    margin: 0 auto; 
    width: 100%; 
    position: relative;
}
#loading-overlay {
    position: absolute; 
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255,255,255,0.96); 
    display: flex; 
    flex-direction: column;
    justify-content: center; 
    align-items: center; 
    border-radius: var(--radius);
    text-align: center; 
    padding: 30px; 
    z-index: 20;
}
#loading-overlay h3 { margin-bottom: 8px; color: var(--text-dark); font-size: 1.3rem; }
#loading-overlay p { color: #64748b; font-size: 0.95rem; max-width: 400px; }
.spinner {
    width: 55px; height: 55px; 
    border: 5px solid #e2e8f0; 
    border-top-color: var(--primary);
    border-radius: 50%; 
    animation: spin 0.9s linear infinite; 
    margin-bottom: 22px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================================
   PANTALLA 5: RESULTADOS
   ========================================================================= */
.result-container { padding: 24px 20px; max-width: 820px; margin: 0 auto; width: 100%; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 250px; font-size: 1.15rem; }
.btn-secondary-action {
    background: #e0e7ff;
    color: var(--primary);
    border: none;
    padding: 8px 14px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.88rem;
    transition: background 0.2s;
}
.btn-secondary-action:hover { background: #c7d2fe; }

.card-section {
    background: var(--white); 
    padding: 22px 24px; 
    border-radius: var(--radius);
    box-shadow: var(--shadow); 
    margin-bottom: 20px; 
    border: 1px solid #e2e8f0;
    animation: fadeIn 0.3s ease;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1.5px solid #f1f5f9;
    padding-bottom: 12px;
    margin-bottom: 14px;
}
.card-header h3 { color: var(--primary); font-size: 1.15rem; font-weight: 700; }
.btn-copy-sec {
    background: #f1f5f9;
    color: #475569;
    border: none;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
}
.btn-copy-sec:hover { background: #e2e8f0; color: #1e293b; }

.card-body p { line-height: 1.6; color: #334155; margin-bottom: 8px; }
.structure-block {
    background: #f8fafc;
    padding: 14px 16px;
    border-radius: 10px;
    margin-bottom: 12px;
    border-left: 4px solid var(--primary);
}
.structure-block h4 { margin-bottom: 6px; color: #1e293b; font-size: 1.05rem; }
.structure-block p { color: #475569; font-size: 0.95rem; }

.member-card {
    background: #fdfdfd;
    border: 1px solid #e2e8f0;
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 14px;
}
.member-tag {
    display: inline-block;
    background: #e0e7ff;
    color: #3730a3;
    padding: 3px 10px;
    border-radius: 15px;
    font-weight: 700;
    font-size: 0.8rem;
    margin-bottom: 10px;
}
.member-card p { font-size: 0.92rem; margin-bottom: 6px; }

.question-item {
    background: #f8fafc;
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 10px;
    border-left: 3px solid #6366f1;
}

/* =========================================================================
   PANTALLA 6: HISTORIAL
   ========================================================================= */
.history-list { padding: 24px 20px; max-width: 640px; margin: 0 auto; width: 100%; }
.history-item {
    background: rgba(255,255,255,0.06); 
    border: 1px solid rgba(255,255,255,0.1);
    padding: 18px 20px; 
    border-radius: 14px; 
    margin-bottom: 15px;
    display: flex; 
    justify-content: space-between; 
    align-items: center;
    transition: all 0.2s ease;
}
.history-item:hover {
    background: rgba(255,255,255,0.1);
    transform: translateX(3px);
}
.history-item h4 { margin-bottom: 4px; font-size: 1.05rem; color: #fff; }
.history-item p { font-size: 0.82rem; color: var(--gray); }
.btn-view {
    background: var(--primary); 
    color: white; 
    border: none; 
    padding: 9px 16px;
    border-radius: 8px; 
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-view:hover { background: var(--primary-hover); }
