:root {
  color-scheme: light;
  --ink: #202124;
  --muted: #65717f;
  --line: #d9e0e7;
  --paper: #ffffff;
  --surface: #f4f7f8;
  --blue: #1f5f8b;
  --green: #2d6a4f;
  --red: #a33a3a;
  --gold: #9a6a16;
  --shadow: 0 18px 45px rgba(37, 48, 60, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: linear-gradient(180deg, #eef4f5 0%, #f8faf9 42%, #ffffff 100%);
  font-family: Arial, Helvetica, sans-serif;
}

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

button {
  border: 0;
  border-radius: 6px;
  padding: 0.72rem 1rem;
  color: #fff;
  background: var(--blue);
  cursor: pointer;
}

button:hover {
  filter: brightness(0.95);
}

button.ghost {
  color: var(--blue);
  background: #e8f1f6;
}

button.danger {
  color: var(--red);
  background: #f8e8e8;
}

.file-button {
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  padding: 0.72rem 1rem;
  cursor: pointer;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 30px 0 18px;
}

.topbar h1,
.section-heading h2 {
  margin: 0;
  line-height: 1.08;
}

.topbar h1 {
  font-size: clamp(1.8rem, 4vw, 3rem);
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar-actions,
.toolbar,
.section-heading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.section-heading {
  justify-content: space-between;
  margin-bottom: 1rem;
}

.app-shell {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto 48px;
}

.panel,
.preview-section {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 1.2rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.code-grid {
  grid-template-columns: repeat(5, minmax(120px, 1fr));
}

label {
  display: grid;
  gap: 0.4rem;
  color: #374151;
  font-size: 0.9rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #c9d3dc;
  border-radius: 6px;
  padding: 0.72rem 0.78rem;
  color: var(--ink);
  background: #fff;
}

textarea {
  resize: vertical;
}

.code-preview {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
  border: 1px solid #cfe0ea;
  border-radius: 8px;
  padding: 0.85rem 1rem;
  background: #f5fafc;
}

.code-preview span {
  color: var(--blue);
  font-family: "Courier New", Courier, monospace;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.code-preview small {
  color: var(--muted);
}

.status-pill {
  border-radius: 999px;
  padding: 0.4rem 0.7rem;
  color: var(--green);
  background: #e7f2ec;
  font-weight: 700;
  white-space: nowrap;
}

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

.student-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: #fff;
}

.student-table th,
.student-table td {
  border-bottom: 1px solid var(--line);
  padding: 0.72rem;
  text-align: left;
  vertical-align: middle;
}

.student-table th {
  color: var(--muted);
  background: #f6f8fa;
  font-size: 0.82rem;
  text-transform: uppercase;
}

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

.student-table .narrow {
  width: 110px;
}

.generated-cell {
  font-family: "Courier New", Courier, monospace;
  font-weight: 700;
}

.remove-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--red);
  background: #f9eaea;
}

.import-box,
.paste-box {
  margin-top: 1rem;
  border: 1px dashed #b8c5cf;
  border-radius: 8px;
  padding: 1rem;
  background: #fbfcfd;
}

.import-box {
  display: grid;
  gap: 0.75rem;
  margin-top: 0;
  margin-bottom: 1rem;
}

.file-drop {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
  background: #fff;
  cursor: pointer;
}

.file-drop span {
  color: var(--blue);
  font-weight: 700;
}

.file-drop small {
  color: var(--muted);
  font-weight: 400;
}

.file-drop input {
  margin-top: 0.75rem;
  padding: 0;
  border: 0;
}

.paste-box summary {
  cursor: pointer;
  font-weight: 700;
}

.paste-box p,
.muted {
  color: var(--muted);
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 2;
  flex-wrap: wrap;
  justify-content: flex-end;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 12px 30px rgba(32, 33, 36, 0.08);
}

.toolbar button:nth-child(2) {
  background: var(--green);
}

.toolbar button:nth-child(3) {
  background: var(--gold);
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 0.8rem;
}

.student-card {
  min-height: 150px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 1.5px solid #243342;
  border-radius: 8px;
  padding: 1rem;
  background: var(--paper);
  break-inside: avoid;
}

.card-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  color: var(--blue);
  font-weight: 700;
}

.student-card h3 {
  margin: 0 0 0.8rem;
  font-size: 1.35rem;
  line-height: 1.16;
  text-align: center;
}

.student-card dl {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 0.65rem 1rem;
  margin: 0;
}

.student-card dt {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.student-card dd {
  margin: 0.2rem 0 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.card-student-id {
  font-family: "Courier New", Courier, monospace;
  font-size: 1.35rem;
  letter-spacing: 0.08em;
}

.empty-state {
  display: grid;
  min-height: 180px;
  place-items: center;
  border: 1px dashed #b8c5cf;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .form-grid,
  .code-grid {
    grid-template-columns: 1fr;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar {
    justify-content: stretch;
  }

  .toolbar button {
    flex: 1 1 160px;
  }
}

@media print {
  @page {
    size: A4;
    margin: 8mm;
  }

  body {
    background: #fff;
  }

  .topbar,
  .panel,
  .toolbar,
  .preview-section > .section-heading,
  .empty-state {
    display: none !important;
  }

  .app-shell,
  .preview-section {
    display: block;
    width: auto;
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  .cards-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 4mm;
  }

  .student-card {
    min-height: 30mm;
    border-radius: 3mm;
    padding: 4mm 5mm;
    page-break-inside: avoid;
  }

  .student-card h3 {
    margin-bottom: 3mm;
    font-size: 13pt;
  }

  .student-card dl {
    grid-template-columns: 24mm 1fr;
    gap: 2mm 4mm;
  }

  .student-card dt {
    font-size: 7.5pt;
  }

  .student-card dd {
    font-size: 10pt;
  }

  .card-student-id {
    font-size: 14pt;
  }
}
