/* --- NEO-BRUTALIST TRACE TABLE STYLES --- */

body.trace-page {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #0f172a;
    margin: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #1e293b;
}

/* --- HEADER BAR (EXACT NEO-BRUTALIST MATCH) --- */
.fc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: #0f172a;
    border-bottom: 3px solid #1e293b;
    gap: 15px;
    z-index: 200;
    flex-shrink: 0;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.3);
}

.fc-header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.fc-header-left a {
    display: flex;
    align-items: center;
}

.fc-divider {
    width: 2px;
    height: 26px;
    background: #334155;
}

.fc-back-link {
    font-size: 0.85rem;
    font-weight: 800;
    color: #94a3b8;
    text-decoration: none;
    transition: color 0.2s;
}

.fc-back-link:hover {
    color: #60a5fa;
}

#project-title-display {
    color: #fde047;
    font-weight: 900;
    font-size: 0.85rem;
    background: #1e293b;
    padding: 5px 12px;
    border-radius: 4px;
    border: 1px solid #334155;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fc-header-center {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #1e293b;
    border: 2px solid #334155;
    border-radius: 6px;
    padding: 6px 16px;
}

.fc-header-center span {
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.9rem;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 6px;
}

.fc-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.fc-toolbar-btn {
    padding: 6px 14px;
    background: #1e293b;
    border: 2px solid #334155;
    color: #e2e8f0;
    font-weight: 800;
    font-size: 0.82rem;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.fc-toolbar-btn:hover {
    background: #334155;
    color: white;
    border-color: #64748b;
    transform: translateY(-1px);
}

.fc-toolbar-btn:active {
    transform: translateY(1px);
}

.fc-toolbar-sep {
    width: 2px;
    height: 24px;
    background: #334155;
}

/* --- WORKSPACE CONTAINER --- */
.trace-container {
    display: flex;
    flex: 1;
    min-height: 0;
    padding: 16px;
    gap: 18px;
    background: #0f172a;
}

.trace-code-panel {
    flex: 0 0 24%;
    display: flex;
    flex-direction: column;
    background: white;
    min-width: 200px;
    max-width: 290px;
    border: 4px solid #1e293b;
    box-shadow: 6px 6px 0px #000000;
    border-radius: 4px;
    overflow: hidden;
    transition: flex 0.22s ease, min-width 0.22s ease, max-width 0.22s ease, background 0.2s ease;
    position: relative;
}

.collapsed-tab-content {
    display: none;
}

.trace-code-panel.collapsed {
    flex: 0 0 44px !important;
    min-width: 44px !important;
    max-width: 44px !important;
    background: #1e293b !important;
    cursor: pointer;
    user-select: none;
    border-color: #1e293b !important;
    box-shadow: 4px 4px 0px #000000 !important;
}

.trace-code-panel.collapsed:hover {
    background: #334155 !important;
}

.trace-code-panel.collapsed .panel-header,
.trace-code-panel.collapsed #monaco-code-container {
    display: none !important;
}

.trace-code-panel.collapsed .collapsed-tab-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    height: 100%;
    gap: 20px;
    color: #f8fafc;
    padding: 16px 0;
}

.collapsed-tab-icon {
    font-size: 0.85rem;
    color: #38bdf8;
    background: #0f172a;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 2px solid #334155;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.collapsed-tab-label {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    font-weight: 900;
    font-size: 0.78rem;
    letter-spacing: 2px;
    color: #cbd5e1;
    text-transform: uppercase;
    white-space: nowrap;
}

.trace-grid-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    min-width: 0;
    border: 4px solid #1e293b;
    box-shadow: 6px 6px 0px #000000;
    border-radius: 4px;
    overflow: hidden;
}

.panel-header {
    background: #1e293b;
    color: white;
    padding: 10px 14px;
    font-weight: 900;
    font-size: 0.88rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 4px solid #1e293b;
    flex-shrink: 0;
}

.trace-legend-banner {
    display: flex;
    gap: 20px;
    padding: 8px 14px;
    background: #f1f5f9;
    border-bottom: 3px solid #1e293b;
    font-size: 0.8rem;
    font-weight: 800;
    flex-wrap: wrap;
    align-items: center;
    flex-shrink: 0;
    color: #1e293b;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-box {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid black;
    border-radius: 2px;
}

.correct-box { background: #d1fae5; }
.carry-box { background: #fef3c7; }
.wrong-box { background: #fee2e2; }

.table-wrapper {
    flex: 1;
    overflow: auto;
    padding: 10px;
    background: #ffffff;
}

.brutal-table {
    width: 100%;
    border-collapse: collapse;
    border: 3px solid #1e293b;
    table-layout: auto;
}

.brutal-table th {
    background: #1e293b;
    color: #f8fafc;
    border: 2px solid #1e293b;
    padding: 8px 5px;
    text-align: center;
    font-weight: 900;
    font-family: 'Fira Code', monospace;
    font-size: 0.82rem;
    position: sticky;
    top: 0;
    z-index: 10;
    letter-spacing: 0;
    white-space: nowrap;
}

.brutal-table td {
    border: 2px solid #1e293b;
    padding: 0;
    position: relative;
    height: auto;
    min-height: 42px;
    background: white;
    vertical-align: middle;
}

.brutal-table tr:nth-child(even) td {
    background: #f8fafc;
}

.cell-input {
    width: 100%;
    min-height: 40px;
    border: none;
    outline: none;
    background: transparent;
    padding: 8px 6px;
    font-family: 'Fira Code', monospace;
    font-size: 15px;
    font-weight: 700;
    text-align: center;
    color: #1e293b;
    box-sizing: border-box;
    display: block;
}

.cell-input:focus {
    background: #eff6ff !important;
    box-shadow: inset 0 0 0 2px #2563eb;
}

/* Validation Highlights */
.cell-correct {
    background-color: #d1fae5 !important;
}

.cell-wrong {
    background-color: #fee2e2 !important;
}

.cell-carry-down-warning {
    background-color: #fef3c7 !important;
}

.cell-tooltip {
    display: block;
    width: 100%;
    font-size: 0.74rem;
    font-weight: 900;
    padding: 3px 4px;
    border-top: 1px dashed rgba(0, 0, 0, 0.25);
    text-align: center;
    line-height: 1.25;
    box-sizing: border-box;
}

.cell-wrong .cell-tooltip {
    color: #dc2626;
    background: #fff1f2;
}

.cell-carry-down-warning .cell-tooltip {
    color: #d97706;
    background: #fffbeb;
}

.print-code {
    display: none;
    font-family: 'Fira Code', monospace;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    padding: 15px;
    margin: 0;
}

/* --- PRINT RULES (CAMBRIDGE EXAM WORKSHEET LAYOUT) --- */
@media print {
    body.trace-page {
        overflow: visible !important;
        height: auto !important;
        background: white !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    .fc-header, .panel-header, .trace-legend-banner, #monaco-code-container, #trace-modal {
        display: none !important;
    }
    .trace-container {
        display: flex !important;
        flex-direction: row !important;
        padding: 0 !important;
        margin: 0 !important;
        gap: 20px !important;
        height: auto !important;
        overflow: visible !important;
    }
    .trace-code-panel {
        flex: 0 0 36% !important;
        width: 36% !important;
        border: 1px solid black !important;
        box-shadow: none !important;
        overflow: visible !important;
        height: auto !important;
    }
    .print-code {
        display: block !important;
    }
    .trace-grid-panel {
        flex: 1 !important;
        width: 64% !important;
        border: 1px solid black !important;
        box-shadow: none !important;
        overflow: visible !important;
        height: auto !important;
    }
    .table-wrapper {
        overflow: visible !important;
        padding: 0 !important;
    }
    .brutal-table, .brutal-table th, .brutal-table td {
        border: 1px solid black !important;
        background: white !important;
        color: black !important;
    }
    .brutal-table th {
        background: #f1f5f9 !important;
        color: black !important;
    }
    .cell-input {
        color: black !important;
        font-weight: normal !important;
    }
    /* Hide validation tooltips / background colors on paper worksheet so student gets clean practice grid */
    .cell-correct, .cell-wrong, .cell-carry-down-warning {
        background-color: white !important;
    }
    .cell-tooltip {
        display: none !important;
    }
}
