/* ============================================================================
 * app.css — shared base for all Calvin Center app pages.
 * ----------------------------------------------------------------------------
 * Tokens live in tokens.css (imported below). Page-specific styling
 * (lesson card, event card, feeding grid, usage grid, etc.) still lives
 * inline in each page's <style> block or its own stylesheet.
 *
 * hub.css (homepage, /volunteers/, /documents/) is separate — different
 * page archetype (centered card on scenic background, no header).
 * ========================================================================== */

@import url("/tokens.css");

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  /* Header height — simple single-row header. Pages with a taller two-row
     header (lessons, calendar) set body class `header-tall` to override. */
  --header-offset: 56px;
}

/* ── BASE ────────────────────────────────────────────────────────────────── */
html, body {
  height: 100%;
}

body {
  font-family: 'Source Sans 3', sans-serif;
  background: transparent;
  color: var(--text);
  min-height: 100vh;
  padding-top: calc(var(--header-offset) + env(safe-area-inset-top));
}

/* Pages that want a non-scrolling body (calendar, feeding, etc.)
   opt in with <body class="app-body-fixed">. Lessons does NOT use this —
   see web/lessons/style.css for its custom behavior. */
html:has(body.app-body-fixed) {
  height: 100%;
  overflow: hidden;
}
body.app-body-fixed {
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── SCENIC BACKGROUND ───────────────────────────────────────────────────── */
.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.sky-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #d4eaf5 0%, #e8f4fb 35%, var(--cream) 70%);
}

.sun {
  position: absolute;
  top: 10%;
  left: 12%;
  width: clamp(40px, 6vw, 72px);
  height: clamp(40px, 6vw, 72px);
  border-radius: 50%;
  background: radial-gradient(circle, #ffe98a 0%, #f5c842 60%, transparent 100%);
  box-shadow: 0 0 40px 10px rgba(245, 200, 66, 0.3);
}

.hill {
  position: absolute;
  bottom: 0;
  left: -5%;
  width: 110%;
  border-radius: 50% 50% 0 0 / 40% 40% 0 0;
}

.hill-far  { height: 38%; bottom: 18%; background: #c8dab0;       opacity: 0.55; }
.hill-mid  { height: 32%; bottom: 8%;  background: #a8c882;       opacity: 0.7; }
.hill-near { height: 22%;              background: var(--meadow); opacity: 0.85; }

/* Fence & horse SVG — only used on pages that include the markup
   (lessons / calendar). The CSS is here so any page could opt in. */
.fence {
  position: absolute;
  bottom: 19%;
  left: 0;
  width: 100%;
  z-index: 2;
}
.fence-svg { width: 100%; height: 60px; }

.horse-wrap {
  position: absolute;
  bottom: 19.5%;
  right: 8%;
  z-index: 3;
  width: clamp(70px, 10vw, 140px);
}
.horse-svg { width: 100%; height: auto; display: block; }

@media (max-width: 767px) {
  .horse-wrap { width: 80px; }
}

/* ── HEADER (simple, single-row) ─────────────────────────────────────────── */
.header {
  background: linear-gradient(135deg, var(--sky-dark) 0%, var(--sky) 100%);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  min-height: var(--header-offset);
  display: flex;
  align-items: center;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}

.header-title,
.header-title h1 {
  flex: 1;
  text-align: center;
  color: var(--white);
  font-family: 'Playfair Display', serif;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.2;
}
.header-title h1 { margin: 0; }

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-user {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
  font-weight: 500;
}

/* ── HEADER (tall, two-row variant — used by lessons & calendar) ─────────── */
body.header-tall {
  --header-offset: 76px;
}

.header.header-tall {
  flex-direction: column;
  align-items: stretch;
  padding: 0;
}

.header.header-tall .header-inner {
  flex-direction: column;
  gap: 0;
  max-width: 900px;
}

.header-row {
  width: 100%;
  display: flex;
  align-items: center;
}

.header-row-title {
  justify-content: center;
  padding: calc(8px + env(safe-area-inset-top)) 14px 2px;
}

.header-row-controls {
  justify-content: space-between;
  padding: 0 14px 6px;
  min-height: 34px;
}

.header-controls-left,
.header-controls-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-controls-left  { flex: 1; }
.header-controls-right { flex: 1; justify-content: flex-end; }

.header.header-tall .header-title,
.header.header-tall .header-title h1 {
  flex: 0 1 auto;
  font-size: 22px;
}

.header.header-tall .header-user {
  flex: 0 1 auto;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.85);
  text-align: center;
}

/* ── BACK / REFRESH PILL BUTTONS IN HEADER ───────────────────────────────── */
.header-back,
.refresh-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: var(--white);
  border-radius: 50px;
  padding: 5px 12px;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s;
}

.header-back:hover,
.header-back:active,
.refresh-btn:hover,
.refresh-btn:active {
  background: rgba(255, 255, 255, 0.25);
}

.header-back svg,
.refresh-btn svg {
  width: 18px;
  height: 18px;
}

.header-back img {
  width: 26px;
  height: 26px;
  display: block;
}

/* ── MAIN WRAPPERS ───────────────────────────────────────────────────────── */
main,
.main-narrow {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.25rem 1rem 4rem;
  position: relative;
  z-index: 1;
}

@media (max-width: 520px) {
  main,
  .main-narrow { padding: 1rem 0.85rem 4rem; }
}

/* For fixed-body pages that manage their own scroll region. */
.main-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px 40px;
  position: relative;
  z-index: 1;
}

/* ── LOADING / SPINNER ───────────────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 60px 0;
  color: var(--text);
  font-size: 15px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--cream-dark);
  border-top-color: var(--sky);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── ANIMATIONS ──────────────────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

/* ============================================================================
 * CENTRALIZED COMPONENTS — used across multiple app pages.
 * ========================================================================== */

/* ── TOAST (top, dark pill; with optional .toast-error red variant) ──────── */
.toast {
  position: fixed;
  top: calc(var(--header-offset) + env(safe-area-inset-top) + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--white);
  padding: 10px 20px;
  border-radius: 50px;
  font-size: 14px;
  font-weight: 500;
  z-index: 500;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { opacity: 1; }
.toast.toast-error { background: var(--red); }

/* ── BUTTONS ─────────────────────────────────────────────────────────────── */
.btn {
  padding: 7px 14px;
  font-size: 15px;
  font-family: 'Source Sans 3', sans-serif;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s;
  white-space: nowrap;
}
.btn:hover  { background: var(--cream); }
.btn:active { background: var(--cream-dark); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-sm { padding: 4px 11px; font-size: 14px; }

.btn-primary {
  background: var(--sky);
  color: var(--white);
  border-color: var(--sky-dark);
}
.btn-primary:hover  { background: var(--sky-dark); }
.btn-primary:active { background: var(--sky-dark); filter: brightness(0.92); }
.btn-primary:disabled:hover { background: var(--sky); }

.btn-danger {
  background: var(--white);
  color: var(--red);
  border-color: var(--red);
}
.btn-danger:hover  { background: var(--red-light); }
.btn-danger:active { background: var(--red-light); filter: brightness(0.94); }

/* Mobile: bump tap targets */
@media (max-width: 600px) {
  .btn    { min-height: 44px; padding: 10px 16px; }
  .btn-sm { min-height: 38px; padding: 8px 14px; font-size: 15px; }
}

/* ── MODAL (standard CRUD modal) ─────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.40);
  z-index: 200;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  padding-top: 6vh;
  overflow-y: auto;
}
.modal-overlay.open { display: flex; }
body:has(.modal-overlay.open) { overflow: hidden; }

.modal {
  background: var(--white);
  border-radius: 14px;
  width: 100%;
  max-width: 540px;
  max-height: 86vh;
  max-height: 86dvh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.2);
}

.modal-header {
  background: linear-gradient(135deg, var(--sky-dark) 0%, var(--sky) 100%);
  padding: 14px 18px;
  padding-left: max(18px, env(safe-area-inset-left));
  padding-right: max(18px, env(safe-area-inset-right));
  position: sticky;
  top: 0;
  z-index: 2;
}

.modal-title {
  font-family: 'Playfair Display', serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--white);
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.modal-header-actions .modal-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-body {
  padding: 18px;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 18px 18px;
  padding-bottom: max(18px, calc(18px + env(safe-area-inset-bottom)));
  position: sticky;
  bottom: 0;
  background: var(--white);
  border-top: 1px solid var(--cream-dark);
}

.modal-msg {
  font-size: 15px;
  color: var(--red);
  margin-top: 8px;
  min-height: 18px;
}

/* In-modal header action buttons (sticky save/cancel over gradient) */
.header-btn {
  background: rgba(255, 255, 255, 0.15);
  color: var(--white);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s;
  flex-shrink: 0;
  min-width: 72px;
  text-align: center;
}
.header-btn:hover  { background: rgba(255, 255, 255, 0.25); }
.header-btn:active { background: rgba(255, 255, 255, 0.35); }

.header-btn-save {
  background: var(--white);
  color: var(--sky-dark);
  border-color: var(--white);
  font-weight: 600;
}
.header-btn-save:hover  { background: var(--cream); }
.header-btn-save:active { background: var(--cream-dark); }

@media (max-width: 600px) {
  .modal-overlay { padding-top: 2vh; }
  .modal {
    max-height: 94vh;
    max-height: 94dvh;
  }
  .modal-body { padding: 14px; padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  .header-btn { min-height: 36px; padding: 8px 14px; }
}

/* ── CONFIRM OVERLAY ─────────────────────────────────────────────────────── */
.confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.40);
  z-index: 400;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.confirm-overlay.open { display: flex; }

.confirm-box {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 400px;
  width: 100%;
}
.confirm-msg {
  font-size: 17px;
  margin-bottom: 16px;
  line-height: 1.5;
  color: var(--text);
}
.confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ── FORM FIELDS (iOS Settings style, used across all app forms) ─────────── */
.field-group {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 12px;
}
.field-group > .field-row:first-of-type {
  border-radius: var(--radius) var(--radius) 0 0;
}
.field-group > .field-row:last-of-type {
  border-radius: 0 0 var(--radius) var(--radius);
}

.field-group-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text);
  padding: 10px 14px 0;
}

.field-row {
  padding: 8px 14px;
  border-bottom: 1px solid var(--cream-dark);
}
.field-row:last-child { border-bottom: none; }

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text);
  margin-bottom: 2px;
}

.field-input {
  width: 100%;
  border: none;
  background: transparent;
  font-size: 14px;
  font-family: 'Source Sans 3', sans-serif;
  color: var(--text);
  outline: none;
  padding: 4px 0;
  line-height: 1.4;
}
.field-input::placeholder { color: #bbb; }

textarea.field-input { resize: vertical; min-height: 60px; }

select.field-input {
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%232a2218' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 4px center;
  padding-right: 20px;
}

/* Number spinner hidden */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type=number] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* iOS zoom prevention: Safari auto-zooms on focus for any form control
   with computed font-size < 16px, and doesn't zoom back out on blur. Bump
   all form controls to 16px on touch devices only — desktop keeps 14px. */
@media (hover: none) and (pointer: coarse) {
  .field-input,
  input[type=date].field-input,
  input[type=time].field-input,
  textarea.field-input,
  select.field-input {
    font-size: 16px;
  }
}

/* ── TABLE (base for sortable/browse tables) ─────────────────────────────── */
.table-wrap {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

table { width: 100%; border-collapse: collapse; font-size: 15px; }

th {
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--cream);
}

td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

.td-name { font-weight: 500; }
.td-sub  { color: var(--text); font-size: 14px; }
.td-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

@media (max-width: 600px) {
  td, th { padding: 8px 10px; }
  .td-actions { justify-content: flex-end; }
}

/* ── TABS ────────────────────────────────────────────────────────────────── */
.tab {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 14px 18px 12px;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
  margin-bottom: -1px;
}
.tab:hover  { color: var(--text); }
.tab:active { background: rgba(74, 154, 191, 0.08); }
.tab.active {
  color: var(--sky-dark);
  border-bottom-color: var(--sky);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

@media (max-width: 600px) {
  .tab { padding: 14px 16px; min-height: 48px; }
}

/* ── TOGGLE SWITCH ───────────────────────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}
.toggle-label {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}
.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  cursor: pointer;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--cream-dark);
  border-radius: 11px;
  border: 1px solid var(--border);
  transition: background 0.2s;
}
.toggle input:checked + .toggle-track {
  background: var(--sky);
  border-color: var(--sky-dark);
}
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: var(--white);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s;
  pointer-events: none;
}
.toggle input:checked ~ .toggle-thumb { transform: translateX(18px); }

/* ── BADGE BASE (variants stay per-page) ─────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: 13px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 5px;
  margin: 1px 2px 1px 0;
  line-height: 1.5;
}

/* ── EMPTY STATE ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text);
  font-size: 16px;
}
.empty-state-sm {
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--text);
  font-size: 15px;
}
/* Hero variant — big icon, used for full-page empty states */
.empty-state-hero {
  text-align: center;
  padding: 60px 20px;
  color: var(--text);
}
.empty-state-hero .icon {
  font-size: 48px;
  margin-bottom: 12px;
}
.empty-state-hero p {
  font-size: 16px;
}
