:root {
  --primary: #2169ac;
  --primary-dark: #154e80;
  --secondary: #89ccff;
  --mist: #e7f4ff;
  --paper: #f3f7fb;
  --ink: #1c1917;
  --stone: #78716c;
  --line: #e7e5e4;
  --white: #ffffff;
  --danger: #b42318;
  --danger-mist: #fee4e2;
  --amber: #9a5b00;
  --amber-mist: #fff4e5;
  --ok: #067647;
  --ok-mist: #e6f6ee;
  --shadow: 0 16px 40px rgba(21, 78, 128, 0.08);
  --radius: 18px;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: clip;
}

button, input { font: inherit; }

img { max-width: 100%; }

h1, h2, p { margin: 0; }

h1 { font-size: 2rem; letter-spacing: -0.03em; }

h2 { font-size: 1.15rem; }

.muted { color: var(--stone); }

.eyebrow {
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.gate {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: safe center;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  overflow: auto;
  background:
    radial-gradient(circle at top, var(--secondary), transparent 42%),
    var(--paper);
}

.gate-card {
  width: min(420px, 100%);
  padding: clamp(18px, 5vw, 28px);
  display: grid;
  gap: 14px;
}

.logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
}

.logo-small {
  width: 42px;
  height: 42px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
  font-weight: 650;
}

input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid #d6d3d1;
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--white);
  color: var(--ink);
  font-size: 16px;
}

input:focus {
  outline: 3px solid rgba(33, 105, 172, 0.25);
  border-color: var(--primary);
}

.button {
  border: 0;
  border-radius: 12px;
  min-height: 44px;
  padding: 12px 16px;
  background: var(--primary);
  color: white;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.button:hover { background: var(--primary-dark); }

.button:disabled {
  opacity: 0.55;
  cursor: default;
}

.button-ghost {
  background: var(--white);
  color: var(--primary-dark);
  border: 1px solid #c5dff3;
}

.button-ghost:hover { background: var(--mist); }

.button-danger {
  background: var(--white);
  color: var(--danger);
  border: 1px solid #f3c7c3;
}

.button-danger:hover { background: var(--danger-mist); }

.form-error, .banner {
  color: var(--danger);
  background: var(--danger-mist);
  border-radius: 12px;
  padding: 10px 12px;
}

.shell { min-height: 100vh; min-height: 100dvh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px 16px;
  align-items: center;
  padding:
    max(12px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    12px
    max(16px, env(safe-area-inset-left));
  background: rgba(243, 247, 251, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand, .topbar-actions, .block-head, .price-row, .person, .option, .payment-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand { text-align: left; flex: 1 1 auto; }

.topbar-actions {
  margin-left: auto;
  max-width: 100%;
  justify-content: flex-end;
}

.admin-email {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: min(420px, 46vw);
}

.page {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding:
    20px
    max(16px, env(safe-area-inset-right))
    max(40px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  display: grid;
  gap: clamp(20px, 4vw, 28px);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
  gap: 12px;
}

.stat {
  padding: 18px 20px;
  background: var(--mist);
  border-color: #c5dff3;
  box-shadow: none;
}

.stat-value {
  font-size: clamp(1.6rem, 4vw, 2rem);
  font-weight: 750;
  letter-spacing: -0.04em;
}

.block { display: grid; gap: 12px; min-width: 0; }

.block-head {
  flex-wrap: wrap;
  justify-content: space-between;
}

.block-head h2 { flex: 1 1 140px; }

.block-head input,
.block-head .button {
  flex: 1 1 180px;
  width: auto;
  max-width: 320px;
}

.stack { display: grid; gap: 10px; min-width: 0; }

.split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
  gap: 22px;
  align-items: start;
}

.price-row {
  padding: 16px;
  flex-wrap: wrap;
  align-items: end;
  box-shadow: none;
}

.price-row label { flex: 1 1 180px; }

.price-row .button { flex: 1 1 120px; }

.payment, .person, .option, .empty {
  padding: 16px;
  box-shadow: none;
  min-width: 0;
}

.payment { display: grid; gap: 10px; }

.payment p, .payment strong, .person-main span, .option-main span {
  overflow-wrap: anywhere;
}

.payment img.shot {
  width: 100%;
  height: clamp(160px, 42vw, 280px);
  object-fit: cover;
  border-radius: 14px;
  background: var(--paper);
  cursor: zoom-in;
}

.payment-actions { flex-wrap: wrap; justify-content: flex-end; }

.payment .payment-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr));
}

.person, .option {
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
}

.person-main, .option-main {
  display: grid;
  gap: 2px;
  flex: 1 1 180px;
  min-width: 0;
}

.person-main strong, .option-main strong {
  overflow-wrap: anywhere;
}

.pill {
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--paper);
  color: var(--stone);
  white-space: normal;
  text-align: center;
  max-width: 100%;
}

.pill-ok { background: var(--ok-mist); color: var(--ok); }

.pill-wait { background: var(--amber-mist); color: var(--amber); }

.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--stone);
}

dialog {
  width: min(460px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  margin: auto;
  border: 0;
  border-radius: 20px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(28, 25, 23, 0.45); }

#dialog form, #viewer {
  display: grid;
  gap: 14px;
  padding: clamp(16px, 4vw, 22px);
  max-height: calc(100dvh - 24px);
  overflow: auto;
}

#dialog-body { display: grid; gap: 12px; }

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.dialog-actions .button { flex: 1 1 120px; }

#viewer {
  width: min(860px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
}

#viewer img {
  width: 100%;
  max-height: 75vh;
  object-fit: contain;
  background: var(--paper);
  border-radius: 12px;
}

.empty { color: var(--stone); }

@media (max-width: 560px) {
  .topbar-actions {
    flex: 1 1 100%;
    margin-left: 0;
    justify-content: space-between;
  }

  .block-head input,
  .block-head .button,
  .price-row .button {
    flex-basis: 100%;
    max-width: none;
  }

  .admin-email {
    max-width: none;
    flex: 1 1 auto;
  }

  h1 { font-size: 1.7rem; }
}
