/* ============================================================
   JunZen AI — Cuestionario de Autoevaluación PLA/FT
   Premium Design System — Aligned with Onboarding
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --primary: #00d1b2;
    --primary-hover: #00b89c;
    --primary-soft: rgba(0, 209, 178, 0.1);
    --secondary: #1e293b;
    --accent-blue: #3b82f6;
    --accent-purple: #8b5cf6;
    --danger: #ef4444;
    --warning: #f59e0b;
    --success: #10b981;
    --bg: #f0f4f8;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 10px;
    --shadow-card: 0 4px 24px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.04);
    --shadow-hover: 0 12px 40px rgba(0,0,0,0.12);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --block-0: #3b82f6;
    --block-1: #8b5cf6;
    --block-2: #ef4444;
    --block-3: #10b981;
}

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

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ─── Layout ─────────────────────────────────────────────── */
.cuestionario-wrapper {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(ellipse at 0% 0%, rgba(0,209,178,0.06) 0%, transparent 60%),
        radial-gradient(ellipse at 100% 100%, rgba(59,130,246,0.06) 0%, transparent 60%),
        var(--bg);
}

.cuest-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 48px;
    background: rgba(255,255,255,0.9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.cuest-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
}
.logo-square {
    width: 38px; height: 38px;
    background: var(--primary);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 15px; color: white;
    letter-spacing: -0.5px;
    box-shadow: 0 4px 12px rgba(0,209,178,0.3);
}
.logo-name {
    font-weight: 800; font-size: 20px;
    color: var(--secondary); letter-spacing: -0.5px;
}

.header-badge {
    background: var(--primary-soft);
    border: 1px solid rgba(0,209,178,0.25);
    color: var(--primary);
    font-size: 11px; font-weight: 700;
    padding: 5px 12px; border-radius: 100px;
    text-transform: uppercase; letter-spacing: 0.05em;
    flex-shrink: 0;
}

.header-jz-id {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    background: #f1f5f9;
    color: var(--text-main);
    font-size: 13px; font-weight: 700;
    padding: 6px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    display: none; /* Shown via JS */
}

@media (max-width: 768px) {
    .header-jz-id { position: static; transform: none; order: 3; width: 100%; text-align: center; margin-top: 10px; }
    .cuest-header { flex-wrap: wrap; }
}

/* ─── Progress Bar ─────────────────────────────────────────── */
.global-progress {
    height: 4px;
    background: var(--border);
    position: relative;
}
.global-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #00b4d8);
    border-radius: 2px;
    transition: width 0.5s ease;
}

/* ─── Main Content ─────────────────────────────────────────── */
.cuest-main {
    flex: 1;
    padding: 40px 24px 80px;
    max-width: 860px;
    margin: 0 auto;
    width: 100%;
}

/* ─── Screens ─────────────────────────────────────────────── */
.screen {
    display: none;
    animation: fadeSlideIn 0.45s cubic-bezier(0.4,0,0.2,1);
}
.screen.active { display: block; }

@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeSlideOut {
    from { opacity: 1; transform: translateY(0); }
    to   { opacity: 0; transform: translateY(-16px); }
}

/* ─── HERO / Welcome ──────────────────────────────────────── */
.hero-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 64px 56px;
    text-align: center;
    box-shadow: var(--shadow-card);
    position: relative;
    overflow: hidden;
}
.hero-card::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--accent-blue), var(--accent-purple));
}
.hero-chip {
    display: inline-flex; align-items: center; gap: 8px;
    background: var(--primary-soft);
    border: 1px solid rgba(0,209,178,0.2);
    color: var(--primary);
    font-size: 13px; font-weight: 700;
    padding: 7px 18px; border-radius: 100px;
    margin-bottom: 24px;
    letter-spacing: 0.03em;
}
.hero-chip svg { width: 14px; height: 14px; }

.hero-title {
    font-size: 44px; font-weight: 800;
    color: var(--secondary); line-height: 1.15;
    letter-spacing: -1px; margin-bottom: 20px;
}
.hero-title span { color: var(--primary); }

.hero-subtitle {
    font-size: 18px; color: var(--text-muted);
    max-width: 560px; margin: 0 auto 48px;
    line-height: 1.75;
}

.hero-blocks {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 16px; margin-bottom: 48px;
}
.hero-block {
    padding: 20px 14px;
    border-radius: var(--radius-md);
    background: #f8fafc;
    border: 1px solid var(--border);
    text-align: center;
}
.hero-block-title { font-size: 14px; font-weight: 700; color: var(--secondary); margin-bottom: 6px; }
.hero-block-desc { font-size: 12px; color: var(--text-muted); line-height: 1.5; }

.hero-block.block-0 { border-top: 3px solid var(--accent-blue); }
.hero-block.block-1 { border-top: 3px solid var(--accent-purple); }
.hero-block.block-2 { border-top: 3px solid var(--danger); }
.hero-block.block-3 { border-top: 3px solid var(--success); }

.btn-start {
    display: inline-flex; align-items: center; gap: 12px;
    background: var(--primary);
    color: white;
    padding: 18px 48px;
    border-radius: 14px;
    font-size: 18px; font-weight: 700;
    border: none; cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 6px 20px rgba(0,209,178,0.35);
    text-decoration: none;
}
.btn-start:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(0,209,178,0.45);
}
.btn-start svg { width: 22px; height: 22px; }

/* ─── Step Header ─────────────────────────────────────────── */
.step-header {
    display: flex;
    align-items: center;
    gap: 0;
    margin-bottom: 32px;
}

.step-header-text h2 {
    font-size: 24px; font-weight: 800;
    color: var(--secondary); margin-bottom: 4px; letter-spacing: -0.5px;
}
.step-header-text p { font-size: 14px; color: var(--text-muted); }

/* ─── Block Nav (Stepper) ─────────────────────────────────── */
.block-stepper {
    display: flex; gap: 8px; margin-bottom: 36px;
    flex-wrap: wrap;
}
.block-step {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 16px;
    border-radius: 100px; font-size: 13px; font-weight: 600;
    background: var(--border);
    color: var(--text-muted);
    transition: var(--transition);
    cursor: default;
}
.block-step.active    { background: var(--primary); color: white; }
.block-step.completed { background: rgba(0,209,178,0.1); color: var(--primary); }
.block-step .step-num {
    width: 20px; height: 20px;
    border-radius: 50%; background: rgba(255,255,255,0.3);
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 800;
}
.block-step.active .step-num { background: rgba(0,0,0,0.15); }
.block-step.completed .step-num { background: var(--primary); color: white; font-size: 10px; }

/* ─── Card / Section ──────────────────────────────────────── */
.section-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 36px;
    box-shadow: var(--shadow-card);
    margin-bottom: 20px;
    border: 1px solid rgba(255,255,255,0.8);
    position: relative;
}
.section-title {
    font-size: 16px; font-weight: 700;
    color: var(--secondary);
    display: flex; align-items: center; gap: 10px;
    padding-bottom: 16px; margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
}
.section-title svg { width: 18px; height: 18px; color: var(--primary); }
.section-num {
    width: 26px; height: 26px;
    background: var(--primary-soft);
    color: var(--primary);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 800; flex-shrink: 0;
}

/* ─── Form Elements ───────────────────────────────────────── */
.form-grid {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.form-grid.three { grid-template-columns: 1fr 1fr 1fr; }
.form-grid.full  { grid-template-columns: 1fr; }

.field {
    display: flex; flex-direction: column;
    gap: 7px;
}
.field.full { grid-column: 1 / -1; }

.field label {
    font-size: 13px; font-weight: 600;
    color: var(--secondary);
}
.field label .req { color: var(--danger); margin-left: 3px; }

.field-input, .field-select, .field-textarea {
    width: 100%;
    padding: 13px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px; font-family: 'Inter', sans-serif;
    color: var(--text-main);
    background: #fafbfc;
    transition: var(--transition);
    outline: none;
    appearance: none;
}
.field-input:focus, .field-select:focus, .field-textarea:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(0,209,178,0.1);
}
.field-input.error, .field-select.error {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(239,68,68,0.1);
}
.error-highlight {
    border: 1.5px solid var(--danger) !important;
    background: rgba(239,68,68,0.03) !important;
    box-shadow: 0 0 0 4px rgba(239,68,68,0.1) !important;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.field-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 42px;
    cursor: pointer;
}
.field-textarea {
    resize: vertical; min-height: 100px;
}

.field-hint { font-size: 11px; color: var(--text-muted); }
.field-error { font-size: 12px; color: var(--danger); font-weight: 500; }

/* ─── Yes/No Toggle ───────────────────────────────────────── */
.yn-group { display: flex; gap: 10px; }
.yn-option {
    flex: 1; padding: 11px 0;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    text-align: center;
    font-size: 14px; font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    background: #fafbfc;
}
.yn-option:hover { border-color: var(--primary); color: var(--primary); background: white; }
.yn-option.selected-yes { background: rgba(0,209,178,0.08); border-color: var(--primary); color: var(--primary); }
.yn-option.selected-no  { background: rgba(239,68,68,0.08); border-color: var(--danger); color: var(--danger); }
.yn-option.selected     { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

/* ─── Radio / Checkbox Chips ──────────────────────────────── */
.chip-group { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.chip-option {
    padding: 9px 18px; border-radius: 100px;
    border: 1.5px solid var(--border);
    font-size: 13px; font-weight: 600;
    color: var(--text-muted); cursor: pointer;
    transition: var(--transition); background: #fafbfc;
    user-select: none;
}
.chip-option:hover    { border-color: var(--primary); color: var(--primary); background: white; }
.chip-option.selected, .chip-option.active { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

/* ─── Risk Level Select Cards ─────────────────────────────── */
.risk-select-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 14px; }
.risk-select-card {
    padding: 22px 14px; border-radius: var(--radius-md);
    border: 2px solid var(--border); background: #fafbfc;
    text-align: center; cursor: pointer;
    transition: var(--transition);
}
.risk-select-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); }
.risk-select-card .rsc-icon { font-size: 30px; margin-bottom: 10px; }
.risk-select-card .rsc-label { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.risk-select-card .rsc-desc { font-size: 12px; color: var(--text-muted); }
.risk-select-card.bajo-sel { border-color: var(--success); background: rgba(16,185,129,0.05); }
.risk-select-card.bajo-sel .rsc-label { color: var(--success); }
.risk-select-card.medio-sel { border-color: var(--warning); background: rgba(245,158,11,0.05); }
.risk-select-card.medio-sel .rsc-label { color: var(--warning); }
.risk-select-card.alto-sel { border-color: var(--danger); background: rgba(239,68,68,0.05); }
.risk-select-card.alto-sel .rsc-label { color: var(--danger); }

/* ─── Multi-risk Chips (Block 3.2) ───────────────────────── */
.multi-risk-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.multi-risk-item {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    cursor: pointer; transition: var(--transition);
    background: #fafbfc;
}
.multi-risk-item:hover { background: white; border-color: var(--primary); }
.multi-risk-item.selected { border-color: var(--primary); background: var(--primary-soft); }
.multi-risk-checkbox {
    width: 20px; height: 20px;
    border-radius: 6px; border: 2px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: var(--transition);
}
.multi-risk-item.selected .multi-risk-checkbox {
    background: var(--primary); border-color: var(--primary); color: white;
}
.multi-risk-label { font-size: 13px; font-weight: 600; color: var(--secondary); }

/* ─── Percentage Inputs Row ───────────────────────────────── */
.pct-row { display: flex; gap: 12px; align-items: flex-end; }
.pct-field { flex: 1; }
.pct-field label { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; display: block; }
.pct-input {
    width: 100%; padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px; font-family: 'Inter', sans-serif;
    color: var(--text-main); background: #fafbfc;
    transition: var(--transition); outline: none;
    text-align: center;
}
.pct-input:focus { border-color: var(--primary); background: white; box-shadow: 0 0 0 4px rgba(0,209,178,0.1); }
.pct-label { font-size: 22px; color: var(--text-muted); padding-bottom: 12px; }

/* ─── Info Note Box ───────────────────────────────────────── */
.info-note {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 14px 18px; border-radius: var(--radius-sm);
    background: rgba(59,130,246,0.06);
    border: 1px solid rgba(59,130,246,0.15);
    margin-top: 16px;
}
.info-note svg { width: 18px; height: 18px; color: var(--accent-blue); flex-shrink: 0; margin-top: 1px; }
.info-note p { font-size: 13px; color: #3b82f6; line-height: 1.5; }

/* ─── Navigation Footer ───────────────────────────────────── */
.cuest-footer {
    display: flex; align-items: center;
    justify-content: space-between;
    gap: 16px; margin-top: 32px;
    padding: 0 4px;
}

.btn-back, .btn-next {
    display: inline-flex; align-items: center; gap: 10px;
    padding: 14px 32px;
    border-radius: var(--radius-sm);
    font-size: 16px; font-weight: 700;
    border: none; cursor: pointer;
    transition: var(--transition);
}
.btn-back {
    background: transparent;
    color: var(--text-muted);
    border: 1.5px solid var(--border);
}
.btn-back:hover { border-color: var(--primary); color: var(--primary); }
.btn-back svg, .btn-next svg { width: 20px; height: 20px; }

.btn-next {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 16px rgba(0,209,178,0.3);
    margin-left: auto;
}
.btn-next:hover { background: var(--primary-hover); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,209,178,0.4); }
.btn-next:disabled { background: var(--border); color: var(--text-light); box-shadow: none; cursor: not-allowed; transform: none; }

/* ─── RESULT SCREEN ───────────────────────────────────────── */
.result-hero {
    background: var(--surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-card);
    margin-bottom: 24px;
}
.result-hero-top {
    padding: 48px 48px 40px;
    text-align: center;
    position: relative;
    overflow: hidden;
}
.result-hero-top.bajo   { background: linear-gradient(135deg,rgba(16,185,129,0.08),rgba(16,185,129,0.02)); border-top: 5px solid var(--success); }
.result-hero-top.medio  { background: linear-gradient(135deg,rgba(245,158,11,0.08),rgba(245,158,11,0.02)); border-top: 5px solid var(--warning); }
.result-hero-top.alto   { background: linear-gradient(135deg,rgba(239,68,68,0.08),rgba(239,68,68,0.02)); border-top: 5px solid var(--danger); }

.result-badge {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 8px 22px; border-radius: 100px;
    font-size: 13px; font-weight: 800;
    letter-spacing: 0.08em; text-transform: uppercase;
    margin-bottom: 20px;
}
.bajo .result-badge  { background: rgba(16,185,129,0.12); color: var(--success); }
.medio .result-badge { background: rgba(245,158,11,0.12); color: var(--warning); }
.alto .result-badge  { background: rgba(239,68,68,0.12); color: var(--danger); }

.result-title {
    font-size: 32px; font-weight: 800;
    letter-spacing: -0.5px; margin-bottom: 14px;
    color: var(--secondary);
}
.result-subtitle { font-size: 16px; color: var(--text-muted); max-width: 520px; margin: 0 auto 36px; }

.score-clusters {
    display: flex; gap: 20px; justify-content: center;
    flex-wrap: wrap; margin-bottom: 8px;
}
.score-cluster {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 22px; border-radius: var(--radius-sm);
    background: rgba(0,0,0,0.04); min-width: 160px;
}
.sc-icon { font-size: 24px; }
.sc-info {}
.sc-label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.sc-value { font-size: 22px; font-weight: 800; color: var(--secondary); }

.result-outputs {
    display: grid; grid-template-columns: repeat(2,1fr);
    gap: 16px; padding: 36px 48px;
    border-top: 1px solid var(--border);
}
.result-output-item {
    display: flex; align-items: flex-start; gap: 14px;
    padding: 18px; border-radius: var(--radius-sm);
    background: #f8fafc; border: 1px solid var(--border);
}
.roi-icon {
    width: 42px; height: 42px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; font-size: 18px;
}
.roi-icon.auto   { background: rgba(0,209,178,0.1); }
.roi-icon.matriz { background: rgba(139,92,246,0.1); }
.roi-icon.report { background: rgba(59,130,246,0.1); }
.roi-icon.manual { background: rgba(245,158,11,0.1); }
.roi-title { font-size: 14px; font-weight: 700; color: var(--secondary); margin-bottom: 3px; }
.roi-desc { font-size: 12px; color: var(--text-muted); line-height: 1.5; }

.result-action-bar {
    padding: 28px 48px;
    border-top: 1px solid var(--border);
    display: flex; gap: 14px; align-items: center;
    justify-content: center; flex-wrap: wrap;
}

.btn-download {
    display: inline-flex; align-items: center; gap: 10px;
    padding: 15px 32px; border-radius: var(--radius-md);
    font-size: 15px; font-weight: 700;
    border: none; cursor: pointer; transition: var(--transition);
}
.btn-download.primary {
    background: var(--primary); color: white;
    box-shadow: 0 4px 16px rgba(0,209,178,0.3);
}
.btn-download.primary:hover { background: var(--primary-hover); transform: translateY(-2px); }
.btn-download.secondary {
    background: white; color: var(--secondary);
    border: 1.5px solid var(--border);
}
.btn-download.secondary:hover { border-color: var(--primary); color: var(--primary); }
.btn-download svg { width: 18px; height: 18px; }

.new-cuest-btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 12px 24px; border-radius: var(--radius-md);
    font-size: 14px; font-weight: 600;
    background: transparent; color: var(--text-muted);
    border: 1.5px solid var(--border); cursor: pointer;
    transition: var(--transition);
}
.new-cuest-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ─── Success Toast — v52 flush 0px al ras (debug entre bloques) ─── */
.toast {
    position: fixed; left: 0; bottom: 0;
    transform: translateY(100%);
    background: var(--secondary); color: white;
    padding: 14px 28px; border-radius: 0 14px 0 0;
    font-size: 14px; font-weight: 600;
    display: flex; align-items: center; gap: 10px;
    z-index: 9999; transition: transform 0.4s ease;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.toast.show { transform: translateY(0); }
.toast svg  { width: 18px; height: 18px; color: var(--primary); }

/* ─── Loading Spinner ─────────────────────────────────────── */
.spinner {
    width: 20px; height: 20px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: none;
}
.btn-next.loading .spinner { display: block; }
.btn-next.loading span { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
    .cuest-header { padding: 14px 20px; }
    .cuest-main { padding: 24px 16px 60px; }
    .hero-card { padding: 40px 24px; }
    .hero-title { font-size: 30px; }
    .hero-blocks { grid-template-columns: repeat(2,1fr); }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid.three { grid-template-columns: 1fr; }
    .section-card { padding: 24px; }
    .result-outputs { grid-template-columns: 1fr; }
    .result-hero-top { padding: 36px 24px; }
    .result-action-bar { padding: 24px; }
    .result-outputs { padding: 24px; }
    .risk-select-grid { grid-template-columns: 1fr; }
    .multi-risk-grid { grid-template-columns: 1fr; }
    .score-clusters { flex-direction: column; align-items: center; }
    /* Gate3 polish — responsive 1fr para ponderación y N/F/F */
    .ponderacion-item { grid-template-columns: 1fr !important; gap: 10px; }
    #cp_nff_wrap .form-grid { grid-template-columns: 1fr !important; }
    #cp_nff_wrap { gap: 10px; }
}
@media (max-width: 480px) {
    .block-stepper { gap: 6px; }
    .block-step { font-size: 11px; padding: 6px 12px; }
    .hero-blocks { grid-template-columns: 1fr; }
    .cuest-footer { flex-direction: column; }
    .btn-back, .btn-next { width: 100%; justify-content: center; }
}
/* Gate3 polish — responsive 375px: OTP 6 dígitos sin overflow horizontal
   (los inputs llevan letter-spacing:12px y width:240px inline; !important gana al inline) */
@media (max-width: 375px) {
    #auth_otp, #auth_otp_email {
        width: 100% !important;
        max-width: 100% !important;
        font-size: 24px !important;
        letter-spacing: 6px !important;
        padding-left: 10px !important;
        padding-right: 4px !important;
    }
    .otp-container { gap: 6px !important; }
}

/* Toasts — v52 flush 0px al ras (debug) — unifica .toast y .global-toast */
.toast, .global-toast {
    position: fixed !important;
    left: 0 !important;
    bottom: 0 !important;
    right: auto !important;
    top: auto !important;
    transform: translateY(100%) !important;
    background: var(--secondary) !important;
    color: white !important;
    padding: 14px 28px !important;
    border-radius: 0 14px 0 0 !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    z-index: 9999 !important;
    transition: transform 0.4s ease !important;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2) !important;
}
.toast.show, .global-toast.show {
    transform: translateY(0) !important;
}
.global-toast.error { background: #fee2e2 !important; color: #991b1b !important; border: 1px solid #fecaca !important; }
.global-toast.error::before { content: '❌'; margin-right: 8px; }
.global-toast.info { background: #e0f2fe !important; color: #0369a1 !important; border: 1px solid #bae6fd !important; }
.global-toast.info::before { content: 'ℹ️'; margin-right: 8px; }

/* ══════════════════ MOTOR DE RIESGOS EBR ══════════════════ */

/* 3.1 Sliders de Ponderación */
.ponderacion-list { display: flex; flex-direction: column; gap: 20px; margin-bottom: 24px; }
.ponderacion-item { 
    background: #f8fafc; padding: 16px; border-radius: 12px; border: 1px solid var(--border);
    display: grid; grid-template-columns: 1fr 200px 60px; align-items: center; gap: 16px;
}
/* Gate3 — contraste AA stickyScore: pill primary-soft con texto secondary */
#stickyScore {
    background: var(--primary-soft) !important;
    color: var(--secondary) !important;
    padding: 2px 10px;
    border-radius: 999px;
    border: 1px solid rgba(0,209,178,0.25);
}
#stickyScore[aria-invalid="true"] { border-color: var(--danger); }
.field-select[aria-invalid="true"], .field-textarea[aria-invalid="true"] { border-color: var(--danger) !important; box-shadow: 0 0 0 3px rgba(239,68,68,0.1) !important; }
.p-factor-name { font-weight: 700; color: var(--secondary); font-size: 14px; }
.p-slider { 
    -webkit-appearance: none; width: 100%; height: 6px; background: #e2e8f0; 
    border-radius: 5px; outline: none; transition: 0.2s;
}
.p-slider::-webkit-slider-thumb {
    -webkit-appearance: none; width: 18px; height: 18px; background: var(--primary); 
    border-radius: 50%; cursor: pointer; border: 3px solid white; box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
.p-val-badge { 
    background: var(--secondary); color: white; padding: 4px 8px; border-radius: 6px; 
    font-size: 13px; font-weight: 700; text-align: center;
}
.total-badge {
    display: inline-block; padding: 8px 16px; border-radius: 8px; font-weight: 800;
    font-size: 15px; margin-top: 10px; transition: var(--transition);
}

/* 3.2 Cards de Riesgo */
.riesgos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; margin-top: 12px; }
.risk-card {
    background: white; border: 1.5px solid var(--border); border-radius: 14px; padding: 16px;
    cursor: pointer; transition: var(--transition); position: relative;
}
.risk-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.risk-card.selected { border-color: var(--primary); background: var(--primary-soft); }
.rc-header { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.rc-icon { font-size: 20px; filter: grayscale(1); transition: 0.2s; }
.risk-card.selected .rc-icon { filter: grayscale(0); }
.rc-title { font-weight: 700; font-size: 14px; color: var(--secondary); line-height: 1.3; }
.rc-meta { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; margin-bottom: 4px; }

.rc-controls { 
    display: none; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; padding-top: 16px; 
    border-top: 1px dashed var(--border);
}
.risk-card.selected .rc-controls { display: grid; }
.rc-field label { font-size: 10px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 6px; }
.rc-select { width: 100%; padding: 8px; border-radius: 8px; border: 1px solid var(--border); font-size: 13px; font-weight: 600; outline: none; }

/* Indicadores de Riesgo */
.score-summary-bar {
    margin-top: 24px; padding: 16px; background: var(--secondary); border-radius: 12px;
    display: flex; justify-content: space-around; color: white; font-weight: 700; font-size: 14px;
}
.score-summary-bar span { color: var(--primary); font-size: 18px; margin-left: 8px; }

/* 3.3 Controles */
.controles-list { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.control-accordeon { 
    border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: white;
}
.ca-header { 
    padding: 14px 20px; background: #f8fafc; cursor: pointer; display: flex; 
    align-items: center; justify-content: space-between; font-weight: 700; font-size: 14px;
}
.ca-body { padding: 16px; display: none; }
.ca-body.open { display: block; }

.control-item {
    display: flex; align-items: flex-start; gap: 12px; padding: 14px; border-radius: 12px;
    margin-bottom: 10px; border: 1.5px solid var(--border); cursor: pointer; transition: 0.2s;
    background: white; flex-direction: column;
}
.control-item:hover { border-color: var(--primary); background: #f8fafc; }
.control-item.selected { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 4px 12px rgba(0,209,178,0.1); }
.ci-header { display: flex; align-items: center; gap: 12px; width: 100%; }
.ci-checkbox { width: 22px; height: 22px; border: 2px solid var(--border); border-radius: 6px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.control-item.selected .ci-checkbox { background: var(--primary); border-color: var(--primary); }
.ci-info { flex: 1; }
.ci-name { font-weight: 600; font-size: 13px; color: var(--secondary); }
.ci-eff { font-size: 11px; color: var(--text-muted); font-weight: 700; margin-top: 2px; }

.residual-hero { 
    margin-top: 32px; display: flex; justify-content: center;
}
.residual-box {
    background: white; border: 2px solid var(--border); border-radius: 20px; padding: 24px 48px;
    text-align: center; box-shadow: var(--shadow);
}
.res-label { font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; margin-bottom: 8px; }
.res-value { font-size: 48px; font-weight: 900; color: var(--secondary); line-height: 1; }
.res-badge { 
    display: inline-block; margin-top: 12px; padding: 6px 14px; border-radius: 30px; 
    font-size: 12px; font-weight: 800; color: white; background: #cbd5e1;
}


/* Tooltip de descripción para Risk Cards y Controles */
.rc-tooltip {
    position: absolute; bottom: 105%; left: 50%; transform: translateX(-50%);
    background: #1e293b; color: white; padding: 12px 16px; border-radius: 10px;
    font-size: 12px; width: 260px; line-height: 1.4; pointer-events: none;
    opacity: 0; transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1); z-index: 1000; 
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); text-align: left;
    border: 1px solid rgba(255,255,255,0.1);
}
.rc-tooltip::after {
    content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
    border-width: 6px; border-style: solid; border-color: #1e293b transparent transparent transparent;
}
.risk-card:hover .rc-tooltip, .control-item:hover .rc-tooltip { 
    opacity: 1; bottom: 110%; 
}
.control-item { overflow: visible !important; } /* Permitir que el tooltip se vea */
.risk-card { overflow: visible !important; }

/* ══════════════════ PANELES EBR RSB / RI / RR ══════════════════ */

.ebr-score-panel {
    margin-top: 28px;
    background: var(--secondary);
    border-radius: 16px;
    padding: 20px 24px;
    color: white;
}
.ebr-panel-residual { background: #1a2744; }

.ebr-panel-title {
    font-size: 13px;
    font-weight: 700;
    color: rgba(255,255,255,0.6);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 16px;
}

.ebr-panel-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.ebr-score-item {
    flex: 1;
    min-width: 110px;
    background: rgba(255,255,255,0.07);
    border-radius: 10px;
    padding: 12px 14px;
    text-align: center;
    border: 1px solid rgba(255,255,255,0.1);
    transition: all 0.3s ease;
}

/* Colores semánticos por tipo */
.ebr-rsb   { border-color: rgba(148,163,184,0.35); }
.ebr-ri-la { border-color: rgba(251,146,60,0.4); }
.ebr-ri-ft { border-color: rgba(167,139,250,0.4); }
.ebr-rr-la { border-color: rgba(0,209,178,0.4); }
.ebr-rr-ft { border-color: rgba(0,209,178,0.4); }

.ebr-score-label {
    font-size: 10px;
    font-weight: 700;
    color: rgba(255,255,255,0.5);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 6px;
}

.ebr-score-value {
    font-size: 28px;
    font-weight: 900;
    line-height: 1;
    margin-bottom: 4px;
    transition: all 0.4s ease;
}
.ebr-val-sm { font-size: 20px; }

.ebr-rsb   .ebr-score-value { color: #94a3b8; }
.ebr-ri-la .ebr-score-value { color: #fb923c; }
.ebr-ri-ft .ebr-score-value { color: #a78bfa; }
.ebr-rr-la .ebr-score-value { color: var(--primary); }
.ebr-rr-ft .ebr-score-value { color: var(--primary); }

.ebr-score-sub {
    font-size: 10px;
    color: rgba(255,255,255,0.35);
}
.ebr-guarantee {
    color: #10b981;
    font-weight: 700;
}

.ebr-arrow {
    font-size: 18px;
    color: rgba(255,255,255,0.25);
    flex-shrink: 0;
}
.ebr-divider {
    width: 1px;
    height: 50px;
    background: rgba(255,255,255,0.1);
    flex-shrink: 0;
    margin: 0 4px;
}

/* Score consolidado final */
.ebr-consolidated {
    background: rgba(0,209,178,0.12);
    border: 1px solid rgba(0,209,178,0.3);
    border-radius: 12px;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.ebr-consolidated-label {
    font-size: 12px;
    font-weight: 700;
    color: rgba(255,255,255,0.6);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.ebr-consolidated-value {
    font-size: 36px;
    font-weight: 900;
    color: var(--primary);
    line-height: 1;
    transition: all 0.4s ease;
}
.ebr-consolidated-badge {
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 800;
    background: #64748b;
    color: white;
    transition: all 0.3s ease;
}
.ebr-consolidated-badge.badge-bajo  { background: var(--success); color: white; border: 1px solid var(--success); }
.ebr-consolidated-badge.badge-medio { background: #fef3c7; color: #92400e; border: 1px solid #f59e0b; }
.ebr-consolidated-badge.badge-alto  { background: var(--danger); color: white; border: 1px solid var(--danger); }
.ebr-consolidated-formula {
    font-size: 11px;
    color: rgba(255,255,255,0.3);
    margin-left: auto;
    font-family: monospace;
}

.ebr-panel-note {
    font-size: 10px;
    color: rgba(255,255,255,0.25);
    text-align: right;
    font-style: italic;
}

@media (max-width: 640px) {
    .ebr-panel-row { gap: 8px; }
    .ebr-score-value { font-size: 22px; }
    .ebr-arrow, .ebr-divider { display: none; }
    .ebr-consolidated { flex-direction: column; align-items: flex-start; gap: 8px; }
    .ebr-consolidated-formula { margin-left: 0; }
}

/* ══════════════════ OJITO BLOQUE 0 — v51 ══════════════════ */
.password-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}
.password-wrapper .field-input {
    padding-right: 44px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.password-toggle {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-muted);
    transition: color 0.2s ease, background 0.2s ease;
}
.password-toggle:hover {
    color: var(--secondary);
    background: rgba(0,0,0,0.04);
}
.password-toggle:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0,209,178,0.35);
}
.password-toggle svg,
.password-toggle i,
.password-toggle .pw-icon {
    width: 18px;
    height: 18px;
}

/* ══════════════════ SCREEN COMPLETADO — v51 ══════════════════ */
.hero-card.is-completed {
    border: 1px solid rgba(0,209,178,0.2);
}
.hero-card.is-completed .hero-chip {
    background: rgba(16,185,129,0.1);
    border-color: rgba(16,185,129,0.2);
    color: var(--success);
}
.completed-actions {
    display: flex;
    gap: 14px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 28px;
}
.completed-actions .btn-start.secondary {
    background: white;
    color: var(--secondary);
    border: 1.5px solid var(--border);
    box-shadow: none;
}
.completed-actions .btn-start.secondary:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Modal confirmar nuevo */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.55);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
}
.modal-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 32px;
    max-width: 460px;
    width: 100%;
    box-shadow: var(--shadow-hover);
    text-align: center;
}
.modal-card h3 {
    font-size: 18px;
    font-weight: 800;
    color: var(--secondary);
    margin-bottom: 10px;
}
.modal-card p {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 24px;
    line-height: 1.6;
}
.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}
.modal-actions button {
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    border: 1.5px solid var(--border);
    background: white;
    transition: var(--transition);
}
.modal-actions button.primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.modal-actions button.primary:hover { background: var(--primary-hover); }
.modal-actions button:hover { border-color: var(--primary); color: var(--primary); }

/* ─── Gate3 polish — modalControlPers coherente con modalConfirmNew ──────────── */
#modalControlPers { z-index: 10000; } /* por encima de stickyRiesgoCard (z-index 5) y modalConfirmNew (9999) — coherente */
#modalControlPers .modal-card { text-align: left; max-width: 560px; }

/* Gate3 — info-tooltip Q3.2: botón accesible con aria-describedby */
.info-tooltip {
    display: inline-flex; align-items: center; justify-content: center;
    width: 20px; height: 20px; border-radius: 50%;
    background: #e0f2fe; color: #0c4a6e; border: 1px solid #0ea5e9;
    font-size: 11px; font-weight: 700; cursor: help; flex-shrink: 0;
    vertical-align: middle;
}
.info-tooltip:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.tooltip-bubble {
    position: absolute; bottom: 125%; left: 50%; transform: translateX(-50%);
    background: #1e293b; color: white; padding: 10px 14px; border-radius: 8px;
    font-size: 12px; line-height: 1.5; width: 260px; max-width: min(260px, calc(100vw - 32px)); z-index: 10010;
    box-shadow: 0 8px 20px rgba(0,0,0,0.15); text-align: left;
    display: none;
}
.tooltip-bubble::after {
    content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
    border-width: 6px; border-style: solid; border-color: #1e293b transparent transparent transparent;
}
.info-tooltip:hover + .tooltip-bubble, .info-tooltip:focus + .tooltip-bubble, .info-tooltip[aria-expanded="true"] + .tooltip-bubble { display: block; }
.field.has-tooltip { position: relative; overflow: visible; }

/* Gate3 — contador 500 con warn >450 */
.cp-counter { font-size: 11px; color: var(--text-muted); text-align: right; transition: color 0.2s; }
.cp-counter.warn { color: #b45309; font-weight: 700; }
.cp-counter.over { color: var(--danger); font-weight: 700; }

/* Gate3 — preview BORRADOR watermark fixed (viewport-locked) */
#previewWatermark {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%,-50%) rotate(-18deg) !important;
    font-size: 56px !important;
    font-weight: 900 !important;
    color: rgba(239,68,68,0.14) !important;
    letter-spacing: 10px !important;
    pointer-events: none !important;
    z-index: 5 !important;
    white-space: nowrap;
}
#previewContainer.has-watermark { position: relative; overflow: hidden; }
/* asegurar heatmap leyenda SSOT visible */
.ebr-heatmap-legend { font-size: 10px; color: #64748b; text-align: center; margin-top: 6px; }

/* ══════════════════ G5.3 — Bloque 3.5/3.6 — Tolerancia → Perfil ══════════════════ */
/* Contraste AA: badges #166534/#dcfce7, #92400e/#fef3c7, #1e40af/#eff6ff superan 4.5:1; texto sobre fondo blanco usa var(--secondary) #1e293b (7:1) */
#sectionTolerancia35 .field-input[aria-invalid="true"],
#sectionTolerancia35 .field-select[aria-invalid="true"],
#sectionTolerancia35 .field-textarea[aria-invalid="true"],
#sectionPerfil36 .field-input[aria-invalid="true"],
#sectionPerfil36 .field-select[aria-invalid="true"],
#sectionPerfil36 .field-textarea[aria-invalid="true"] { border-color: var(--danger) !important; box-shadow: 0 0 0 3px rgba(239,68,68,0.12) !important; }
#tolPreviewBox, #perPreviewBox { max-height: 420px; }
#sectionPerfil36[style*="pointer-events: none"] button { cursor: not-allowed; }
@media (max-width: 768px) {
    #sectionTolerancia35 .form-grid.three, #sectionPerfil36 .form-grid.three { grid-template-columns: 1fr !important; }
    #tolPreviewBox, #perPreviewBox { margin-left: -4px; margin-right: -4px; }
}
