:root {
    --brand-blue: #2b6e8a;
    --brand-green: #648f3f;
    --brand-gold: #d8ab2a;
    --brand-red: #c34b5a;
    --ink: #1f2d3d;
    --muted: #5f7185;
    --bg: #e9eff4;
    --surface: #ffffff;
    --surface-soft: #f7fafc;
    --border: #bfd0de;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Arial, sans-serif;
    color: var(--ink);
    background: linear-gradient(150deg, #e7eef4 0%, #f4f8f4 50%, #edf4f8 100%);
    min-height: 100vh;
}

.topbar {
    min-height: 62px;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
    background: linear-gradient(90deg, #234f67 0%, var(--brand-blue) 100%);
    color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.22);
}

.brand {
    flex: 1;
    min-width: 0;
    font-size: 24px;
    font-weight: 800;
    letter-spacing: 0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.session-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    background: rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    padding: 6px 10px;
}

.user-menu {
    position: relative;
}

.user-menu-toggle {
    cursor: pointer;
    user-select: none;
}

.user-menu-toggle::after {
    content: "▾";
    font-size: 11px;
}

.user-menu summary {
    list-style: none;
}

.user-menu summary::-webkit-details-marker {
    display: none;
}

.user-menu-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    width: 200px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 10px 24px rgba(28, 57, 80, 0.15);
    padding: 6px;
    z-index: 50;
}

.user-menu-item {
    width: 100%;
    display: block;
    text-decoration: none;
    color: var(--ink);
    border-radius: 8px;
    border: 0;
    background: transparent;
    padding: 8px 10px;
    text-align: left;
    font-weight: 700;
    font-size: 14px;
}

.user-menu-item:hover {
    background: #edf4f9;
}

.user-menu-btn {
    cursor: pointer;
}

.subnav {
    background: #f1f6fa;
    border-bottom: 1px solid var(--border);
    padding: 8px 12px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.subnav-link {
    text-decoration: none;
    color: var(--ink);
    border: 1px solid var(--border);
    background: #fff;
    padding: 7px 12px;
    border-radius: 10px;
    font-weight: 700;
}

.subnav-link.active {
    background: #e7f1f7;
    border-color: #7fa9c4;
    color: #1b4f6a;
}

.page-shell {
    max-width: 1480px;
    margin: 0 auto;
    padding: 14px;
}

.page-shell-full {
    max-width: none;
    margin: 0;
    padding: 8px 10px 0;
    height: calc(100dvh - 62px);
    overflow: hidden;
}

.page-title {
    margin: 0 0 8px;
    font-size: 16px;
    font-weight: 900;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 8px 18px rgba(27, 59, 82, 0.08);
}

.card-title {
    margin: 0 0 10px;
    font-size: 13px;
    font-weight: 900;
}

.btn {
    border: 1px solid var(--border);
    background: #fff;
    color: var(--ink);
    padding: 9px 14px;
    border-radius: 12px;
    font-weight: 800;
    font-size: 15px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn:hover {
    filter: brightness(0.97);
}

.btn-primary {
    background: #1e5685;
    border-color: #1e5685;
    color: #fff;
}

.btn-secondary {
    background: #e8f1f7;
    border-color: #7fa8c3;
    color: #1e4f6f;
}

.btn-danger {
    background: #f9e8ec;
    border-color: #cf8c97;
    color: #8a2f3d;
}

.btn-ghost {
    background: transparent;
    border-color: rgba(255, 255, 255, 0.42);
    color: #fff;
}

.btn-toolbar {
    padding: 6px 10px;
    border-radius: 10px;
    background: #2d3540;
    border-color: #4a5567;
    color: #dce5f0;
    font-size: 13px;
}

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

.btn.is-disabled {
    pointer-events: none;
    cursor: not-allowed;
    opacity: 0.6;
}

.flash {
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid;
    margin-bottom: 12px;
    font-weight: 600;
}

.flash ul {
    margin: 0;
    padding-left: 16px;
}

.flash.success {
    background: #eaf4e6;
    border-color: #a8c993;
    color: #3f6324;
}

.flash.error {
    background: #fcebed;
    border-color: #e4a8b2;
    color: #8c3441;
}

.metric-label {
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--muted);
    font-weight: 800;
}

.metric-value {
    margin: 4px 0 0;
    font-size: 24px;
    font-weight: 900;
}

.grid {
    display: grid;
}

.grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.progress-filter-row {
    grid-template-columns: repeat(5, minmax(170px, 1fr)) auto;
    align-items: center;
}

.progress-filter-row > input,
.progress-filter-row > select {
    min-height: 46px;
    border-radius: 12px !important;
    border: 1px solid #a9bfd2 !important;
    padding: 9px 14px !important;
    font-size: 15px;
    line-height: 1.25;
    background: #fff;
    color: #12253a;
}

.progress-filter-row > input[disabled],
.progress-filter-row > select[disabled] {
    opacity: 1;
    color: var(--ink);
    background: #fff;
}

.progress-filter-row > .row {
    align-items: center;
}

.progress-filter-row > .row .btn {
    min-height: 46px;
}

.progress-filter-row > input:focus,
.progress-filter-row > select:focus {
    outline: none;
    border-color: #6da1e5 !important;
    box-shadow: 0 0 0 4px rgba(109, 161, 229, 0.35);
}

.gap16 {
    gap: 16px;
}

.mt12 { margin-top: 12px; }
.mt16 { margin-top: 16px; }
.mt20 { margin-top: 20px; }
.mb12 { margin-bottom: 12px; }

.row {
    display: flex;
}

.row.wrap {
    flex-wrap: wrap;
}

.row.center {
    align-items: center;
}

.row.between {
    justify-content: space-between;
}

.row.gap8 {
    gap: 8px;
}

.pagination-controls {
    margin-top: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.online-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    display: inline-block;
    border: 1px solid transparent;
}

.online-dot-active {
    background: #f2c84a;
    border-color: #c49a22;
    box-shadow: 0 0 0 2px rgba(242, 200, 74, 0.25);
}

.online-dot-offline {
    background: #c7d4df;
    border-color: #9db0c1;
}

.table td.online-dot-cell,
.table th.online-dot-cell {
    text-align: center;
    vertical-align: middle;
}

.muted {
    color: var(--muted);
}

.notice {
    border: 1px solid #b8cedf;
    border-radius: 10px;
    background: #f2f8fc;
    color: #244c67;
    padding: 10px 12px;
    line-height: 1.4;
}

.link {
    font-weight: 800;
    color: #1e5f87;
}

.inline-link-btn {
    border: 0;
    padding: 0;
    background: transparent;
    color: #1e5f87;
    font: inherit;
    font-weight: 800;
    text-decoration: underline;
    cursor: pointer;
}

.modal-open {
    overflow: hidden;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(18, 33, 49, 0.55);
    display: grid;
    place-items: center;
    padding: 16px;
    z-index: 1000;
}

.modal-card {
    width: min(820px, 96vw);
    max-height: 84vh;
    overflow: auto;
    background: #fff;
    border: 1px solid #b8cedf;
    border-radius: 12px;
    padding: 14px;
}

.modal-content {
    line-height: 1.45;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    text-align: left;
    border-bottom: 1px solid #d7e2eb;
    padding: 8px;
    vertical-align: middle;
}

.table.table-center th,
.table.table-center td {
    text-align: center;
    vertical-align: middle;
}

.table th {
    text-transform: uppercase;
    color: #5c6f83;
    font-size: 15px;
    letter-spacing: 0.3px;
}

.sortable-header {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 18px;
}

.sortable-header::after {
    content: "↕";
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    color: #8ca0b3;
}

.sortable-header[data-sort-direction="asc"]::after {
    content: "↑";
    color: #2a5676;
}

.sortable-header[data-sort-direction="desc"]::after {
    content: "↓";
    color: #2a5676;
}

.table.compact th,
.table.compact td {
    padding: 6px;
}

.status {
    display: inline-flex;
    border-radius: 999px;
    padding: 4px 10px;
    font-weight: 800;
    border: 1px solid;
    text-transform: capitalize;
}

.status-not_commenced {
    background: #fbecee;
    border-color: #d99ba5;
    color: #8a2e3d;
}

.status-commenced {
    background: #fbf5e4;
    border-color: #d7ba66;
    color: #7b620f;
}

.status-completed {
    background: #ebf4e6;
    border-color: #a9c791;
    color: #3f6324;
}

.status-na {
    background: #edf2f7;
    border-color: #c9d4df;
    color: #5f6e7d;
}

.status-pending {
    background: #fbf5e4;
    border-color: #d7ba66;
    color: #7b620f;
}

.status-ready {
    background: #ebf4e6;
    border-color: #a9c791;
    color: #3f6324;
}

.status-error {
    background: #fbecee;
    border-color: #d99ba5;
    color: #8a2e3d;
}

.status-correct {
    background: #e8f0ff;
    border-color: #9bb9f8;
    color: #2454c5;
}

.status-imprecise {
    background: #fbf5e4;
    border-color: #d7ba66;
    color: #7b620f;
}

.status-incorrect {
    background: #fbecee;
    border-color: #d99ba5;
    color: #8a2e3d;
}

.center-wrap {
    min-height: calc(100vh - 120px);
    display: grid;
    place-items: center;
}

.login-card {
    width: min(460px, 92vw);
}

.stack-form {
    display: grid;
    gap: 10px;
}

.field-wrap {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.stack-form input:not([type="checkbox"]):not([type="radio"]),
.stack-form select,
.stack-form textarea,
.grid-form input:not([type="checkbox"]):not([type="radio"]),
.grid-form select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 9px 10px;
    font: inherit;
    background: #fff;
}

.is-invalid {
    border-color: #c34b5a !important;
    background: #fff8f8 !important;
}

.field-error-text {
    margin: 0;
    color: #8c3441;
    font-size: 12px;
    line-height: 1.3;
    font-weight: 600;
}

.field-span-all {
    grid-column: 1 / -1;
}

.stack-form textarea {
    resize: vertical;
}

.grid-form {
    display: grid;
    gap: 10px;
}

.grid-span-4 {
    grid-column: span 4;
}

.password-generator-row {
    grid-column: span 2;
    display: grid;
    grid-template-columns: minmax(200px, 1fr) auto auto;
    gap: 10px;
    align-items: center;
}

.checkbox-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    max-width: 100%;
    gap: 8px;
    font-weight: 600;
    white-space: normal;
}

.checkbox-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
    flex: 0 0 auto;
}

.import-errors {
    background: #fcebed;
    border: 1px solid #e4a8b2;
    border-radius: 10px;
    padding: 10px;
}

.import-errors ul {
    margin: 8px 0 0;
    padding-left: 18px;
}

.narrow {
    max-width: 780px;
}

.hidden {
    display: none !important;
}

.page-builder-card {
    width: 90%;
    max-width: 90%;
    margin-left: auto;
    margin-right: auto;
    height: calc(100dvh - 110px);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.builder-mode-group .btn.active {
    background: #1e5685;
    border-color: #1e5685;
    color: #fff;
}

.builder-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 8px;
    border: 1px solid #c7d6e2;
    border-radius: 10px;
    background: #f6fbff;
    margin-bottom: 10px;
}

.builder-surface {
    flex: 1;
    min-height: 360px;
    width: 100%;
    border: 1px solid #c7d6e2;
    border-radius: 10px;
    background: #fff;
    padding: 16px;
    overflow: auto;
    line-height: 1.5;
}

.builder-surface:focus {
    outline: 2px solid #7fa8c3;
    outline-offset: 1px;
}

.builder-code {
    width: 100%;
    min-height: 360px;
    border: 1px solid #c7d6e2;
    border-radius: 10px;
    padding: 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 13px;
    line-height: 1.45;
    resize: vertical;
    background: #fff;
}

.builder-css {
    min-height: 180px;
}

.workspace-head {
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.workspace-head-right {
    justify-content: flex-end;
}

.workspace-head h1 {
    margin: 0;
    font-size: 34px;
    font-weight: 900;
}

.timer {
    font-weight: 800;
    color: #274f67;
}

.workspace-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 297px;
    gap: 10px;
    height: 100%;
    min-height: 0;
}

.viewer-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 0;
    border-color: #2a323d;
    background: #252d38;
}

.secure-preview-panel {
    height: calc(100dvh - 130px);
}

.secure-preview-scroll {
    height: 100%;
}

.viewer-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    border-bottom: 1px solid #3b4656;
    background: #2c3541;
}

.page-indicator {
    color: #9db1c9;
    font-weight: 700;
    margin-left: 2px;
}

.viewer-main {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.thumbs {
    width: 126px;
    border-right: 1px solid #3b4656;
    padding: 8px;
    overflow-y: auto;
    overflow-x: hidden;
    background: #293241;
}

.thumbs.hidden {
    display: none;
}

.thumb-item {
    border: 1px solid #5f7ea1;
    border-radius: 8px;
    padding: 4px;
    margin-bottom: 10px;
    cursor: pointer;
    color: #ccdaec;
    text-align: center;
}

.thumb-item.active {
    background: #3f556f;
}

.thumb-item canvas {
    width: 100%;
    height: auto;
    border-radius: 4px;
    display: block;
    background: #fff;
}

.thumb-placeholder {
    width: 100%;
    height: 130px;
    border-radius: 4px;
    background: linear-gradient(180deg, #f0f4f8 0%, #dce5ef 100%);
    border: 1px solid #c7d4e2;
}

.pdf-scroll {
    flex: 1;
    min-width: 0;
    overflow: auto;
    background: radial-gradient(circle at top, #3a4556 0%, #2a323d 65%);
    padding: 10px;
}

.pdf-pages {
    min-height: 100%;
}

.pdf-page {
    margin-bottom: 12px;
}

.pdf-page canvas {
    display: block;
    margin: 0 auto;
    background: #fff;
    box-shadow: 0 2px 10px rgba(12, 18, 26, 0.4);
}

.judge-panel {
    min-height: 0;
    overflow: auto;
}

.judge-panel h2 {
    margin: 0 0 12px;
    font-size: 16px;
    font-weight: 800;
    line-height: 1.15;
}

.judge-form label {
    font-weight: 700;
    color: #4b627a;
    font-size: 13px;
}

.judge-table-wrap {
    border: 1px solid #bdd0de;
    border-radius: 14px;
    overflow: hidden;
}

.judge-panel .table.compact {
    margin: 0;
}

.judge-panel .table.compact th,
.judge-panel .table.compact td {
    padding: 6px 8px;
}

.judge-panel .table.compact th {
    background: #f3f7fa;
    font-size: 11px;
}

.judge-panel .table.compact th:nth-child(2),
.judge-panel .table.compact th:nth-child(3),
.judge-panel .table.compact td:nth-child(2),
.judge-panel .table.compact td:nth-child(3) {
    text-align: center;
}

.judge-panel .table.compact input[type="radio"] {
    width: 16px;
    height: 16px;
}

.judge-panel .table.compact td {
    font-size: 12px;
}

.judge-panel .btn {
    font-size: 13px;
    padding: 6px 10px;
    border-radius: 10px;
}

.judge-panel select {
    font-size: 13px;
    padding: 6px 8px;
}

.judge-panel .current-performance-hint {
    margin: 4px 0 0;
    font-size: 50%;
    line-height: 1.25;
}

.panel-timer {
    margin-top: 12px;
    text-align: right;
    font-size: 13px;
    font-weight: 800;
    color: #274f67;
}

.stack-table {
    table-layout: fixed;
}

.stack-table col.col-sample {
    width: 34%;
}

.stack-table col.col-status {
    width: 26%;
}

.stack-table col.col-time {
    width: 22%;
}

.stack-table col.col-action {
    width: 18%;
}

.stack-table td:nth-child(2),
.stack-table td:nth-child(3),
.stack-table td:nth-child(4) {
    vertical-align: middle;
}

.form-row {
    display: grid;
    gap: 8px;
}

.info-block {
    border-top: 1px solid #d9e2ea;
    padding-top: 12px;
}

.sample-caption {
    margin-top: 10px;
    font-size: 24px;
    font-weight: 900;
    color: #5a6a7d;
    line-height: 1.2;
}

@media (max-width: 1200px) {
    .workspace-grid {
        grid-template-columns: minmax(0, 1fr) 253px;
    }

    .workspace-head h1,
    .card-title,
    .page-title {
        font-size: 24px;
    }

    .judge-panel h2 { font-size: 14px; }
}

@media (max-width: 980px) {
    .grid-2,
    .grid-3,
    .grid-4,
    .progress-filter-row,
    .workspace-grid {
        grid-template-columns: 1fr;
    }

    .workspace-grid {
        height: auto;
    }

    .viewer-panel {
        min-height: 500px;
    }

    .grid-span-4 {
        grid-column: auto;
    }

    .password-generator-row {
        grid-column: auto;
        grid-template-columns: 1fr;
    }

    .pagination-controls {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-builder-card {
        height: auto;
    }

    .builder-surface,
    .builder-code {
        min-height: 280px;
    }
}
