/* ==============================================================================
   ESTILOS MODERNOS: TUTOR DE IDIOMAS & CORRECTOR DE CÓDIGO CON IA
   ARQUITECTURA: CSS3 Puro con Custom Properties (Variables de Diseño)
   ============================================================================== */

:root {
    --bg-base: #0a0d14;
    --bg-surface: #121824;
    --bg-surface-elevated: #1a2234;
    --bg-surface-soft: #232d42;

    --border-subtle: #222d42;
    --border-focus: #3b82f6;

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --accent-primary: #3b82f6;
    --accent-hover: #2563eb;
    --accent-glow: rgba(59, 130, 246, 0.25);

    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.12);
    --success-border: #059669;

    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.12);
    --danger-border: #dc2626;

    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.12);

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    background-color: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-sans);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
}

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

/* HEADER Y SESIÓN DEL USUARIO */
.header-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(8px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.brand-icon {
    font-size: 1.8rem;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.brand-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.brand-subtitle {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

/* USER SESSION CARD */
.user-session-card {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-lg);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #10b981, #3b82f6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.95rem;
}

.user-name {
    font-size: 0.88rem;
    font-weight: 600;
}

.user-email {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.user-metrics {
    display: flex;
    gap: 0.5rem;
    border-left: 1px solid var(--border-subtle);
    padding-left: 1rem;
}

.metric-badge {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.6rem;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 600;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
}

.metric-badge.streak { color: #f97316; }
.metric-badge.score { color: #eab308; }
.metric-badge.avg { color: #06b6d4; }
.metric-lbl { font-size: 0.7rem; color: var(--text-muted); font-weight: 400; }

/* ESPACIO DE TRABAJO (GRID DE 3 COLUMNAS) */
.main-workspace {
    display: grid;
    grid-template-columns: 340px 1fr 340px;
    gap: 1.5rem;
    padding: 1.5rem;
    flex: 1;
}

.workspace-column {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* CARDS COMUNES */
.panel-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.panel-title {
    font-size: 1.05rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

/* FILTROS */
.filter-grid {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    margin-bottom: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.custom-select {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    outline: none;
    transition: var(--transition);
}

.custom-select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* RETO ACTIVO */
.challenge-card {
    border-left: 4px solid var(--accent-primary);
}

.challenge-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.challenge-badges {
    display: flex;
    gap: 0.4rem;
}

.tag {
    font-size: 0.68rem;
    font-weight: 700;
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
}

.tag-category { background: rgba(59, 130, 246, 0.2); color: #60a5fa; }
.tag-lang { background: rgba(168, 85, 247, 0.2); color: #c084fc; }
.tag-level { background: rgba(16, 185, 129, 0.2); color: #34d399; }

.challenge-id-badge {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.challenge-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.challenge-desc {
    font-size: 0.86rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.instruction-box {
    background: var(--bg-surface-elevated);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    border: 1px dashed var(--border-subtle);
}

.instruction-header {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--warning);
    margin-bottom: 0.25rem;
}

.instruction-box p {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.base-code-box {
    background: #080b11;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.box-title-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.75rem;
    background: var(--bg-surface-elevated);
    font-size: 0.75rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-subtle);
}

.btn-link {
    background: none;
    border: none;
    color: var(--accent-primary);
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
}

.btn-link:hover { text-decoration: underline; }

.base-code-box pre {
    padding: 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: #e2e8f0;
    overflow-x: auto;
    white-space: pre-wrap;
    max-height: 150px;
}

/* EDITOR DE SOLUCIÓN */
.editor-card {
    display: flex;
    flex-direction: column;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.editor-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.char-counter {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.editor-wrapper {
    position: relative;
    margin: 0.5rem 0 1rem 0;
}

.code-editor {
    width: 100%;
    min-height: 260px;
    background: #080b11;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 1rem;
    font-family: var(--font-mono);
    font-size: 0.92rem;
    color: #f1f5f9;
    resize: vertical;
    outline: none;
    line-height: 1.6;
    transition: var(--transition);
}

.code-editor:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.editor-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.safety-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-dot.green {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.safety-text {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* BOTONES */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.88rem;
    padding: 0.65rem 1.25rem;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: white;
    box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    transform: translateY(-1px);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-surface-soft);
    border-color: var(--text-muted);
}

.btn-ghost {
    background: none;
    border: 1px solid transparent;
    color: var(--text-secondary);
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
}

.btn-ghost:hover {
    color: var(--text-primary);
    background: var(--bg-surface-elevated);
}

.btn-full { width: 100%; }

/* SPINNER */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s ease-in-out infinite;
}

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

.hidden { display: none !important; }

/* PANEL DE RETROALIMENTACIÓN DE LA IA */
.feedback-card {
    border-top: 4px solid var(--accent-primary);
    animation: fadeIn 0.3s ease-out;
}

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

.feedback-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 1rem;
    margin-bottom: 1.25rem;
}

.timestamp-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* VELOCÍMETRO / GAUGE */
.gauge-component {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.gauge-circle {
    position: relative;
    width: 110px;
    height: 60px;
}

.gauge-svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}

.gauge-bg {
    fill: none;
    stroke: var(--bg-surface-soft);
    stroke-width: 10;
    stroke-linecap: round;
}

.gauge-fill {
    fill: none;
    stroke: var(--success);
    stroke-width: 10;
    stroke-linecap: round;
    stroke-dasharray: 126;
    stroke-dashoffset: 126; /* dinámico */
    transition: stroke-dashoffset 1s ease-in-out, stroke 0.4s ease;
}

.gauge-value-box {
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
}

.gauge-number {
    font-size: 1.35rem;
    font-weight: 800;
}

.gauge-max {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.status-pill {
    font-size: 0.7rem;
    font-weight: 800;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    letter-spacing: 0.05em;
}

.status-pill.approved {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid var(--success-border);
}

.status-pill.failed {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid var(--danger-border);
}

/* SECCIONES DE FEEDBACK */
.feedback-section {
    margin-bottom: 1.25rem;
}

.section-title-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.section-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.explanation-box {
    background: var(--bg-surface-elevated);
    padding: 0.85rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    color: #e2e8f0;
    line-height: 1.6;
    border-left: 3px solid #38bdf8;
}

/* ERRORES DETECTADOS (ROJO) */
.badge-count {
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
    background: var(--danger-bg);
    color: var(--danger);
    font-weight: 700;
}

.error-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.error-item-card {
    background: #190e11;
    border: 1px solid var(--danger-border);
    border-left: 5px solid var(--danger);
    padding: 0.85rem;
    border-radius: var(--radius-md);
}

.error-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.4rem;
}

.error-type {
    font-weight: 700;
    font-size: 0.8rem;
    color: #f87171;
    text-transform: uppercase;
}

.error-location {
    font-size: 0.75rem;
    font-family: var(--font-mono);
    color: #fca5a5;
    background: rgba(239, 68, 68, 0.2);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
}

.error-desc {
    font-size: 0.84rem;
    color: #fecaca;
    margin-bottom: 0.5rem;
}

.error-suggest {
    font-size: 0.82rem;
    color: #e2e8f0;
    background: rgba(0, 0, 0, 0.4);
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius-sm);
}

.no-errors-card {
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    color: var(--success);
    padding: 0.85rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    text-align: center;
    font-size: 0.88rem;
}

/* VERSIÓN CORREGIDA (VERDE) */
.corrected-code-box {
    background: #091710;
    border: 1px solid var(--success-border);
    border-left: 5px solid var(--success);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.corrected-code-box pre {
    padding: 1rem;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: #a7f3d0;
    overflow-x: auto;
    white-space: pre-wrap;
    line-height: 1.6;
}

/* CONSEJO PROACTIVO */
.tip-card {
    display: flex;
    gap: 0.85rem;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(139, 92, 246, 0.1));
    border: 1px solid rgba(99, 102, 241, 0.4);
    padding: 0.85rem 1rem;
    border-radius: var(--radius-md);
}

.tip-icon { font-size: 1.4rem; }
.tip-title { font-size: 0.84rem; font-weight: 700; color: #a5b4fc; margin-bottom: 0.2rem; }
.tip-text { font-size: 0.82rem; color: #cbd5e1; }

/* HISTORIAL (COLUMNA DERECHA) */
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-desc {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.history-desc code {
    background: var(--bg-surface-elevated);
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    font-family: var(--font-mono);
}

.history-list-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: calc(100vh - 240px);
    overflow-y: auto;
    padding-right: 0.3rem;
}

.empty-history {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    border: 1px dashed var(--border-subtle);
    border-radius: var(--radius-md);
}

.history-item {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
}

.history-item:hover {
    border-color: var(--border-focus);
    background: var(--bg-surface-soft);
}

.history-item-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.35rem;
}

.history-tag {
    font-size: 0.7rem;
    font-weight: 700;
    color: #93c5fd;
}

.history-score-badge {
    font-size: 0.75rem;
    font-weight: 800;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
}

.history-score-badge.passed {
    background: var(--success-bg);
    color: var(--success);
}

.history-score-badge.failed {
    background: var(--danger-bg);
    color: var(--danger);
}

.history-item-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.25rem;
}

.history-item-footer {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* TOASTS */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 999;
}

.toast {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    animation: slideIn 0.25s ease;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--accent-primary); }

/* RESPONSIVE */
@media (max-width: 1200px) {
    .main-workspace {
        grid-template-columns: 300px 1fr;
    }
    .right-pane {
        grid-column: 1 / -1;
    }
}

@media (max-width: 768px) {
    .header-nav {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    .user-session-card {
        width: 100%;
        justify-content: space-between;
    }
    .main-workspace {
        grid-template-columns: 1fr;
    }
}
