:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #18212f;
  --muted: #687386;
  --line: #d8dee8;
  --accent: #1769e8;
  --accent-strong: #0d52c4;
  --warm: #b8621b;
  --ok: #1e7f55;
  --shadow: 0 18px 50px rgba(24, 33, 47, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-layout {
  display: grid;
  grid-template-columns: 204px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  border-right: 1px solid var(--line);
  background: #fff;
  padding: 18px 15px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 7px 18px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
}

.brand strong,
.brand span {
  display: block;
  line-height: 1.15;
}

.brand span {
  font-size: 12px;
  font-weight: 700;
}

.side-nav {
  display: grid;
  gap: 7px;
  padding: 18px 0;
}

.side-nav a,
.side-nav button {
  display: flex;
  align-items: center;
  min-height: 40px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  padding: 10px 12px;
  text-align: left;
  text-decoration: none;
  font-size: 13px;
  font-weight: 750;
}

.side-nav a.active,
.side-nav a:hover,
.side-nav button:hover {
  background: #eaf2ff;
  color: var(--accent);
}

.side-nav-secondary {
  margin-top: auto;
  border-top: 1px solid var(--line);
}

.sync-card {
  display: grid;
  gap: 5px;
  border: 1px solid #cfe0fb;
  border-radius: 8px;
  background: #f3f8ff;
  padding: 11px;
  color: var(--muted);
  font-size: 11px;
}

.sync-card strong {
  color: var(--ink);
  line-height: 1.35;
}

.shell {
  width: min(1240px, calc(100vw - 236px));
  margin: 0 auto;
  padding: 28px 22px 40px;
}

.topbar {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 27px;
  line-height: 1.04;
}

h2 {
  font-size: 24px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

h3 {
  font-size: 18px;
}

.summary-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  padding: 10px 14px;
  color: var(--muted);
  font-weight: 700;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-actions button {
  min-height: 40px;
  border-color: var(--accent);
  color: var(--accent);
}

.page-subtitle,
.home-panel-head p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.home-panel {
  padding: 20px;
}

.home-panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.home-panel-head h2 {
  font-size: 20px;
}

.home-panel-head button {
  border-color: var(--accent);
  color: var(--accent);
}

.control-layout {
  display: grid;
  grid-template-columns: minmax(340px, 1.15fr) minmax(320px, 0.85fr);
  gap: 22px;
}

.student-area,
.report-options {
  display: grid;
  align-content: start;
  gap: 15px;
}

.student-search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

.student-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 105, 232, 0.12);
}

.overview-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.overview-stats div {
  min-height: 108px;
  border: 1px solid #cfe0fb;
  border-radius: 8px;
  background: #f4f8ff;
  padding: 16px;
}

.overview-stats div:last-child {
  border-color: #cfe9d9;
  background: #f3fbf6;
}

.overview-stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.overview-stats strong {
  display: block;
  margin-top: 8px;
  font-size: 32px;
}

.report-buttons {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 10px;
}

.workspace {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 22px rgba(24, 33, 47, 0.05);
}

.controls {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 16px;
  padding: 18px;
}

.fetch-box,
.settings-section {
  display: grid;
  gap: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 14px;
}

.api-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
}

.status-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--muted);
  padding: 6px 9px;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.status-badge.ready {
  border-color: rgba(30, 127, 85, 0.28);
  background: rgba(30, 127, 85, 0.08);
  color: var(--ok);
}

.status-badge.missing,
.status-badge.error {
  border-color: rgba(184, 98, 27, 0.28);
  background: rgba(184, 98, 27, 0.08);
  color: var(--warm);
}

.api-fields {
  display: grid;
  gap: 10px;
}

.settings-dialog {
  width: min(760px, calc(100vw - 28px));
  max-height: min(780px, calc(100vh - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
}

.settings-dialog::backdrop {
  background: rgba(24, 33, 47, 0.48);
}

.merge-dialog {
  width: min(560px, calc(100vw - 28px));
}

.merge-panel {
  gap: 18px;
}

.merge-panel > .hint {
  margin: 0;
  line-height: 1.5;
}

.merge-name-list {
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.merge-name-list legend {
  color: var(--muted);
  padding: 0 6px;
  font-size: 13px;
  font-weight: 800;
}

.merge-name-list label {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 7px;
  padding: 9px 10px;
  cursor: pointer;
  font-weight: 750;
}

.merge-name-list label:hover {
  background: #f3f7fd;
}

.merge-name-list input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.merge-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.settings-panel {
  display: grid;
  gap: 14px;
  max-height: inherit;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 18px;
}

.settings-head,
.section-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.section-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  min-height: 38px;
  border-radius: 50%;
  padding: 0;
  font-size: 26px;
  line-height: 1;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

label span strong {
  color: var(--ink);
}

input[type="date"],
input[type="text"],
input[type="password"],
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.12);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.grid-two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.bulk-picker {
  display: grid;
  gap: 8px;
}

.bulk-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.bulk-picker-head > div {
  display: flex;
  gap: 6px;
}

.bulk-picker-head button {
  min-height: 30px;
  padding: 5px 8px;
  font-size: 12px;
}

.student-checklist {
  display: grid;
  gap: 4px;
  max-height: 235px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 8px;
}

.student-checklist p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.student-check {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.student-check[hidden] {
  display: none;
}

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

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 9px 13px;
  font-weight: 850;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.primary:not(:disabled):hover {
  background: var(--accent-strong);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.diagnostics {
  max-height: 96px;
  margin: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--muted);
  padding: 9px 10px;
  font-size: 12px;
  line-height: 1.4;
}

.report {
  min-width: 0;
  margin-top: 18px;
  padding: 20px;
}

.report-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.report-head > div:first-child {
  min-width: 0;
}

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

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

.stats div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: #fbfcfe;
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stats strong {
  display: block;
  margin-top: 4px;
  font-size: 28px;
  line-height: 1;
}

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

table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
}

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

th {
  background: #f6f8fb;
  color: #425066;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

td {
  font-size: 14px;
}

tr:last-child td {
  border-bottom: 0;
}

.lesson-ok {
  color: var(--ok);
  font-weight: 850;
}

.lesson-zero {
  color: var(--warm);
  font-weight: 850;
}

.session-id {
  max-width: 150px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.empty {
  height: 120px;
  color: var(--muted);
  text-align: center;
}

.message-box {
  margin-top: 18px;
}

textarea {
  min-height: 210px;
  resize: vertical;
  line-height: 1.5;
}

.bulk-reports {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.bulk-report-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 14px;
}

.bulk-card-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.bulk-card-head h3 {
  font-size: 18px;
  overflow-wrap: anywhere;
}

.bulk-card-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.bulk-card-actions span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.mini-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.mini-table-wrap table {
  min-width: 520px;
}

.bulk-report-card textarea {
  min-height: 150px;
  background: white;
}

/* Reference-aligned desktop dashboard */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
}

.app-layout {
  grid-template-columns: 238px minmax(0, 1fr);
}

.sidebar {
  padding: 22px 15px 18px;
}

.brand {
  padding: 4px 8px 24px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
}

.side-nav {
  gap: 8px;
  padding-top: 22px;
}

.side-nav a,
.side-nav button {
  min-height: 46px;
  padding: 11px 14px;
  font-size: 14px;
}

.side-nav-secondary {
  border-top: 0;
  padding-bottom: 8px;
}

.sync-card {
  display: none;
}

.shell {
  width: min(1320px, calc(100vw - 270px));
  padding: 24px 24px 42px;
}

.topbar {
  align-items: center;
  margin-bottom: 22px;
}

h1 {
  font-size: 25px;
}

.top-actions button {
  min-width: 142px;
  border-color: var(--line);
  color: var(--ink);
  font-size: 13px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(24, 33, 47, 0.06);
}

.home-panel {
  padding: 22px;
}

.fetch-row {
  display: grid;
  grid-template-columns: 1fr 1fr .9fr .78fr;
  align-items: end;
  gap: 22px;
}

.fetch-row label {
  display: grid;
  gap: 8px;
}

.fetch-row label > span,
.bulk-picker-head > span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 750;
}

.fetch-row input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 9px 12px;
  color: var(--ink);
}

.fetch-row button {
  width: 100%;
}

.home-divider {
  height: 1px;
  margin: 18px 0;
  background: var(--line);
}

.control-layout {
  grid-template-columns: minmax(340px, .85fr) minmax(460px, 1.35fr);
  gap: 28px;
}

.bulk-picker-head > div {
  margin-left: auto;
}

.student-checklist {
  max-height: 218px;
}

.fetch-state {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 70px;
  border: 1px solid #cfe0fb;
  border-radius: 7px;
  background: #f5f9ff;
  padding: 14px 18px;
}

.success-check {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 2px solid #19a15f;
  border-radius: 50%;
  color: #198754;
  font-weight: 900;
}

.fetch-state div {
  display: grid;
  gap: 3px;
}

.fetch-state strong {
  font-size: 13px;
}

.fetch-state span:last-child {
  color: var(--muted);
  font-size: 12px;
}

.overview-stats div {
  min-height: 112px;
}

.overview-stats strong {
  display: block;
  margin-top: 12px;
  font-size: 30px;
}

.report-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

.report-buttons > button {
  width: min(260px, 100%);
}

.report {
  padding: 18px 20px;
}

.report-head {
  align-items: center;
}

.report-head h2 {
  font-size: 20px;
}

.report.bulk-mode > .stats,
.report.bulk-mode > .table-wrap,
.report.bulk-mode > .message-box {
  display: none;
}

.bulk-reports {
  gap: 8px;
  margin-top: 16px;
}

.bulk-report-card {
  padding: 0;
  overflow: hidden;
  background: #fff;
}

.bulk-card-head {
  align-items: center;
  margin: 0;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
}

.bulk-card-head::-webkit-details-marker {
  display: none;
}

.bulk-card-head::after {
  content: "⌄";
  margin-left: 4px;
  color: var(--muted);
  font-size: 18px;
}

.bulk-report-card[open] .bulk-card-head::after {
  transform: rotate(180deg);
}

.bulk-card-head h3 {
  font-size: 15px;
}

.bulk-card-actions button {
  min-height: 34px;
  border-color: #b9d2fb;
  color: var(--accent);
  padding: 6px 12px;
  font-size: 12px;
}

.bulk-card-content {
  display: grid;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 0 14px 14px;
}

.mini-table-wrap {
  border: 0;
  border-radius: 0;
}

.mini-table-wrap th,
.mini-table-wrap td {
  padding: 9px 11px;
  font-size: 12px;
}

.bulk-report-card textarea {
  min-height: 140px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
}

@media (max-width: 1050px) {
  .fetch-row {
    grid-template-columns: 1fr 1fr;
  }

  .control-layout {
    grid-template-columns: 1fr;
  }
}

.student-message-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  margin-bottom: 8px;
}

.student-message-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.student-message-head button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 7px 11px;
  font-size: 12px;
}

@media (max-width: 980px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px 16px;
  }

  .brand {
    border-bottom: 0;
    padding: 0;
  }

  .side-nav {
    display: flex;
    justify-content: center;
    padding: 0;
  }

  .side-nav-secondary {
    margin: 0;
    border: 0;
  }

  .side-nav-secondary #sidebarLogout,
  .sync-card {
    display: none;
  }

  .shell {
    width: min(100% - 28px, 900px);
    padding: 22px 0 36px;
  }

  .control-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .shell {
    width: min(100vw - 22px, 640px);
    padding-top: 16px;
  }

  .sidebar {
    grid-template-columns: 1fr auto;
  }

  .side-nav:first-of-type {
    display: none;
  }

  .topbar,
  .report-head {
    align-items: stretch;
    flex-direction: column;
  }

  .summary-pill {
    width: fit-content;
  }

  .top-actions {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .home-panel-head,
  .bulk-card-head,
  .student-message-head {
    align-items: stretch;
    flex-direction: column;
  }

  .overview-stats,
  .report-buttons,
  .grid-two {
    grid-template-columns: 1fr;
  }

  .report-buttons,
  .merge-actions {
    flex-direction: column;
  }

  .report-buttons > button,
  .merge-actions > button {
    width: 100%;
  }

  .controls {
    position: static;
  }

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