: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;
}

.disabled-label {
    cursor: default;
    opacity: 0.72;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px clamp(10px, 3vw, 24px);
    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: 8px;
    flex: 1 1 auto;
    min-width: 0;
}

.topbar-title > div:nth-child(2) {
    min-width: 0;
}

.topbar-title .brand-mark {
    width: 36px;
    height: 36px;
    font-size: 0.85rem;
    flex: 0 0 auto;
}

.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.78rem;
}

.topbar-icons {
    display: flex;
    gap: 4px;
    margin-left: 4px;
    flex: 0 0 auto;
}

.icon-button,
.menu-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    min-height: 38px;
    border-radius: var(--radius);
    background: #e7ece8;
    color: var(--ink);
    cursor: pointer;
}

.icon-button svg,
.menu-button svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.menu-wrap {
    position: relative;
    flex: 0 0 auto;
}

.menu-button {
    gap: 8px;
    padding: 0 10px;
    font-weight: 800;
    background: var(--ink);
    color: #fff;
}

.menu-short {
    display: none;
}

.menu-popover {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    width: min(220px, calc(100vw - 20px));
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: var(--shadow);
}

.menu-item {
    width: 100%;
    min-height: 40px;
    padding: 9px 10px;
    border-radius: 6px;
    background: transparent;
    color: var(--ink);
    text-align: left;
    font-weight: 800;
    cursor: pointer;
}

.menu-item.active,
.menu-item:hover {
    background: #eef3ef;
}

.layout {
    padding: 14px clamp(10px, 3vw, 28px) 40px;
}

.content {
    width: min(1140px, 100%);
    margin: 0 auto;
    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;
}

.entry-panel {
    padding-bottom: 14px;
}

.entry-panel .panel-header {
    margin-block-end: 10px;
}

.entry-panel h2 {
    margin-block-end: 4px;
}

.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: minmax(330px, 1fr) minmax(430px, 1.35fr) minmax(150px, 0.55fr);
    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;
}

.evaluation-cards {
    display: none;
    gap: 10px;
}

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

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

.evaluation-card-head strong {
    font-size: 1.1rem;
}

.evaluation-card-head span,
.evaluation-counts {
    color: var(--muted);
    font-weight: 800;
    font-size: 0.85rem;
}

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

.evaluation-metric {
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #f8faf8;
}

.evaluation-metric span,
.evaluation-metric strong {
    display: block;
}

.evaluation-metric span {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
}

.evaluation-metric strong {
    margin-top: 2px;
    font-size: 1.05rem;
}

.evaluation-counts {
    margin-top: 10px;
}

.ranking-explanation p:last-child {
    margin-bottom: 0;
}

.ranking-section {
    margin-block-end: 18px;
}

.ranking-section > h3 {
    margin-left: 2px;
}

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

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

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

.ranking-card-head strong {
    min-width: 0;
    overflow-wrap: anywhere;
}

.ranking-card-head span {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
}

.ranking-list {
    display: grid;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.ranking-list li {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 8px;
    align-items: center;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #f8faf8;
}

.rank-badge {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--ink);
    color: #fff;
    font-weight: 800;
}

.ranking-list strong,
.ranking-list small {
    display: block;
    min-width: 0;
    overflow-wrap: anywhere;
}

.ranking-list small,
.ranking-empty {
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 700;
}

.ranking-empty {
    padding: 10px;
    border: 1px dashed var(--line);
    border-radius: var(--radius);
    background: #f8faf8;
}

.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-row.is-absent,
.student-admin-row.is-absent {
    background: #f3f4f2;
    color: var(--muted);
}

.student-row.is-absent {
    border-style: dashed;
}

.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::placeholder {
    color: #aeb7b0;
    opacity: 1;
}

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

.compact-input[readonly]::placeholder {
    color: #95a199;
}

.entry-mode {
    display: grid;
    grid-template-columns: auto minmax(0, 260px);
    gap: 10px;
    align-items: center;
    margin-top: 12px;
}

.compact-riege-panel {
    padding-bottom: 14px;
}

.compact-riege-columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 22px;
}

.compact-riege-list {
    margin: 0;
    padding-left: 26px;
}

.compact-riege-list li {
    min-height: 34px;
    padding: 7px 9px 7px 4px;
    border-bottom: 1px solid var(--line);
    font-weight: 800;
}

.compact-riege-list li.is-absent {
    color: var(--muted);
    text-decoration: line-through;
}

.compact-riege-list span {
    overflow-wrap: anywhere;
}

.riege-column-toggle {
    display: none;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px;
    align-items: center;
    margin-top: 12px;
}

@media (max-width: 420px) {
    .compact-riege-columns {
        grid-template-columns: 1fr;
    }

    .compact-riege-columns.force-two {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0 10px;
    }

    .compact-riege-columns.force-two .compact-riege-list {
        padding-left: 20px;
    }

    .compact-riege-columns.force-two .compact-riege-list li {
        min-height: 30px;
        padding: 5px 4px 5px 2px;
        font-size: 0.82rem;
    }

    .riege-column-toggle {
        display: grid;
    }
}

.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.ok::before {
    content: "✓ ";
}

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

.absent-note {
    min-height: 42px;
    display: flex;
    align-items: center;
    border: 1px dashed var(--line);
    border-radius: var(--radius);
    padding: 8px 10px;
    color: var(--muted);
    font-weight: 800;
    background: #f8faf8;
}

.student-row.save-pulse {
    border-color: rgba(31, 122, 90, 0.65);
    box-shadow: 0 0 0 3px rgba(31, 122, 90, 0.1);
}

.student-row.save-error {
    border-color: rgba(180, 35, 24, 0.65);
}

.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);
}

.certificate-workspace {
    display: grid;
    grid-template-columns: minmax(260px, 0.9fr) minmax(300px, 1.1fr);
    gap: 18px;
    align-items: start;
}

.certificate-list-panel,
.certificate-detail-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.certificate-list-panel {
    overflow: hidden;
}

.certificate-list-head,
.certificate-list-button {
    display: grid;
    grid-template-columns: 70px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
}

.certificate-list-head {
    padding: 10px 12px;
    background: #eef3ef;
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 800;
}

.certificate-list {
    max-height: 62vh;
    overflow-y: auto;
}

.certificate-list-button {
    width: 100%;
    min-height: 42px;
    padding: 9px 12px;
    border-top: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    text-align: left;
    cursor: pointer;
}

.certificate-list-button:hover,
.certificate-list-button.active {
    background: #eef3ef;
}

.certificate-list-button.active {
    box-shadow: inset 4px 0 0 var(--accent);
}

.certificate-list-button.is-absent {
    color: var(--muted);
    background: #f3f4f2;
}

.certificate-list-button span {
    color: var(--muted);
    font-weight: 800;
}

.certificate-list-button strong {
    min-width: 0;
    overflow-wrap: anywhere;
}

.certificate-detail-panel {
    padding: 14px;
}

.certificate-detail-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: start;
    margin-bottom: 10px;
}

.certificate-detail-header > div {
    min-width: 0;
}

.certificate-detail-header h3 {
    margin-bottom: 2px;
    overflow-wrap: anywhere;
    line-height: 1.2;
}

.certificate-detail-header p {
    margin: 0;
    font-size: 0.92rem;
}

.certificate-detail-header .button {
    min-height: 38px;
    padding: 8px 12px;
    align-self: start;
}

.performance-list {
    display: grid;
    gap: 8px;
}

.rank-lines {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.rank-lines span {
    padding: 7px 9px;
    border-radius: var(--radius);
    background: #e7f2ec;
    color: var(--accent);
    font-size: 0.86rem;
    font-weight: 800;
}

.performance-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 4px 12px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #f8faf8;
}

.performance-item span {
    color: var(--muted);
    font-weight: 800;
}

.performance-item strong {
    text-align: right;
}

.performance-item small {
    grid-column: 1 / -1;
    color: var(--muted);
    font-weight: 700;
}

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);
}

.system-check-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #f8faf8;
    color: var(--ink);
    cursor: pointer;
    text-align: left;
    font-weight: 800;
    margin-bottom: 12px;
}

.system-check-toggle strong {
    color: var(--accent);
}

.admin-filter {
    margin-bottom: 12px;
}

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

.student-admin-row {
    display: grid;
    grid-template-columns: minmax(130px, 1.1fr) minmax(130px, 1.1fr) minmax(88px, 0.6fr) minmax(76px, 0.5fr) minmax(120px, 0.8fr) minmax(105px, 0.7fr) auto;
    gap: 8px;
    align-items: end;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

.mini-field {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.mini-field span,
.check-field span {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
}

.mini-field .input {
    min-height: 38px;
    padding: 7px 9px;
}

.check-field {
    min-height: 38px;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 7px 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #f8faf8;
    font-weight: 800;
}

.check-field input {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

.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: 980px) {
    .toolbar {
        grid-template-columns: 1fr;
        gap: 8px;
    }

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

    .student-admin-row .button {
        width: 100%;
    }
}

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

    .entry-mode {
        grid-template-columns: auto minmax(0, 1fr);
        margin-top: 8px;
    }

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

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

    .student-admin-row {
        grid-template-columns: 1fr;
    }

    .certificate-workspace {
        grid-template-columns: 1fr;
    }

    .certificate-list {
        max-height: 42vh;
    }

    .evaluation-table-panel {
        display: none;
    }

    .evaluation-cards {
        display: grid;
    }

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

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

@media (max-width: 520px) {
    .panel {
        padding: 14px;
    }

    .certificate-detail-panel {
        padding: 12px;
    }

    .certificate-detail-header {
        gap: 8px;
    }

    .certificate-detail-header h3 {
        font-size: 0.98rem;
    }

    .certificate-detail-header p {
        font-size: 0.86rem;
    }

    .certificate-detail-header .button {
        min-height: 36px;
        padding: 7px 10px;
        font-size: 0.9rem;
    }

    .performance-item {
        padding: 9px 10px;
    }

    .topbar-title span {
        display: none;
    }

    .menu-current {
        display: none;
    }

    .menu-short {
        display: inline;
    }

    .segmented button {
        min-height: 32px;
        padding: 6px 10px;
    }

    .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;
    }
}
