/* Church Security — App pages (public forms + admin hub)
   Layout only. Tokens only, no raw hex. Loads after tokens.css and components.css. */

/* ---------- Page column: phone first, a 560px column on desktop ---------- */

.page {
  width: 100%;
  max-width: calc(560px + 2 * var(--space-4));
  margin: 0 auto;
  padding:
    0
    max(var(--space-4), env(safe-area-inset-right))
    calc(var(--space-6) + env(safe-area-inset-bottom))
    max(var(--space-4), env(safe-area-inset-left));
}

/* Focus jumps (first bad field) stop below the sticky header */
html:has(.page > .kit-header) { scroll-padding-top: calc(104px + env(safe-area-inset-top)); }

.page > .kit-header {
  top: calc(var(--space-3) + env(safe-area-inset-top));
  width: 100%;
  margin: calc(var(--space-3) + env(safe-area-inset-top)) 0 var(--space-4);
}

/* ---------- Headings the components style only as h2/h3 ---------- */

.section-heading h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-title);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.empty-state h2 {
  margin: 0 0 var(--space-1);
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.015em;
}

h2.sample-label {
  margin: 0;
  padding: 0 var(--space-1);
}

/* Headings get focus after a swap; no ring on a non-control */
[tabindex="-1"]:focus { outline: none; }

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

.form-card { gap: var(--space-5); }

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

.field[aria-invalid="true"] { box-shadow: inset 0 0 0 1.5px var(--alert-ink); }

.date-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: var(--space-2);
}

.date-grid .date-choice { min-width: 0; }

.form-card [type="submit"] { width: 100%; }

.done-symbol {
  background-color: var(--clear-tint);
  color: var(--clear-ink);
  font-weight: 800;
}

/* ---------- Admin app shell ---------- */

.page.has-tabbar {
  padding-top: calc(var(--space-3) + env(safe-area-inset-top));
  padding-bottom: calc(112px + env(safe-area-inset-bottom));
}

.app-bar > div { min-width: 0; }

.app-bar h1 {
  margin: 2px 0 0;
  font-size: var(--text-display);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.025em;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
  margin-top: var(--space-4);
}

/* The column is phone-width on every screen, so staffing stays stacked */
.panel .staffing { grid-template-columns: minmax(0, 1fr); }

.app-tabbar {
  position: fixed;
  left: max(var(--space-3), env(safe-area-inset-left));
  right: max(var(--space-3), env(safe-area-inset-right));
  bottom: calc(var(--space-3) + env(safe-area-inset-bottom));
  z-index: 40;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  max-width: 420px;
  margin: 0 auto;
}

a.tab { text-decoration: none; }

/* Clear the floating tab bar */
.app-toast { bottom: calc(92px + env(safe-area-inset-bottom)); }

.stepper {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.stepper-value {
  min-width: 2.5ch;
  font-family: var(--font-display);
  font-size: var(--text-title);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

/* Title and buttons share a line; the buttons drop below on narrow phones */
.link-row { flex-wrap: wrap; }
.link-row .person-text { flex: 1 1 120px; }

.row-actions {
  display: flex;
  gap: var(--space-2);
  margin-left: auto;
}

/* =====================================================================
   Admin web app
   /admin/ only. Add-only: everything above stays as the forms use it.
   Phone first (app bar + floating tab bar); 1000px+ gets the glass sidebar.
   ===================================================================== */

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

html:has(dialog[open]) { overflow: hidden; }
html:has(body.admin-body) { scrollbar-gutter: stable; }

.admin-nav { display: none; }

.admin-main {
  width: 100%;
  max-width: calc(720px + 2 * var(--space-4));
  min-width: 0;
  margin: 0 auto;
  padding:
    calc(var(--space-3) + env(safe-area-inset-top))
    max(var(--space-4), env(safe-area-inset-right))
    calc(112px + env(safe-area-inset-bottom))
    max(var(--space-4), env(safe-area-inset-left));
}

#main:focus { outline: none; }

.app-tabbar { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.admin-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: var(--space-1) var(--space-2) var(--space-4);
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.015em;
  white-space: nowrap;
}

.admin-brand .brand-avatar {
  width: 36px;
  height: 36px;
  padding: 7px;
  border-radius: 10px;
}

.admin-nav .nav-item {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: var(--touch);
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-field);
  background: transparent;
  color: var(--text-main);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 140ms var(--ease), color 140ms var(--ease), transform var(--dur-press) var(--ease);
}

.admin-nav .nav-item .icon {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
}

@media (hover: hover) {
  .admin-nav .nav-item:hover { background-color: var(--neutral-tint); }
}

.admin-nav .nav-item:active { transform: scale(0.97); }

.admin-nav .nav-item[aria-current="page"] {
  background-color: var(--selected-bg);
  color: var(--selected-ink);
  font-weight: 600;
}

.admin-nav .nav-item[aria-current="page"] .icon { color: inherit; }

.admin-nav-foot {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: auto;
  padding-top: var(--space-2);
  border-top: 1px solid var(--divider);
}

.admin-nav-foot .nav-item { color: var(--text-muted); }

/* Buttons that carry an icon and a word */
.admin-body .liquid-btn-primary .icon,
.admin-body .liquid-btn .icon,
.admin-body .ghost .icon { width: 20px; height: 20px; }

/* ---------- Shared pieces ---------- */

.section-title,
.card-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-headline);
  font-weight: 800;
  letter-spacing: -0.01em;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-width: 0;
}

.admin-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
  padding: 18px;
  border-radius: var(--radius-group);
  background: var(--surface);
  box-shadow: var(--surface-edge);
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}

.card-aside {
  color: var(--text-muted);
  font-size: var(--text-caption);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.admin-search {
  display: block;
  flex: 1 1 110px;
  min-width: 0;
}

.status.small {
  min-height: 24px;
  padding: 0 9px;
  font-size: 12px;
}

.row-chevron {
  display: inline-flex;
  flex-shrink: 0;
  color: var(--text-muted);
}

.row-chevron .icon { width: 18px; height: 18px; }

.row-error {
  flex-basis: 100%;
  margin: -4px 0 0 52px;
}

/* "Sign in" inside an error line: same color, a full-size tap target */
.field-error a {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch);
  margin: -13px 0;
  padding: 0 4px;
  color: inherit;
  font-weight: 700;
}

/* Full-width row buttons: inset focus ring so the rounded list doesn't clip it */
.team-row:focus-visible,
.post-main:focus-visible,
.count-row:focus-visible { outline-offset: -3px; }

/* Skeleton rows the height of real rows */
.skeleton-list {
  gap: 0;
  padding: 0;
}

.skeleton-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 64px;
  padding: 10px var(--space-4);
}

.skeleton-row + .skeleton-row { border-top: 1px solid var(--divider); }

.skeleton-avatar {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.skeleton-lines {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

.skeleton.tiny {
  width: 32%;
  height: 10px;
}

.skeleton-block { min-height: 132px; }

/* ---------- Overview ---------- */

.ov {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}

.ov-tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}

.ov-tiles > div { min-height: 76px; }
.ov-hero-skeleton { min-height: 96px; }
.ov-tile-skeleton { min-height: 76px; padding: var(--space-3); }

.stat-hero.is-staffed .sample-label { color: var(--clear-ink); }

.ov-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
}

.count-rows {
  display: flex;
  flex-direction: column;
  margin: 0 -10px;
}

.count-row {
  appearance: none;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 52px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-field);
  background: transparent;
  color: var(--text-main);
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 140ms var(--ease), transform var(--dur-press) var(--ease);
}

@media (hover: hover) {
  .count-row:hover { background-color: var(--neutral-tint); }
}

.count-row:active { transform: scale(0.98); }

.count-label,
.count-row .status { margin-right: auto; }

.count-label {
  font-size: var(--text-body);
  font-weight: 600;
}

.count-value {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.count-list {
  display: flex;
  flex-direction: column;
  margin: 0;
}

.count-list > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 10px 0;
}

.count-list > div + div { border-top: 1px solid var(--divider); }

.count-list dt {
  min-width: 0;
  overflow: hidden;
  font-size: var(--text-body);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.count-list dd {
  flex-shrink: 0;
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.dd-pair {
  display: inline-flex;
  gap: var(--space-2);
}

.dd-muted {
  color: var(--text-muted);
  font-weight: 500;
}

.mix-groups {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
}

.mix-group { min-width: 0; }
.mix-group h3 { margin: 0 0 2px; }

/* ---------- Team ---------- */

.team-toolbar .segments {
  order: 3;
  flex: 1 1 100%;
  max-width: none;
}

.team-row {
  appearance: none;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 140ms var(--ease);
}

@media (hover: hover) {
  .team-row:hover,
  .post-main:hover { background-color: var(--group-bg); }
}

.team-row:active,
.post-main:active { background-color: var(--group-hover); }

.team-name {
  display: flex;
  flex: 1;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.team-head { display: none; }

.team-skills {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

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

.forms-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-5);
  align-items: start;
}

.forms-section,
.posts-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}

.link-person,
.lead-row { flex-wrap: wrap; }

.link-person .person-text,
.lead-row .person-text { flex: 1 1 110px; }

.person-text .pill-line { display: flex; }

.archived-toggle { align-self: flex-start; }

/* ---------- Posts & times ---------- */

.time-blocks {
  display: flex;
  flex-direction: column;
}

/* Title and Save share the top line; fields below; an error line under those */
.time-block {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "title save" "fields fields";
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  padding: var(--space-4) 0;
}

.time-block:first-child { padding-top: var(--space-1); }
.time-block:last-child { padding-bottom: 0; }
.time-block + .time-block { border-top: 1px solid var(--divider); }

.block-title {
  display: flex;
  grid-area: title;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: var(--text-body);
  font-weight: 700;
}

/* Unsaved: a copper dot by the title, and Save lights up */
.time-block.is-dirty .block-title::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--copper);
}

.time-fields {
  display: grid;
  grid-area: fields;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.time-fields > .stack:first-child:nth-last-child(3) { grid-column: 1 / -1; }

.block-foot { display: contents; }
.block-foot [data-action="save"] { grid-area: save; }

.block-foot .field-error {
  grid-column: 1 / -1;
  margin: -4px 0 0;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-height: 18px;
}

.label-row .time-clear {
  min-height: 28px;
  margin: -6px -8px -6px 0;
  padding: 0 8px;
  color: var(--text-muted);
  font-size: 13px;
}

.label-row .time-clear::after { inset: -8px -4px; }

.field[type="time"] {
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
  text-align: left;
}

.field[type="time"]::-webkit-date-and-time-value { text-align: left; }

.post-row {
  gap: 0;
  min-height: 0;
  padding: 0;
}

.post-main {
  appearance: none;
  display: flex;
  flex: 1;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  min-height: 64px;
  padding: 10px var(--space-3) 10px var(--space-4);
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 140ms var(--ease);
}

.post-order {
  display: flex;
  flex-shrink: 0;
  gap: var(--space-2);
  padding-right: var(--space-2);
}

.post-needs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.person-text .post-needs { margin-top: 4px; }

.post-cell {
  min-width: 0;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.posts-head { display: none; }

.stepper-group {
  display: flex;
  flex-direction: column;
  padding: 0 var(--space-3);
  border-radius: var(--radius-field);
  background-color: var(--field-bg);
  box-shadow: var(--field-edge);
}

.stepper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 60px;
}

.stepper-row + .stepper-row { border-top: 1px solid var(--divider); }

.stepper-label {
  min-width: 0;
  overflow: hidden;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Sheets & confirm ---------- */

.admin-sheet {
  max-height: calc(100dvh - env(safe-area-inset-top) - var(--space-4));
  overflow: hidden;
}

.admin-sheet[open] {
  display: flex;
  flex-direction: column;
}

.admin-sheet .sheet-form {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  padding: 0;
}

.admin-sheet .sheet-header {
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--divider);
}

.sheet-top {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
  padding-top: var(--space-2);
}

.sheet-top h2 { overflow-wrap: anywhere; }

.sheet-status {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.sheet-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-5);
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-5);
}

.sheet-footer {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5) calc(var(--space-4) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--divider);
  background: var(--surface);
}

.sheet-footer .liquid-btn-primary {
  width: 100%;
  margin-top: 0;
}

.sheet-alert { margin: 0; }

.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.sheet-actions > * { flex: 1 1 140px; }

.sheet-danger {
  padding-top: var(--space-5);
  border-top: 1px solid var(--divider);
}

.blackout-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.admin-confirm h2 { overflow-wrap: anywhere; }
.admin-confirm .demo-row { flex-wrap: wrap; }

@keyframes sheet-in-right {
  from { opacity: 0; transform: translateX(32px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Tablet: 640px+ ---------- */

@media (min-width: 640px) {
  .admin-sheet {
    width: min(520px, calc(100vw - 32px));
    max-height: min(88dvh, 880px);
  }

  .ov-tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }

  .mix-groups {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-5);
  }

  .time-fields { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr); }
  .time-fields > .stack:first-child:nth-last-child(3) { grid-column: auto; }
  .time-fields > .stack:only-child { grid-column: 2; }
}

/* ---------- Narrow phones ---------- */

@media (max-width: 400px) {
  .team-row .row-chevron { display: none; }
}

/* ---------- Desktop: 1000px+ ---------- */

@media (min-width: 1000px) {
  .admin-shell {
    display: grid;
    grid-template-columns: 248px minmax(0, 1100px);
    justify-content: center;
    gap: var(--space-6);
    padding: 0 max(var(--space-5), env(safe-area-inset-right)) 0 max(var(--space-4), env(safe-area-inset-left));
  }

  .admin-nav {
    display: flex;
    position: sticky;
    top: var(--space-4);
    height: calc(100dvh - 2 * var(--space-4));
    max-height: none;
    margin: var(--space-4) 0;
    padding: var(--space-3) 10px;
  }

  .admin-main {
    max-width: none;
    margin: 0;
    padding: var(--space-5) 0 var(--space-7);
  }

  .app-tabbar,
  .admin-theme-phone { display: none; }

  .app-bar { padding: var(--space-3) 4px 0; }

  .app-toast { bottom: calc(var(--space-5) + env(safe-area-inset-bottom)); }

  .panel {
    gap: var(--space-5);
    margin-top: var(--space-5);
  }

  /* Overview: hero + four tiles in one row, cards in three columns */
  .panel .staffing.ov-stats { grid-template-columns: minmax(0, 1.2fr) minmax(0, 2fr); }
  .ov-tiles .font-display { font-size: 24px; }
  .ov-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ov-wide { grid-column: 1 / -1; }
  .admin-card { padding: var(--space-5); }

  /* Team: a table-like list */
  .team-toolbar {
    flex-wrap: nowrap;
    gap: var(--space-3);
  }

  .team-toolbar .admin-search { flex: 0 1 300px; }

  .team-toolbar .segments {
    order: 0;
    flex: 0 1 auto;
    width: auto;
  }

  .team-toolbar .liquid-btn-primary { margin-left: auto; }

  .team-head,
  .team-row {
    display: grid;
    grid-template-columns: minmax(0, 2.2fr) minmax(0, 1.1fr) minmax(0, 0.9fr) minmax(0, 1.5fr) 128px 18px;
    align-items: center;
    gap: var(--space-4);
  }

  .team-head,
  .posts-head {
    min-height: 40px;
    padding: 0 var(--space-4);
    border-bottom: 1px solid var(--divider);
    color: var(--text-muted);
    font-size: var(--text-label);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .team-cell {
    min-width: 0;
    overflow: hidden;
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .team-cell.is-unset,
  .post-cell.is-unset { color: var(--text-muted); }

  .team-status { justify-self: start; }

  /* Forms: links side by side, then personal links | interest */
  .roster.link-roster {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .roster.link-roster .person:not(.hidden) ~ .person:not(.hidden) {
    border-top: 0;
    border-left: 1px solid var(--divider);
  }

  .forms-grid { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }

  .link-person .person-text { flex-basis: 160px; }

  /* Posts: each time block is one row; the post list gets columns */
  .time-block {
    grid-template-columns: 112px minmax(0, 1fr) auto;
    grid-template-areas: "title fields save";
    align-items: end;
    column-gap: var(--space-5);
  }

  .block-title { min-height: var(--touch); }
  .block-foot [data-action="save"] { margin-bottom: 4px; }
  .block-foot .field-error { grid-column: 2 / -1; }

  .posts-head {
    display: grid;
    grid-template-columns: 36px minmax(0, 2fr) 96px 132px minmax(0, 1.3fr) 96px;
    align-items: center;
    column-gap: var(--space-4);
    padding: 0 var(--space-2) 0 var(--space-4);
  }

  .post-main {
    display: grid;
    grid-template-columns: 36px minmax(0, 2fr) 96px 132px minmax(0, 1.3fr);
    column-gap: var(--space-4);
    padding: 10px var(--space-4);
  }

  .admin-sheet {
    width: 480px;
    height: calc(100dvh - 2 * var(--space-4));
    max-height: none;
    margin: var(--space-4) var(--space-4) var(--space-4) auto;
  }

  .admin-sheet[open] { animation: sheet-in-right var(--dur-sheet) var(--ease); }
}

/* Phone-only / wide-only bits. Last, so they win over the layouts above. */
@media (max-width: 999.98px) {
  .admin-body .only-wide { display: none; }
}

@media (min-width: 1000px) {
  .admin-body .only-phone { display: none; }
}
