:root {
  color-scheme: light;
  --ink: #1c2430;
  --muted: #697386;
  --line: #d9dee8;
  --soft: #f5f7fb;
  --paper: #ffffff;
  --accent: #256f86;
  --accent-strong: #18546b;
  --good: #247b58;
  --class-line: #c93a3a;
  --warn: #b36b1f;
  --shadow: 0 14px 38px rgba(31, 42, 68, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  background: #eef2f6;
}

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

button {
  border: 0;
  cursor: pointer;
}

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

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(17, 34, 48, 0.64), rgba(17, 34, 48, 0.64)),
    url("https://images.unsplash.com/photo-1524995997946-a1c2e315a42f?auto=format&fit=crop&w=1800&q=80") center/cover;
}

.login-panel {
  width: min(480px, 100%);
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 32px;
}

.brand-mark {
  width: min(175px, 100%);
  height: 45px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: white;
  background: var(--accent);
  font-weight: 800;
  font-size: 23px;
  white-space: nowrap;
}

.login-panel h1,
.workspace-header h2,
.sidebar h1,
.panel h3 {
  margin: 0;
  letter-spacing: 0;
}

.sidebar h1 {
  white-space: nowrap;
  font-size: 28px;
}

.login-panel p,
.eyebrow {
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 10px;
  margin-top: 20px;
}

.login-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

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

textarea {
  resize: vertical;
  line-height: 1.55;
}

.form-message {
  min-height: 20px;
  margin: 0;
  color: var(--warn);
}

.app-shell {
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: 100vh;
}

.sidebar {
  min-height: 100vh;
  background: #111827;
  color: #fff;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sidebar .eyebrow {
  color: #9ca3af;
}

.sidebar-header,
.workspace-header,
.panel-heading,
.tool-row,
.header-actions,
.legend {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-header,
.workspace-header,
.panel-heading {
  justify-content: space-between;
}

.tool-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  align-items: stretch;
  gap: 10px;
}

#studentSearch {
  width: 100%;
}

#addClassButton {
  width: 58px;
  padding: 0;
  white-space: nowrap;
}

.class-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.student-list {
  display: grid;
  gap: 8px;
  overflow: auto;
  padding-right: 4px;
}

.student-card {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
  align-items: center;
  text-align: left;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: white;
}

.class-icon-button {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-weight: 900;
}

.student-card.active .class-icon-button {
  background: #e8f0f3;
  color: var(--accent-strong);
}

.student-card.active .class-icon-button.delete-class {
  color: #9b2c2c;
}

.student-card.active {
  background: #fff;
  color: var(--ink);
}

.student-card span {
  color: #aab3c2;
  font-size: 13px;
}

.student-card.active span {
  color: var(--muted);
}

.primary-button,
.secondary-button,
.icon-button,
.login-row button {
  border-radius: 8px;
  min-height: 40px;
  padding: 0 14px;
  font-weight: 700;
}

.primary-button,
.login-row button {
  background: var(--accent);
  color: white;
}

.primary-button:hover,
.login-row button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  background: #e8f0f3;
  color: var(--accent-strong);
}

.danger-button {
  background: #f7e8e8;
  color: #9b2c2c;
}

.icon-button {
  background: rgba(255, 255, 255, 0.12);
  color: white;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.workspace-header {
  padding-bottom: 10px;
}

.compact-header {
  display: flex;
}

.workspace-header .logout-button {
  flex: 0 0 auto;
}

.account-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 0 0 auto;
}

.account-actions button {
  min-height: 36px;
  padding: 0 12px;
  font-size: 14px;
}

.eyebrow {
  margin: 0 0 5px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.page-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.tab-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-weight: 800;
}

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

.summary-strip div,
.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 18px rgba(31, 42, 68, 0.04);
}

.summary-strip div {
  padding: 14px 16px;
}

.summary-strip span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.summary-strip strong {
  display: block;
  margin-top: 4px;
  font-size: 26px;
}

.content-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.page-section {
  display: none;
  gap: 16px;
}

.page-section.active {
  display: grid;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.profile-form,
.score-grid,
.report-controls {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.profile-form {
  grid-template-columns: repeat(3, minmax(150px, 1fr));
}

.new-student-form {
  grid-template-columns: repeat(6, minmax(92px, 1fr)) 64px;
  align-items: end;
  column-gap: 12px;
  row-gap: 8px;
}

.new-student-form label {
  grid-template-rows: 18px 42px;
  align-items: end;
  gap: 4px;
  text-align: center;
}

.new-student-form input {
  height: 42px;
  padding-top: 0;
  padding-bottom: 0;
}

.add-student-icon {
  width: 64px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
  align-self: end;
  padding: 0 10px;
}

.add-student-icon:hover {
  background: var(--accent-strong);
}

.existing-student-picker {
  margin-top: 14px;
}

.student-directory {
  margin-top: 16px;
}

.student-directory h4 {
  margin: 0 0 10px;
}

.selected-row td {
  background: #edf7fa;
}

.directory-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.table-input {
  min-height: 34px;
  padding: 6px 8px;
  border-radius: 6px;
}

.table-action {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.import-box {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.import-box p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.file-button {
  display: grid;
  place-items: center;
  min-height: 42px;
  border-radius: 8px;
  padding: 0 14px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
  cursor: pointer;
}

.file-button input {
  display: none;
}

.student-picker-row,
.report-student-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: end;
  gap: 12px;
  margin-top: 14px;
}

.score-update-row {
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr auto;
  gap: 12px;
  align-items: end;
  margin-top: 14px;
}

.score-update-row > label,
.score-grid label {
  grid-template-rows: 18px 42px;
  align-items: end;
  gap: 4px;
}

.score-grid label {
  text-align: center;
}

.score-update-row select,
.score-grid input {
  height: 42px;
  padding-top: 0;
  padding-bottom: 0;
}

.compare-toggle {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.compare-toggle input {
  width: 18px;
  height: 18px;
}

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

.score-grid {
  grid-template-columns: repeat(7, minmax(82px, 1fr));
  margin-top: 0;
}

.score-save-button {
  min-width: 64px;
  height: 42px;
  padding: 0 12px;
}

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

.term-actions {
  justify-content: flex-start;
}

.segmented {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  padding: 0 12px;
  font-weight: 800;
}

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

.daily-compact {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
  align-items: start;
}

.daily-student-row {
  display: grid;
  grid-template-columns: minmax(320px, 460px) 1fr;
  gap: 12px;
  align-items: stretch;
  margin-top: 14px;
}

.daily-student-row label {
  display: grid;
  grid-template-columns: 78px 1fr;
  align-items: stretch;
  gap: 10px;
  min-height: 88px;
}

.student-select-label span {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 18px;
  font-weight: 800;
  line-height: 1.45;
  text-align: center;
}

.daily-student-row select {
  height: 100%;
  min-height: 48px;
}

.inline-issues {
  grid-template-columns: repeat(4, minmax(110px, 1fr));
  align-self: stretch;
}

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

.checkbox-grid label {
  grid-template-columns: auto 1fr;
  align-items: center;
  color: var(--ink);
  background: var(--soft);
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 8px;
}

.checkbox-grid input {
  width: 18px;
  height: 18px;
}

.wide-label {
  margin-top: 0;
}

.daily-history {
  display: grid;
  gap: 8px;
  grid-column: 1 / -1;
}

.history-list {
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 8px;
}

.history-table table,
.score-table table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 13px;
}

.history-table th,
.history-table td,
.score-table th,
.score-table td {
  border: 1px solid var(--line);
  padding: 8px;
  text-align: center;
  vertical-align: top;
  background: #fff;
}

.history-table th,
.score-table th {
  background: #eef4f7;
  color: var(--accent-strong);
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}

.history-table input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.history-table td:has(input[type="checkbox"]) {
  text-align: center;
  vertical-align: middle;
}

.history-list > p {
  margin: 6px;
  color: var(--muted);
  font-size: 13px;
}

.history-group-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
}

.history-group-heading h4 {
  margin: 0;
}

.history-delete-button {
  min-height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
}

.daily-history-editor {
  width: 100%;
  min-height: 82px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font: inherit;
  line-height: 1.45;
  text-align: center;
}

.daily-history-actions {
  min-width: 120px;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}

.history-table td.daily-history-actions {
  vertical-align: middle;
}

.daily-history-action-group {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.daily-history-actions button {
  min-height: 30px;
  padding: 0 9px;
  margin: 2px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
}

.history-item {
  border-bottom: 1px solid var(--line);
  padding: 8px 4px;
}

.history-item:last-child {
  border-bottom: 0;
}

.history-item strong,
.history-item span {
  display: block;
  font-size: 12px;
}

.history-item span {
  color: var(--accent-strong);
  margin: 3px 0;
}

.history-item p {
  margin: 4px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.score-table-wrap {
  margin-top: 16px;
}

.score-table-wrap h4 {
  margin: 0;
}

.table-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.table-delete-button {
  min-height: 34px;
  padding: 0 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
}

.table-delete-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.score-table {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.report-history-editor {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font: inherit;
  line-height: 1.5;
}

.report-history-actions {
  min-width: 132px;
  padding: 8px;
  text-align: center;
  white-space: nowrap;
}

.score-table td.report-history-actions {
  vertical-align: middle;
}

.report-history-action-group {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.report-history-actions button {
  min-height: 32px;
  padding: 0 10px;
  margin: 2px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
}

.directory-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
}

.student-directory .score-table td {
  text-align: center;
  vertical-align: middle;
}

.student-directory .score-table td input {
  text-align: center;
}

.score-panel .score-table td {
  text-align: center;
  vertical-align: middle;
}

.score-panel .score-table td input[type="checkbox"] {
  margin: 0 auto;
}

canvas {
  width: 100%;
  max-height: 360px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(#ffffff, #fbfcfe);
}

@media (min-width: 1380px) {
  .profile-form {
    grid-template-columns: repeat(6, minmax(120px, 1fr));
  }

  .new-student-form {
    grid-template-columns: repeat(6, minmax(112px, 1fr)) 64px;
  }

  .score-grid {
    grid-template-columns: repeat(7, minmax(105px, 1fr));
  }
}

.legend {
  color: var(--muted);
  font-size: 13px;
}

.line {
  display: inline-block;
  width: 22px;
  height: 3px;
  margin-right: 6px;
  vertical-align: middle;
}

.line.student {
  background: var(--accent);
}

.line.class {
  background: var(--class-line);
}

.report-controls {
  grid-template-columns: repeat(4, minmax(180px, 1fr));
}

.report-field textarea {
  display: none;
}

.student-info-chip {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 10px 12px;
  color: var(--muted);
  font-weight: 800;
}

.report-field {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfe;
}

.report-field-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.report-field-header span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

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

.template-actions .secondary-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.prompt-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(17, 24, 39, 0.42);
}

.prompt-dialog {
  width: min(620px, 100%);
  display: grid;
  gap: 14px;
  padding: 18px;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.prompt-dialog h3 {
  margin: 0;
}

.account-dialog {
  width: min(960px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  overflow: auto;
}

.modal-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-close-button {
  min-height: 34px;
  padding: 0 12px;
}

.password-form {
  display: grid;
  gap: 12px;
}

.password-form button {
  justify-self: end;
}

.admin-create-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(160px, 0.7fr) auto;
  gap: 10px;
  align-items: center;
}

.admin-table {
  max-height: 460px;
  overflow: auto;
}

.admin-table table {
  min-width: 980px;
}

.admin-page-content {
  display: grid;
  gap: 16px;
  margin-top: 14px;
}

.admin-section {
  display: grid;
  gap: 10px;
}

.admin-section-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.admin-section h4 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.admin-section-heading .secondary-button {
  justify-self: end;
  min-height: 34px;
  padding: 0 14px;
}

.admin-page-panel .admin-create-row {
  margin-bottom: 4px;
}

.admin-action-group {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.admin-action-group button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

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

@media (max-width: 1250px) {
  .daily-compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .daily-history {
    grid-column: span 2;
  }
}

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

  .sidebar {
    min-height: auto;
  }

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

  .profile-form,
  .score-grid,
  .daily-compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .new-student-form {
    grid-template-columns: repeat(6, minmax(86px, 1fr)) 64px;
    overflow-x: auto;
  }

  .daily-history {
    grid-column: span 2;
  }
}

@media (max-width: 640px) {
  .workspace {
    padding: 16px;
  }

  .workspace-header,
  .panel-heading,
  .header-actions,
  .login-row {
    align-items: stretch;
    flex-direction: column;
  }

  .profile-form,
  .score-grid,
  .report-controls,
  .checkbox-grid,
  .student-picker-row,
  .daily-compact,
  .admin-create-row {
    grid-template-columns: 1fr;
  }

  .new-student-form {
    grid-template-columns: repeat(6, minmax(86px, 1fr)) 64px;
  }

  .daily-history {
    grid-column: auto;
  }
}
