/* =========================================
   SIMULATOR PAGE - Updated Design System
   ========================================= */

/* Global Layout Fixes */
html, body {
    height: 100%;
    margin: 0;
    overflow-x: hidden;
    background-color: var(--bg-base);
    font-family: var(--font-main);
}

/* Base Layout */
.layout {
    display: flex;
    gap: 1.5rem;
    height: 85vh;
    min-height: 600px;
    padding: 1.5rem;
    box-sizing: border-box;
    margin-bottom: 2rem;
    position: relative;
    z-index: 1;
}

/* Sidebar */
.sidebar {
    width: 300px;
    background: var(--bg-elevated);
    padding: 1.25rem;
    border-radius: 16px;
    border: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
    flex-shrink: 0;
}

/* Workspace (Graph area) */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

/* Controls */
.control-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.control-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0;
    text-align: center;
}

.cluster-input, .control-select {
    background: var(--bg-base);
    border: 1px solid var(--border-default);
    color: var(--text-primary);
    padding: 0.6rem;
    border-radius: 8px;
    font-size: 0.95rem;
    width: 100%;
    box-sizing: border-box;
    font-family: var(--font-main);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.cluster-input:focus, .control-select:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.k-controls {
    display: flex;
    gap: 0.5rem;
}

.k-controls input {
    text-align: center;
}

/* Buttons - scoped to simulator layout only */
.layout .btn {
    padding: 0.6rem 1.2rem;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
    color: white;
    font-size: 0.95rem;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-family: var(--font-main);
}

.layout .btn:hover:not(:disabled) { 
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}
.layout .btn:disabled { opacity: 0.5; cursor: not-allowed; }

.layout .btn-outline {
    background: transparent;
    border: 1px solid var(--border-strong);
    color: var(--text-secondary);
}
.layout .btn-outline:hover { 
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--text-muted);
    color: var(--text-primary);
}

.layout .btn-secondary {
    background: var(--bg-surface);
    border: 1px solid var(--primary-500);
    color: var(--primary-400);
}
.layout .btn-secondary:hover:not(:disabled) {
    background: var(--bg-muted);
}

.layout .btn-primary {
    background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
    color: white;
}
.layout .btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-400), var(--primary-500));
}

/* Stats Bar */
.stats-bar {
    display: flex;
    gap: 1rem;
    margin-bottom: 0;
    flex-shrink: 0;
}

.stat-chip {
    background: var(--bg-elevated);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-size: 0.85rem;
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
}

.stat-value {
    color: var(--text-primary);
    font-weight: 600;
    margin-left: 0.25rem;
}

.simulator-progress-note {
    display: inline-flex;
    align-items: center;
    align-self: flex-start;
    gap: 0.65rem;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    border: 1px solid rgba(16, 185, 129, 0.32);
    background: rgba(16, 185, 129, 0.12);
    color: var(--text-primary);
    font-size: 0.9rem;
    line-height: 1.4;
}

.simulator-progress-note i {
    width: 18px;
    height: 18px;
    color: var(--success);
    flex-shrink: 0;
}

.simulator-progress-note a {
    color: var(--success);
    font-weight: 700;
    text-decoration: none;
}

.simulator-progress-note a:hover {
    text-decoration: underline;
}

/* Graph Card */
.graph-card {
    flex: 1;
    background: var(--bg-elevated);
    border-radius: 16px;
    border: 1px solid var(--border-subtle);
    padding: 0.5rem;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

#plot {
    width: 100%;
    height: 100%;
    min-height: 0;
}

/* Step Controls (Bottom) */
.step-control {
    background: var(--bg-elevated);
    padding: 0.75rem;
    border-radius: 12px;
    border: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
    position: relative;
    z-index: 2;
}

.step-control__buttons {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.step-control__speed {
    width: 140px;
    flex-shrink: 0;
}

.step-speed-label {
    display: block;
    margin-bottom: 0.35rem;
    text-align: left;
}

.slider-container {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.step-label {
    font-family: var(--font-mono);
    font-size: 1rem;
    min-width: 2rem;
    color: var(--text-secondary);
}

input[type="range"] {
    flex: 1;
    cursor: pointer;
    height: 6px;
    margin: 0;
    accent-color: var(--primary-500);
}

/* Help Box */
.help-box {
    margin-top: auto;
    background: var(--bg-base);
    padding: 1rem;
    border-radius: 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
    border: 1px solid var(--border-subtle);
}

.help-box strong {
    color: var(--primary-400);
}

/* MODAL STYLES (Dendrogram) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(12, 10, 9, 0.85);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    padding: 2.5rem 1.5rem 1.5rem 1.5rem;
    width: 80%;
    max-width: 900px;
    position: relative;
    box-shadow: var(--shadow-elevated);
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-default);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    z-index: 10;
    transition: all 0.2s;
}
.modal-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--border-strong);
}

/* Transitions */
.fade-enter-active, .fade-leave-active {
    transition: opacity 0.3s ease;
}
.fade-enter-from, .fade-leave-to {
    opacity: 0;
}

/* V-cloak to hide raw templates */
[v-cloak] {
    display: none !important;
}

/* Custom Scrollbar for sidebar */
.sidebar::-webkit-scrollbar {
    width: 6px;
}
.sidebar::-webkit-scrollbar-track {
    background: var(--bg-base);
}
.sidebar::-webkit-scrollbar-thumb {
    background: var(--bg-muted);
    border-radius: 3px;
}

/* =========================================
   TASKS PAGE STYLES
   ========================================= */

.tasks-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 2rem;
}

.page-title {
    font-size: 2.5rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.page-subtitle {
    color: var(--text-muted);
    margin-bottom: 3rem;
    font-size: 1.1rem;
}

.algorithm-section {
    margin-bottom: 3rem;
}

.algo-title {
    color: var(--primary-400);
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--bg-elevated);
    padding-bottom: 0.5rem;
}

.task-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.task-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    padding: 1.5rem;
    text-decoration: none;
    transition: transform 0.2s, border-color 0.2s;
    display: flex;
    flex-direction: column;
}

.task-card:hover {
    transform: translateY(-4px);
    border-color: var(--primary-500);
}

.task-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.difficulty-badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.6rem;
    border-radius: 12px;
    font-weight: 600;
}
.difficulty-badge.level-1 { background: rgba(16, 185, 129, 0.2); color: var(--success); }
.difficulty-badge.level-2 { background: rgba(245, 158, 11, 0.2); color: var(--warning); }
.difficulty-badge.level-3 { background: rgba(239, 68, 68, 0.2); color: var(--danger); }

.task-order {
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.task-title {
    color: var(--text-primary);
    font-size: 1.25rem;
    margin: 0 0 1rem 0;
}

.task-meta {
    margin-top: auto;
    display: flex;
    justify-content: flex-end;
}

.algo-tag {
    background: var(--bg-base);
    color: var(--text-muted);
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    font-size: 0.8rem;
    border: 1px solid var(--border-subtle);
}

/* CHALLENGE DETAIL STYLES */
.back-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    margin-bottom: 1rem;
    transition: color 0.2s;
}
.back-link:hover {
    color: var(--primary-400);
}

.badge-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.description-content code {
    background: var(--bg-base);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.9em;
    color: var(--text-secondary);
}

.result-box {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 12px;
    display: none;
    font-family: var(--font-main);
    line-height: 1.4;
}

.result-box.success {
    display: block;
    background: rgba(16, 185, 129, 0.15);
    color: #a7f3d0;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.result-box.error {
    display: block;
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Simulator control buttons - scoped to layout */
.layout .control-group--actions {
    margin-top: 0.5rem;
}

.layout .control-group--actions .btn-outline {
    margin-bottom: 0.25rem;
    width: 100%;
}

.layout .control-group--actions .btn {
    width: 100%;
}

.layout .control-group--actions .btn-secondary {
    margin-top: 0.25rem;
    width: 100%;
}

/* Dendrogram plot container */
#dendrogram-plot {
    width: 100%;
    height: 500px;
}

/* =========================================
   MOBILE RESPONSIVE STYLES
   ========================================= */

/* Mobile Toggle Button - Hidden on desktop */
.sidebar-toggle {
    display: none;
    position: fixed;
    bottom: 15px;
    right: 15px;
    z-index: 1002;
    background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
    color: white;
    border: none;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.3);
    transition: all 0.2s ease;
    font-family: var(--font-main);
}

.sidebar-toggle:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.sidebar-toggle.active {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

/* Close button inside sidebar (hidden on desktop) */
.sidebar-close {
    display: none;
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border-default);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    line-height: 1;
    z-index: 10;
    transition: all 0.2s;
}

.sidebar-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.15);
}

/* Tablet breakpoint */
@media (max-width: 1024px) {
    .layout {
        gap: 1rem;
        padding: 1rem;
        height: 80vh;
    }

    .sidebar {
        width: 260px;
        padding: 1rem;
    }

    .control-label {
        font-size: 0.75rem;
    }

    .help-box {
        font-size: 0.8rem;
        padding: 0.75rem;
    }
}

/* Mobile breakpoint */
@media (max-width: 768px) {
    /* Show toggle button */
    .sidebar-toggle {
        display: flex;
    }

    /* Layout adjustments */
    .layout {
        flex-direction: column;
        height: auto;
        min-height: 70vh;
        padding: 0.5rem;
        padding-bottom: 60px;
        gap: 0.5rem;
    }

    /* Sidebar becomes centered modal */
    .sidebar {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%) scale(0.95);
        width: 300px;
        max-width: 90%;
        height: auto;
        max-height: 85vh;
        z-index: 1001;
        border-radius: 16px;
        opacity: 0;
        visibility: hidden;
        transition: all 0.25s ease;
        padding: 1rem;
        padding-top: 45px;
        overflow-y: auto;
        gap: 0.6rem;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    }

    .sidebar--open {
        opacity: 1;
        visibility: visible;
        transform: translate(-50%, -50%) scale(1);
    }

    /* Show close button */
    .sidebar-close {
        display: flex;
    }

    /* Workspace takes full width */
    .workspace {
        width: 100%;
        min-height: 65vh;
    }

    /* Stats bar scrollable */
    .stats-bar {
        overflow-x: auto;
        padding-bottom: 0.25rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 0.5rem;
    }

    .stats-bar::-webkit-scrollbar {
        display: none;
    }

    .stat-chip {
        flex-shrink: 0;
        font-size: 0.75rem;
        padding: 0.25rem 0.6rem;
    }

    /* Graph card */
    .graph-card {
        min-height: 55vh;
        border-radius: 8px;
    }

    /* Step controls compact */
    .step-control {
        padding: 0.4rem;
        gap: 0.4rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    .step-control__buttons {
        width: 100%;
        justify-content: center;
    }

    .step-control__speed {
        width: 100%;
    }

    .step-control .btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }

    .slider-container {
        width: 100%;
        order: 1;
        margin-top: 0.25rem;
    }

    /* Control groups */
    .control-group {
        margin-bottom: 0.5rem;
        gap: 0.35rem;
    }

    .control-label {
        font-size: 0.7rem;
    }

    .cluster-input {
        padding: 0.45rem;
        font-size: 0.85rem;
    }

    .k-controls {
        width: 100%;
    }

    .k-controls .cluster-input {
        flex: 1;
    }

    /* Buttons in sidebar */
    .layout .btn {
        padding: 0.45rem 0.8rem;
        font-size: 0.85rem;
    }

    /* Help box */
    .help-box {
        font-size: 0.75rem;
        padding: 0.6rem;
        line-height: 1.4;
    }

    /* Modal adjustments */
    .modal-content {
        width: 95%;
        padding: 2rem 1rem 1rem 1rem;
        max-height: 90vh;
        overflow-y: auto;
    }

    #dendrogram-plot {
        height: 350px;
    }
}

/* Small mobile */
@media (max-width: 480px) {
    .layout {
        padding: 0.5rem;
        padding-bottom: 70px;
    }

    .sidebar-toggle {
        bottom: 15px;
        right: 15px;
        padding: 10px 16px;
        font-size: 0.85rem;
    }

    .stat-chip {
        font-size: 0.75rem;
        padding: 0.25rem 0.6rem;
    }

    .graph-card {
        min-height: 45vh;
        border-radius: 8px;
    }

    .step-control .btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }

    .step-label {
        font-size: 0.85rem;
    }

    /* Buttons in sidebar */
    .layout .btn {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }

    .control-label {
        font-size: 0.7rem;
    }
}

/* Landscape mobile */
@media (max-width: 896px) and (orientation: landscape) {
    .layout {
        min-height: 90vh;
    }

    .graph-card {
        min-height: 60vh;
    }

    .sidebar {
        padding-top: 40px;
    }
}

/* Overlay for sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

@media (max-width: 768px) {
    .sidebar--open + .workspace::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        pointer-events: none;
    }
}
