.modal-backdrop { position: fixed; top: 0; left: 0; right: 0; bottom: 0; height: 100vh; height: 100dvh; max-height: 100dvh; background: rgba(26, 25, 22, 0.45); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 200; padding: var(--s-5); animation: nx-fadeIn 160ms var(--ease-out); }
.modal-backdrop[hidden] { display: none; }
@keyframes nx-fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal { width: 100%; max-width: 560px; background: var(--bg-elevated); border-radius: var(--r-2xl); box-shadow: var(--shadow-xl); max-height: 90vh; max-height: 90dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; animation: nx-slideUp 220ms var(--ease-out); }
.modal--wide { max-width: 720px; }
@keyframes nx-slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal__head { padding: var(--s-5) var(--s-6) var(--s-4); border-bottom: 1px solid var(--border-subtle); display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s-4); }
.modal__crumb { font-size: 10px; font-weight: 600; letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--fg-3); }
.modal__title { font-family: var(--font-serif); font-size: 32px; line-height: 1.1; letter-spacing: -0.015em; font-weight: 400; margin: 4px 0 0; }
.modal__title em { color: var(--accent); font-style: italic; }
.modal__sub { font-size: var(--text-sm); color: var(--fg-2); margin-top: 4px; }
.modal__close { width: 32px; height: 32px; border-radius: var(--r-full); border: 1px solid var(--border-subtle); background: var(--surface); font-size: 20px; color: var(--fg-2); cursor: pointer; line-height: 1; display: grid; place-items: center; font-family: inherit; }
.modal__close:hover { background: var(--bg-hover); }
.modal__body { padding: var(--s-5) var(--s-6); overflow-y: auto; display: grid; gap: var(--s-4); }
.modal__foot { padding: var(--s-4) var(--s-6); border-top: 1px solid var(--border-subtle); background: var(--surface-2); display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.modal__hint { font-family: var(--font-mono); font-size: 11px; color: var(--fg-3); }

.field { display: grid; gap: 6px; }
.field label { font-size: 11px; font-weight: 600; letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--fg-3); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }
.field-row--3 { grid-template-columns: 1.2fr 1fr 0.7fr; }
textarea.nx-input { min-height: 70px; padding-top: 10px; padding-bottom: 10px; resize: vertical; font-family: inherit; }
select.nx-input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%23625f55' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 34px; }
.pill-grid { display: flex; gap: 6px; flex-wrap: wrap; }
.pill-opt { padding: 7px 12px; border: 1px solid var(--border); border-radius: var(--r-full); background: var(--surface); font-size: var(--text-sm); color: var(--fg-2); cursor: pointer; font-family: inherit; min-height: 34px; }
.pill-opt:hover { border-color: var(--border-strong); }
.pill-opt.on { background: var(--accent-soft); color: var(--accent-soft-fg); border-color: var(--accent-border); font-weight: 600; }

.toast { position: fixed; bottom: var(--s-6); left: 50%; transform: translateX(-50%); background: var(--paper-800); color: #f5f2e8; padding: 12px 18px; border-radius: var(--r-full); font-size: var(--text-sm); font-weight: 500; display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow-xl); z-index: 200; animation: nx-toastIn 240ms var(--ease-spring); max-width: 90vw; }
.toast[hidden] { display: none; }
.toast svg { width: 18px; height: 18px; color: #a5b4fc; flex-shrink: 0; }
.toast--success svg { color: #6b9b6b; }
.toast--danger svg { color: #d97757; }
@keyframes nx-toastIn { from { transform: translate(-50%, 20px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

.is-new, .just-added { background: var(--accent-soft) !important; animation: nx-highlight 2.2s var(--ease-out); }
@keyframes nx-highlight { 0% { background: var(--accent); color: white; } 100% { background: transparent; color: inherit; } }

.modal__body { min-height: 0; }

@media (max-width: 768px) {
  body:has(.modal-backdrop:not([hidden])) .nx-mobile-nav,
  body:has(.seat-modal:not([hidden])) .nx-mobile-nav { display: none !important; }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    width: 100%;
    max-height: 100%;
    border-radius: var(--r-2xl) var(--r-2xl) 0 0;
    margin-top: auto;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    animation: nx-sheetUp 240ms cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  .modal::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    margin: 8px auto 0;
    border-radius: 2px;
    background: var(--border);
  }
  .modal__head { padding: var(--s-3) var(--s-4) var(--s-3); gap: var(--s-3); }
  .modal__title { font-size: 24px; }
  .modal__body { padding: var(--s-4); gap: var(--s-3); }
  .modal__foot {
    padding: var(--s-3) var(--s-4);
    padding-bottom: calc(var(--s-3) + env(safe-area-inset-bottom, 0px));
    flex-wrap: nowrap;
    gap: var(--s-2);
    position: sticky;
    bottom: 0;
    z-index: 1;
  }
  .modal__foot > div { flex: 1 1 auto; justify-content: flex-end; }
  .modal__foot .nx-btn { flex: 1 1 auto; min-height: 44px; font-size: var(--text-sm); }
  .modal__hint { display: none; }

  .modal .field-row,
  .modal .field-row--2,
  .modal .field-row--3 { grid-template-columns: 1fr !important; }

  /* 16px font prevents iOS from zooming the viewport when focusing form controls. */
  .modal input,
  .modal select,
  .modal textarea,
  .modal .nx-input { font-size: 16px !important; min-height: 44px; }
  .modal textarea,
  .modal textarea.nx-input { min-height: 72px; }
}

@media (max-width: 380px) {
  .modal__title { font-size: 20px; }
  .modal__head { padding: var(--s-3) var(--s-3); }
  .modal__body { padding: var(--s-3); }
  .modal__foot { padding: var(--s-3); padding-bottom: calc(var(--s-3) + env(safe-area-inset-bottom, 0px)); }
}

@keyframes nx-sheetUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

/* Lock body scroll while a modal is open — prevents iOS rubber-band
   jumping the sheet around when the user scrolls inside fields. */
html.nx-modal-open, html.nx-modal-open body {
  overflow: hidden;
  touch-action: none;
}
