/* ═══════════════════════════════════════════════════════════════
   Mobile layout (≤ 859px) — touch-first, single column, thumb reach.
   Paired with /assets/portal.mobile.js and /assets/admin.mobile.js.
   Every interactive target is at least 44px tall.
   ═══════════════════════════════════════════════════════════════ */

:root {
  --m-gutter: 16px;
  --m-head: 56px;
}

body { font-size: 16px; } /* stops iOS zooming inputs on focus */

.btn { min-height: 3rem; }
.btn--sm { min-height: 2.75rem; }
.btn--icon-only { width: 3rem; }
.field input, .field select { min-height: 3rem; font-size: 1rem; }
.icon-btn { width: 2.75rem; height: 2.75rem; }
.icon-picker__opt { width: 2.75rem; height: 2.75rem; }

/* ── Login ───────────────────────────────────────────────────── */
.m-login-shell {
  min-height: 100dvh;
  display: grid;
  align-content: center;
  padding: var(--m-gutter);
  padding-top: max(var(--m-gutter), env(safe-area-inset-top));
  padding-bottom: max(var(--m-gutter), env(safe-area-inset-bottom));
  background:
    radial-gradient(600px 320px at 50% 0%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 70%),
    var(--bg);
}
.m-login {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-2);
}
.m-login__brand {
  display: grid;
  justify-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.m-login__title {
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.m-login__sub {
  margin-bottom: var(--space-5);
  text-align: center;
  font-size: 13px;
  color: var(--ink-3);
}

/* ── Shell ───────────────────────────────────────────────────── */
/* Flex, not a fixed grid template: the portal shell and the management shell
   have different numbers of rows, and the out-of-flow sheet/scrim are not grid
   items at all — so a hard-coded `grid-template-rows` put the footer in the
   stretch track and pushed its bottom edge off-screen. Flex adapts to whatever
   children each screen has. */
.m-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  /* Keep the footer clear of the home indicator / browser chrome. */
  padding-bottom: env(safe-area-inset-bottom);
}
.m-shell > .m-main { flex: 1 1 auto; }
.m-shell > .m-head,
.m-shell > .m-filters,
.m-shell > .m-foot,
.m-shell > .m-presence-line { flex: 0 0 auto; }

.m-head {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  height: var(--m-head);
  padding: 0 var(--m-gutter);
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
}
.m-head__left { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.m-head__right { display: flex; align-items: center; gap: var(--space-3); flex: none; }
.m-head .brand-badge { width: 2.125rem; height: 2.125rem; }
.m-head .brand-badge .brand-mark { width: 1.25rem; }
.m-head__title {
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.m-presence {
  appearance: none;
  display: grid;
  place-content: center;
  min-width: 2.75rem; height: 2.75rem;
  padding: 0 var(--space-2);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-2);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.m-presence-line {
  padding: var(--space-2) var(--m-gutter);
  font-size: 12px;
  color: var(--ink-3);
}

/* ── Filters ─────────────────────────────────────────────────── */
.m-filters {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--m-gutter);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.m-filters::-webkit-scrollbar { display: none; }
.m-chip {
  appearance: none;
  flex: none;
  min-height: 2.75rem;
  padding: 0 var(--space-4);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-2);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.m-chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

/* ── List ────────────────────────────────────────────────────── */
.m-main { padding: 0 var(--m-gutter) var(--space-6); }
.m-list { display: grid; gap: var(--space-4); }
.m-rows { display: grid; gap: var(--space-2); }

.m-group {
  margin-bottom: calc(-1 * var(--space-3));
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.m-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}

.m-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 16px;
  align-items: center;
  gap: var(--space-3);
  min-height: 62px;
  padding: var(--space-3) var(--space-4);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
  -webkit-tap-highlight-color: color-mix(in srgb, var(--accent) 12%, transparent);
}
.m-row:last-child { border-bottom: 0; }
.m-row:active { background: var(--surface-2); }
.m-row__icon {
  display: grid;
  place-content: center;
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--on-accent);
}
.m-row__text { display: grid; gap: 2px; min-width: 0; }
.m-row__name { font-size: 15px; font-weight: 500; }
.m-row__sub {
  font-size: 13px;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.m-row__arrow { color: var(--ink-3); font-size: 20px; text-align: right; }

.m-empty {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-4);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  text-align: center;
  color: var(--ink-3);
}
.m-empty h2 { font-size: 16px; color: var(--ink-2); }

/* ── Footer ──────────────────────────────────────────────────── */
.m-foot {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4) var(--m-gutter);
  padding-bottom: max(var(--space-4), env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  text-align: center;
}
.m-foot__note { font-size: 12px; color: var(--ink-3); }
.m-foot__actions { display: flex; justify-content: center; gap: var(--space-2); }

/* ── Presence sheet ──────────────────────────────────────────── */
.m-scrim {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgb(0 0 0 / 0.4);
}
.m-sheet {
  position: fixed;
  z-index: 71;
  left: 0; right: 0; bottom: 0;
  display: grid;
  gap: var(--space-3);
  max-height: 80dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-3) var(--m-gutter);
  padding-bottom: max(var(--space-5), env(safe-area-inset-bottom));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  animation: sheet-up 0.22s ease;
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
.m-sheet__grip {
  width: 38px; height: 4px;
  margin: 0 auto;
  border-radius: 999px;
  background: var(--line-strong);
}
.m-sheet__title { font-size: 14px; }
.m-sheet__list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-3); }
.m-sheet__row { display: flex; align-items: center; gap: var(--space-3); font-size: 14px; }
.m-sheet__tag {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 11px;
  color: var(--ink-3);
}
.m-sheet__typing { margin-left: 6px; font-size: 12px; color: var(--ink-2); }

/* ── Admin (mobile) ──────────────────────────────────────────── */
.m-admin-body { display: grid; gap: var(--space-3); }

.m-edit {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.m-edit__summary {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 56px;
  padding: 0 var(--space-4);
  cursor: pointer;
  list-style: none;
}
.m-edit__summary::-webkit-details-marker { display: none; }
.m-edit__icon { color: var(--ink); display: grid; place-content: center; flex: none; }
.m-edit__name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.m-edit__off {
  margin-left: auto;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 11px;
  color: var(--ink-3);
}
.m-edit[open] .m-edit__summary { border-bottom: 1px solid var(--line); }
.m-edit__body { padding: var(--space-4); background: var(--surface-2); }
.m-edit__tools { display: grid; gap: var(--space-3); }
.m-edit__move { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.m-add {
  margin-top: var(--space-4);
  padding: var(--space-4);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}
.m-add h3 { font-size: 14px; margin-bottom: var(--space-4); }

.m-panel__body {
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.m-sec { padding-bottom: var(--space-4); margin-bottom: var(--space-4); border-bottom: 1px solid var(--line); }
.m-sec h4 { font-size: 14px; margin-bottom: var(--space-1); }
.m-sec .btn { margin-bottom: var(--space-2); }

/* Live cursors are pointer-only; never render them on touch. */
.cursor-layer { display: none; }
