/* =============================================================================
   Life Group Testimony Portal — stylesheet
   Mobile-first, single 640px breakpoint, light by default + prefers-color-scheme.
   Brand: indigo (#4f46e5). No external assets, no CDN imports.
   ========================================================================== */

/* -----------------------------------------------------------
   Design tokens
   ----------------------------------------------------------- */
:root {
  /* Brand */
  --brand: #4f46e5;
  --brand-strong: #4338ca;
  --brand-soft: #eef2ff;
  --brand-ring: rgba(79, 70, 229, 0.35);

  /* Surface */
  --bg: #f7f7fb;
  --surface: #ffffff;
  --surface-2: #fafafe;
  --border: #e5e7eb;
  --border-strong: #d1d5db;

  /* Text */
  --text: #111827;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;

  /* Status */
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --success: #059669;

  /* Effects */
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.04);
  --shadow-md: 0 4px 14px rgba(17, 24, 39, 0.08);
  --shadow-lg: 0 18px 40px rgba(17, 24, 39, 0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --focus-ring: 0 0 0 3px var(--brand-ring);

  /* Type */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #818cf8;
    --brand-strong: #6366f1;
    --brand-soft: #1e1b4b;
    --brand-ring: rgba(129, 140, 248, 0.45);

    --bg: #0b0b14;
    --surface: #14141f;
    --surface-2: #181826;
    --border: #262635;
    --border-strong: #34344a;

    --text: #f3f4f6;
    --text-muted: #a1a1aa;
    --text-faint: #71717a;

    --danger: #f87171;
    --danger-soft: #3f1d1d;
    --success: #34d399;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 18px 40px rgba(0, 0, 0, 0.55);
  }
}

/* -----------------------------------------------------------
   Reset / base
   ----------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

h1, h2, h3 { color: var(--text); margin: 0; line-height: 1.25; }
p { margin: 0; }
button { font-family: inherit; }

/* Ensure the HTML `hidden` attribute always wins over component display rules.
   Several elements below (.loading, .filters, .testimony-grid, .field) use
   display: flex / grid, which would otherwise override the UA-default
   display: none from `hidden` and leave the spinner/grid visible when the JS
   toggles `el.hidden = true`. */
[hidden] { display: none !important; }

.muted { color: var(--text-muted); }
.small { font-size: 13px; }

/* Buttons styled as text — used for "back", "resend", etc. */
.link-button {
  background: none;
  border: 0;
  padding: 0;
  color: var(--brand);
  cursor: pointer;
  font: inherit;
  text-decoration: none;
}
.link-button:hover { text-decoration: underline; }
.link-button:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: 4px; }

/* -----------------------------------------------------------
   Brand mark
   ----------------------------------------------------------- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: var(--text);
}
.brand__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  color: white;
  box-shadow: 0 6px 18px var(--brand-ring);
}
.brand__name { letter-spacing: -0.01em; }

/* -----------------------------------------------------------
   Auth screen (index.html)
   ----------------------------------------------------------- */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  position: relative;
  overflow: hidden;
}

/* Soft aurora background — decorative, behind the card. */
.bg-aurora {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 60% 50% at 15% 10%, rgba(99, 102, 241, 0.22), transparent 60%),
    radial-gradient(ellipse 50% 40% at 85% 90%, rgba(168, 85, 247, 0.18), transparent 60%),
    radial-gradient(ellipse 50% 35% at 60% 30%, rgba(56, 189, 248, 0.12), transparent 60%);
  filter: blur(8px);
}

.auth-shell {
  width: 100%;
  max-width: 440px;
}

.auth-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-lg);
}

.auth-card__header { margin-bottom: 20px; }
.auth-card__title  { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.auth-card__lede   { margin-top: 8px; color: var(--text-muted); font-size: 14px; }
.auth-card__footer { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }

.auth-step[data-active="false"] { display: none; }

.auth-form { margin-top: 22px; display: flex; flex-direction: column; gap: 16px; }

.auth-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.auth-meta__divider { color: var(--text-faint); }

@media (min-width: 640px) {
  .auth-card { padding: 36px; }
  .auth-card__title { font-size: 24px; }
}

/* -----------------------------------------------------------
   Form fields
   ----------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.field input[type="email"],
.field input[type="text"],
.field input[type="search"],
.select {
  appearance: none;
  width: 100%;
  padding: 11px 14px;
  font-size: 15px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.field input:focus-visible,
.select:focus-visible {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--focus-ring);
}

.field--inline { flex-direction: column; gap: 4px; }
.field--grow { flex: 1 1 240px; }

.select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) center, calc(100% - 13px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

/* -----------------------------------------------------------
   OTP digit inputs
   ----------------------------------------------------------- */
.otp-inputs {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.otp-input {
  appearance: none;
  width: 100%;
  aspect-ratio: 1 / 1.15;
  text-align: center;
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}
.otp-input:focus-visible {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--focus-ring);
  transform: translateY(-1px);
}
.otp-input.has-value { background: var(--brand-soft); }

@media (min-width: 640px) {
  .otp-inputs { gap: 10px; }
  .otp-input  { font-size: 26px; }
}

/* -----------------------------------------------------------
   Buttons
   ----------------------------------------------------------- */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, box-shadow 120ms ease;
  user-select: none;
}
.btn:disabled { cursor: not-allowed; opacity: 0.7; }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.btn--primary {
  background: var(--brand);
  color: white;
  box-shadow: 0 6px 16px var(--brand-ring);
}
.btn--primary:hover:not(:disabled) { background: var(--brand-strong); transform: translateY(-1px); }
.btn--primary:active { transform: translateY(0); }

.btn--ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text);
}
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); }

.btn--small { padding: 8px 14px; font-size: 13px; border-radius: var(--radius-sm); }

.btn__spinner {
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  display: none;
  animation: spin 700ms linear infinite;
}
.btn.is-loading .btn__label   { opacity: 0; }
.btn.is-loading .btn__spinner { display: inline-block; position: absolute; }
.btn.is-loading { pointer-events: none; }

@keyframes spin { to { transform: rotate(360deg); } }

/* -----------------------------------------------------------
   Inline form errors
   ----------------------------------------------------------- */
.form-error {
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}

/* -----------------------------------------------------------
   Top nav (dashboard.html)
   ----------------------------------------------------------- */
.topnav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: saturate(140%) blur(8px);
}
.topnav__inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topnav__right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (min-width: 640px) {
  .user-name { max-width: 240px; }
}

/* -----------------------------------------------------------
   Dashboard layout
   ----------------------------------------------------------- */
.dashboard {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 80px;
}
.dashboard__hero { margin-bottom: 24px; }
.dashboard__title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.dashboard__subtitle { margin-top: 6px; font-size: 14px; }

@media (min-width: 640px) {
  .dashboard__title { font-size: 34px; }
}

/* -----------------------------------------------------------
   Overview panel (KPIs + category bar chart)
   ----------------------------------------------------------- */
.overview {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 20px;
}
@media (min-width: 880px) {
  .overview {
    grid-template-columns: minmax(260px, 1fr) minmax(360px, 1.4fr);
    align-items: stretch;
  }
}

/* KPI row — 2 columns on mobile, 4 columns on desktop. */
.kpis {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (min-width: 880px) {
  .kpis {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    align-content: start;
  }
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  min-height: 80px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}
.kpi__value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.1;
  /* Smaller font for dates (which contain spaces) — see modifier class below. */
}
.kpi__value--small {
  font-size: 18px;
  font-weight: 600;
}
.kpi__label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Category bar chart */
.cat-chart {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cat-chart__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.cat-chart__title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0;
}
.cat-chart__hint { margin: 0; }
.cat-chart__empty { margin: 4px 0 0; }

.cat-bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cat-row {
  /* Button reset so the row looks like a row, not a button. */
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  width: 100%;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  display: grid;
  grid-template-columns: minmax(110px, 28%) 1fr auto;
  align-items: center;
  gap: 12px;
  transition: background 120ms ease, border-color 120ms ease;
}
.cat-row:hover {
  background: var(--surface-2);
  border-color: var(--border);
}
.cat-row:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.cat-row--active {
  background: var(--brand-soft);
  border-color: var(--brand);
}
.cat-row__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cat-row__bar {
  position: relative;
  height: 10px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.cat-row__fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--brand) 0%, var(--brand-strong) 100%);
  border-radius: inherit;
  transition: width 200ms ease;
}
.cat-row--active .cat-row__fill {
  background: linear-gradient(90deg, var(--brand-strong) 0%, var(--brand) 100%);
}
.cat-row__count {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  min-width: 28px;
  text-align: right;
}

/* Filters bar — flex layout so an arbitrary number of filter fields can wrap
   neatly; the Search field carries `field--grow` to fill remaining space. */
.filters {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}
@media (min-width: 640px) {
  .filters {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: end;
    gap: 16px;
    padding: 18px 20px;
  }
}

/* Date range filter — two native date inputs separated by an en dash, with an
   optional inline "Clear" link button that appears only when at least one bound is set. */
.date-range {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.date-range__sep {
  color: var(--text-muted);
  user-select: none;
}
.date-input {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  min-width: 140px;
}
.date-input:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-color: var(--brand);
}
.date-range__clear {
  font-size: 13px;
}

/* Small role badge shown next to the user's name in the top nav for
   Pastor / Admin all-access users. */
.role-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--brand-soft);
  color: var(--brand-strong);
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 8px;
  vertical-align: middle;
}

/* -----------------------------------------------------------
   Loading, empty, error states
   ----------------------------------------------------------- */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 16px;
}
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.empty-state,
.error-state {
  text-align: center;
  padding: 48px 16px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}
.empty-state__icon { font-size: 32px; color: var(--brand); margin-bottom: 8px; }
.empty-state__title { font-size: 18px; margin-bottom: 4px; }
.error-state h2 { font-size: 18px; margin-bottom: 6px; color: var(--danger); }
.error-state .btn { margin-top: 14px; }

/* -----------------------------------------------------------
   Testimony cards
   ----------------------------------------------------------- */
.testimony-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.testimony-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
  animation: card-in 320ms ease both;
}
.testimony-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.testimony-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.testimony-card__date {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.category-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-strong);
  white-space: nowrap;
}

.testimony-card__body {
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.testimony-card__footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
}
.testimony-card__author { font-weight: 500; color: var(--text); }

@keyframes card-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Respect users who prefer reduced motion. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
