/* ============================================================
   RESET & VARIABLES
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #1e3a5f;
  --primary-light: #2563eb;
  --accent: #f59e0b;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --danger: #ef4444;
  --success: #16a34a;
  --warning: #f59e0b;

  --lead:    #7c3aed;
  --senior:  #2563eb;
  --junior:  #16a34a;
  --trainee: #ea580c;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  font-size: 16px;
}

/* ============================================================
   APP SHELL
   ============================================================ */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  box-shadow: 0 0 40px rgba(0,0,0,0.08);
}

#app-header {
  background: var(--primary);
  color: white;
  padding: 0.8rem 1rem;
  padding-top: calc(0.8rem + env(safe-area-inset-top));
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

#page-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

#main-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ============================================================
   BOTTOM NAV
   ============================================================ */
#bottom-nav {
  display: flex;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 500;
  transition: color 0.15s;
}

.nav-btn.active {
  color: var(--primary);
}

.nav-icon {
  width: 22px;
  height: 22px;
}

/* ============================================================
   VIEW HEADER (week/month nav)
   ============================================================ */
.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.view-period {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text);
}

.icon-btn {
  width: 2rem;
  height: 2rem;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  background: var(--card-bg);
  cursor: pointer;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  line-height: 1;
  flex-shrink: 0;
}

.icon-btn:active {
  background: var(--bg);
}

/* ============================================================
   SCHEDULE VIEW
   ============================================================ */
.schedule-days {
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.day-section {
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--card-bg);
}

.day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.45rem 0.75rem;
  background: #dde6f0;
}

.day-section.today .day-header {
  background: var(--primary);
  color: white;
}

.day-name {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.day-date-label {
  font-size: 0.8rem;
  font-weight: 500;
}

.no-classes {
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ============================================================
   CLASS CARDS
   ============================================================ */
.class-card {
  padding: 0.55rem 0.75rem;
  border-top: 1px solid var(--border);
}

.class-card.cancelled {
  opacity: 0.55;
  background: #f8f8f8;
}

.admin-class-card {
  cursor: pointer;
}

.admin-class-card:active {
  background: #f0f5ff;
}

.class-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.2rem;
}

.class-title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.class-time {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--primary-light);
  flex-shrink: 0;
}

.class-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.class-meta-row {
  display: flex;
  gap: 0.6rem;
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.staff-ok   { color: var(--success); font-weight: 600; }
.staff-low  { color: var(--danger);  font-weight: 600; }
.staff-high { color: var(--warning); font-weight: 600; }

.member-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.member-chip {
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.73rem;
  font-weight: 500;
  color: white;
}

.no-staff {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

.cancelled-badge {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--danger);
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.tag-oneoff {
  font-size: 0.63rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #7c3aed;
  background: #ede9fe;
  padding: 2px 6px;
  border-radius: 10px;
  letter-spacing: 0.04em;
}

.override-badge {
  font-size: 0.63rem;
  font-weight: 700;
  background: #fef3c7;
  color: #92400e;
  padding: 2px 6px;
  border-radius: 10px;
}

.edit-hint {
  font-size: 0.7rem;
  color: var(--primary-light);
  margin-top: 0.25rem;
  font-style: italic;
}

/* ============================================================
   LEVEL COLORS (shared)
   ============================================================ */
.level-lead    { background: var(--lead); }
.level-senior  { background: var(--senior); }
.level-junior  { background: var(--junior); }
.level-trainee { background: var(--trainee); }

.level-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  color: white;
}

/* ============================================================
   PERSON VIEW
   ============================================================ */
.person-selector-bar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.member-select {
  flex: 1;
  padding: 0.45rem 0.6rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.875rem;
  background: var(--card-bg);
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
}

.person-schedule {
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.person-day {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--card-bg);
}

.person-day-header {
  background: #dde6f0;
  padding: 0.4rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.person-class-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--border);
}

.person-class-info {
  flex: 1;
  min-width: 0;
}

.person-class-info .class-name {
  display: block;
  margin-bottom: 1px;
}

.person-class-info .class-meta {
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* ============================================================
   EMPTY / UTILITY STATES
   ============================================================ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  gap: 0.5rem;
  color: var(--text-muted);
  text-align: center;
  font-size: 0.9rem;
}

.empty-text {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-style: italic;
  padding: 0.4rem 0;
}

.hidden { display: none !important; }

/* ============================================================
   ADMIN SUBNAV
   ============================================================ */
.admin-subnav {
  display: flex;
  background: var(--card-bg);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.subnav-btn {
  flex: 1;
  padding: 0.7rem 0;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.15s;
  margin-bottom: -2px;
}

.subnav-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.admin-body {
  padding: 0.75rem;
  padding-bottom: 1.5rem;
}

/* ============================================================
   ADMIN LOGIN
   ============================================================ */
.login-card {
  max-width: 320px;
  margin: 2rem auto;
  background: var(--card-bg);
  border-radius: 16px;
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  border: 1px solid var(--border);
}

.login-card h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
}

.login-card p {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

.login-card .form-group {
  width: 100%;
}

.error-text {
  color: var(--danger);
  font-size: 0.82rem;
  text-align: center;
}

/* ============================================================
   ADMIN SECTIONS
   ============================================================ */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}

.section-header h3 {
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.section-gap {
  margin-top: 1.5rem;
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.75rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  gap: 0.5rem;
}

.list-item-info {
  flex: 1;
  min-width: 0;
}

.list-item-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.list-item-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.list-item-actions {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  flex-shrink: 0;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  border: none;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.1s;
  text-align: center;
  white-space: nowrap;
}

.btn:active { opacity: 0.8; }

.btn-primary   { background: var(--primary); color: white; }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-danger    { background: var(--danger); color: white; }
.btn-ghost     { background: none; color: var(--text-muted); border: 1.5px solid var(--border); }

.btn-sm {
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
  border-radius: 6px;
}

.btn-full { width: 100%; }

.btn-icon-danger {
  background: none;
  border: none;
  color: #cbd5e1;
  cursor: pointer;
  font-size: 1rem;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}

.btn-icon-danger:active {
  color: var(--danger);
  background: #fee2e2;
}

.logout-btn {
  display: block;
  margin: 0.5rem auto 1rem;
  padding: 0.4rem 1.2rem;
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
}

/* ============================================================
   FORMS
   ============================================================ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  width: 100%;
}

.form-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.form-input {
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  width: 100%;
  background: var(--card-bg);
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-row {
  display: flex;
  gap: 0.6rem;
  width: 100%;
}

.form-row .form-group {
  flex: 1;
}

.warning-note {
  font-size: 0.8rem;
  color: #92400e;
  background: #fef3c7;
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
}

/* ============================================================
   MODAL
   ============================================================ */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 100;
}

#modal-container {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  z-index: 101;
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: env(safe-area-inset-bottom);
}

.modal-sheet {
  background: var(--card-bg);
  border-radius: 16px 16px 0 0;
  padding: 1.25rem 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto -0.25rem;
}

.modal-sheet h3 {
  font-size: 1.05rem;
  font-weight: 700;
}

.modal-subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: -0.5rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.modal-actions-stack {
  flex-direction: column;
}

.modal-actions-stack .btn {
  width: 100%;
}

/* Assign member checkboxes */
.member-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 45vh;
  overflow-y: auto;
}

.member-checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.65rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.1s, background 0.1s;
}

.member-checkbox-label:has(input:checked) {
  border-color: var(--primary-light);
  background: #eff6ff;
}

.member-checkbox-label input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  cursor: pointer;
  accent-color: var(--primary);
  flex-shrink: 0;
}

.member-checkbox-name {
  flex: 1;
  font-weight: 500;
  font-size: 0.875rem;
}

.assign-status {
  font-size: 0.78rem;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  font-weight: 600;
}

.status-default  { background: #f1f5f9; color: var(--text-muted); }
.status-override { background: #fef3c7; color: #92400e; }
