/* Layout */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background-color: #f5f7fb;
    color: #1f2933;
}

.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 260px;
    height: 100vh;
    padding: 24px 18px;
    padding-top: 70px; /* Space for hamburger button */
    border-right: 1px solid #d0d7e2;
    background: #f8fafc;
    overflow-y: auto;
    overflow-x: hidden; /* Prevent horizontal scroll in sidebar */
    transition: transform 0.3s ease;
    z-index: 999;
}

.sidebar.collapsed {
    transform: translateX(-260px);
}

/* Hamburger toggle button - fixed position, always visible */
.sidebar-toggle {
    position: fixed;
    top: 16px;
    left: 16px;
    width: 40px;
    height: 40px;
    background: #0b4f71;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    padding: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transition: background 0.2s ease;
    z-index: 1001;
}

.sidebar-toggle:hover {
    background: #094561;
}

.sidebar-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: white;
    border-radius: 2px;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Hamburger animation when sidebar collapsed */
.sidebar.collapsed ~ .sidebar-toggle span:nth-child(1),
.sidebar-toggle.collapsed span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.sidebar.collapsed ~ .sidebar-toggle span:nth-child(2),
.sidebar-toggle.collapsed span:nth-child(2) {
    opacity: 0;
}

.sidebar.collapsed ~ .sidebar-toggle span:nth-child(3),
.sidebar-toggle.collapsed span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.app-title {
    margin: 0 0 16px 4px;
    font-size: 18px;
    font-weight: 600;
    color: #102a43;
    text-align: right;
}

.steps-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.step-item {
    text-align: left;
    border-radius: 999px;
    padding: 10px 16px;
    border: none;
    background: transparent;
    font-size: 14px;
    cursor: pointer;
    color: #52606d;
    transition: background 0.15s ease;
}

.step-item:not(:disabled):hover {
    background: #e8ecf1;
}

.step-item.active {
    background: #0b4f71;
    color: #ffffff;
    font-weight: 600;
    box-shadow: 0 0 0 1px #0b4f71;
}

.step-item:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Step content switching */
.step-content {
    display: none;
}

.step-content.active {
    display: block;
}

/* Main panel */
.main-panel {
    margin-left: 260px;
    flex: 1;
    padding: 24px 32px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    max-width: calc(100vw - 260px - 64px); /* viewport - sidebar - padding */
    overflow-x: hidden;
    transition: margin-left 0.3s ease, max-width 0.3s ease;
}

.sidebar.collapsed ~ .main-panel {
    margin-left: 0;
    max-width: calc(100vw - 64px); /* viewport - padding only */
}

.main-header h2 {
    margin: 0;
    font-size: 22px;
    color: #102a43;
}

.step-subtitle {
    margin: 4px 0 0;
    font-size: 14px;
    color: #6b7b8f;
}

/* Uploader */
.uploader-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 100%;
    overflow-x: auto;
}

.drop-zone {
    border: 2px dashed #0b4f71;
    border-radius: 8px;
    background: #ffffff;
    padding: 32px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.drop-zone:hover {
    background: #f0f7ff;
    box-shadow: 0 0 0 1px #cfe3ff;
}

.drop-zone.drag-over {
    background: #e1efff;
    border-color: #083b66;
    box-shadow: 0 0 0 2px #a5c4ff;
}

#file-input {
    display: none;
}

.drop-zone-content {
    text-align: center;
}

.drop-main-text {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #102a43;
}

.drop-sub-text {
    margin: 4px 0 0;
    font-size: 13px;
    color: #6b7b8f;
}

/* Helper row */
.helper-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.secondary-btn {
    border-radius: 999px;
    border: 1px solid #b8c4d6;
    padding: 6px 14px;
    font-size: 13px;
    background: #ffffff;
    cursor: pointer;
    color: #102a43;
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.secondary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.secondary-btn:not(:disabled):hover {
    background: #f0f4ff;
    border-color: #94a3bd;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}

.primary-btn {
    border-radius: 999px;
    border: none;
    padding: 6px 14px;
    font-size: 13px;
    background: #0b4f71;
    color: #ffffff;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.15s ease, box-shadow 0.15s ease;
}

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

.primary-btn:not(:disabled):hover {
    background: #083b66;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}

.file-label {
    font-size: 13px;
    color: #52606d;
}

.file-label.no-file {
    color: #9fb3c8;
}

/* Instructions */
.instructions {
    margin-top: 4px;
    padding: 12px 14px;
    border-radius: 8px;
    background: #f8fafc;
    border: 1px solid #dde7f3;
}

.instructions h3 {
    margin: 0 0 6px;
    font-size: 14px;
    font-weight: 600;
    color: #102a43;
}

.instructions p {
    margin: 4px 0;
    font-size: 13px;
    color: #52606d;
}

.mono {
    font-family: "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 12px;
}

/* Status bar */
.status-bar {
    min-height: 24px;
    font-size: 13px;
}

.status-bar.info {
    color: #52606d;
}

.status-bar.success {
    color: #03543f;
}

.status-bar.error {
    color: #9b1c1c;
}

.status-bar .badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 1px 6px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    margin-right: 6px;
}

.badge.ok {
    background: #def7ec;
    color: #03543f;
}

.badge.fail {
    background: #fde8e8;
    color: #9b1c1c;
}

/* Preview */
.preview-section {
    margin-top: 8px;
    border-radius: 8px;
    border: 1px solid #d0d7e2;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 280px);
}

.preview-header {
    padding: 10px 14px;
    border-bottom: 1px solid #e1e7f0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.preview-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #102a43;
}

.preview-meta {
    margin: 0;
    font-size: 12px;
    color: #6b7b8f;
}

.preview-container {
    overflow: auto;
    padding: 0;
}

/* Table */
.normalized-table {
    border-collapse: collapse;
    font-size: 12px;
    min-width: 100%;
    background: #ffffff;
}

.normalized-table th,
.normalized-table td {
    border: 1px solid #e4e7eb;
    padding: 3px 6px;
    white-space: nowrap;
}

.normalized-table th {
    position: sticky;
    top: 0;
    background: #f4f7fb;
    z-index: 1;
    font-weight: 600;
}

/* Students Grouping */
.students-container {
    margin: 16px 0;
    overflow-x: auto;
}

.students-table {
    border-collapse: collapse;
    font-size: 13px;
    background: #ffffff;
    width: 100%;
}

.students-table th,
.students-table td {
    border: 1px solid #d0d7e2;
    padding: 12px;
    text-align: left;
    vertical-align: top;
}

.students-table th {
    background: #f4f7fb;
    font-weight: 600;
    color: #102a43;
}

.students-table td.class-name {
    background: #f8fafc;
    font-weight: 600;
    white-space: nowrap;
}

.ability-checkboxes {
    display: flex;
    gap: 16px;
}

.ability-checkboxes label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    cursor: pointer;
}

.ability-checkboxes input[type="checkbox"] {
    cursor: pointer;
}

.student-checkboxes {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 300px;
    overflow-y: auto;
}

.student-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
    padding: 4px 0;
}

.student-checkbox-label:hover {
    background: #f0f4ff;
}

.student-checkbox-label input[type="checkbox"] {
    cursor: pointer;
    flex-shrink: 0;
}

/* Teacher Matrix */
.teacher-matrix-container {
    overflow-x: auto;
    margin: 16px 0;
}

.teacher-matrix {
    border-collapse: collapse;
    font-size: 13px;
    background: #ffffff;
    width: auto;
}

.teacher-matrix th,
.teacher-matrix td {
    border: 1px solid #d0d7e2;
    padding: 8px 12px;
    text-align: center;
}

.teacher-matrix th {
    background: #f4f7fb;
    font-weight: 600;
    color: #102a43;
}

.teacher-matrix td.class-name {
    background: #f8fafc;
    font-weight: 600;
    text-align: left;
}

.teacher-matrix td.disabled-cell {
    background: #e8ecf1;
}

.teacher-matrix input[type="text"] {
    width: 100px;
    padding: 4px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    font-size: 13px;
}

.teacher-matrix input[type="text"]:focus {
    outline: none;
    border-color: #0b4f71;
    box-shadow: 0 0 0 2px rgba(11, 79, 113, 0.1);
}

/* Sidebar footer */
.sidebar-footer {
    padding: 20px 0 0 0;
    margin-top: 20px;
    border-top: 1px solid #d0d7e2;
}

/* Back link */
.back-link {
    display: inline-block;
    color: #0b4f71;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
}

.back-link:hover {
    color: #083b66;
    text-decoration: underline;
}

/* Matching Results */
.matching-section {
    margin-top: 16px;
    border-radius: 8px;
    border: 1px solid #d0d7e2;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 480px);
}

.match-group {
    padding: 0 14px 12px;
}

.match-item {
    padding: 8px 12px;
    margin: 4px 0;
    background: #f8fafc;
    border-radius: 6px;
    border: 1px solid #e1e7f0;
    font-size: 13px;
}

.match-group.conflict .match-item {
    background: #fef5f5;
    border-color: #f5c2c7;
}

.match-group.unmatched .match-item {
    background: #fef5f5;
    border-color: #f5c2c7;
}

.match-group.matched .match-item {
    background: #f0fdf4;
    border-color: #bbf7d0;
}

.status-details {
    margin: 8px 0 0;
    padding-left: 20px;
    font-size: 12px;
}

.status-details li {
    margin: 2px 0;
}

/* Responsive */
@media (max-width: 900px) {
    .sidebar {
        display: none;
    }

    .main-panel {
        padding: 16px;
    }

    .preview-section {
        max-height: none;
    }

    .matching-section {
        max-height: none;
    }
}

/* Filter Controls for Item 3 */
.filter-controls {
    background: #ffffff;
    border: 1px solid #d0d7e2;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 24px;
}

.filter-group {
    margin-bottom: 20px;
}

.filter-group:last-child {
    margin-bottom: 0;
}

.filter-group h3 {
    margin: 0 0 10px 0;
    font-size: 14px;
    font-weight: 600;
    color: #102a43;
}

.filter-options {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.filter-options label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
    padding: 4px 0;
}

.filter-options input[type="radio"],
.filter-options input[type="checkbox"] {
    cursor: pointer;
}

/* Results Display */
.results-container {
    background: #ffffff;
    border: 1px solid #d0d7e2;
    border-radius: 8px;
    padding: 20px;
    min-height: 400px;
    overflow-x: auto;
    overflow-y: visible;
}

.subject-analysis-table {
    border-collapse: collapse;
    font-size: 13px;
    width: 100%;
    margin: 20px 0;
}

.subject-analysis-table th,
.subject-analysis-table td {
    border: 1px solid #d0d7e2;
    padding: 8px 12px;
    text-align: center;
}

.subject-analysis-table th {
    background: #f4f7fb;
    font-weight: 600;
    color: #102a43;
    position: sticky;
    top: 0;
}

.subject-analysis-table td.class-name {
    background: #f8fafc;
    font-weight: 600;
    text-align: left;
}

.subject-analysis-table td.al-cell {
    font-family: 'Courier New', monospace;
}

/* Table and Histogram Layout */
.table-with-histogram {
    display: flex;
    flex-direction: column; /* Changed to column for vertical stacking */
    gap: 30px;
    margin-bottom: 40px;
    align-items: stretch; /* Stretch to full width */
}

/* Below 1200px, stack vertically */
@media (max-width: 1200px) {
    .table-with-histogram {
        flex-direction: column;
    }
    
    .table-section {
        width: 100% !important;
    }
    
    .histogram-section {
        width: 100% !important;
    }
}

.table-section {
    width: 100%; /* Full width */
    min-width: 0; /* Allow flex item to shrink */
}

.table-section h3 {
    margin: 0 0 16px 0;
    color: #102a43;
    font-size: 18px;
    font-weight: 600;
}

/* Histogram Styles */
.histogram-section {
    width: 100%; /* Full width */
    min-width: 0; /* Allow shrinking */
    padding: 20px; /* Restored to 20px since we have full width now */
    background: #f8fafc;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box; /* Include padding in width calculation */
}

.histogram-section h4 {
    margin: 0 0 16px 0;
    color: #102a43;
    font-size: 14px;
    font-weight: 600;
}

.histogram {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    flex: 1;
    gap: 8px; /* Restored to 8px since we have more space */
    padding: 10px 0;
    min-height: 240px;
    width: 100%; /* Ensure it uses container width */
}

.histogram-bar-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1; /* Keep flex: 1 for even distribution */
    max-width: 80px; /* Restored to 80px since we have more space */
    min-width: 40px; /* Minimum width */
}

.histogram-bar {
    width: 100%;
    background: linear-gradient(to top, #3b82f6, #60a5fa);
    border-radius: 4px 4px 0 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 4px;
    min-height: 20px;
    transition: all 0.3s ease;
    position: relative;
}

.histogram-bar:hover {
    background: linear-gradient(to top, #2563eb, #3b82f6);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.histogram-bar .bar-value {
    color: white;
    font-size: 12px;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.histogram-label {
    margin-top: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #334155;
}

/* Responsive styles for sidebar collapse */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-260px);
    }
    
    .sidebar.collapsed {
        transform: translateX(-260px);
    }
    
    .main-panel {
        margin-left: 0;
        max-width: calc(100vw - 64px);
    }
    
    .sidebar.collapsed ~ .main-panel {
        margin-left: 0;
        max-width: calc(100vw - 64px);
    }
}

@media (max-width: 768px) {
    .main-panel {
        padding: 16px;
        max-width: calc(100vw - 32px);
    }
    
    .sidebar.collapsed ~ .main-panel {
        max-width: calc(100vw - 32px);
    }
    
    .sidebar-toggle {
        top: 12px;
        left: 12px;
        width: 36px;
        height: 36px;
    }
    
    .sidebar-toggle span {
        width: 20px;
    }
    
    .sidebar {
        padding-top: 64px; /* Adjusted for smaller button */
    }
}
