/* Mobile-first: base rules target the smallest screens (320px+),
   larger layouts are layered on with min-width media queries. */

:root {
  --color-bg: #f7f8fa;
  --color-surface: #ffffff;
  --color-text: #1b1f24;
  --color-muted: #5b6470;
  --color-border: #dfe3e8;
  --color-primary: #2f6fed;
  --color-primary-active: #2559c4;
  --color-danger: #c0392b;
  --radius: 10px;
  --tap-min: 44px;
  --header-h: 56px;
}

* {
  box-sizing: border-box;
}

html {
  /* Fluid base font size: 16px at 320px wide, 18px at 1920px wide. */
  font-size: clamp(16px, 15.3px + 0.18vw, 18px);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

h1 {
  font-size: clamp(1.4rem, 1.1rem + 1vw, 2rem);
  margin: 0 0 1rem;
}

a {
  color: var(--color-primary);
}

/* ---------- Header / hamburger nav ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 1rem;
  max-width: 960px;
  margin: 0 auto;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
  color: var(--color-text);
}

.nav-toggle {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: var(--tap-min);
  height: var(--tap-min);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--color-text);
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.nav-toggle[aria-expanded="true"] span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.nav-toggle[aria-expanded="true"] span:nth-child(2) {
  opacity: 0;
}
.nav-toggle[aria-expanded="true"] span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.nav-menu {
  display: flex;
  flex-direction: column;
  max-height: 0;
  overflow: hidden;
  background: var(--color-surface);
  border-bottom: 1px solid transparent;
  transition: max-height 0.2s ease;
}

.nav-menu.is-open {
  max-height: 320px;
  border-bottom-color: var(--color-border);
}

.nav-menu a {
  display: flex;
  align-items: center;
  min-height: var(--tap-min);
  padding: 0 1.25rem;
  text-decoration: none;
  color: var(--color-text);
  font-weight: 500;
}

.nav-menu a:active,
.nav-menu a:focus-visible {
  background: var(--color-bg);
}

/* Desktop / tablet: inline nav, hide the hamburger */
@media (min-width: 640px) {
  .nav-toggle {
    display: none;
  }

  .nav-menu {
    max-height: none;
    overflow: visible;
    flex-direction: row;
    gap: 1.5rem;
    max-width: 960px;
    margin: 0 auto;
    padding: 0 1rem;
    box-sizing: border-box;
  }

  .nav-menu a {
    min-height: auto;
    padding: 0;
  }
}

/* ---------- Page layout ---------- */

.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

/* ---------- Home page ---------- */

.lede {
  color: var(--color-muted);
  margin: 0 0 1.5rem;
  max-width: 60ch;
}

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  min-width: 160px;
  flex: 1 1 160px;
}

.stat-value {
  font-size: clamp(1.5rem, 1.2rem + 1vw, 2rem);
  font-weight: 700;
  line-height: 1.1;
}

.stat-label {
  color: var(--color-muted);
  font-size: 0.85rem;
}

.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 560px) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 960px) {
  .card-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.feature-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-decoration: none;
  color: var(--color-text);
  min-height: 44px;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.feature-card:hover,
.feature-card:focus-visible {
  border-color: var(--color-primary);
  transform: translateY(-2px);
}

.feature-icon {
  width: 28px;
  height: 28px;
  color: var(--color-primary);
}

.feature-title {
  font-weight: 700;
}

.feature-desc {
  color: var(--color-muted);
  font-size: 0.9rem;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

/* ---------- Forms & buttons ---------- */

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
  max-width: 420px;
}

.form-group label {
  font-weight: 600;
  font-size: 0.9rem;
}

input[type="text"] {
  min-height: var(--tap-min);
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  /* 16px prevents iOS Safari from auto-zooming on focus */
  font-size: 16px;
  width: 100%;
  background: var(--color-surface);
  color: var(--color-text);
}

input[type="text"]:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-min);
  min-width: var(--tap-min);
  padding: 0.6rem 1.25rem;
  border: 0;
  border-radius: 8px;
  background: var(--color-primary);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

button:hover {
  background: var(--color-primary-active);
}

button:disabled {
  background: var(--color-border);
  color: var(--color-muted);
  cursor: not-allowed;
}

.status-message {
  min-height: 1.5em;
  margin-top: 0.75rem;
  color: var(--color-muted);
}

.status-message--success {
  color: #1e7e34;
  font-weight: 600;
}

.status-message--error {
  color: var(--color-danger);
  font-weight: 600;
}

.success-banner {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.75rem;
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius);
  background: #e6f4ea;
  border: 1px solid #b7ddc0;
  color: #1e7e34;
  font-weight: 600;
}

.success-banner__icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

/* ---------- Person thumbnails (people list) ---------- */

.person-thumb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--color-bg);
  vertical-align: middle;
}

.person-thumb--placeholder {
  color: var(--color-muted);
  font-weight: 700;
  border: 1px solid var(--color-border);
}

/* ---------- Camera capture ---------- */

.capture-stage {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 480px;
}

.video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #0d0f12;
  border-radius: var(--radius);
  overflow: hidden;
}

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

/* ---------- Responsive tables (attendance / people) ---------- */

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

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

th,
td {
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
}

thead {
  background: var(--color-bg);
}

/* Below 560px, reflow each row into a labeled card instead of a
   horizontally-scrolling table, so nothing spills past the viewport. */
@media (max-width: 559px) {
  .table-wrap table,
  .table-wrap thead,
  .table-wrap tbody,
  .table-wrap th,
  .table-wrap td,
  .table-wrap tr {
    display: block;
  }

  .table-wrap thead {
    position: absolute;
    left: -9999px;
  }

  .table-wrap tr {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    padding: 0.25rem 0.75rem;
  }

  .table-wrap td {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    border-bottom: 1px solid var(--color-bg);
    padding: 0.6rem 0;
  }

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

  .table-wrap td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--color-muted);
  }
}
