:root {
    --bg: #f3efe5;
    --surface: #fffdf8;
    --surface-alt: #f7f1e4;
    --ink: #1f2933;
    --muted: #5b6670;
    --accent: #8c2f39;
    --accent-dark: #5f2027;
    --line: #dccfb7;
    --success: #1f6f50;
    --error: #9f2d2d;
    --info: #295a8a;
    --shadow: 0 20px 50px rgba(70, 46, 20, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    background:
        radial-gradient(circle at top left, rgba(140, 47, 57, 0.14), transparent 32%),
        linear-gradient(180deg, #f8f3e8 0%, var(--bg) 100%);
    color: var(--ink);
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-dark);
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 253, 248, 0.95);
    backdrop-filter: blur(8px);
}

.brand {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--ink);
}

.role-chip {
    display: inline-block;
    margin-left: 0.75rem;
    padding: 0.25rem 0.5rem;
    background: var(--surface-alt);
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    font-size: 0.85rem;
}

.nav {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.nav-account-stack {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
}

.container {
    width: min(1600px, calc(100vw - 2rem));
    margin: 0 auto;
    padding: 2rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.narrow-card {
    width: 100%;
    max-width: none;
}

.auth-shell {
    min-height: calc(100vh - 160px);
    display: grid;
    place-items: center;
}

.auth-card {
    width: min(460px, 100%);
}

.page-head,
.section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.stats-grid,
.grid-two {
    display: grid;
    gap: 1.25rem;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    margin-bottom: 1.5rem;
}

.stat-card {
    background: linear-gradient(135deg, #fffaf2 0%, #f6eee0 100%);
}

.stat-label {
    display: block;
    color: var(--muted);
}

.stat-value {
    font-size: 2rem;
}

.form-stack {
    display: grid;
    gap: 1rem;
}

.draft-banner,
.action-row,
.candidate-switcher,
.print-actions,
.print-form {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 1rem;
}

.marking-toolbar {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.75rem;
}

.draft-banner {
    min-width: 320px;
}

.candidate-switcher label {
    min-width: auto;
    max-width: none;
    font-weight: 700;
}

.candidate-switcher select {
    width: min(420px, 100%);
    flex: 0 1 420px;
}

.inline-label {
    display: inline-flex;
    align-items: center;
    gap: 0;
    font-weight: 700;
}

.inline-select {
    width: min(320px, 100%);
    flex: 0 1 320px;
}

label {
    display: grid;
    gap: 0.35rem;
    font-weight: 600;
}

input,
textarea,
button {
    font: inherit;
}

input,
textarea {
    width: 100%;
    padding: 0.8rem 0.9rem;
    border-radius: 12px;
    border: 1px solid #cdbd9f;
    background: #fffdfa;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.input-invalid {
    border-color: var(--error);
    background: rgba(159, 45, 45, 0.06);
    color: var(--error);
}

.input-help {
    margin: 0.35rem 0 0;
    font-size: 0.8rem;
    line-height: 1.2;
}

.input-help-error {
    color: var(--error);
    font-weight: 700;
}

.validation-message {
    margin: 0;
    color: var(--error);
    font-weight: 700;
}

.last-saved {
    margin: 0;
    text-align: right;
    color: var(--muted);
    font-size: 0.95rem;
}

.total-error {
    color: var(--error);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

button {
    border: 0;
    border-radius: 12px;
    padding: 0.85rem 1rem;
    background: var(--accent);
    color: white;
    cursor: pointer;
}

button:hover {
    background: var(--accent-dark);
}

.button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    padding: 0.85rem 1rem;
    background: var(--accent);
    color: white;
    cursor: pointer;
}

.button-link:hover {
    color: white;
    background: var(--accent-dark);
}

.print-action-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 260px;
    min-height: 48px;
    text-align: center;
    white-space: nowrap;
}

.marks-action-button {
    display: inline-block;
    margin-top: 0.4rem;
    padding: 0.3rem 0.6rem;
    border-radius: 10px;
    background: #b11f2a;
    color: white;
    font-weight: 700;
    font-size: 0.85rem;
    border: 0;
    cursor: pointer;
}

.marks-action-button:hover {
    background: #861721;
}

.button-secondary {
    background: #b7ab93;
    color: var(--ink);
}

.button-secondary:hover {
    background: #a5987f;
}

.button-danger {
    background: #9f2d2d;
}

.button-danger:hover {
    background: #7e2222;
}

.checkbox {
    grid-template-columns: auto 1fr;
    align-items: center;
}

.checkbox input {
    width: auto;
}

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

.table-wrap {
    overflow-x: auto;
}

th,
td {
    text-align: left;
    padding: 0.9rem 0.75rem;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

.criteria-table th,
.criteria-table td {
    min-width: 120px;
}

.criteria-table th:first-child,
.criteria-table td:first-child {
    min-width: 150px;
    position: sticky;
    left: 0;
    background: var(--surface);
}

.criteria-table input {
    min-width: 110px;
}

.total-row td {
    background: var(--surface-alt);
}

.total-cell {
    min-width: 120px;
    text-align: center;
    vertical-align: middle;
    background: var(--surface-alt);
}

.dashboard-criteria-table tbody tr:first-child td,
.dashboard-criteria-table tbody tr:nth-child(2) td {
    background: rgba(247, 241, 228, 0.6);
}

.dashboard-criteria-table th,
.dashboard-criteria-table td {
    min-width: 104px;
}

.candidate-summary-row td:first-child {
    background: var(--surface);
}

.mark-pair {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    white-space: nowrap;
    font-size: 0.84rem;
}

.mark-pair-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
}

.mark-pair-label {
    font-size: 0.64rem;
    line-height: 1.1;
    color: var(--muted);
}

.mark-pair-value,
.mark-pair-weighted {
    font-variant-numeric: tabular-nums;
}

.mark-pair-weighted {
    color: var(--muted);
}

.mark-pair-separator {
    color: var(--muted);
}

.compact-criterion-cell {
    font-size: 0.9rem;
}

.compact-criterion-title {
    display: block;
    font-size: 0.92rem;
    line-height: 1.15;
}

.compact-criterion-description {
    font-size: 0.76rem;
    line-height: 1.2;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(31, 41, 51, 0.45);
    z-index: 1000;
}

.modal-overlay[hidden] {
    display: none;
}

.modal-card {
    width: min(420px, 100%);
    padding: 1.25rem;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.modal-card h2 {
    margin: 0 0 0.5rem;
}

.modal-card p {
    margin: 0 0 1rem;
    color: var(--muted);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

th {
    color: var(--muted);
    font-size: 0.9rem;
}

.inline-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.inline-form input {
    min-width: 160px;
}

.flash-stack {
    display: grid;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.flash {
    padding: 0.85rem 1rem;
    border-radius: 12px;
    border: 1px solid transparent;
}

.flash-success {
    background: rgba(31, 111, 80, 0.1);
    color: var(--success);
    border-color: rgba(31, 111, 80, 0.2);
}

.flash-error {
    background: rgba(159, 45, 45, 0.1);
    color: var(--error);
    border-color: rgba(159, 45, 45, 0.2);
}

.flash-info {
    background: rgba(41, 90, 138, 0.1);
    color: var(--info);
    border-color: rgba(41, 90, 138, 0.2);
}

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

@media (max-width: 720px) {
    .topbar,
    .page-head,
    .section-head,
    .inline-form,
    .draft-banner,
    .action-row,
    .candidate-switcher,
    .marking-toolbar,
    .print-actions,
    .print-form {
        flex-direction: column;
        align-items: stretch;
    }

    .container {
        padding: 1rem;
        width: 100%;
    }
}
