:root {
  color-scheme: light;
  --page-bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --text: #17202a;
  --muted: #6d7784;
  --border: #e2e8f0;
  --header: #14213d;
  --header-border: #7c8ca8;
  --control: #eef3fb;
  --accent: #2f6fed;
  --link: #145dcc;
  --shadow: 0 8px 24px #17202a12;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page-bg: #0b1220;
  --surface: #111b2e;
  --surface-muted: #16243b;
  --text: #e6edf3;
  --muted: #9aabc0;
  --border: #2b3b55;
  --header: #0d1729;
  --header-border: #7087aa;
  --control: #1a2a43;
  --accent: #78a7ff;
  --link: #9cc0ff;
  --shadow: 0 10px 28px #0006;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--page-bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  transition: background-color .18s ease, color .18s ease;
}

button, input, select, textarea {
  font: inherit;
  font-size: 14px;
}

button, input, select, textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

button {
  padding: 8px 11px;
  background: var(--control);
  cursor: pointer;
}

button:hover { filter: brightness(.98); }
button:disabled { cursor: wait; opacity: .65; }

a, .link-button { color: var(--link); }
a { text-underline-offset: 2px; }
.muted { color: var(--muted); }

.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  width: 100%;
  padding: 14px 28px;
  background: var(--header);
  color: #fff;
}

.app-brand {
  margin-right: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 21px;
  font-weight: 750;
  letter-spacing: -.01em;
}

.app-brand:hover { filter: none; opacity: .86; }

.app-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.app-nav button, .header-tools button {
  min-height: 36px;
  padding: 8px 11px;
  border-color: var(--header-border);
  background: transparent;
  color: #fff;
  white-space: nowrap;
}

.app-nav button:hover, .header-tools button:hover { background: #ffffff18; filter: none; }
.header-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 4px;
  padding-left: 12px;
  border-left: 1px solid var(--header-border);
}
 .theme-control {
  display: flex;
  align-items: center;
  padding: 2px;
  border: 1px solid #ffffff2e;
  border-radius: 10px;
  background: #ffffff0d;
}
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  min-width: 34px;
  min-height: 32px;
  padding: 6px 0 !important;
  border: 0 !important;
  border-radius: 8px !important;
  background: transparent !important;
  font-size: 13px;
  font-weight: 650;
}
.theme-toggle-icon {
  font-size: 15px;
  line-height: 1;
}
.auth-actions { display: flex; align-items: center; gap: 8px; }
button[hidden] { display: none; }

.page-shell {
  max-width: 1400px;
  margin: 22px auto;
  padding: 0 20px 32px;
}

.login-page { max-width: 560px; margin-top: 9vh; }
.settings-page { max-width: 850px; }
.sync-page { max-width: 850px; }
.logs-page { max-width: 1250px; }
.matches-page { max-width: 1000px; }
.pending-page { max-width: 900px; }
.changelog-page { max-width: 900px; }

.page-heading { margin: 12px 0 18px; }
.page-heading h1, .card h1 { margin: 4px 0 8px; font-size: 30px; letter-spacing: -.025em; }
.page-heading p { margin: 0; }
.eyebrow { color: var(--accent); font-size: 12px; font-weight: 750; letter-spacing: .09em; text-transform: uppercase; }

.toolbar, .card, .table-card {
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.toolbar { display: grid; grid-template-columns: minmax(240px, 520px) auto auto auto auto; align-items: center; justify-content: center; gap: 12px; padding: 14px 16px; }
.discrepancies-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; padding: 14px 16px 0; }
.discrepancies-heading h2 { margin: 0; font-size: 18px; }
.discrepancy-group-filter { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.discrepancy-group-filter select { min-width: 150px; }
.discrepancies-table { min-width: 760px; }
.discrepancies-table th:first-child { min-width: 190px; }
.discrepancies-table th:nth-child(3) { min-width: 200px; }
.discrepancies-table td:nth-child(4), .discrepancies-table td:nth-child(5) { font-weight: 650; white-space: nowrap; }
.discrepancies-table td:last-child { font-variant-numeric: tabular-nums; white-space: nowrap; }
.search-wrap { min-width: 0; width: 100%; }
.search-wrap input, .status-filter { display: block; width: 100%; height: 40px; min-height: 40px; margin: 0; }
.checkbox-label { display: flex; align-items: center; gap: 7px; height: 40px; white-space: nowrap; }
.checkbox-label input { width: auto; margin: 0; }
.status-filter { min-width: 145px; }
.task-count { display: inline-flex; align-items: center; height: 40px; white-space: nowrap; }

input, select, textarea { padding: 9px 10px; outline: none; }
input:focus, select:focus, textarea:focus, button:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px #2f6fed2a; }
.details { white-space: pre-wrap; }
.student-card { padding: 16px; }
.student-card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.student-card-header h2 { margin: 0; font-size: 18px; }

.table-card { overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); color: var(--text); }
th, td { padding: 11px 9px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: var(--surface-muted); font-size: 13px; white-space: nowrap; }
tbody tr:hover { background: var(--surface-muted); }
.tasks-table { min-width: 960px; table-layout: fixed; }
.tasks-table th, .tasks-table td { text-align: center; vertical-align: middle; overflow-wrap: anywhere; }
.tasks-table th { white-space: normal; }
.tasks-table th:nth-child(1) { width: 17%; }
.tasks-table th:nth-child(2) { width: 8%; }
.tasks-table th:nth-child(3) { width: 19%; }
.tasks-table th:nth-child(4) { width: 10%; }
.tasks-table th:nth-child(5) { width: 9%; }
.tasks-table th:nth-child(6) { width: 8%; }
.tasks-table th:nth-child(7) { width: 10%; }
.tasks-table th:nth-child(8) { width: 19%; }
.tasks-table .status { white-space: normal; }
.link-button { padding: 0; border: 0; background: transparent; text-align: left; }
.link-button:hover { filter: none; text-decoration: underline; }
.student-name { font-weight: 600; }
.status { font-weight: 650; white-space: nowrap; }
.review { display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; }
.review input { min-width: 180px; }
.review button { max-width: 100%; white-space: normal; }
.submission-list summary { color: var(--link); cursor: pointer; }
.submission-list div { display: grid; gap: 4px; margin-top: 7px; }
.task-row { cursor: pointer; }
.task-row:focus-visible td { outline: 2px solid var(--accent); outline-offset: -2px; }
.task-row .review { cursor: default; }
.attempt-count { font-variant-numeric: tabular-nums; font-weight: 650; text-align: center; }

.primary { border-color: transparent; background: var(--accent); color: #fff; }
.primary:hover { filter: brightness(1.06); }

.auth-card, .narrow-card { padding: 24px; }
.auth-card h1 { font-size: 30px; }
.auth-card p { margin: 0 0 22px; }
form label { display: grid; gap: 7px; margin: 16px 0; }
form input { width: 100%; }
.auth-card .primary { width: 100%; margin-top: 8px; }
.auth-card .login-link { display: flex; align-items: center; justify-content: center; min-height: 40px; border-radius: 8px; font-weight: 650; text-decoration: none; }

.task-error-area:not([hidden]) { margin-bottom: 16px; }

@media (min-width: 1001px) and (max-width: 1150px) {
  .tasks-table th:nth-child(6), .tasks-table th:nth-child(7) { padding-inline: 4px; }
}

@media (max-width: 1000px) {
  .tasks-table, .tasks-table tbody { display: block; min-width: 0; width: 100%; }
  .tasks-table thead { display: none; }
  .tasks-table tbody { display: grid; gap: 12px; padding: 12px; }
  .tasks-table tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; padding: 8px 14px; border: 1px solid var(--border); border-radius: 10px; }
  .tasks-table td { display: flex; flex-direction: column; justify-content: center; gap: 4px; min-width: 0; padding: 10px 2px; }
  .tasks-table td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 700; }
  .tasks-table td:last-child, .tasks-table td[colspan] { grid-column: 1 / -1; border-bottom: 0; }
  .tasks-table td[colspan]::before { content: none; }
}

@media (max-width: 650px) {
  .tasks-table tr { grid-template-columns: minmax(0, 1fr); }
  .tasks-table td:last-child, .tasks-table td[colspan] { grid-column: 1; }
}

.sync-status { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 24px 0 18px; padding: 14px 16px; border-radius: 9px; background: var(--surface-muted); color: var(--muted); }
.sync-status strong { color: var(--text); font-weight: 650; text-align: right; }

.error, .ok, .msg { padding: 11px 13px; border-radius: 8px; }
.error { background: #ffe3e3; color: #8f1d2c; }
.ok, .msg { background: #e3f7e8; color: #116329; }
:root[data-theme="dark"] .error { background: #4a2029; color: #ffb8bd; }
:root[data-theme="dark"] .ok, :root[data-theme="dark"] .msg { background: #173c2a; color: #b8f0c7; }

.log-toolbar { display: flex; align-items: end; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.log-toolbar label { display: grid; gap: 6px; }
.log-search { flex: 1 1 360px; }
.log-groups { display: grid; gap: 12px; }
.log-group { overflow: hidden; padding: 0; }
.log-group-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--surface-muted); }
.log-group-header h2 { margin: 0; font-size: 16px; }
.log-group-count { color: var(--muted); font-size: 13px; white-space: nowrap; }
.log-table-scroll { overflow-x: auto; }
.logs-table { min-width: 620px; table-layout: fixed; }
.logs-table th:first-child { width: 205px; }
.logs-table th:nth-child(2) { width: 115px; }
.logs-table td { vertical-align: middle; }
.log-entry-time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.log-level-badge { display: inline-flex; align-items: center; min-height: 24px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 750; }
.log-level-badge.debug { background: #e8eef8; color: #52627a; }
.log-level-badge.info { background: #e3f7e8; color: #247a3b; }
.log-level-badge.warning { background: #fff1c2; color: #7a5a00; }
.log-level-badge.error { background: #ffe3e3; color: #b42332; }
.log-level-badge.critical { background: #7f1d2d; color: #fff; }
.log-level-badge.other { background: var(--control); color: var(--text); }
:root[data-theme="dark"] .log-level-badge.debug { background: #25364f; color: #bdcbe0; }
:root[data-theme="dark"] .log-level-badge.info { background: #173c2a; color: #9fe6ad; }
:root[data-theme="dark"] .log-level-badge.warning { background: #4a3c18; color: #ffe08b; }
:root[data-theme="dark"] .log-level-badge.error { background: #4a2029; color: #ff8c8c; }
.log-action { min-width: 0; }
.log-message-preview { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.log-message-details { margin-top: 8px; }
.log-message-details summary { color: var(--link); cursor: pointer; font-weight: 650; }
.log-message-full { max-height: 360px; margin: 8px 0 0; padding: 12px; overflow: auto; border-radius: 8px; background: var(--surface-muted); color: var(--text); font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; }
.log-empty { padding: 16px; }

.matches-page > p { margin-top: 0; }
.candidate { display: inline-flex; align-items: center; gap: 8px; margin: 7px 7px 0 0; padding: 8px; border-radius: 8px; background: var(--control); color: var(--text); }
.issue-card { padding: 16px; }
.issue-card + .issue-card { margin-top: 12px; }
.user-row { padding: 12px 0; border-bottom: 1px solid var(--border); }
.user-row:last-child { border-bottom: 0; }
.user-row input { max-width: 360px; margin: 0 8px; }

.changelog-list { display: grid; gap: 12px; }
.release-card { padding: 20px 22px; }
.release-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.release-head h2 { margin: 8px 0 0; font-size: 20px; }
.release-version { display: inline-block; padding: 3px 8px; border-radius: 999px; background: var(--control); color: var(--accent); font-weight: 750; }
.release-changes { display: grid; gap: 10px; margin: 18px 0 0; padding: 0; list-style: none; }
.release-changes li { display: flex; align-items: baseline; gap: 9px; }
.change-type { flex: 0 0 auto; min-width: 82px; padding: 3px 7px; border-radius: 5px; background: var(--control); color: var(--muted); font-size: 12px; font-weight: 700; text-align: center; }
.change-type.added { color: #247a3b; }
.change-type.fixed { color: #9b5b00; }
:root[data-theme="dark"] .change-type.added { color: #9fe6ad; }
:root[data-theme="dark"] .change-type.fixed { color: #ffd18a; }

@media (max-width: 800px) {
  .app-header { padding: 12px 16px; }
  .app-brand { font-size: 19px; }
  .app-nav { width: 100%; }
  .app-nav button { flex: 1; }
  .header-tools {
    width: 100%;
    justify-content: flex-end;
    margin-left: 0;
    padding-left: 0;
    border-left: 0;
  }
  .toolbar { grid-template-columns: minmax(0, 1fr); justify-items: stretch; }
  .search-wrap { width: 100%; }
  .checkbox-label, .status-filter, .task-count { height: 39px; justify-self: center; }
  .status-filter { width: min(100%, 240px); }
  .page-shell { margin-top: 16px; padding: 0 12px 24px; }
  .page-heading h1, .card h1 { font-size: 26px; }
  .sync-status { align-items: flex-start; flex-direction: column; gap: 5px; }
  .sync-status strong { text-align: left; }
  .release-head { flex-direction: column; gap: 8px; }
  .release-changes li { align-items: flex-start; flex-direction: column; gap: 4px; }
}
