:root {
  --brand: #3f6087;
  --brand-dark: #2d4c70;
  --brand-soft: #eaf0f6;
  --accent: #3f91df;
  --text: #26313d;
  --muted: #687583;
  --border: #c8d0d8;
  --surface: #ffffff;
  --background: #f4f6f8;
  --danger: #a52a2a;
  --danger-soft: #fff3f2;
  --shadow: 0 3px 16px rgba(30, 48, 67, 0.08);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--background);
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background: var(--background);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select {
  touch-action: manipulation;
}

button:focus-visible,
.admin-link:focus-visible,
select:focus-visible,
textarea:focus-visible,
input[type="password"]:focus-visible,
input:focus-visible + span {
  outline: 3px solid rgba(63, 145, 223, 0.3);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.access-page {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px 16px;
  place-items: center;
}

.access-card {
  width: min(100%, 440px);
  padding: 34px;
  border: 1px solid #e2e6ea;
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.access-card > img {
  display: block;
  width: min(72%, 250px);
  height: auto;
  margin: 0 auto 30px;
}

.access-card > p:not(.eyebrow) {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.access-form {
  display: grid;
  gap: 12px;
  margin-top: 26px;
}

.access-form label {
  color: #303b46;
  font-weight: 650;
}

.access-form input[type="password"] {
  width: 100%;
  height: 54px;
  padding: 0 15px;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  background: #fff;
}

.access-form input[type="password"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(63, 145, 223, 0.13);
  outline: 0;
}

.access-form .primary-button {
  width: 100%;
  margin-top: 4px;
}

.access-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.9rem;
  line-height: 1.4;
}

.access-back {
  justify-self: center;
  color: var(--brand-dark);
  font-size: 0.9rem;
  font-weight: 700;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}

.install-button,
.admin-link {
  position: fixed;
  z-index: 15;
  top: max(12px, env(safe-area-inset-top));
  display: grid;
  width: 42px;
  height: 42px;
  padding: 10px;
  place-items: center;
  border: 1px solid #d9e0e6;
  border-radius: 50%;
  color: var(--brand);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 3px 12px rgba(30, 48, 67, 0.12);
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.install-button {
  right: 14px;
}

.admin-link {
  left: 14px;
}

.install-button:hover,
.admin-link:hover {
  color: #fff;
  border-color: var(--brand);
  background: var(--brand);
}

.install-button svg,
.admin-link svg {
  width: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.page {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 28px 16px 44px;
}

.card {
  padding: 28px;
  border: 1px solid #e2e6ea;
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand-panel {
  display: grid;
  min-height: 190px;
  place-items: center;
  padding: 18px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.brand-panel img {
  display: block;
  width: min(78%, 380px);
  height: auto;
}

.card-heading {
  margin: 32px 0 28px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--brand);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: #28333e;
  font-size: clamp(1.75rem, 5vw, 2.25rem);
  line-height: 1.15;
}

.card-heading > p:last-child {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.field {
  margin-top: 26px;
}

.field label,
.field legend {
  display: block;
  margin-bottom: 10px;
  padding: 0;
  color: #303b46;
  font-size: 1rem;
  font-weight: 650;
}

.optional {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
}

.select-wrap {
  position: relative;
}

select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  background: #fff;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

select:hover,
textarea:hover {
  border-color: #9ba8b5;
}

select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(63, 145, 223, 0.13);
  outline: 0;
}

select {
  height: 58px;
  padding: 0 50px 0 16px;
  appearance: none;
  cursor: pointer;
}

select:disabled {
  cursor: wait;
  color: var(--muted);
  background: #f5f6f7;
}

.select-icon {
  position: absolute;
  top: 50%;
  right: 19px;
  width: 0;
  height: 0;
  border-top: 7px solid #5e6872;
  border-right: 6px solid transparent;
  border-left: 6px solid transparent;
  pointer-events: none;
  transform: translateY(-50%);
}

.members-field {
  min-width: 0;
  padding: 0;
  border: 0;
}

.field-help {
  margin: -4px 0 14px;
  color: var(--muted);
  font-size: 0.875rem;
}

#visitor-field .field-help {
  margin: 8px 0 0;
}

.member-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.member-choice {
  position: relative;
  margin: 0 !important;
  cursor: pointer;
}

.member-choice input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.member-choice span {
  display: grid;
  min-width: 94px;
  min-height: 52px;
  padding: 10px 16px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #46515c;
  background: #fff;
  font-size: 1rem;
  font-weight: 550;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}

.member-choice:hover span {
  border-color: #91a1b0;
  transform: translateY(-1px);
}

.member-choice input:checked + span {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

textarea {
  min-height: 112px;
  padding: 14px 16px;
  resize: vertical;
  line-height: 1.45;
}

.character-count {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: right;
}

.field-error {
  margin: 9px 0 0;
  color: var(--danger);
  font-size: 0.875rem;
}

.inline-status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 26px;
  color: var(--muted);
  font-size: 0.9rem;
}

.spinner,
.button-spinner {
  width: 19px;
  height: 19px;
  border: 2px solid #cdd7e0;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.notice {
  display: grid;
  gap: 4px;
  margin-bottom: 22px;
  padding: 14px 16px;
  border: 1px solid #edc4c0;
  border-radius: 7px;
  color: #70231f;
  background: var(--danger-soft);
  font-size: 0.9rem;
  line-height: 1.4;
}

.notice code {
  font-size: 0.85em;
}

.text-button {
  width: max-content;
  margin-top: 4px;
  padding: 0;
  border: 0;
  color: var(--brand-dark);
  background: transparent;
  font-weight: 750;
  text-decoration: underline;
  cursor: pointer;
}

.action-bar {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 12px max(16px, calc((100vw - 728px) / 2)) calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid #dce1e6;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 -4px 18px rgba(36, 48, 60, 0.06);
}

.primary-button {
  min-height: 52px;
  padding: 12px 18px;
  border-radius: 6px;
  font-weight: 750;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.primary-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid var(--accent);
  color: #fff;
  background: var(--accent);
}

.primary-button:hover:not(:disabled) {
  border-color: #287bc8;
  background: #287bc8;
}

.primary-button:active:not(:disabled) {
  transform: translateY(1px);
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.button-spinner {
  display: none;
  width: 17px;
  height: 17px;
  border-color: rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
}

.primary-button.is-loading .button-spinner {
  display: block;
}

.success-page {
  position: fixed;
  z-index: 40;
  inset: 0;
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(32px, env(safe-area-inset-top)) 24px max(28px, env(safe-area-inset-bottom));
  place-items: center;
  overflow-y: auto;
  background: #fff;
}

.success-content {
  display: flex;
  width: min(100%, 520px);
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.success-mark {
  display: grid;
  width: 88px;
  height: 88px;
  margin-bottom: 28px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--brand);
  box-shadow: 0 12px 30px rgba(63, 96, 135, 0.23);
}

.success-mark svg {
  width: 46px;
  fill: currentColor;
}

.success-family {
  margin: 22px 0 5px;
  font-size: 1.2rem;
  font-weight: 750;
}

.success-members {
  max-width: 440px;
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.success-actions {
  display: grid;
  width: min(100%, 330px);
  gap: 8px;
  margin-top: 34px;
}

.success-action {
  width: min(100%, 330px);
}

.success-action svg {
  width: 20px;
  fill: currentColor;
}

.success-brand {
  position: absolute;
  right: 24px;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: 24px;
  text-align: center;
  pointer-events: none;
}

.success-brand img {
  width: 150px;
  max-height: 52px;
  object-fit: contain;
  opacity: 0.28;
}

@media (max-width: 600px) {
  .access-card {
    padding: 28px 22px;
  }

  .app-shell {
    padding-bottom: calc(78px + env(safe-area-inset-bottom));
  }

  .page {
    padding: 0px 0 0px;
  }

  .card {
    padding: 22px 20px 30px;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .brand-panel {
    min-height: 156px;
    padding: 14px;
  }

  .card-heading {
    margin: 27px 0 22px;
  }

  .member-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .member-choice span {
    min-width: 0;
  }

  .action-bar {
    grid-template-columns: 1fr;
    padding-right: 16px;
    padding-left: 16px;
  }
}

@media (max-width: 380px) {
  .brand-panel {
    min-height: 140px;
  }

  .member-grid {
    grid-template-columns: 1fr;
  }
}
