:root {
  color-scheme: light;
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --text: #172033;
  --muted: #637086;
  --line: #d9e0eb;
  --primary: #176b63;
  --primary-dark: #10524c;
  --accent: #d89216;
  --danger: #a43232;
  --shadow: 0 18px 45px rgba(23, 32, 51, 0.12);
}

* {
  box-sizing: border-box;
}

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

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 48px);
  background: #162033;
  color: #fff;
}

.eyebrow {
  margin: 0 0 4px;
  color: #aebbd0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1;
}

h2 {
  font-size: 1.05rem;
}

.summary {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.summary span,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  padding: 0 12px;
  color: #eef4ff;
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.86rem;
  font-weight: 700;
}

.scan-launch {
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
}

.layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 340px)) 1fr;
  gap: 18px;
  padding: 22px clamp(18px, 4vw, 48px) 48px;
  align-items: start;
}

.panel,
.student-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

label {
  display: block;
  margin: 14px 0 7px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

select,
textarea,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
}

select {
  height: 44px;
  padding: 0 12px;
}

input {
  height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 190px;
  padding: 12px;
  resize: vertical;
  line-height: 1.45;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 800;
}

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

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

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

.ghost,
.icon-button {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 16px;
}

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

.cloud-box {
  border-top: 2px solid var(--line);
  margin-top: 18px;
  padding-top: 16px;
}

.cloud-box h3 {
  font-size: 1.05rem;
  margin: 0 0 4px;
}

.cloud-status {
  color: #e2666b;
  font-weight: 900;
  margin-bottom: 10px;
}

.cloud-status.is-synced {
  color: #2fa86b;
}

.cloud-actions {
  grid-template-columns: 1fr 1fr;
}

.admin-box {
  border-top: 2px solid var(--line);
  margin-top: 18px;
  padding-top: 16px;
}

.admin-box h3 {
  font-size: 1.05rem;
  margin: 0 0 4px;
}

.admin-status {
  color: var(--muted);
  font-weight: 900;
  margin-bottom: 10px;
}

.admin-status.is-connected {
  color: #218255;
}

.admin-status.is-error {
  color: var(--danger);
}

.admin-actions {
  grid-template-columns: 1fr 1fr;
}

.admin-logout {
  width: 100%;
  margin-top: 10px;
}

.export-row {
  grid-template-columns: 1fr 1fr;
}

.laser-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.scan-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1726;
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.camera-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #c6d2e3;
  font-weight: 800;
}

.camera-empty[hidden] {
  display: none !important;
}

.scanner-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 38, 0.66);
}

.scanner-modal[hidden] {
  display: none !important;
}

.scanner-card {
  width: min(720px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(15, 23, 38, 0.34);
}

.scanner-modal-title h2 {
  margin-top: 3px;
  font-size: 1.55rem;
}

.scanner-modal-title .eyebrow {
  color: var(--muted);
}

.scanner-close {
  width: 48px;
  min-width: 48px;
  height: 48px;
  padding: 0;
  font-size: 1.6rem;
}

.scanner-card .scan-frame {
  width: 100%;
}

.scanner-feedback {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.scanner-feedback .status {
  width: max-content;
  border-color: var(--line);
  color: var(--text);
  background: var(--surface-2);
}

.scanner-feedback .scan-result {
  margin-top: 0;
}

.scan-result {
  min-height: 84px;
  margin-top: 14px;
  padding: 14px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
}

.statement-preview {
  display: grid;
  gap: 8px;
  min-height: 130px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.84rem;
}

.statement-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
}

.statement-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(217, 224, 235, 0.72);
}

.statement-row:last-child {
  border-bottom: 0;
}

.statement-main {
  min-width: 0;
}

.statement-main span,
.statement-money small {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.statement-main strong {
  display: block;
  color: var(--text);
  margin-top: 2px;
  line-height: 1.25;
  overflow-wrap: break-word;
}

.statement-money {
  flex: 0 0 auto;
  min-width: 96px;
  text-align: right;
  color: var(--text);
  font-weight: 800;
}

.scan-result strong {
  display: block;
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 6px;
}

.cards-area {
  grid-column: 1 / -1;
  min-width: 0;
}

.admin-dashboard {
  grid-column: 1 / -1;
  min-width: 0;
}

.admin-dashboard-title p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.88rem;
}

.admin-class-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.admin-class-item {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.admin-class-button {
  width: 100%;
  min-height: 94px;
  padding: 12px;
  border: 0;
  border-radius: 0;
  background: var(--surface-2);
  color: var(--text);
  text-align: left;
}

.admin-class-button:hover,
.admin-class-button.is-selected {
  border-color: var(--primary);
  background: #edf8f5;
}

.admin-class-button strong,
.admin-class-button span,
.admin-class-button small {
  display: block;
}

.admin-class-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 0 10px 10px;
}

.admin-class-actions button {
  min-width: 0;
  min-height: 44px;
  padding: 6px 8px;
  font-size: 0.78rem;
  line-height: 1.15;
}

.admin-class-actions .admin-delete-class {
  color: #fff;
  border-color: var(--danger);
  background: var(--danger);
}

.admin-class-actions .admin-delete-class:hover {
  background: #842727;
}

.admin-class-button span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.84rem;
}

.admin-class-button small {
  margin-top: 8px;
  color: var(--muted);
}

.admin-class-detail {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.admin-empty {
  min-height: 110px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px dashed #aeb9c9;
  border-radius: 8px;
  padding: 18px;
  text-align: center;
}

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

.admin-detail-head p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.86rem;
}

.admin-student-table {
  width: 100%;
  border-collapse: collapse;
}

.admin-student-table th,
.admin-student-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.admin-student-table th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.admin-student-table td:last-child,
.admin-student-table th:last-child {
  text-align: right;
}

.cards-title {
  align-items: flex-end;
}

.cards-title p {
  max-width: 420px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

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

.empty-state {
  grid-column: 1 / -1;
  min-height: 240px;
  display: grid;
  place-items: center;
  border: 1px dashed #aeb9c9;
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.54);
  text-align: center;
  padding: 24px;
}

.student-card {
  overflow: hidden;
}

.card-face {
  min-height: 168px;
  padding: 18px;
  color: white;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0)),
    linear-gradient(135deg, #15233a 0%, #176b63 58%, #d89216 130%);
}

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

.card-brand {
  font-weight: 900;
}

.student-name {
  margin-top: 30px;
  font-size: 1.25rem;
  font-weight: 900;
  line-height: 1.15;
  word-break: break-word;
}

.card-number {
  margin-top: 14px;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  word-spacing: 6px;
}

.card-bottom {
  margin-top: 16px;
  color: #dce7f5;
  font-size: 0.82rem;
  font-weight: 800;
}

.card-details {
  display: grid;
  grid-template-columns: 1fr 92px;
  gap: 12px;
  padding: 14px;
  align-items: center;
}

.detail-list {
  display: grid;
  gap: 8px;
  font-size: 0.9rem;
}

.detail-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}

.detail-list span {
  color: var(--muted);
  font-weight: 800;
}

.qr-box {
  display: grid;
  place-items: center;
  min-width: 92px;
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.qr-box canvas,
.qr-box img,
.qr-box svg {
  width: 84px;
  height: 84px;
}

.qr-error {
  color: var(--danger);
  font-size: 0.72rem;
  font-weight: 800;
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr 0.7fr 1fr;
  gap: 10px;
  padding: 0 14px 14px;
}

.card-actions button {
  min-height: 36px;
  font-size: 0.84rem;
}

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

  .cards-area {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .topbar,
  .section-title,
  .cards-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .summary {
    justify-content: flex-start;
  }

  .scanner-card {
    padding: 14px;
  }

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

  .button-row {
    grid-template-columns: 1fr;
  }

  .statement-row,
  .statement-head,
  .admin-detail-head {
    flex-direction: column;
    align-items: stretch;
  }

  .admin-student-table {
    font-size: 0.84rem;
  }

  .statement-money {
    text-align: left;
  }
}

@media print {
  body {
    background: white;
  }

  .topbar,
  .controls,
  .scanner,
  .scanner-modal,
  .teacher-panel,
  .bank-panel,
  .cards-title,
  .card-actions {
    display: none;
  }

  .layout {
    display: block;
    padding: 0;
  }

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

  .student-card {
    box-shadow: none;
    break-inside: avoid;
  }
}
