/* =====================================================================
   River Church — STAFF PORTAL styles.
   Loaded after /css/theme.css and /css/app.css. Adds layout + components
   the portal needs (tables, badges, dialogs). No colors or fonts are
   defined here — everything references theme.css variables.
   ===================================================================== */

:root { --portal-max: 1120px; }

body { background: var(--color-surface); }

/* ---- Header / nav ---- */
.portal-header {
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-line);
  position: sticky; top: 0; z-index: 20;
}
.portal-header .bar {
  max-width: var(--portal-max); margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap;
}
.portal-header .brand, .login-card .brand {
  font-family: var(--font-heading); font-weight: var(--weight-heading); font-size: 1.125rem;
  color: var(--color-headline); text-decoration: none; letter-spacing: 0.02em; text-transform: uppercase; line-height: 1.1;
}
.portal-header .brand { margin-right: auto; }
.portal-header .brand small {
  display: block; font-family: var(--font-body); font-weight: var(--weight-body);
  font-size: 0.75rem; text-transform: none; letter-spacing: 0; color: var(--color-muted);
}
.portal-nav { display: flex; gap: var(--space-1); flex-wrap: wrap; }
.portal-nav a {
  font-family: var(--font-heading); font-weight: var(--weight-button); font-size: 0.875rem;
  color: var(--color-muted); text-decoration: none; padding: 8px 12px; border-radius: var(--radius-sm);
  min-height: 36px; display: inline-flex; align-items: center;
}
.portal-nav a:hover { color: var(--color-accent); background: var(--color-accent-soft); }
.portal-nav a.active { color: var(--color-accent); background: var(--color-accent-soft); }
.portal-user { font-size: 0.875rem; color: var(--color-muted); display: flex; align-items: center; gap: var(--space-2); }

/* ---- Page ---- */
.page { max-width: var(--portal-max); margin: 0 auto; padding: var(--space-5) var(--space-4) var(--space-8); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-5); }
.page-head h1 { margin: 0; font-size: clamp(1.5rem, 2vw + 1rem, 2rem); }
.page-head p { margin: var(--space-1) 0 0; color: var(--color-muted); }
.page-head .head-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.crumbs { font-size: 0.875rem; color: var(--color-muted); margin-bottom: var(--space-2); }
.crumbs a { text-decoration: none; }

.card { background: var(--color-bg); }
.card h2, .card h3 { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-4); }
.card-head h2, .card-head h3 { margin: 0; }
.grid-2 { display: grid; gap: var(--space-4); }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-2 > .span-2 { grid-column: 1 / -1; } }
.grid-3 { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

/* ---- Stats ---- */
.stat { background: var(--color-bg); border: 1px solid var(--color-line); border-radius: var(--radius); padding: var(--space-4); }
.stat .label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-muted); font-family: var(--font-heading); font-weight: var(--weight-button); }
.stat .value { font-family: var(--font-heading); font-weight: var(--weight-heading); font-size: 1.75rem; color: var(--color-headline); line-height: 1.1; margin-top: var(--space-1); }
.stat .sub { font-size: 0.8125rem; color: var(--color-muted); }

/* ---- Toolbar / filters ---- */
.toolbar { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: flex-end; margin-bottom: var(--space-4); }
.toolbar .field { margin: 0; flex: 1 1 160px; }
.toolbar .field.grow { flex: 2 1 220px; }
.toolbar .field label { font-size: 0.75rem; margin-bottom: 4px; }
.toolbar .btn { flex: 0 0 auto; }

/* ---- Form controls not covered by app.css ---- */
.field select, .field textarea {
  width: 100%; min-height: var(--tap-min); padding: 10px 14px; font: inherit; font-size: 1rem;
  color: var(--color-ink); background: var(--color-bg); border: 1px solid var(--color-line); border-radius: var(--radius);
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.field select:focus, .field textarea:focus { outline: none; border-color: var(--color-accent); box-shadow: var(--focus-ring); }
.field input[type="checkbox"], .check input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--color-accent); }
/* label.check inside .field must beat app.css .field label { display:block } */
.check, .field label.check { display: flex; align-items: center; gap: var(--space-2); font-size: 0.9375rem; cursor: pointer; }
.field-row.three { grid-template-columns: 1fr; }
@media (min-width: 700px) { .field-row.three { grid-template-columns: 1fr 1fr 1fr; } }
.initials-input { text-transform: uppercase; letter-spacing: 0.12em; font-family: var(--font-heading); font-weight: var(--weight-button); max-width: 120px; }

/* Result picker (radio cards) */
.result-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--space-2); }
.result-picker label {
  display: flex; align-items: center; gap: var(--space-2); padding: 10px 12px; min-height: var(--tap-min);
  border: 2px solid var(--color-line); border-radius: var(--radius); cursor: pointer; font-size: 0.9375rem; background: var(--color-bg);
}
.result-picker input, .field input[type="radio"] { width: 20px; height: 20px; min-height: 0; padding: 0; margin: 0; flex: 0 0 auto; accent-color: var(--color-accent); }
.result-picker label:has(input:checked) { border-color: var(--color-accent); background: var(--color-accent-soft); }
.result-picker label.danger:has(input:checked) { border-color: var(--color-error); background: var(--color-error-bg); }

/* ---- Event form v2: share link, image ---- */
.slug-row { display: flex; align-items: stretch; }
.slug-prefix {
  display: inline-flex; align-items: center; padding: 0 12px; border: 1px solid var(--color-line); border-right: 0;
  border-radius: var(--radius) 0 0 var(--radius); background: var(--color-surface); color: var(--color-muted);
  font-family: var(--font-heading); font-weight: var(--weight-button); font-size: 0.9375rem;
}
.slug-row input { border-radius: 0 var(--radius) var(--radius) 0; }
.field input[type="file"] { padding: 8px 12px; }
.image-preview { margin-top: var(--space-2); display: flex; align-items: flex-end; gap: var(--space-3); }
.image-preview img { max-width: 240px; max-height: 140px; border-radius: var(--radius-sm); border: 1px solid var(--color-line); object-fit: cover; }
.event-banner { display: block; width: 100%; max-height: 320px; object-fit: cover; border-radius: var(--radius-lg); border: 1px solid var(--color-line); margin-bottom: var(--space-5); }
.share-link { font-size: 0.875rem; color: var(--color-muted); margin: var(--space-1) 0 0; }
.share-link a { word-break: break-all; }
.share-link .btn-link { margin-left: var(--space-2); font-size: 0.8125rem; }

/* ---- Buttons ---- */
.btn-sm { min-height: 36px; padding: 6px 14px; font-size: 0.875rem; border-radius: var(--radius-sm); }
.btn-danger { background: var(--color-bg); color: var(--color-error); border-color: var(--color-error); }
.btn-danger:hover:not(:disabled) { background: var(--color-error-bg); }
.btn-link { background: none; border: 0; padding: 0; color: var(--color-accent); font: inherit; cursor: pointer; text-decoration: underline; }
.btn-group { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* ---- Tables ---- */
.table-wrap { background: var(--color-bg); border: 1px solid var(--color-line); border-radius: var(--radius-lg); overflow: hidden; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
table.data th, table.data td { padding: 12px 14px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--color-line); }
table.data th {
  font-family: var(--font-heading); font-weight: var(--weight-button); font-size: 0.75rem; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--color-muted); background: var(--color-surface); white-space: nowrap;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--color-surface); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.row-actions, table.data th.row-actions { text-align: right; white-space: nowrap; }
table.data a.row-link { color: var(--color-headline); font-weight: var(--weight-button); font-family: var(--font-heading); text-decoration: none; }
table.data a.row-link:hover { color: var(--color-accent); }
table.data .sub { display: block; font-size: 0.8125rem; color: var(--color-muted); font-weight: var(--weight-body); font-family: var(--font-body); }
table.data tr.family-head td { background: var(--color-surface); font-weight: var(--weight-button); }
table.data tr.member td:first-child { padding-left: 28px; }
.empty { padding: var(--space-6) var(--space-4); text-align: center; color: var(--color-muted); }

/* Stack rows into cards on small screens */
@media (max-width: 720px) {
  table.data.stack thead { display: none; }
  table.data.stack tr { display: block; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-line); }
  table.data.stack td { display: flex; justify-content: space-between; gap: var(--space-3); padding: 4px 0; border: 0; text-align: left !important; }
  table.data.stack td::before { content: attr(data-label); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-muted); font-family: var(--font-heading); font-weight: var(--weight-button); flex: 0 0 40%; }
  table.data.stack td.no-label::before { display: none; }
  table.data.stack td.row-actions { justify-content: flex-start; }
}

/* ---- Badges / status ---- */
.badge {
  display: inline-block; font-family: var(--font-heading); font-weight: var(--weight-button); font-size: 0.75rem;
  letter-spacing: 0.03em; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--color-line);
  background: var(--color-bg); color: var(--color-muted); white-space: nowrap;
}
.badge.open, .badge.good { color: var(--color-success); border-color: var(--color-success); background: var(--color-success-bg); }
.badge.closed, .badge.warn { color: var(--color-error); border-color: var(--color-error); background: var(--color-error-bg); }
.badge.hidden-status, .badge.neutral { color: var(--color-muted); border-color: var(--color-line); background: var(--color-surface); }
.badge.accent { color: var(--color-accent); border-color: var(--color-accent); background: var(--color-accent-soft); }
.badge.dnc { color: var(--color-on-accent); background: var(--color-error); border-color: var(--color-error); }

.status-select { margin-left: 8px; font: inherit; font-size: 0.8125rem; padding: 4px 6px; border-radius: var(--radius-sm); border: 1px solid var(--color-line); background: var(--color-bg); color: var(--color-ink); }

/* ---- Progress ---- */
.progress { height: 8px; background: var(--color-line); border-radius: 999px; overflow: hidden; min-width: 80px; }
.progress > span { display: block; height: 100%; background: var(--color-accent); border-radius: 999px; transition: width .3s; }
.progress.full > span { background: var(--color-error); }
.progress.lg { height: 14px; }
.capacity { display: flex; align-items: center; gap: var(--space-2); min-width: 140px; }
.capacity .num { font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 0.875rem; }

/* ---- Dialogs ---- */
dialog.modal {
  border: 1px solid var(--color-line); border-radius: var(--radius-lg); padding: 0; width: min(560px, calc(100vw - 32px));
  box-shadow: var(--shadow); color: var(--color-ink); background: var(--color-bg);
}
dialog.modal::backdrop { background: color-mix(in srgb, var(--color-headline) 45%, transparent); }
dialog.modal form, dialog.modal .modal-body { padding: var(--space-5); }
dialog.modal h2 { font-size: 1.25rem; margin-bottom: var(--space-4); }
dialog.modal .actions { margin-top: var(--space-5); }
dialog.modal.wide { width: min(820px, calc(100vw - 32px)); }

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--color-headline); color: var(--color-on-accent); padding: 12px 20px; border-radius: var(--radius);
  box-shadow: var(--shadow); font-size: 0.9375rem; opacity: 0; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--color-error); }
.toast.success { background: var(--color-success); }

/* ---- Timeline (call log) ---- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 56px 1fr; gap: var(--space-3); padding: var(--space-3) 0; border-bottom: 1px solid var(--color-line); }
.timeline li:last-child { border-bottom: 0; }
.timeline .who {
  width: 48px; height: 48px; border-radius: 50%; background: var(--color-accent-soft); color: var(--color-accent);
  display: flex; align-items: center; justify-content: center; font-family: var(--font-heading); font-weight: var(--weight-heading); font-size: 0.875rem;
}
.timeline .meta { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; font-size: 0.8125rem; color: var(--color-muted); }
.timeline .note { margin: var(--space-1) 0 0; white-space: pre-wrap; }

/* ---- Misc ---- */
.pager { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-top: var(--space-4); font-size: 0.875rem; color: var(--color-muted); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: var(--space-2) var(--space-3); font-size: 0.9375rem; margin: 0; }
.kv dt { color: var(--color-muted); }
.kv dd { margin: 0; word-break: break-word; }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--space-4); }
.login-card { width: 100%; max-width: 400px; background: var(--color-bg); border: 1px solid var(--color-line); border-radius: var(--radius-lg); padding: var(--space-6); box-shadow: var(--shadow); }
.login-card .brand { display: block; text-align: center; margin-bottom: var(--space-5); }
.dropzone {
  display: block;
  border: 2px dashed var(--color-line); border-radius: var(--radius-lg); padding: var(--space-6); text-align: center;
  background: var(--color-bg); cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--color-accent); background: var(--color-accent-soft); }
.mapping-grid { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.preview-wrap { overflow-x: auto; border: 1px solid var(--color-line); border-radius: var(--radius); }
.preview-wrap table.data { font-size: 0.8125rem; }
.preview-wrap th, .preview-wrap td { white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.report-list { max-height: 260px; overflow: auto; font-size: 0.875rem; margin: 0; padding-left: 20px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.875rem; }
.inline-alert { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
