:root {
  --bg: #f4f7fa;
  --bg2: #eef3f8;
  --card: #ffffff;
  --text: #17202a;
  --muted: #64748b;
  --border: #d8e0e8;
  --primary: #168f8b;
  --primary-dark: #0c6e7a;
  --secondary: #ecf0f1;
  --secondary-text: #202938;
  --success: #14804a;
  --danger: #b42318;
  --warning: #b7791f;
  --soft-blue: #e9fbf9;
  --shadow: 0 12px 32px rgba(18, 35, 47, 0.08);
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; padding: 18px 20px 22px; }
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}
.app-header h1 { margin: 0; font-size: clamp(1.8rem, 2.4vw, 2.3rem); }
.app-header p { margin: 8px 0 0; color: var(--muted); }
.api-pill {
  padding: 10px 14px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
  box-shadow: var(--shadow);
}
.api-pill.online { color: #166534; background: #ecfdf5; border-color: #bbf7d0; }
.api-pill.offline { color: #92400e; background: #fff7ed; border-color: #fed7aa; }

.screen-grid-2, .split-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.stack-12 > * + *, .stack-16 > * + * { margin-top: 16px; }
.card, .section-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card-title, .section-card h3 { margin: 0; font-size: 1.35rem; }
.card-subtitle { margin: 8px 0 0; color: var(--muted); font-size: 0.96rem; }
.action-block { display: flex; flex-direction: column; gap: 6px; }
.action-help { color: var(--muted); font-size: 0.86rem; line-height: 1.4; }
.message-box {
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #f8fafc;
}
.message-box.info { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }
.message-box.success { background: #ecfdf5; border-color: #bbf7d0; color: #166534; }
.message-box.warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.message-box.error { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.offline-banner {
  margin-bottom: 16px;
  font-weight: 700;
}
.offline-queue-detail {
  margin-top: 8px;
  font-size: 0.95rem;
  line-height: 1.35;
}
.offline-queue-list {
  display: grid;
  gap: 12px;
}
.offline-queue-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}
.offline-queue-item h3 {
  margin: 0;
  font-size: 1.05rem;
}
.offline-status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 800;
  vertical-align: middle;
}
.offline-status-waiting { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }
.offline-status-retrying { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.offline-status-failed { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.offline-status-synced { background: #ecfdf5; border-color: #bbf7d0; color: #166534; }
.offline-queue-item p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.35;
}
.offline-queue-item details {
  margin-top: 10px;
}
.offline-queue-item pre {
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8fafc;
}
.offline-queue-actions {
  display: grid;
  gap: 8px;
  min-width: 130px;
}
.message-list { margin: 8px 0 0; padding-left: 18px; }
.message-list li + li { margin-top: 4px; }

.button {
  min-height: 48px;
  padding: 12px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  line-height: 1.2;
  text-align: center;
  vertical-align: middle;
}
.button:disabled { opacity: .65; cursor: not-allowed; }
.button-primary { background: var(--primary); color: #fff; }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { background: var(--secondary); color: var(--secondary-text); border-color: #d5dbe1; }
.button-service { background: var(--secondary); color: var(--secondary-text); border-color: #d5dbe1; }
.button-danger { background: var(--danger); color: #fff; }
.button-success { background: var(--success); color: #fff; }
.button-warning { background: var(--warning); color: #fff; }
.button-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.button-wide { width: 100%; justify-content: flex-start; text-align: left; }
.button-inline {
  min-height: 34px;
  padding: 6px 10px;
  margin-left: 8px;
}
.home-path-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, .8fr);
  gap: 20px;
  align-items: stretch;
}
.path-card {
  min-height: 100%;
}
.primary-path {
  border-color: #b7dfff;
  background: linear-gradient(180deg, #ffffff 0%, #f7fbff 100%);
}
.primary-action-grid, .service-action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.service-picker {
  margin-top: 20px;
}
.home-action {
  min-height: 64px;
  padding: 16px 20px;
  font-size: 1.05rem;
}
.home-action-button {
  align-items: center;
  border-radius: var(--radius);
  font-weight: 800;
  line-height: 1.25;
  white-space: normal;
}
.home-action-button.button-primary,
.home-action-button.button-secondary,
.home-action-button.button-service {
  box-shadow: inset 0 -1px 0 rgba(17, 24, 39, 0.08);
}
.service-action-grid .action-block {
  min-width: 0;
}
.stepper {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.stepper-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  font-weight: 700;
}
.stepper-item.active {
  border-color: #91cdfa;
  background: #eff8ff;
  color: var(--primary-dark);
}
.stepper-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--secondary);
  color: var(--secondary-text);
}
.stepper-item.active .stepper-number {
  background: var(--primary);
  color: #fff;
}

.bottom-actions, .inline-actions, .toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.bottom-actions .button, .inline-actions .button, .toolbar-actions .button {
  min-width: 150px;
}
.form-grid, .lookup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 700; font-size: 0.94rem; }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 46px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
  padding: 11px 12px;
  color: var(--text);
}
.field input.invalid, .field select.invalid, .field textarea.invalid {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, .12);
}
.field-error {
  color: var(--danger);
  font-size: 0.82rem;
  font-weight: 700;
}
.field textarea { min-height: 110px; resize: vertical; }
.field-hint { color: var(--muted); font-size: 0.82rem; }
.readonly-box {
  min-height: 120px;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #f8fafc;
  white-space: pre-wrap;
}

.returning-youth-search {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8fafc;
}
.returning-youth-actions {
  align-items: stretch;
}
.returning-youth-actions input {
  flex: 1 1 240px;
  min-height: 48px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 11px 12px;
}
.returning-youth-results {
  margin-top: 10px;
}
.confirmation-details {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}
.confirmation-detail-row {
  display: grid;
  grid-template-columns: minmax(120px, .45fr) minmax(0, 1fr);
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.confirmation-detail-row:last-child {
  border-bottom: 0;
}
.confirmation-detail-row span {
  color: var(--muted);
}
.confirmation-detail-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}
.event-card-list {
  display: none;
  gap: 12px;
}
.event-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  background: #fff;
}
.event-card input {
  margin-top: 4px;
}
.event-card-body {
  display: grid;
  gap: 5px;
  line-height: 1.35;
}
.event-card-title {
  font-weight: 800;
  color: var(--text);
}
.event-card-description {
  white-space: pre-wrap;
  color: var(--muted);
}
.event-flyer {
  display: grid;
  gap: 7px;
  align-items: start;
  width: fit-content;
}
.event-flyer-preview {
  display: block;
  width: min(100%, 320px);
  max-height: 300px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
.event-flyer a {
  font-weight: 800;
  color: var(--primary);
}
table { width: 100%; border-collapse: collapse; min-width: 760px; }
thead th {
  position: sticky; top: 0; background: #f8fafc; color: #374151;
  text-align: left; font-size: 0.86rem; border-bottom: 1px solid var(--border); padding: 12px;
}
tbody td { padding: 12px; border-bottom: 1px solid #edf2f7; font-size: 0.93rem; vertical-align: top; }
tr:hover td { background: #fafcff; }

.calendar-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}
.calendar-cell, .calendar-day-header {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}
.calendar-day-header {
  padding: 12px;
  text-align: center;
  font-weight: 700;
  background: #f8fafc;
}
.calendar-cell {
  min-height: 150px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.calendar-cell.today { background: #dcffdc; }
.calendar-day-number { font-weight: 700; font-size: .95rem; }
.calendar-events { display: flex; flex-direction: column; gap: 6px; overflow: auto; }
.calendar-event {
  padding: 6px 8px;
  border-radius: var(--radius);
  border: 1px solid #cde5ff;
  background: var(--soft-blue);
  font-size: .78rem;
  line-height: 1.3;
}
.calendar-empty { background: #f8fafc; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 700;
  background: #eef6ff;
  color: #15558a;
  border: 1px solid #cde5ff;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,.45); }
.modal-card {
  position: relative;
  width: min(760px, calc(100vw - 28px));
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(15,23,42,.22);
  padding: 20px;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}
.modal-header h2 { margin: 0; }
.modal-header p { margin: 6px 0 0; color: var(--muted); }
.icon-button {
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--border);
  background: #fff; font-size: 1.5rem; line-height: 1;
}
.checkbox-list { display: grid; gap: 10px; margin-bottom: 16px; }
.purpose-search-row {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}
.purpose-search-row label,
.purpose-group h3 {
  margin: 0;
  font-weight: 800;
}
.purpose-search-row input {
  width: 100%;
  min-height: 46px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
  padding: 11px 12px;
  color: var(--text);
}
.purpose-group {
  display: grid;
  gap: 8px;
}
.purpose-group + .purpose-group {
  margin-top: 16px;
}
.purpose-group-options {
  display: grid;
  gap: 10px;
}
.checkbox-item {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px; border: 1px solid var(--border);
  border-radius: var(--radius); background: #fff;
}
.checkbox-item.event-derived {
  background: #f8fbff;
  border-color: #bfdbfe;
}
.purpose-option .checkbox-text {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.purpose-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: .75rem;
  font-weight: 800;
  line-height: 1;
}
.checkbox-meta { display: flex; flex-direction: column; gap: 4px; }
.checkbox-meta small { color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; }
.toast-container {
  position: fixed; right: 16px; bottom: 16px; z-index: 1100; display: flex; flex-direction: column; gap: 10px;
}
.toast {
  min-width: 260px; max-width: 420px; padding: 12px 14px; border-radius: var(--radius); box-shadow: var(--shadow); color: #fff;
}
.toast.success { background: #15803d; }
.toast.error { background: #b91c1c; }
.toast.info { background: #1d4ed8; }
.toast.warn { background: #a16207; }

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1900;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, .52);
  padding: 24px;
}
.loading-panel {
  width: min(420px, 100%);
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(15,23,42,.22);
  padding: 26px;
  text-align: center;
  display: grid;
  gap: 12px;
}
.loading-panel h2 {
  margin: 0;
  font-size: 1.45rem;
}
.loading-panel p {
  margin: 0;
  color: var(--muted);
}
.loading-spinner {
  width: 44px;
  height: 44px;
  border: 4px solid #dbeafe;
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto;
  animation: spin .9s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.privacy-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111827;
  color: #fff;
  padding: 24px;
}
.privacy-panel {
  width: min(460px, 100%);
  text-align: center;
  display: grid;
  gap: 16px;
}
.privacy-panel h2 {
  margin: 0;
  font-size: 2rem;
}
.privacy-panel p {
  margin: 0;
  color: #d1d5db;
}

.staff-attendance-toolbar .field {
  gap: 8px;
}

.staff-attendance-toolbar .field .button,
.staff-attendance-toolbar .field button {
  width: 100%;
}

.attendance-counts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.attendance-counts > div {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  padding: 12px;
  display: grid;
  gap: 4px;
}

.attendance-counts strong {
  font-size: 1.35rem;
}

.attendance-counts span {
  color: var(--muted);
  font-size: .86rem;
  font-weight: 700;
}

.attendance-list {
  display: grid;
  gap: 12px;
}

.attendance-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  padding: 14px;
}

.attendance-row.cancelled {
  background: #f8fafc;
  opacity: .78;
}

.attendance-person h3 {
  margin: 0;
  font-size: 1.05rem;
}

.attendance-person p {
  margin: 5px 0 0;
  color: var(--muted);
}

.attendance-status {
  min-width: 112px;
  border-radius: 999px;
  padding: 8px 10px;
  text-align: center;
  font-weight: 800;
  border: 1px solid var(--border);
  background: #f8fafc;
}

.attendance-status.attended { color: #166534; background: #ecfdf5; border-color: #bbf7d0; }
.attendance-status.no-show { color: #92400e; background: #fffbeb; border-color: #fde68a; }
.attendance-status.cancelled { color: #475569; background: #f1f5f9; border-color: #cbd5e1; }
.attendance-status.unmarked { color: #1d4ed8; background: #eff6ff; border-color: #bfdbfe; }

.attendance-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.attendance-actions .button {
  min-width: 112px;
}

@media (max-width: 980px) {
  .screen-grid-2, .split-form, .form-grid, .lookup-grid, .home-path-grid { grid-template-columns: 1fr; }
  .app-header { flex-direction: column; align-items: stretch; }
  .calendar-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  table { min-width: 640px; }
  .attendance-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
  .attendance-status {
    width: fit-content;
  }
  .attendance-actions {
    justify-content: stretch;
  }
  .attendance-actions .button {
    flex: 1 1 120px;
  }
  .offline-queue-item {
    grid-template-columns: 1fr;
  }
  .offline-queue-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .app-shell { padding: 14px; }
  .card, .section-card { padding: 16px; border-radius: var(--radius); }
  .calendar-grid { grid-template-columns: 1fr; }
  .bottom-actions, .inline-actions, .toolbar-actions, .modal-actions { flex-direction: column; }
  .button { width: 100%; }
  .primary-action-grid, .service-action-grid, .stepper { grid-template-columns: 1fr; }
  .attendance-counts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .event-card-list { display: grid; }
  .event-table-wrap { display: none; }
}

.checkbox-item.compact { align-items: center; padding: 10px 12px; }
.checkbox-item.compact .checkbox-text { font-size: 1rem; }
.checkbox-item.compact input { width: 18px; height: 18px; }

.utility-top-row { display:flex; gap:12px; align-items:end; flex-wrap:wrap; }
.utility-grow { flex:1 1 520px; }
.utility-refresh { min-width:220px; }
.utility-form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 980px) { .utility-top-row { flex-direction:column; align-items:stretch; } .utility-refresh { width:100%; } }


.pantry-qr-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8fafc;
  padding: 16px;
  display: grid;
  gap: 14px;
}

.pantry-qr-title {
  margin: 0;
  font-size: 1.1rem;
}

.pantry-qr-box {
  min-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: #fff;
  padding: 14px;
}

.pantry-qr-image {
  max-width: min(300px, 100%);
  max-height: 300px;
  object-fit: contain;
}

.password-reset-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.password-reset-panel {
  width: min(100%, 520px);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

.password-reset-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.password-reset-brand img {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.password-reset-panel h1 {
  margin: 0;
  font-size: 1.7rem;
}

.password-reset-panel .field-stack {
  display: grid;
  gap: 16px;
  margin-top: 22px;
}

.password-reset-panel label {
  display: grid;
  gap: 7px;
  font-weight: 700;
}

.password-reset-panel input {
  width: 100%;
}

.password-reset-status {
  min-height: 24px;
  margin: 16px 0 0;
  font-weight: 700;
}

.password-reset-status.error { color: #b91c1c; }
.password-reset-status.success { color: #166534; }
