:root {
    color-scheme: light;
    --bg: #f7f8fb;
    --panel: #ffffff;
    --text: #18202f;
    --muted: #657086;
    --line: #dbe1ea;
    --accent: #0f766e;
    --accent-strong: #115e59;
    --danger: #b42318;
    --danger-bg: #fff0ee;
    --success: #15803d;
    --success-bg: #ecfdf3;
    --shadow: 0 16px 44px rgba(31, 41, 55, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    line-height: 1.42;
}

.app-shell {
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(247, 248, 251, 0.96)),
        var(--bg);
}

.login-panel {
    width: min(100%, 360px);
    padding: 22px;
    text-align: center;
}

.login-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 16px;
}

.login-header img {
    width: 42px;
    height: 42px;
    object-fit: contain;
}

.login-header strong,
.login-header span {
    display: block;
}

.login-header span {
    color: var(--muted);
    font-size: 0.8rem;
}

.login-panel h1 {
    margin: 0 0 16px;
    font-size: 1.18rem;
    line-height: 1.2;
}

.login-form {
    display: grid;
    gap: 12px;
    text-align: left;
}

.login-form label {
    margin: 0;
    color: var(--muted);
    font-size: 0.76rem;
    letter-spacing: 0;
}

.login-form input[type='password'] {
    width: 100%;
    min-height: 38px;
    margin-top: 6px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 7px 9px;
    font: inherit;
    color: var(--text);
}

.login-form input[type='password']:focus {
    border-color: var(--accent);
    outline: 3px solid rgba(15, 118, 110, 0.14);
}

.login-form button {
    width: 100%;
    margin-top: 2px;
}

.site-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.site-header img {
    width: 58px;
    height: 58px;
    object-fit: contain;
    flex: 0 0 auto;
}

.site-header a {
    color: inherit;
    text-decoration: none;
}

.site-header strong,
.site-header span {
    display: block;
}

.site-header strong {
    font-size: 0.98rem;
}

.site-header span {
    color: var(--muted);
    font-size: 0.84rem;
}

.mode-nav {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.mode-nav a {
    color: var(--muted);
    padding: 8px 12px;
    border-bottom: 2px solid transparent;
    font-weight: 700;
    text-decoration: none;
}

.mode-nav a:hover {
    color: var(--text);
}

.mode-nav a.active {
    border-bottom-color: var(--accent);
    color: var(--accent-strong);
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 16px;
}

.intro {
    margin-bottom: 12px;
    background: linear-gradient(135deg, #ffffff 0%, #edf7f5 100%);
}

.intro h1,
.result-header h2 {
    max-width: 760px;
    margin: 0;
    font-size: clamp(2rem, 4vw, 3.8rem);
    line-height: 1.05;
}

.lede {
    max-width: 680px;
    color: var(--muted);
    font-size: 0.92rem;
    margin: 0;
}

.format-note {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 0.86rem;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--accent-strong);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.upload-panel {
    margin-bottom: 12px;
}

form label {
    display: block;
    margin-bottom: 8px;
    font-weight: 700;
}

.upload-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
}

input[type='file'] {
    width: 100%;
    min-height: 38px;
    padding: 7px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
}

button {
    min-height: 38px;
    padding: 0 14px;
    border: 0;
    border-radius: 6px;
    background: var(--accent);
    color: white;
    font-weight: 700;
    cursor: pointer;
}

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

.clear-storage-form {
    position: fixed;
    right: 12px;
    bottom: 12px;
    z-index: 10;
}

.clear-storage-form button {
    min-height: 26px;
    border: 1px solid #f3b7b0;
    background: #fff;
    color: var(--danger);
    padding: 0 8px;
    font-size: 0.68rem;
    box-shadow: 0 8px 24px rgba(31, 41, 55, 0.12);
}

.clear-storage-form button:hover {
    background: var(--danger-bg);
}

.hint {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.notice {
    margin-bottom: 12px;
    border-radius: 8px;
    padding: 10px 12px;
    font-weight: 700;
}

.notice.error {
    border: 1px solid #f3b7b0;
    background: var(--danger-bg);
    color: var(--danger);
}

.notice.success {
    border: 1px solid #b7e4c7;
    background: var(--success-bg);
    color: var(--success);
}

.notice.warning {
    border: 1px solid #f7d27b;
    background: #fffbeb;
    color: #92400e;
}

.result-header {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: center;
    margin-bottom: 12px;
}

.download-button {
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    padding: 0 12px;
    font-weight: 700;
    text-decoration: none;
}

.download-button:hover {
    background: var(--accent-strong);
}

.download-button.secondary {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
}

.download-button.secondary:hover {
    background: #f8fafc;
}

.report-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.result-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.result-tab {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: stretch;
    border: 1px solid var(--line);
    border-radius: 6px 6px 0 0;
    background: #fff;
    overflow: hidden;
}

.result-tab.active {
    border-color: var(--accent);
    background: var(--accent);
}

.result-tab-button {
    min-height: 34px;
    max-width: 260px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--muted);
    padding: 0 10px 0 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.result-tab-button.active {
    color: #fff;
}

.result-tab-button:hover {
    background: transparent;
    color: var(--text);
}

.result-tab.active .result-tab-button:hover {
    color: #fff;
}

.result-tab-close {
    width: 28px;
    min-height: 34px;
    padding: 0;
    border: 0;
    border-left: 1px solid var(--line);
    border-radius: 0;
    background: transparent;
    color: var(--muted);
    font-size: 0.95rem;
    line-height: 1;
}

.result-tab-close:hover {
    background: #f1f5f9;
    color: var(--danger);
}

.result-tab.active .result-tab-close {
    border-left-color: rgba(255, 255, 255, 0.28);
    color: #fff;
}

.result-tab.active .result-tab-close:hover {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
}

.result-tab-panel {
    display: none;
}

.result-tab-panel.active {
    display: block;
}

.status {
    display: inline-flex;
    min-width: 80px;
    justify-content: center;
    border-radius: 999px;
    padding: 6px 10px;
    font-weight: 800;
}

.status.pass {
    background: var(--success-bg);
    color: var(--success);
}

.status.fail {
    background: var(--danger-bg);
    color: var(--danger);
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}

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

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

.metric strong {
    display: block;
    margin-top: 4px;
    font-size: 1.45rem;
    line-height: 1;
}

.metric.good strong {
    color: var(--success);
}

.metric.bad strong {
    color: var(--danger);
}

.metric.warn strong {
    color: #b45309;
}

.grid {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
    gap: 18px;
    margin-bottom: 18px;
}

h2 {
    margin: 0 0 10px;
    font-size: 1rem;
}

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

.rule-item {
    display: grid;
    grid-template-columns: 14px 1fr;
    gap: 8px;
    align-items: start;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.rule-item small {
    display: block;
    color: var(--muted);
}

.rule-item.warning {
    background: #fffbeb;
}

.dot {
    width: 12px;
    height: 12px;
    margin-top: 6px;
    border-radius: 50%;
}

.dot.pass {
    background: var(--success);
}

.dot.fail {
    background: var(--danger);
}

.dot.warn {
    background: #d97706;
}

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

.credit-map,
.grace-summary {
    margin-bottom: 12px;
}

.missing-credit-panel {
    margin-bottom: 12px;
}

.credit-entry-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 14px;
}

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

.missing-credit-file {
    margin-top: 12px;
    border-top: 1px solid var(--line);
    padding-top: 12px;
}

.credit-input-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 88px;
    gap: 10px;
    align-items: center;
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
    padding: 9px;
}

.credit-input-row strong,
.credit-input-row small {
    display: block;
}

.credit-input-row small {
    color: var(--muted);
    font-weight: 400;
}

.credit-input-row input {
    width: 100%;
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 6px 8px;
}

.credit-entry-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

.grace-summary p {
    margin: 5px 0 0;
    color: var(--muted);
}

.grace-summary strong {
    color: var(--text);
}

.credit-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.credit-list span {
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f8fafc;
    padding: 5px 8px;
    color: var(--muted);
}

.credit-list strong {
    color: var(--text);
}

.student-card {
    box-shadow: none;
}

.student-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: start;
}

.student-header h2 {
    margin-bottom: 2px;
}

.student-header p {
    margin: 0 0 8px;
    color: var(--muted);
}

.student-metrics {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 6px;
    margin: 10px 0;
}

.student-metrics.provisional-metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    max-width: 520px;
}

.student-metrics span {
    position: relative;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 7px;
    color: var(--muted);
    font-size: 0.76rem;
}

.student-metrics span.verified {
    padding-right: 28px;
}

.metric-check {
    position: absolute;
    top: 6px;
    right: 7px;
    display: inline-flex;
    width: 15px;
    height: 15px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--success-bg);
    color: var(--success);
    font-size: 0.68rem;
    font-weight: 800;
    line-height: 1;
}

.student-metrics strong {
    display: block;
    color: var(--text);
    font-size: 0.94rem;
}

.grace-line {
    margin: 8px 0;
    border: 1px solid #f7d27b;
    border-radius: 6px;
    background: #fffbeb;
    color: #92400e;
    padding: 7px 9px;
    font-size: 0.82rem;
}

details {
    margin-top: 8px;
}

summary {
    cursor: pointer;
    color: var(--accent-strong);
    font-weight: 700;
}

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

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

th {
    width: 42%;
    color: var(--muted);
    font-weight: 700;
}

pre {
    max-height: 360px;
    overflow: auto;
    margin: 0;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #101828;
    color: #eef4ff;
    white-space: pre-wrap;
}

code {
    border-radius: 4px;
    background: #eef2f7;
    padding: 2px 5px;
}

.app-footer {
    margin: 18px 0 6px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
    text-align: right;
}

.app-footer a,
.table-action {
    color: var(--accent-strong);
    font-weight: 700;
    text-decoration: none;
}

.app-footer a:hover,
.table-action:hover {
    text-decoration: underline;
}

.credit-filter-panel,
.credit-edit-panel,
.credit-database-panel,
.credit-import-panel,
.import-stats-panel {
    margin-bottom: 12px;
}

.credit-import-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: end;
}

.credit-import-form label {
    display: grid;
    gap: 6px;
    margin: 0;
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 700;
}

.credit-import-form input[type='file'] {
    min-height: 38px;
}

.credit-import-form .hint {
    grid-column: 1 / -1;
}

.import-summary-grid {
    margin-top: 10px;
}

.credit-filter-form,
.credit-edit-form {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    gap: 12px;
    align-items: end;
    width: 100%;
}

.credit-filter-form label,
.credit-edit-form label {
    display: grid;
    gap: 5px;
    margin: 0;
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 700;
}

.credit-filter-form > label,
.credit-edit-form > label {
    min-width: 0;
}

.credit-filter-form input,
.credit-edit-form input {
    display: block;
    width: 100%;
    max-width: none;
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 6px 8px;
    background: #fff;
    color: var(--text);
    font: inherit;
}

.credit-filter-form .credit-entry-actions,
.credit-edit-form .credit-entry-actions {
    grid-column: 1 / -1;
    gap: 8px;
}

.credit-database-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-bottom: 10px;
}

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

.credit-database-table {
    min-width: 860px;
    table-layout: fixed;
}

.credit-import-table {
    min-width: 980px;
    table-layout: fixed;
}

.credit-database-table th,
.credit-database-table td,
.credit-import-table th,
.credit-import-table td {
    width: auto;
    padding: 9px 10px;
}

.credit-database-table th:nth-child(1),
.credit-database-table td:nth-child(1) {
    width: 110px;
}

.credit-database-table th:nth-child(2),
.credit-database-table td:nth-child(2) {
    width: 340px;
}

.credit-database-table th:nth-child(3),
.credit-database-table td:nth-child(3) {
    width: 90px;
}

.credit-database-table th:nth-child(4),
.credit-database-table td:nth-child(4) {
    width: 150px;
}

.credit-database-table th:nth-child(5),
.credit-database-table td:nth-child(5) {
    width: 150px;
}

.credit-database-table th:nth-child(6),
.credit-database-table td:nth-child(6) {
    width: 80px;
}

.credit-database-table td {
    overflow-wrap: anywhere;
}

.credit-database-table tbody tr:hover {
    background: #f8fafc;
}

.credit-import-table th:nth-child(1),
.credit-import-table td:nth-child(1) {
    width: 240px;
}

.credit-import-table th:nth-child(2),
.credit-import-table td:nth-child(2) {
    width: 100px;
}

.credit-import-table th:nth-child(3),
.credit-import-table td:nth-child(3),
.credit-import-table th:nth-child(4),
.credit-import-table td:nth-child(4),
.credit-import-table th:nth-child(5),
.credit-import-table td:nth-child(5),
.credit-import-table th:nth-child(6),
.credit-import-table td:nth-child(6) {
    width: 90px;
}

.credit-import-table th:nth-child(7),
.credit-import-table td:nth-child(7) {
    width: 100px;
}

.credit-import-table td {
    overflow-wrap: anywhere;
}

@media (max-width: 760px) {
    .app-shell {
        width: min(100% - 20px, 1120px);
        padding: 16px 0;
    }

    .site-header img {
        width: 48px;
        height: 48px;
    }

    .panel {
        padding: 14px;
    }

    .upload-row,
    .grid,
    .summary-grid,
    .student-metrics,
    .result-header,
    .credit-entry-header,
    .missing-credit-grid,
    .credit-import-form,
    .credit-filter-form,
    .credit-edit-form,
    .credit-database-header,
    .report-actions {
        grid-template-columns: 1fr;
        display: grid;
    }

    .student-header {
        display: grid;
    }

    button {
        width: 100%;
    }

    .result-tab-button {
        width: auto;
    }

    .result-tab-close {
        width: 28px;
        flex: 0 0 28px;
    }
}
