:root {
  color-scheme: light;
  --ink: #1f2a32;
  --muted: #6a747c;
  --line: #d9e0e3;
  --surface: #ffffff;
  --page: #eef4f1;
  --green: #2c7a58;
  --green-soft: #e6f2ec;
  --coral: #b84c3f;
  --coral-soft: #f7e8e5;
  --blue: #315f8c;
  --blue-soft: #e7eef6;
  --shadow: 0 16px 34px rgba(31, 42, 50, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

body:not(.role-parent):not(.role-school) .app-shell,
body.role-parent .school-only,
body.role-parent .stats-grid,
body.role-parent .date-box label,
body.role-parent #sessionDate,
body.role-parent #syncStatus,
body.role-parent #scanMode,
body.role-parent label[for="scanMode"] {
  display: none;
}

body.role-parent .role-gate,
body.role-school .role-gate {
  display: none;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 7px;
  background: var(--blue);
  color: white;
  cursor: pointer;
  font-weight: 700;
  padding: 0 16px;
}

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

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

input,
select {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  padding: 0 12px;
}

label,
.eyebrow {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 6px;
  text-transform: uppercase;
}

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

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

h2 {
  font-size: 1.25rem;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 26px 0 34px;
}

.role-gate {
  align-items: center;
  display: grid;
  min-height: 100vh;
  padding: 20px;
}

.role-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin: 0 auto;
  max-width: 540px;
  padding: 26px;
  width: 100%;
}

.role-card h1 {
  font-size: clamp(2rem, 8vw, 3rem);
  margin-bottom: 18px;
}

.role-actions {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 12px;
}

.topbar {
  align-items: end;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 0 22px;
}

.date-box {
  width: min(230px, 100%);
}

.sync-status {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  margin: 7px 0 0;
}

.mode-banner {
  background: var(--ink);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: white;
  font-size: clamp(1.7rem, 6vw, 3rem);
  font-weight: 800;
  line-height: 1;
  margin-bottom: 14px;
  padding: 18px;
  text-align: center;
}

body.role-parent .mode-banner {
  background: var(--coral);
}

body.role-school .mode-banner {
  background: var(--blue);
}

.logout-btn {
  margin-top: 8px;
  width: 100%;
}

.stats-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 14px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.stat span {
  color: var(--muted);
  display: block;
  font-size: 0.88rem;
}

.stat strong {
  display: block;
  font-size: 2rem;
  margin-top: 3px;
}

.stat.present {
  background: var(--green-soft);
}

.stat.gone {
  background: var(--coral-soft);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
  padding: 18px;
}

.add-panel {
  margin-bottom: 14px;
}

.scan-panel {
  margin-bottom: 14px;
}

.child-form {
  display: grid;
  gap: 8px;
}

.form-row {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr minmax(170px, 0.45fr) minmax(130px, 0.35fr) auto;
}

.workspace {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(320px, 0.85fr) minmax(420px, 1.15fr);
}

.report-panel,
.accounting-panel {
  margin-top: 14px;
}

.report-controls {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(160px, 0.3fr) 1fr;
  margin-bottom: 12px;
}

.report-summary {
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 8px;
}

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

.secondary {
  background: var(--blue-soft);
  color: var(--blue);
}

.badge {
  align-items: center;
  background: #f2eadf;
  border: 1px solid #e2d0b8;
  border-radius: 999px;
  color: #795734;
  display: inline-flex;
  font-size: 0.84rem;
  font-weight: 700;
  min-height: 30px;
  padding: 0 12px;
}

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

.fake-camera {
  overflow: hidden;
  position: relative;
  aspect-ratio: 1;
  background:
    linear-gradient(90deg, rgba(49, 95, 140, 0.12) 1px, transparent 1px),
    linear-gradient(rgba(49, 95, 140, 0.12) 1px, transparent 1px),
    #f8fbfc;
  background-size: 18px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  place-items: center;
}

.scanner-video {
  height: 100%;
  inset: 0;
  object-fit: cover;
  opacity: 0;
  position: absolute;
  width: 100%;
}

.fake-camera.is-scanning .scanner-video {
  opacity: 1;
}

.scan-frame {
  position: relative;
  width: 62%;
  aspect-ratio: 1;
  border: 4px solid var(--blue);
  border-radius: 8px;
  box-shadow: 0 0 0 999px rgba(255, 255, 255, 0.32);
}

.scan-controls {
  align-content: start;
  display: grid;
  gap: 10px;
}

.scan-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.scan-message {
  color: var(--muted);
  margin: 0;
}

.parent-confirmation {
  background: var(--green-soft);
  border: 1px solid rgba(44, 122, 88, 0.35);
  border-radius: 8px;
  color: var(--green);
  display: none;
  font-size: 1.05rem;
  font-weight: 800;
  padding: 14px;
}

.parent-confirmation.is-visible {
  display: block;
}

.children-list {
  display: grid;
  gap: 10px;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 22px;
  text-align: center;
}

.child-card {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr auto;
  padding: 12px;
}

.child-card__name {
  display: block;
  font-size: 1rem;
}

.child-card__family,
.child-card__class {
  color: var(--muted);
  display: block;
  font-size: 0.9rem;
  margin-top: 3px;
}

.child-card__number {
  background: #f2eadf;
  border: 1px solid #e2d0b8;
  border-radius: 999px;
  color: #795734;
  display: inline-flex;
  font-size: 0.82rem;
  font-weight: 800;
  margin-bottom: 6px;
  padding: 4px 9px;
}

.child-card__status {
  color: var(--muted);
  display: block;
  font-size: 0.9rem;
  margin-top: 3px;
}

.child-card.is-present {
  border-color: rgba(44, 122, 88, 0.35);
  background: var(--green-soft);
}

.child-card.is-gone {
  border-color: rgba(184, 76, 63, 0.35);
  background: var(--coral-soft);
}

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

.present-btn {
  background: var(--green);
}

.leave-btn {
  background: var(--coral);
}

.qr-btn {
  min-width: 42px;
}

.icon-btn {
  background: #edf0f1;
  color: var(--ink);
  min-width: 42px;
  padding: 0;
}

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
}

td:last-child,
th:last-child {
  text-align: right;
  width: 72px;
}

.delete-record {
  background: transparent;
  color: var(--coral);
  min-height: 34px;
  padding: 0 8px;
}

.paid-btn {
  min-height: 34px;
  padding: 0 10px;
}

.paid-btn.is-paid {
  background: var(--green-soft);
  color: var(--green);
}

.paid-btn.is-unpaid {
  background: var(--coral-soft);
  color: var(--coral);
}

.qr-dialog {
  border: 0;
  border-radius: 8px;
  box-shadow: 0 26px 70px rgba(31, 42, 50, 0.25);
  padding: 18px;
  width: min(420px, calc(100% - 28px));
}

.qr-dialog::backdrop {
  background: rgba(31, 42, 50, 0.35);
}

.qr-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  text-align: center;
}

.qr-card h2 {
  font-size: 1.35rem;
  margin-bottom: 8px;
}

.qr-number {
  background: #f2eadf;
  border: 1px solid #e2d0b8;
  border-radius: 999px;
  color: #795734;
  display: inline-flex;
  margin-bottom: 14px;
  padding: 7px 12px;
}

.qr-code {
  background: white;
  display: inline-grid;
  margin: 0 auto;
  padding: 10px;
}

.qr-code svg {
  display: block;
  height: 230px;
  width: 230px;
}

.qr-payload {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 12px 0 0;
  word-break: break-all;
}

.dialog-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}

.backup-toggle {
  bottom: 18px;
  box-shadow: var(--shadow);
  position: fixed;
  right: 18px;
  z-index: 20;
}

.backup-dialog {
  border: 0;
  border-radius: 8px;
  box-shadow: 0 26px 70px rgba(31, 42, 50, 0.25);
  padding: 18px;
  width: min(520px, calc(100% - 28px));
}

.backup-dialog::backdrop {
  background: rgba(31, 42, 50, 0.35);
}

.backup-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.backup-item {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr auto;
  padding: 10px;
}

.backup-item strong,
.backup-item span {
  display: block;
}

.backup-item span {
  color: var(--muted);
  font-size: 0.88rem;
}

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

  .stats-grid,
  .workspace,
  .form-row,
  .scan-grid,
  .report-controls,
  .role-actions {
    grid-template-columns: 1fr;
  }

  .child-card {
    grid-template-columns: 1fr;
  }

  .child-card__actions {
    justify-content: stretch;
  }

  .child-card__actions button {
    flex: 1 1 120px;
  }

  .fake-camera {
    max-width: 220px;
  }
}

@media print {
  body * {
    visibility: hidden;
  }

  .qr-dialog,
  .qr-dialog *,
  .qr-card,
  .qr-card * {
    visibility: visible;
  }

  .qr-dialog {
    box-shadow: none;
    left: 0;
    position: absolute;
    top: 0;
    width: 100%;
  }

  .dialog-actions {
    display: none;
  }
}
