/*
 * Jethro design system. Palette sampled from the Jethro mark: deep navy field, royal blue,
 * and the sky -> cyan -> violet ribbon of the J. Screen-specific styles live in their own
 * files in this folder (all are loaded by stylesheet_link_tag :app); reuse these classes first.
 *
 * Layout     .shell .sidebar .main .topbar .page .page-header .page-actions .grid-2 .grid-3 .grid-4 .stack .row .spacer
 * Surfaces   .panel .panel-header .panel-body .panel-footer .panel--glow .panel--flush .callout .empty-state
 * Data       .stat .stat-value .stat-label .table .table-wrap .kv .mono .muted .faint .num .meter .meter-fill
 * Badges     .badge .badge--ok .badge--warn .badge--danger .badge--info .badge--violet .badge--muted .chip .dot
 * Controls   .btn .btn--primary .btn--ghost .btn--danger .btn--sm .btn--icon .link
 * Forms      .form .field .field-row .label .input .select .textarea .hint .field-errors .checkbox
 * Feedback   .flash .flash--notice .flash--alert
 * Nav        .tabs .tab .tab--active .breadcrumbs
 */

@import url("https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap");

:root {
  --navy-950: #01092d;
  --navy-925: #020c3c;
  --navy-900: #03104d;
  --navy-850: #061a5e;
  --navy-800: #0e206a;
  --royal: #174295;
  --sky: #c1e9fc;
  --cyan: #43b7fd;
  --blue: #3d7bfd;
  --violet: #4449fd;
  --violet-soft: #8a8dff;
  --white: #fdfdfd;

  --ok: #3ee6a8;
  --warn: #ffc857;
  --danger: #ff5d7a;

  --text: #e8f3ff;
  --text-muted: #9db3e0;
  --text-faint: #6077ab;

  --surface: rgba(14, 32, 106, 0.38);
  --surface-strong: rgba(14, 32, 106, 0.62);
  --surface-hover: rgba(23, 66, 149, 0.45);
  --border: rgba(67, 183, 253, 0.16);
  --border-strong: rgba(67, 183, 253, 0.34);
  --glow: 0 0 0 1px rgba(67, 183, 253, 0.18), 0 10px 40px rgba(1, 9, 45, 0.55), 0 0 32px rgba(68, 73, 253, 0.12);

  --ribbon: linear-gradient(135deg, var(--sky) 0%, var(--cyan) 38%, var(--violet) 100%);
  --ribbon-soft: linear-gradient(135deg, rgba(193, 233, 252, 0.16), rgba(67, 183, 253, 0.12) 40%, rgba(68, 73, 253, 0.16));

  --font-display: "Outfit", ui-sans-serif, system-ui, sans-serif;
  --font-body: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius: 14px;
  --radius-sm: 9px;
  --sidebar-width: 248px;

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 85% -10%, rgba(68, 73, 253, 0.22), transparent 60%),
    radial-gradient(900px 600px at -10% 110%, rgba(67, 183, 253, 0.14), transparent 60%),
    linear-gradient(180deg, var(--navy-900) 0%, var(--navy-950) 70%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

/* Faint blueprint grid behind everything. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(67, 183, 253, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(67, 183, 253, 0.045) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at 50% 30%, black 30%, transparent 85%);
  z-index: 0;
}

a { color: var(--cyan); text-decoration: none; }
a:hover { color: var(--sky); }

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; margin: 0; color: var(--white); }
h1 { font-size: 28px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }
p { margin: 0 0 0.75em; }
code, .mono { font-family: var(--font-mono); font-size: 0.92em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.ribbon-text { background: var(--ribbon); -webkit-background-clip: text; background-clip: text; color: transparent; }
.eyebrow { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--cyan); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Shell ---------- */

.shell { position: relative; z-index: 1; display: grid; grid-template-columns: var(--sidebar-width) 1fr; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
  padding: 18px 14px;
  background: linear-gradient(180deg, rgba(3, 16, 77, 0.92), rgba(1, 9, 45, 0.96));
  border-right: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 16px; color: var(--white); }
.brand img { width: 38px; height: 38px; border-radius: 10px; box-shadow: 0 0 22px rgba(67, 183, 253, 0.35); }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 21px; letter-spacing: -0.01em; }
.brand-church { font-size: 11.5px; color: var(--text-muted); line-height: 1.2; }

.nav-section { margin: 14px 8px 4px; font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-faint); }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 500; font-size: 14px;
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.nav-item:hover { background: var(--surface-hover); color: var(--white); }
.nav-item--active { color: var(--white); background: var(--ribbon-soft); border-color: var(--border-strong); box-shadow: inset 3px 0 0 var(--cyan); }
.nav-item svg { width: 17px; height: 17px; flex: none; opacity: 0.9; }
.nav-count { margin-left: auto; font-family: var(--font-mono); font-size: 11px; padding: 1px 7px; border-radius: 999px; background: rgba(68, 73, 253, 0.35); color: var(--white); }

.sidebar-footer { margin-top: auto; padding: 12px 8px 4px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-muted); }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 28px;
  background: rgba(1, 9, 45, 0.72);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar .spacer { flex: 1; }
.topbar-mode { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--cyan); }

.page { padding: 26px 28px 60px; max-width: 1480px; width: 100%; }
.page--wide { max-width: none; }
.page-header { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 22px; }
.page-header .subtitle { color: var(--text-muted); margin-top: 4px; max-width: 760px; }
.page-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.grid-2 { display: grid; gap: 18px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: 18px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { display: grid; gap: 18px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main-side { display: grid; gap: 18px; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }

@media (max-width: 1100px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main-side { grid-template-columns: 1fr; }
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }
.nav-toggle { display: none; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  /* On a phone the sidebar is a slim bar with a menu button; the nav opens as a drawer. */
  .sidebar { position: sticky; top: 0; z-index: 30; height: auto; padding: 10px 16px; gap: 0; }
  .sidebar .brand { padding: 0; }
  .sidebar .brand img { width: 32px; height: 32px; }
  .nav-toggle { display: inline-flex; }
  .sidebar-nav, .sidebar-footer { display: none; }
  .sidebar--open .sidebar-nav { display: flex; max-height: calc(100dvh - 120px); overflow-y: auto; padding-top: 10px; }
  .sidebar--open .sidebar-footer { display: block; }
  .topbar { position: static; flex-wrap: wrap; gap: 10px; }
  .topbar-mode { display: none; }
  .topbar .meter { width: 72px !important; }
  .switcher summary { max-width: 52vw; overflow: hidden; text-overflow: ellipsis; }
  .switcher-menu { right: -8px; max-width: calc(100vw - 24px); }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page { padding: 18px 16px 48px; }
  .topbar { padding: 10px 16px; }
}

/* ---------- Surfaces ---------- */

.panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--glow);
  backdrop-filter: blur(10px);
}
.panel--glow::before {
  content: ""; position: absolute; inset: -1px; border-radius: inherit; padding: 1px; pointer-events: none;
  background: var(--ribbon);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude; opacity: 0.55;
}
.panel-header { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.panel-header h2, .panel-header h3 { font-size: 15px; }
.panel-header .spacer { flex: 1; }
/* Every icon() has a size: an svg with none fills its container (the setup page's giant sparkle). */
.icon { width: 18px; height: 18px; flex: none; }
.panel-header > .icon { color: var(--cyan); }
.panel-body { padding: 16px 18px; }
.panel-footer { padding: 12px 18px; border-top: 1px solid var(--border); }
.panel--flush .panel-body { padding: 0; }

.callout { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--ribbon-soft); border: 1px solid var(--border-strong); color: var(--text); }
.callout--warn { background: rgba(255, 200, 87, 0.08); border-color: rgba(255, 200, 87, 0.35); }
.callout--danger { background: rgba(255, 93, 122, 0.08); border-color: rgba(255, 93, 122, 0.35); }

.empty-state { padding: 34px 20px; text-align: center; color: var(--text-muted); }
.empty-state h3 { color: var(--text); margin-bottom: 6px; }

/* ---------- Data ---------- */

.stat { padding: 16px 18px; }
.stat-value { font-family: var(--font-display); font-size: 32px; font-weight: 600; line-height: 1.1; color: var(--white); font-variant-numeric: tabular-nums; }
.stat-label { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted); margin-top: 4px; }
.stat-delta { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-family: var(--font-mono); font-weight: 500; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text-faint); padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid rgba(67, 183, 253, 0.08); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: rgba(23, 66, 149, 0.22); }
.table .num, .table td.num { text-align: right; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; font-size: 14px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; }

.meter { height: 8px; border-radius: 999px; background: rgba(67, 183, 253, 0.12); overflow: hidden; }
.meter-fill { height: 100%; border-radius: inherit; background: var(--ribbon); box-shadow: 0 0 12px rgba(67, 183, 253, 0.6); }
.meter--warn .meter-fill { background: linear-gradient(90deg, var(--warn), #ff9f57); }
.meter--danger .meter-fill { background: linear-gradient(90deg, #ff9f57, var(--danger)); }

/* ---------- Badges ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 500; line-height: 1.6; white-space: nowrap;
  background: rgba(67, 183, 253, 0.12); color: var(--sky); border: 1px solid rgba(67, 183, 253, 0.28);
}
.badge--ok { background: rgba(62, 230, 168, 0.1); color: var(--ok); border-color: rgba(62, 230, 168, 0.32); }
.badge--warn { background: rgba(255, 200, 87, 0.1); color: var(--warn); border-color: rgba(255, 200, 87, 0.32); }
.badge--danger { background: rgba(255, 93, 122, 0.1); color: var(--danger); border-color: rgba(255, 93, 122, 0.32); }
.badge--info { background: rgba(67, 183, 253, 0.12); color: var(--cyan); }
.badge--violet { background: rgba(68, 73, 253, 0.18); color: var(--violet-soft); border-color: rgba(68, 73, 253, 0.4); }
.badge--muted { background: rgba(157, 179, 224, 0.08); color: var(--text-muted); border-color: rgba(157, 179, 224, 0.2); }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--surface-strong); border: 1px solid var(--border); font-size: 12.5px; color: var(--text); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cyan); display: inline-block; box-shadow: 0 0 8px currentColor; }
.dot--ok { background: var(--ok); color: var(--ok); }
.dot--warn { background: var(--warn); color: var(--warn); }
.dot--danger { background: var(--danger); color: var(--danger); }
.dot--pulse { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.45; transform: scale(0.8); } }

.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 600; font-size: 13px; color: var(--white);
  background: var(--ribbon); box-shadow: 0 0 0 2px rgba(1, 9, 45, 0.8);
}
.avatar--sm { width: 24px; height: 24px; font-size: 10.5px; }
.avatar--lg { width: 48px; height: 48px; font-size: 18px; }

/* ---------- Controls ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  font: 600 13.5px/1.2 var(--font-body); cursor: pointer;
  color: var(--text); background: var(--surface-strong); border: 1px solid var(--border-strong);
  transition: transform 0.1s, box-shadow 0.15s, background 0.15s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-hover); color: var(--white); box-shadow: 0 0 18px rgba(67, 183, 253, 0.25); }
.btn:active { transform: translateY(1px); }
.btn--primary { color: var(--navy-950); background: var(--ribbon); border-color: transparent; }
.btn--primary:hover { color: var(--navy-950); box-shadow: 0 0 24px rgba(67, 183, 253, 0.55); background: var(--ribbon); filter: brightness(1.06); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface); }
.btn--danger { color: var(--danger); border-color: rgba(255, 93, 122, 0.4); background: rgba(255, 93, 122, 0.06); }
.btn--danger:hover { background: rgba(255, 93, 122, 0.14); color: #ffd0d8; box-shadow: 0 0 18px rgba(255, 93, 122, 0.25); }
.btn--sm { padding: 5px 10px; font-size: 12.5px; }
.btn--icon { padding: 6px; }
.btn[disabled], .btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; flex: none; }
button.link { background: none; border: 0; padding: 0; color: var(--cyan); cursor: pointer; font: inherit; }

/* button_to renders a form; keep it inline. */
form.button_to { display: inline; }

/* ---------- Forms ---------- */

.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.label, .field label { font-size: 13px; font-weight: 600; color: var(--text); }
.hint { font-size: 12.5px; color: var(--text-faint); }
.input, .select, .textarea,
.field input[type=text], .field input[type=email], .field input[type=password], .field input[type=number],
.field input[type=date], .field input[type=datetime-local], .field input[type=time], .field input[type=url], .field input[type=search],
.field select, .field textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: rgba(1, 9, 45, 0.6);
  color: var(--text);
  font: 14px/1.4 var(--font-body);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field textarea, .textarea { min-height: 110px; resize: vertical; }
.textarea--code, .field textarea.code { font-family: var(--font-mono); font-size: 13px; min-height: 220px; }
.input:focus, .select:focus, .textarea:focus, .field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(67, 183, 253, 0.18);
}
.field input[type=file] { color: var(--text-muted); }
.checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; }
.checkbox input { accent-color: var(--cyan); width: 16px; height: 16px; }
.field-errors { padding: 10px 14px; border-radius: var(--radius-sm); background: rgba(255, 93, 122, 0.08); border: 1px solid rgba(255, 93, 122, 0.35); color: #ffd0d8; font-size: 13.5px; }
.field-errors ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- Feedback ---------- */

.flash-stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.flash { padding: 11px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface-strong); }
.flash--notice { border-color: rgba(62, 230, 168, 0.4); background: rgba(62, 230, 168, 0.08); }
.flash--alert { border-color: rgba(255, 93, 122, 0.4); background: rgba(255, 93, 122, 0.08); }

/* ---------- Nav ---------- */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab { padding: 9px 14px; color: var(--text-muted); border-bottom: 2px solid transparent; font-weight: 500; white-space: nowrap; }
.tab:hover { color: var(--white); }
.tab--active { color: var(--white); border-bottom-color: var(--cyan); }
.breadcrumbs { font-size: 12.5px; color: var(--text-faint); margin-bottom: 6px; }
.breadcrumbs a { color: var(--text-muted); }

/* ---------- Church switcher / user menu ---------- */

.switcher { position: relative; }
.switcher summary { list-style: none; cursor: pointer; }
.switcher summary::-webkit-details-marker { display: none; }
.switcher-menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 240px; z-index: 20;
  padding: 6px; border-radius: var(--radius); background: var(--navy-900); border: 1px solid var(--border-strong); box-shadow: var(--glow);
}
.switcher-menu form, .switcher-menu a { display: block; }
.switcher-menu button, .switcher-menu a {
  width: 100%; text-align: left; padding: 8px 10px; border-radius: var(--radius-sm);
  background: none; border: 0; color: var(--text); font: 500 13.5px var(--font-body); cursor: pointer;
}
.switcher-menu button:hover, .switcher-menu a:hover { background: var(--surface-hover); }

/* ---------- Auth layout ---------- */

.auth-shell { position: relative; z-index: 1; min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; }
.auth-card { width: min(460px, 100%); padding: 30px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 22px; text-align: center; }
.auth-brand img { width: 84px; height: 84px; border-radius: 20px; box-shadow: 0 0 48px rgba(67, 183, 253, 0.4); }
.auth-brand .brand-name { font-size: 34px; }

.empty-state > svg { width: 38px; height: 38px; margin-bottom: 8px; }
