:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --panel: #ffffff;
  --border: #dbe3ef;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --ok: #0f766e;
  --danger: #b91c1c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body.sidebar-open {
  overflow: hidden;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.82rem;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.login-form input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-top: 6px;
}

.login-form button {
  padding: 12px 16px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

.login-error {
  color: var(--danger);
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 12px;
  padding: 10px 12px;
}

.page {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
  position: relative;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 19;
}

.sidebar {
  background: #0f172a;
  color: white;
  padding: 24px;
}

.sidebar h1 {
  margin: 0;
  font-size: 1.8rem;
}

.subhead {
  color: #cbd5e1;
  margin-bottom: 24px;
}

.class-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.class-link {
  display: block;
  padding: 14px;
  border-radius: 16px;
  color: white;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid transparent;
}

.class-link.active {
  background: rgba(37, 99, 235, 0.35);
  border-color: rgba(191, 219, 254, 0.6);
}

.class-name,
.class-meta {
  display: block;
}

.class-meta {
  color: #cbd5e1;
  font-size: 0.9rem;
  margin-top: 4px;
}

.content {
  padding: 24px;
  min-width: 0;
}

.content > *,
.content-header > div,
.roll-sheet-header > div,
.visitors-header > div,
.tool-card,
.stat-card {
  min-width: 0;
}

.mobile-toolbar {
  display: none;
}

.content-header,
.stats,
.roll-sheet,
.visitors-panel,
.tool-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
}

.content-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 20px;
}

.content-header h2 {
  margin: 0 0 8px;
}

.muted-copy {
  color: var(--muted);
  margin-bottom: 0;
}

.header-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 220px;
}

.header-actions input,
.header-actions button,
.inline-form input,
.inline-form button {
  font: inherit;
}

.header-actions input,
.inline-form input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.header-actions button,
.inline-form button {
  padding: 12px 16px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

.secondary-button {
  background: #e2e8f0;
  color: #0f172a;
}

.stats {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  padding: 16px;
}

.stat-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}

.stat-label {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
}

.toolbar-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.anonymous-counter-panel {
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 20px;
  background: linear-gradient(135deg, #eff6ff, #ffffff);
  border: 1px solid #bfdbfe;
  border-radius: 20px;
  position: sticky;
  top: 12px;
  z-index: 8;
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.12);
}

.counter-kicker {
  display: inline-block;
  margin-bottom: 6px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.anonymous-counter-copy h3 {
  margin: 0 0 8px;
}

.anonymous-counter-copy p {
  margin: 0;
  color: var(--muted);
}

.anonymous-counter-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

.counter-button {
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 18px;
  background: var(--accent);
  color: white;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.22);
}

.counter-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  box-shadow: none;
}

.counter-total-card {
  min-width: 132px;
  padding: 12px 18px;
  border-radius: 18px;
  border: 1px solid #bfdbfe;
  background: white;
  text-align: center;
}

.counter-total-card span,
.counter-total-card strong,
.counter-total-card small {
  display: block;
}

.counter-total-card span,
.counter-total-card small {
  color: var(--muted);
}

.counter-total-card strong {
  font-size: 2rem;
  line-height: 1.1;
}

.tool-card {
  padding: 18px;
}

.tool-card h3,
.roll-sheet-header h3,
.visitors-header h3 {
  margin-top: 0;
}

.inline-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.inline-form input {
  flex: 1 1 220px;
}

.roll-sheet,
.visitors-panel {
  margin-top: 16px;
  padding: 20px;
}

.roll-sheet-header,
.visitors-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.selected-date-card {
  min-width: 132px;
  padding: 12px 14px;
  border-radius: 16px;
  background: #f8fafc;
  border: 1px solid var(--border);
}

.selected-date-card span,
.selected-date-card strong,
.selected-date-card small {
  display: block;
}

.selected-date-card span,
.selected-date-card small {
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
}

.mobile-attendance-list {
  display: none;
}

.mobile-date-strip {
  display: none;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 780px;
}

th,
 td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.student-col {
  position: sticky;
  left: 0;
  background: white;
  text-align: left;
  min-width: 220px;
  z-index: 1;
}

.student-name {
  font-weight: 600;
}

.date-button {
  width: 100%;
  padding: 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
}

.date-button.selected {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.date-button span,
.date-button small {
  display: block;
}

.date-button small {
  color: var(--muted);
}

.check-cell {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: white;
  cursor: pointer;
}

.check-cell.checked,
.visitor-item.checked {
  background: #dcfce7;
  border-color: #16a34a;
}

.check-cell input,
.visitor-item input {
  width: 22px;
  height: 22px;
}

.visitor-list {
  display: grid;
  gap: 12px;
}

.visitor-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #f8fafc;
}

.mobile-check-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #f8fafc;
}

.mobile-check-copy {
  display: grid;
  gap: 4px;
}

.mobile-check-copy strong {
  font-size: 1rem;
}

.mobile-check-copy small {
  color: var(--muted);
}

.mobile-check-card input {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
}

.empty-state {
  margin: 0;
  color: var(--muted);
}

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

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(88vw, 320px);
    overflow: auto;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 20;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .mobile-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
  }

  .mobile-nav-toggle {
    min-height: 44px;
    padding-inline: 18px;
    white-space: nowrap;
  }

  .mobile-class-summary {
    display: grid;
    gap: 2px;
    min-width: 0;
  }

  .mobile-class-summary strong,
  .mobile-class-summary span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .content-header p,
  .tool-card p,
  .visitors-header p,
  .roll-sheet-header p {
    overflow-wrap: anywhere;
  }

  .stats,
  .toolbar-grid {
    grid-template-columns: 1fr;
  }

  .anonymous-counter-panel {
    display: grid;
    gap: 14px;
    top: 72px;
  }

  .anonymous-counter-controls {
    justify-content: space-between;
  }

  .content-header,
  .roll-sheet-header,
  .visitors-header {
    display: grid;
  }

  .header-actions {
    min-width: 0;
  }

  .header-actions button,
  .inline-form button,
  .date-button,
  .check-cell,
  .visitor-item input,
  .mobile-check-card,
  .mobile-check-card input,
  .login-form button {
    min-height: 44px;
  }
}

@media (max-width: 820px) {
  .content {
    padding: 16px;
  }

  .sidebar {
    padding: 20px 16px 28px;
  }

  .sidebar h1 {
    font-size: 1.4rem;
  }

  .content-header,
  .roll-sheet,
  .visitors-panel,
  .tool-card {
    padding: 16px;
  }

  .stats {
    gap: 12px;
    padding: 12px;
  }

  .stat-card {
    padding: 14px;
  }

  .table-wrap {
    display: none;
  }

  .mobile-attendance-list {
    display: grid;
    gap: 12px;
    margin-top: 16px;
  }

  .mobile-date-strip {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(108px, 1fr);
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 4px;
    margin-top: 16px;
  }

  .roll-sheet-header {
    gap: 12px;
  }

  .selected-date-card {
    min-width: 0;
  }

  .inline-form {
    display: grid;
  }

  .counter-button {
    width: 64px;
    height: 64px;
  }

  .counter-total-card {
    flex: 1 1 auto;
    min-width: 0;
  }

  .inline-form input {
    min-height: 44px;
  }
}
