:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --ink: #17201d;
  --muted: #66736f;
  --line: #d8ded8;
  --panel: #ffffff;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #d9f0ed;
  --warn: #9a3412;
  --warn-bg: #fff3e7;
  --danger: #b42318;
  --shadow: 0 12px 32px rgba(23, 32, 29, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

body.modal-open {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  min-height: 100vh;
  padding: calc(env(safe-area-inset-top) + 18px) 14px calc(env(safe-area-inset-bottom) + 150px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 4px 2px 16px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: 0;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.import-panel,
.controls,
.mapping-panel,
.summary-panel,
.status-strip,
.list-header,
.student-card,
.empty-state {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.import-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 10px;
}

.file-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.file-picker span,
.primary-button,
.secondary-button,
.text-button,
.icon-button,
.update-button,
.student-action {
  display: inline-grid;
  min-height: 44px;
  place-items: center;
  border-radius: 7px;
  border: 1px solid transparent;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  cursor: pointer;
}

.file-picker span,
.primary-button {
  width: 100%;
  background: var(--accent);
  color: #fff;
}

.secondary-picker span {
  background: #eef4f0;
  color: var(--ink);
  border-color: var(--line);
}

.secondary-button,
.icon-button,
.update-button {
  background: #eef4f0;
  color: var(--ink);
  border-color: var(--line);
  padding: 0 14px;
}

.update-button {
  min-width: 72px;
  min-height: 40px;
  font-size: 13px;
}

.icon-button {
  width: 44px;
  min-width: 44px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.icon-button:disabled,
.update-button:disabled {
  opacity: 0.55;
}

.secondary-button {
  width: 100%;
}

.text-button {
  min-height: 38px;
  background: transparent;
  color: var(--accent-strong);
  padding: 0 4px;
}

.hidden {
  display: none !important;
}

.mapping-panel,
.summary-panel,
.controls,
.status-strip,
.list-header,
.empty-state {
  margin-top: 12px;
  padding: 12px;
}

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

.mapping-grid {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(110px, 38%) 1fr;
  gap: 8px;
  align-items: center;
}

.field-row label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.field-row select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.summary-item {
  background: #f8faf8;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
}

.summary-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

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

.warning {
  margin-bottom: 12px;
  border: 1px solid #fed7aa;
  border-radius: 7px;
  background: var(--warn-bg);
  color: var(--warn);
  padding: 10px;
  font-size: 14px;
  line-height: 1.35;
}

.controls {
  display: grid;
  gap: 10px;
}

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.mode-tab {
  display: grid;
  place-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8faf8;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  overflow-wrap: anywhere;
  white-space: normal;
}

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

.arrival-panel,
.activity-panel {
  display: grid;
  gap: 10px;
}

.arrival-blocks {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(190px, 78%);
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
}

.arrival-block {
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8faf8;
  color: var(--ink);
  padding: 9px 10px;
  text-align: left;
  scroll-snap-align: start;
}

.arrival-block strong,
.arrival-block span {
  display: block;
}

.arrival-block strong {
  font-size: 13px;
  line-height: 1.25;
}

.arrival-block span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.arrival-block.active {
  border-color: #97d7cf;
  background: var(--accent-soft);
}

.arrival-block.active strong {
  color: var(--accent-strong);
}

.arrival-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.activity-fields {
  display: grid;
  grid-template-columns: minmax(0, 0.82fr) minmax(0, 1.18fr);
  gap: 8px;
}

.arrival-fields label,
.activity-fields label {
  display: grid;
  gap: 5px;
  min-width: 0;
  width: 100%;
}

.arrival-fields span,
.activity-fields span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.arrival-fields input,
.arrival-fields select,
.activity-fields input {
  display: grid;
  align-items: center;
  width: 100%;
  min-height: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 0 9px;
  min-width: 0;
  max-width: 100%;
  font-size: 16px;
  line-height: 42px;
  text-align: center;
  overflow: hidden;
  -webkit-appearance: none;
  appearance: none;
}

.activity-fields input {
  min-height: 40px;
  height: 40px;
  line-height: 40px;
}

.cutoff-fields {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.75fr);
  gap: 8px;
  width: 100%;
  min-width: 0;
}

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

.arrival-stats div {
  display: grid;
  align-content: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8faf8;
  padding: 8px 6px;
  text-align: center;
}

.activity-panel .arrival-stats div {
  padding: 6px 5px;
}

.arrival-stats span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.arrival-stats strong {
  display: block;
  margin-top: 2px;
  font-size: 18px;
}

.activity-panel .arrival-stats strong {
  font-size: 16px;
}

.selected-activity {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  border: 1px solid #97d7cf;
  border-radius: 7px;
  background: var(--accent-soft);
  padding: 10px;
}

.selected-activity span {
  display: block;
  color: var(--accent-strong);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.selected-activity strong {
  display: block;
  margin-top: 3px;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

body[data-mode="activities"] .search-wrap,
body[data-mode="activities"] .tabs,
body[data-mode="activities"] .status-strip,
body[data-mode="activities"] .list-header {
  display: none;
}

.search-wrap {
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: center;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fdfefd;
}

.search-wrap span {
  color: var(--muted);
  text-align: center;
  font-size: 22px;
}

.search-wrap input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

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

.tab {
  display: grid;
  place-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8faf8;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  overflow-wrap: anywhere;
  white-space: normal;
}

.tab span {
  display: block;
  margin-top: 1px;
  color: inherit;
}

.tab.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: #97d7cf;
}

.status-strip {
  box-shadow: none;
}

.status-strip div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.status-strip strong {
  color: var(--ink);
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: none;
}

.list-header strong {
  display: inline-flex;
  min-width: 42px;
  height: 42px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 18px;
}

.student-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  scroll-margin-top: 16px;
}

.student-card {
  padding: 12px;
}

.student-card.removed {
  background: #fbfbfa;
  opacity: 0.78;
}

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

.student-name {
  min-width: 0;
}

.student-name h3,
.student-name-button span {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.student-name-button {
  display: grid;
  justify-items: start;
  gap: 3px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  text-align: left;
}

.student-name-button small {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  border: 1px solid #97d7cf;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 800;
}

.student-name p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.badge {
  height: 28px;
  border-radius: 999px;
  padding: 5px 9px;
  background: #eef4f0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.badge.checked {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.badge.removed {
  background: #fee2e2;
  color: var(--danger);
}

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

.meta-item {
  min-width: 0;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.meta-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.meta-item strong {
  display: block;
  margin-top: 2px;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.notes {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.notes strong {
  color: var(--ink);
}

.remarks-field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.remarks-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.remarks-field textarea {
  width: 100%;
  min-height: 64px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fdfefd;
  color: var(--ink);
  padding: 9px 10px;
  line-height: 1.35;
}

.remarks-field textarea:disabled {
  opacity: 0.6;
}

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

.student-action.check {
  background: var(--accent);
  color: #fff;
}

.student-action.undo {
  background: #eef4f0;
  border-color: var(--line);
  color: var(--ink);
}

.student-action.absent {
  background: var(--warn-bg);
  border-color: #fed7aa;
  color: var(--warn);
}

.student-action:disabled {
  cursor: default;
  opacity: 0.45;
}

.empty-state {
  margin-top: 12px;
  padding: 28px 18px;
  text-align: center;
}

.empty-state p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.4;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  align-items: end;
  background: rgba(23, 32, 29, 0.35);
  padding: 18px 12px calc(env(safe-area-inset-bottom) + 12px);
}

.modal-sheet {
  width: min(100%, 760px);
  max-height: min(78vh, 720px);
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 18px 48px rgba(23, 32, 29, 0.22);
}

.modal-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  border-bottom: 1px solid var(--line);
  padding: 14px;
}

.modal-summary {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.modal-list {
  display: grid;
  gap: 8px;
  max-height: calc(min(78vh, 720px) - 92px);
  overflow-y: auto;
  padding: 10px;
}

.passport-sheet {
  max-height: min(86vh, 760px);
}

.passport-preview {
  display: grid;
  gap: 10px;
  max-height: calc(min(86vh, 760px) - 98px);
  overflow: auto;
  padding: 10px;
  background: #f8faf8;
}

.passport-scan {
  display: grid;
  gap: 8px;
}

.passport-scan strong {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.passport-image {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.passport-pdf {
  width: 100%;
  min-height: 62vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.passport-open-link {
  text-decoration: none;
}

.modal-student {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fdfefd;
  padding: 10px;
}

.modal-student h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
}

.modal-student p,
.modal-student span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
}

.modal-actions strong {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.modal-actions strong.is-present {
  color: var(--accent-strong);
}

.modal-empty {
  padding: 18px 8px;
  color: var(--muted);
  text-align: center;
}

@media (min-width: 700px) {
  .mode-tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .secondary-button {
    width: auto;
  }

  .arrival-fields {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .activity-fields {
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  }

  .arrival-stats {
    grid-template-columns: repeat(4, 1fr);
  }

  .tabs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

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

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

  .modal-student {
    grid-template-columns: 1fr 220px;
    align-items: center;
  }

  .modal-actions {
    grid-template-columns: 1fr 1fr;
    align-items: center;
  }

  .modal-actions strong {
    grid-column: 1 / -1;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  h1 {
    font-size: 27px;
  }

  .tab {
    font-size: 11px;
  }

  .activity-fields span {
    font-size: 10px;
  }

  .activity-fields input {
    padding: 0 8px;
  }

  .arrival-blocks {
    grid-auto-columns: minmax(230px, 86%);
  }

  .cutoff-fields {
    grid-template-columns: 1fr;
  }
}
