:root {
    --bg: #f5f6f3;
    --surface: #ffffff;
    --surface-2: #eef3ef;
    --ink: #16232e;
    --muted: #64707a;
    --line: #d8ded8;
    --accent: #1f7a5a;
    --accent-2: #b68116;
    --danger: #b42318;
    --info: #2b5c8a;
    --shadow: 0 16px 40px rgba(22, 35, 46, 0.08);
    --radius: 8px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--bg);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100%;
    margin: 0;
    background: var(--bg);
    overflow-x: hidden;
}

button,
input,
select {
    font: inherit;
}

button {
    border: 0;
}

a {
    color: inherit;
}

.app {
    min-height: 100vh;
}

.loading-shell,
.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.loading-panel,
.login-panel {
    width: min(420px, 100%);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

.brand-mark {
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--ink);
    color: #fff;
    font-weight: 800;
    letter-spacing: 0;
}

h1,
h2,
h3,
p {
    margin-block-start: 0;
}

h1 {
    font-size: 1.8rem;
    margin-block-end: 8px;
}

h2 {
    font-size: 1.35rem;
    margin-block-end: 12px;
}

h3 {
    font-size: 1rem;
    margin-block-end: 10px;
}

p {
    color: var(--muted);
    line-height: 1.45;
}

.field {
    display: grid;
    gap: 6px;
    margin-block: 14px;
}

.field span,
.label {
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 700;
}

.input,
.select {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: var(--ink);
    padding: 10px 12px;
}

.input:focus,
.select:focus {
    border-color: var(--accent);
    outline: 3px solid rgba(31, 122, 90, 0.16);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 9px 14px;
    border-radius: var(--radius);
    background: var(--ink);
    color: #fff;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

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

.button.ghost {
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--line);
}

.button.danger {
    background: var(--danger);
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.58;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px clamp(14px, 3vw, 28px);
    background: rgba(245, 246, 243, 0.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}

.topbar-title {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.topbar-title .brand-mark {
    width: 42px;
    height: 42px;
    font-size: 0.85rem;
}

.topbar-title strong,
.topbar-title span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-title span {
    color: var(--muted);
    font-size: 0.85rem;
}

.topbar-actions {
    display: flex;
    gap: 8px;
}

.layout {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 22px;
    padding: 22px clamp(14px, 3vw, 28px) 40px;
}

.sidebar {
    align-self: start;
    position: sticky;
    top: 82px;
    display: grid;
    gap: 8px;
}

.nav-button {
    min-height: 44px;
    width: 100%;
    border-radius: var(--radius);
    background: transparent;
    color: var(--ink);
    text-align: left;
    padding: 10px 12px;
    cursor: pointer;
    font-weight: 800;
}

.nav-button.active {
    background: var(--ink);
    color: #fff;
}

.content {
    min-width: 0;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    margin-block-end: 18px;
}

.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-block-end: 12px;
}

.panel-header p {
    margin: 0;
}

.toolbar {
    display: grid;
    grid-template-columns: 1.2fr 1fr 1fr;
    gap: 12px;
    align-items: end;
}

.toolbar > div {
    min-width: 0;
}

.segmented {
    display: flex;
    gap: 4px;
    max-width: 100%;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #f8faf8;
    overflow-x: auto;
}

.segmented button {
    min-height: 36px;
    padding: 8px 12px;
    border-radius: 6px;
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    font-weight: 800;
    white-space: nowrap;
}

.segmented button.active {
    background: var(--accent);
    color: #fff;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.stat {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
}

.stat span {
    display: block;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}

.stat strong {
    display: block;
    margin-top: 4px;
    font-size: 1.35rem;
}

.student-list {
    display: grid;
    gap: 10px;
}

.student-row {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) minmax(260px, 1.6fr) auto;
    gap: 12px;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
}

.student-name {
    min-width: 0;
}

.student-name strong,
.student-name span {
    display: block;
    overflow-wrap: anywhere;
}

.student-name span {
    color: var(--muted);
    font-size: 0.85rem;
}

.result-inputs {
    display: grid;
    gap: 8px;
}

.attempt-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(54px, 1fr)) minmax(74px, 0.8fr);
    gap: 8px;
}

.time-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(80px, 1fr));
    gap: 8px;
}

.compact-input {
    min-height: 42px;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 8px 10px;
    text-align: center;
    background: #fff;
}

.compact-input[readonly] {
    background: #eef3ef;
    color: var(--ink);
    font-weight: 800;
}

.save-state {
    min-width: 78px;
    color: var(--muted);
    font-size: 0.8rem;
    text-align: right;
}

.save-state.ok {
    color: var(--accent);
    font-weight: 800;
}

.save-state.error {
    color: var(--danger);
    font-weight: 800;
}

.empty {
    border: 1px dashed var(--line);
    border-radius: var(--radius);
    padding: 22px;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.66);
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
    background: #fff;
}

th,
td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    white-space: nowrap;
}

th {
    background: #eef3ef;
    font-size: 0.84rem;
    color: var(--muted);
}

td.numeric,
th.numeric {
    text-align: right;
}

.notice {
    border-radius: var(--radius);
    padding: 12px;
    border: 1px solid var(--line);
    background: #fff7e3;
    color: #4f3600;
    margin-block-end: 12px;
}

.notice.danger {
    background: #fff1f0;
    color: var(--danger);
}

.csv-example {
    margin: 10px 0 14px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #f8faf8;
    color: var(--ink);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9rem;
    line-height: 1.55;
    overflow-x: auto;
}

.check-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.check {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px;
    background: #fff;
}

.check strong {
    display: block;
}

.check span {
    display: block;
    color: var(--muted);
    font-size: 0.85rem;
    overflow-wrap: anywhere;
}

.check.ok {
    border-color: rgba(31, 122, 90, 0.35);
}

.check.fail {
    border-color: rgba(180, 35, 24, 0.35);
}

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.message {
    min-height: 22px;
    margin-top: 10px;
    color: var(--muted);
    font-weight: 700;
}

.message.error {
    color: var(--danger);
}

.message.ok {
    color: var(--accent);
}

@media (max-width: 860px) {
    .topbar {
        align-items: flex-start;
    }

    .layout {
        display: block;
        padding-top: 14px;
    }

    .sidebar {
        position: static;
        display: flex;
        overflow-x: auto;
        margin-block-end: 14px;
        padding-bottom: 2px;
    }

    .nav-button {
        min-width: max-content;
        text-align: center;
    }

    .toolbar {
        grid-template-columns: 1fr;
    }

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

    .student-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .save-state {
        text-align: left;
    }
}

@media (max-width: 520px) {
    .topbar {
        display: grid;
    }

    .topbar-actions {
        width: 100%;
    }

    .topbar-actions .button {
        flex: 1;
    }

    .panel {
        padding: 14px;
    }

    .sidebar {
        gap: 4px;
    }

    .nav-button {
        padding: 8px 9px;
        font-size: 0.92rem;
    }

    .stats-grid,
    .check-list {
        grid-template-columns: 1fr;
    }

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

    .attempt-grid .compact-input[readonly] {
        grid-column: span 2;
    }
}
