/* Design & Fix - Learn Mode Variant */
/* Fits into #practice-content (right panel) alongside Learn mode presets */
/* Uses the same --lm-* design tokens defined in shared/learn-mode.css so this
   panel is visually consistent with the rest of Learn mode (e.g. the
   Progress/roadmap tab) instead of its own ad-hoc palette. */

#design-fix-container {
    display: none;
}

body.mode-learn #design-fix-container:not(.hidden) {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    height: 100% !important;
    background: var(--lm-surface, #ffffff) !important;
    padding: 0 !important;
    overflow-y: auto !important;
    scrollbar-width: thin;
    scrollbar-color: var(--lm-border, #e2e8f0) transparent;
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--lm-text, #1e293b);
}

/* ─── Right panel header label (shown while tab bar is hidden) ────────── */
/* Mirrors the canonical .panel-header h2 rule (base/style.css ~L10230) so
   "Design & Fix" reads identically to "COMPONENTS" in the left panel header:
   bold, uppercase, letter-spaced, and centered in the header row. */

#df-panel-header-label {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1 1 auto;
    min-width: 0;
    max-width: calc(100% - 3rem);
    padding-right: 1rem;
    font-size: 13px !important;
    font-weight: 700 !important;
    color: var(--lm-text, #1e293b);
    letter-spacing: 0.06em !important;
    text-transform: uppercase !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ─── Challenge Selector (list of cards) ──────────────────────────────── */

.challenge-selector {
    padding: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.challenge-selector > .selector-header {
    flex-shrink: 0;
}

.challenge-selector > .challenge-grid {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.selector-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--lm-border, #e2e8f0);
    background: var(--lm-surface, #ffffff);
}

/* Scoped with #design-fix-container to out-specificity the global
   "#right-panel h2" rule in base/style.css, which otherwise forces
   uppercase/bold/letter-spacing onto every <h2> inside the right panel —
   this card title is meant to read as a normal headline, not a label. */
#design-fix-container .selector-header h2 {
    margin: 0 0 8px 0;
    font-size: var(--fs-lg, 18px);
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: normal;
    text-transform: none;
    color: var(--lm-text, #1e293b);
}

.selector-header p {
    margin: 0;
    font-size: var(--fs-sm, 13px);
    color: var(--lm-text-dim, #64748b);
}

.challenge-grid {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.challenge-card {
    position: relative;
    padding: 16px 16px 14px 18px;
    background: var(--lm-surface, #ffffff);
    border: 1px solid var(--lm-border, #e2e8f0);
    border-left: 3px solid var(--lm-border, #e2e8f0);
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.challenge-card.difficulty-easy         { border-left-color: var(--lm-green, #16a34a); }
.challenge-card.difficulty-intermediate { border-left-color: var(--lm-amber, #d97706); }
.challenge-card.difficulty-advanced     { border-left-color: var(--lm-red, #dc2626); }

.challenge-card:hover {
    border-color: var(--lm-accent, #3b82f6);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
    transform: translateY(-1px);
}

.challenge-card.difficulty-easy:hover         { border-left-color: var(--lm-green, #16a34a); }
.challenge-card.difficulty-intermediate:hover { border-left-color: var(--lm-amber, #d97706); }
.challenge-card.difficulty-advanced:hover     { border-left-color: var(--lm-red, #dc2626); }

.challenge-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 8px;
}

.challenge-card-title {
    font-size: var(--fs-sm, 14px);
    font-weight: 700;
    color: var(--lm-text, #1e293b);
    line-height: 1.35;
    margin: 0;
}

.challenge-difficulty {
    flex-shrink: 0;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: var(--fs-micro, 10px);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.challenge-difficulty.difficulty-easy         { background: var(--lm-green-bg, rgba(22,163,74,0.08)); color: var(--lm-green, #16a34a); }
.challenge-difficulty.difficulty-intermediate { background: var(--lm-amber-bg, rgba(217,119,6,0.08)); color: var(--lm-amber, #d97706); }
.challenge-difficulty.difficulty-advanced     { background: var(--lm-red-bg, rgba(220,38,38,0.07));   color: var(--lm-red, #dc2626); }

.challenge-card-description {
    font-size: var(--fs-xs, 12px);
    color: var(--lm-text-dim, #64748b);
    line-height: 1.5;
    margin: 0 0 12px 0;
}

.challenge-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 10px;
    border-top: 1px solid var(--lm-border, #e2e8f0);
    font-size: var(--fs-xss, 11px);
    color: var(--lm-text-dim, #64748b);
}

.challenge-points {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 700;
    color: var(--lm-amber, #d97706);
}

.challenge-status {
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--lm-green-bg, rgba(22,163,74,0.08));
    color: var(--lm-green, #16a34a);
    font-weight: 600;
}

/* ─── Challenge Active/Detail View ────────────────────────────────────── */

.design-fix-challenge {
    padding: 0;
}

.challenge-header {
    padding: 14px 20px 16px;
    border-bottom: 1px solid var(--lm-border, #e2e8f0);
    background: var(--lm-surface, #ffffff);
}

.challenge-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 10px;
    padding: 4px 0;
    background: none;
    border: none;
    font-size: var(--fs-xs, 12px);
    font-weight: 600;
    color: var(--lm-text-dim, #64748b);
    cursor: pointer;
    transition: color 0.15s;
}

.challenge-back-btn:hover {
    color: var(--lm-accent, #3b82f6);
}

.challenge-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

#design-fix-container .challenge-title h2 {
    margin: 0 !important;
    font-size: 15px !important;
    font-weight: 600 !important;
    line-height: 1.3 !important;
    letter-spacing: normal !important;
    text-transform: none !important;
    color: var(--lm-text, #1e293b) !important;
}

.difficulty-badge {
    padding: 2px 8px !important;
    border-radius: 4px !important;
    font-size: 10px !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.06em !important;
    flex-shrink: 0;
}

.difficulty-badge.difficulty-easy         { background: var(--lm-green-bg, rgba(22,163,74,0.08)); color: var(--lm-green, #16a34a); }
.difficulty-badge.difficulty-intermediate { background: var(--lm-amber-bg, rgba(217,119,6,0.08)); color: var(--lm-amber, #d97706); }
.difficulty-badge.difficulty-advanced     { background: var(--lm-red-bg, rgba(220,38,38,0.07));   color: var(--lm-red, #dc2626); }

.challenge-meta {
    display: flex;
    gap: 16px;
    font-size: 12px !important;
    color: var(--lm-text-dim, #64748b);
}

.points-display,
.progress-display,
.timer-display {
    display: flex;
    align-items: center;
    gap: 4px;
}

.icon-star,
.icon-clock {
    color: var(--lm-amber, #d97706);
}

#current-points {
    font-weight: 700;
    color: var(--lm-amber, #d97706);
    font-size: var(--fs-sm, 13px);
}

.points-animate {
    animation: pointsBounce 0.5s ease;
}

@keyframes pointsBounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* ─── Scenario ─────────────────────────────────────────────────────────── */

.challenge-scenario {
    background: var(--lm-surface-2, #f8fafc);
    border-left: 3px solid var(--lm-accent, #3b82f6);
    padding: 16px 20px;
    margin: 0;
    border-bottom: 1px solid var(--lm-border, #e2e8f0);
}

.challenge-scenario h3 {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 0 8px 0;
    font-size: 12px !important;
    font-weight: 700;
    color: var(--lm-text-dim, #64748b);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.scenario-text {
    font-size: 13px !important;
    line-height: 1.6;
    color: var(--lm-text, #1e293b);
    margin: 0 0 12px 0;
}

.scenario-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
}

.metric-item {
    padding: 8px 10px;
    background: var(--lm-surface, #ffffff);
    border: 1px solid var(--lm-border, #e2e8f0);
    border-radius: 8px;
    font-size: 12px !important;
}

.metric-label {
    color: var(--lm-text-muted, #94a3b8);
    margin-right: 4px;
}

.metric-item strong,
.metric-value {
    color: var(--lm-text, #1e293b);
    font-weight: 700;
}

.metric-value.error {
    color: var(--lm-red, #dc2626);
}

/* ─── Steps ────────────────────────────────────────────────────────────── */

.steps-section {
    padding: 4px 20px 20px;
}

.challenge-step {
    background: var(--lm-surface, #ffffff);
    border: 1px solid var(--lm-border, #e2e8f0);
    border-radius: 10px;
    padding: 16px;
    margin: 16px 0 0;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.challenge-step.active {
    border-color: var(--lm-accent, #3b82f6);
    box-shadow: 0 0 0 3px var(--lm-accent-dim, rgba(59,130,246,0.10));
}

.challenge-step.completed {
    border-color: var(--lm-green, #16a34a);
}

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

.step-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    background: var(--lm-border, #e2e8f0);
    color: var(--lm-text-dim, #64748b);
    border-radius: 50%;
    font-weight: 700;
    font-size: var(--fs-xss, 11px);
}

.challenge-step.active .step-number {
    background: var(--lm-accent, #3b82f6);
    color: #ffffff;
}

.challenge-step.completed .step-number {
    background: var(--lm-green, #16a34a);
    color: #ffffff;
}

.step-header h4 {
    margin: 0 !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    color: var(--lm-text, #1e293b) !important;
    flex: 1;
    text-transform: none !important;
    letter-spacing: normal !important;
}

.step-status {
    font-size: var(--fs-xs, 12px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.step-status.show {
    opacity: 1;
}

.status-success {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--lm-green, #16a34a);
    font-weight: 600;
}

.status-error {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--lm-red, #dc2626);
    font-weight: 600;
}

.status-info {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--lm-accent, #3b82f6);
    font-weight: 600;
    font-size: 12px !important;
}

.icon-inline {
    display: inline-flex;
    align-items: center;
    vertical-align: -2px;
    color: currentColor;
}

.icon-trophy {
    color: var(--lm-amber, #d97706);
}

.step-instruction,
.step-question {
    font-size: 13px !important;
    line-height: 1.6;
    color: var(--lm-text, #1e293b);
    margin: 0 0 12px 34px;
}

.canvas-hint {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    background: var(--lm-accent-dim, rgba(59,130,246,0.10));
    border-left: 3px solid var(--lm-accent, #3b82f6);
    padding: 10px 12px;
    margin-left: 34px;
    font-size: var(--fs-xs, 12px);
    color: var(--lm-accent, #3b82f6);
    border-radius: 6px;
}

.canvas-hint .icon-inline {
    flex-shrink: 0;
    margin-top: 2px;
}

.step-enter {
    animation: slideIn 0.35s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ─── MCQ Options ──────────────────────────────────────────────────────── */

.mcq-context {
    background: var(--lm-amber-bg, rgba(217,119,6,0.08));
    border-left: 3px solid var(--lm-amber, #d97706);
    padding: 10px 12px;
    margin: 0 0 12px 34px;
    font-size: var(--fs-xs, 12px);
    color: var(--lm-amber, #d97706);
    border-radius: 6px;
}

.mcq-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0 0 14px 34px;
}

.mcq-option {
    display: block;
    padding: 12px;
    border: 1.5px solid var(--lm-border, #e2e8f0);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
    background: var(--lm-surface, #ffffff);
}

.mcq-option:hover {
    border-color: var(--lm-accent, #3b82f6);
    background: var(--lm-accent-dim, rgba(59,130,246,0.10));
}

.mcq-option.selected {
    border-color: var(--lm-accent, #3b82f6);
    background: var(--lm-accent-dim, rgba(59,130,246,0.10));
}

.mcq-option.correct {
    border-color: var(--lm-green, #16a34a);
    background: var(--lm-green-bg, rgba(22,163,74,0.08));
}

.mcq-option.incorrect {
    border-color: var(--lm-red, #dc2626);
    background: var(--lm-red-bg, rgba(220,38,38,0.07));
}

.mcq-option input[type="radio"] {
    margin-right: 10px;
}

.option-label {
    font-weight: 600;
    font-size: var(--fs-sm, 13px);
    color: var(--lm-text, #1e293b);
}

.mcq-option input[type="radio"]:checked + .option-label {
    color: var(--lm-accent, #3b82f6);
}

.option-explanation {
    display: none;
    margin-top: 10px;
    padding: 10px;
    background: var(--lm-surface-2, #f8fafc);
    border-radius: 6px;
    font-size: var(--fs-xs, 12px);
    line-height: 1.5;
    color: var(--lm-text-dim, #64748b);
}

.mcq-option.selected .option-explanation,
.mcq-option.correct .option-explanation,
.mcq-option.incorrect .option-explanation {
    display: block;
}

/* ─── Configuration Form ───────────────────────────────────────────────── */

.config-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin: 0 0 14px 34px;
}

.config-field label {
    display: block;
    font-weight: 600;
    color: var(--lm-text, #1e293b);
    margin-bottom: 6px;
    font-size: var(--fs-xs, 12px);
}

.config-field input {
    width: 100%;
    padding: 8px 10px;
    border: 1.5px solid var(--lm-border, #e2e8f0);
    border-radius: 6px;
    font-size: var(--fs-sm, 13px);
    color: var(--lm-text, #1e293b);
    background: var(--lm-surface, #ffffff);
    transition: border-color 0.15s ease;
}

.config-field input:focus {
    outline: none;
    border-color: var(--lm-accent, #3b82f6);
}

.field-hint {
    display: block;
    margin-top: 4px;
    font-size: var(--fs-xss, 11px);
    color: var(--lm-text-muted, #94a3b8);
    font-style: italic;
}

/* ─── Buttons ──────────────────────────────────────────────────────────── */

.btn-submit-algorithm,
.btn-submit-config,
.btn-run-simulation {
    margin-left: 34px;
    padding: 9px 18px;
    background: var(--lm-accent, #3b82f6);
    color: #ffffff !important;
    border: none;
    border-radius: 8px;
    font-size: 13px !important;
    font-weight: 600 !important;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-submit-algorithm:hover,
.btn-submit-config:hover,
.btn-run-simulation:hover {
    background: #2563eb;
}

.btn-submit-algorithm:disabled,
.btn-submit-config:disabled,
.btn-run-simulation:disabled {
    background: var(--lm-border, #e2e8f0);
    color: var(--lm-text-muted, #94a3b8);
    cursor: not-allowed;
    transform: none;
}

.btn-run-simulation {
    background: var(--lm-green, #16a34a);
    margin-left: 0;
}

.btn-run-simulation:hover {
    background: #15803d;
}

.challenge-actions {
    text-align: center;
    padding: 20px;
}

.spinner {
    display: inline-block;
    width: 13px;
    height: 13px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ─── Completion Modal ─────────────────────────────────────────────────── */

.design-fix-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.design-fix-modal .modal-content {
    background: var(--lm-surface, #ffffff);
    border-radius: 14px;
    width: 90%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(2,6,23,0.22), 0 4px 16px rgba(2,6,23,0.10);
    animation: modalSlideIn 0.25s ease;
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(-16px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.design-fix-modal .modal-header {
    padding: 24px;
    text-align: center;
    border-bottom: 1px solid var(--lm-border, #e2e8f0);
}

.design-fix-modal .modal-header h2 {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 0 0 10px 0;
    font-size: var(--fs-xl, 20px);
    font-weight: 700;
    color: var(--lm-text, #1e293b);
    text-transform: none;
    letter-spacing: normal;
}

.final-points {
    font-size: var(--fs-2xl, 26px);
    font-weight: 700;
    color: var(--lm-green, #16a34a);
}

.design-fix-modal .modal-body {
    padding: 20px 24px;
}

.completion-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}

.stat-item {
    text-align: center;
}

.stat-label {
    display: block;
    font-size: var(--fs-xss, 10px);
    color: var(--lm-text-muted, #94a3b8);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 6px;
}

.stat-value {
    display: block;
    font-size: var(--fs-lg, 18px);
    font-weight: 700;
    color: var(--lm-text, #1e293b);
}

.simulation-results h3 {
    margin: 0 0 12px 0;
    font-size: var(--fs-sm, 14px);
    font-weight: 700;
    color: var(--lm-text, #1e293b);
    text-transform: none;
    letter-spacing: normal;
}

.result-item {
    padding: 10px 12px;
    margin-bottom: 8px;
    border-radius: 8px;
    font-size: var(--fs-xs, 12px);
    font-weight: 600;
}

.result-item.success {
    background: var(--lm-green-bg, rgba(22,163,74,0.08));
    color: var(--lm-green, #16a34a);
}

.result-item.fail {
    background: var(--lm-red-bg, rgba(220,38,38,0.07));
    color: var(--lm-red, #dc2626);
}

.modal-actions {
    padding: 16px 24px 24px;
    text-align: center;
}

.btn-next-challenge {
    padding: 11px 26px;
    background: var(--lm-accent, #3b82f6);
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-size: var(--fs-sm, 14px);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.btn-next-challenge:hover {
    background: #2563eb;
}

/* ─── Responsive ───────────────────────────────────────────────────────── */

@media (max-width: 768px), (max-width: 1023px) and (max-height: 500px) {
    .challenge-meta {
        flex-wrap: wrap;
        gap: 10px;
    }

    .scenario-metrics {
        grid-template-columns: 1fr;
    }

    .completion-stats {
        grid-template-columns: 1fr;
        gap: 12px;
    }
}
