/* ============================================================
   Auth + Wallet modals
   Self-contained — only references tokens defined in tokens.css.
   ============================================================ */

/* ---------- Scrim host ---------- */
.modal-host {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 16px 16px;
  background: rgba(0, 0, 0, 0.62);
  overflow-y: auto;
  opacity: 0;
  transition: opacity var(--t) var(--ease);
}
.modal-host.open {
  display: flex;
  opacity: 1;
  animation: modalHostIn var(--t) var(--ease);
}
@keyframes modalHostIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ---------- Modal panel ---------- */
.modal-host .modal {
  position: relative;
  width: 100%;
  max-width: 480px;
  background: var(--surface-800);
  border: 1px solid var(--hairline-2);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg), var(--shadow-2xl);
  color: var(--text-primary);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 64px);
  animation: modalPanelIn 220ms var(--ease);
}
.modal-host .modal[data-kind="wallet"] {
  max-width: 720px;
}
@keyframes modalPanelIn {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .modal-host,
  .modal-host .modal {
    animation: none !important;
    transition: none !important;
  }
}

@media (max-width: 600px) {
  .modal-host {
    padding: 0;
    align-items: stretch;
  }
  .modal-host .modal,
  .modal-host .modal[data-kind="wallet"] {
    max-width: 100%;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    border: 0;
  }
}

/* ---------- Header (tabs row + close) ---------- */
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 14px 20px;
  border-bottom: 1px solid var(--hairline);
  background: var(--surface-900);
}
.modal-head h2 {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}
.modal-tabs {
  display: inline-flex;
  background: var(--surface-700);
  padding: 4px;
  border-radius: var(--r-pill);
  gap: 2px;
}
.modal-tab {
  appearance: none;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--r-pill);
  white-space: nowrap;
  transition: background-color var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease);
}
.modal-tab:hover { color: var(--text-primary); }
.modal-tab[aria-current="page"] {
  background: var(--surface-500);
  color: var(--text-primary);
}

.modal-close {
  width: 36px; height: 36px;
  display: inline-flex;
  align-items: center; justify-content: center;
  color: var(--text-muted);
  border-radius: var(--r-md);
  flex: none;
  background: transparent;
}
.modal-close:hover { background: var(--hairline); color: var(--text-primary); }
.modal-close svg { width: 18px; height: 18px; }

/* ---------- Body ---------- */
.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-height: 0;
}

/* ---------- Fields ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field > label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.field input,
.field select {
  background: var(--surface-700);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  color: var(--text-primary);
  padding: 12px 14px;
  font-size: var(--text-sm);
  outline: 0;
  transition: border-color var(--t-fast) var(--ease),
              background-color var(--t-fast) var(--ease);
  width: 100%;
}
.field input::placeholder { color: var(--text-dim); }
.field input:focus,
.field select:focus {
  border-color: var(--brand-blue);
  background: var(--surface-600);
}
.field select {
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
                    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: right 16px center, right 11px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

/* Field with a trailing affordance (e.g. show/hide password) */
.field .input-wrap {
  position: relative;
  display: flex;
  align-items: stretch;
}
.field .input-wrap input { padding-right: 56px; }
.field .input-wrap .trailing {
  position: absolute;
  right: 4px; top: 50%;
  transform: translateY(-50%);
  height: 32px;
  padding: 0 10px;
  display: inline-flex; align-items: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: transparent;
  border-radius: var(--r-sm);
}
.field .input-wrap .trailing:hover { color: var(--text-primary); background: var(--hairline); }

.field .err {
  color: var(--brand-red);
  font-size: 12px;
  margin-top: 2px;
  min-height: 0;
}
.field.error input,
.field.error select {
  border-color: var(--brand-red);
}

.form-row {
  display: flex;
  gap: 8px;
}
.form-row > * { flex: 1; min-width: 0; }

/* Checkbox row */
.checkbox {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: var(--text-sm);
  color: var(--text-muted);
  line-height: 1.4;
  cursor: pointer;
  user-select: none;
}
.checkbox input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px; height: 18px;
  flex: none;
  margin-top: 2px;
  background: var(--surface-700);
  border: 1px solid var(--hairline-2);
  border-radius: var(--r-sm);
  display: inline-grid;
  place-content: center;
  cursor: pointer;
}
.checkbox input[type="checkbox"]:checked {
  background: var(--brand-blue);
  border-color: var(--brand-blue);
}
.checkbox input[type="checkbox"]:checked::after {
  content: "";
  width: 5px; height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}
.checkbox a {
  color: var(--brand-blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.link {
  color: var(--brand-blue);
  font-size: var(--text-sm);
  font-weight: 600;
}
.link:hover { color: var(--brand-blue-hover); text-decoration: underline; }

/* Promo collapser */
.promo-toggle {
  background: transparent;
  color: var(--brand-blue);
  font-size: var(--text-sm);
  font-weight: 600;
  text-align: left;
  padding: 4px 0;
}
.promo-toggle:hover { color: var(--brand-blue-hover); text-decoration: underline; }

/* ---------- Submit ---------- */
.modal-submit {
  position: relative;
  width: 100%;
  padding: 13px 20px;
  background: var(--brand-blue);
  color: var(--text-on-brand);
  font-size: var(--text-base);
  font-weight: 700;
  border-radius: var(--r-md);
  box-shadow: var(--btn-shadow);
  transition: filter var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.modal-submit:hover { background: var(--brand-blue-hover); }
.modal-submit[disabled] { opacity: 0.6; cursor: not-allowed; filter: none; }
.modal-submit.loading { pointer-events: none; }
.modal-submit .spinner {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  animation: spin 700ms linear infinite;
  display: none;
}
.modal-submit.loading .spinner { display: inline-block; }
.modal-submit.loading .label { opacity: 0.6; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Register form blurb + optional details ---------- */
.auth-blurb {
  margin: 0 0 6px;
  padding: 12px 14px;
  background: linear-gradient(135deg, rgba(3, 230, 37, 0.12), rgba(20, 117, 225, 0.08));
  border: 1px solid rgba(3, 230, 37, 0.25);
  border-radius: var(--r-md);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.4;
}
.auth-more {
  background: var(--surface-700);
  border-radius: var(--r-md);
  border: 1px solid var(--hairline-2);
  margin: 4px 0;
}
.auth-more > summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 14px;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: space-between;
  user-select: none;
}
.auth-more > summary::-webkit-details-marker { display: none; }
.auth-more > summary::after {
  content: "+"; font-size: 18px; font-weight: 800; color: var(--text-muted);
  transition: transform var(--t-fast) var(--ease);
}
.auth-more[open] > summary::after { content: "−"; }
.auth-more[open] > summary { color: var(--text-primary); border-bottom: 1px solid var(--hairline); }
.auth-more > .field { padding: 0 14px; }
.auth-more > .field:first-of-type { padding-top: 10px; }
.auth-more > .field:last-of-type { padding-bottom: 14px; }

/* ---------- "or sign in with" divider ---------- */
.modal-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 4px 0;
}
.modal-divider::before,
.modal-divider::after {
  content: "";
  height: 1px;
  background: var(--hairline-2);
}

.oauth-row.modal-oauth {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.oauth-row.modal-oauth .oauth-btn {
  background: var(--surface-700);
  height: 44px;
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--btn-shadow);
  color: var(--text-primary);
  transition: background-color var(--t-fast) var(--ease);
}
.oauth-row.modal-oauth .oauth-btn:hover { background: var(--surface-500); }
.oauth-row.modal-oauth .oauth-btn svg { width: 22px; height: 22px; }
.oauth-row.loading { pointer-events: none; }
.oauth-row .oauth-btn.loading {
  position: relative;
  background: var(--surface-500);
}
.oauth-row .oauth-btn.loading svg { opacity: 0.35; }
.oauth-row .oauth-btn.loading::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 18px; height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.25);
  border-top-color: var(--brand-blue);
  animation: spin 700ms linear infinite;
}

.legal-note {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  text-align: center;
  padding-top: 4px;
}
.legal-note a { color: var(--brand-blue); }

.modal-footnote {
  text-align: center;
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin: 8px 0 0;
  padding-top: 6px;
}
.modal-footnote a {
  color: var(--brand-blue);
  font-weight: 700;
  text-decoration: none;
}
.modal-footnote a:hover { text-decoration: underline; }

/* ============================================================
   Wallet modal
   ============================================================ */
.modal[data-kind="wallet"] .modal-body {
  padding: 0;
}
.wallet-grid {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 460px;
  height: 100%;
}
@media (max-width: 600px) {
  .wallet-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
}

.currency-list {
  background: var(--surface-900);
  border-right: 1px solid var(--hairline);
  padding: 8px;
  overflow-y: auto;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
@media (max-width: 600px) {
  .currency-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--hairline);
    padding: 8px;
    gap: 6px;
    max-height: 76px;
  }
  .currency-list::-webkit-scrollbar { display: none; }
}
.currency-row {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 12px;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease);
  text-align: left;
  width: 100%;
  flex: none;
}
.currency-row:hover {
  background: var(--surface-700);
  color: var(--text-primary);
}
.currency-row[aria-current="true"] {
  background: var(--surface-700);
  color: var(--text-primary);
}
.currency-row .ccy-icon {
  width: 28px; height: 28px;
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--brand-gold);
}
.currency-row .ccy-icon svg { width: 28px; height: 28px; }
.currency-row .ccy-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.currency-row .ccy-code {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-primary);
}
.currency-row .ccy-balance {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.wallet-pane {
  padding: 20px;
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.wallet-pane h3 {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--text-primary);
}
.wallet-pane p, .wallet-pane li {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.qr-wrap {
  display: flex;
  justify-content: center;
  padding: 8px 0 4px;
}
.qr {
  width: 200px;
  height: 200px;
  background: #fff;
  padding: 10px;
  border-radius: var(--r-md);
}
.qr svg { width: 100%; height: 100%; display: block; }

.address {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-700);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 10px 12px;
}
.address .addr-text {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.address .copy-btn {
  flex: none;
  padding: 6px 12px;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-primary);
  background: var(--surface-500);
  border-radius: var(--r-sm);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.address .copy-btn:hover { background: var(--surface-400); }
.address .copy-btn.copied { background: var(--brand-green); color: #07140A; }

.notes {
  background: var(--surface-700);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 12px 14px;
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.6;
}
.notes strong { color: var(--text-primary); }

.fee-row {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-sm);
  color: var(--text-muted);
  padding: 2px 2px 0;
}
.fee-row .val { color: var(--text-primary); font-variant-numeric: tabular-nums; }

.vault-stat {
  background: var(--surface-700);
  border-radius: var(--r-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.vault-stat .label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.vault-stat .amt {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   Topbar (logged-in chrome) — minimal additions when Auth
   mutates .topbar .actions
   ============================================================ */
.topbar .actions .wallet-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-700);
  border-radius: var(--r-md);
  padding: 5px 5px 5px 14px;
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
}
.topbar .actions .wallet-pill .pill-amt { font-variant-numeric: tabular-nums; }
.topbar .actions .wallet-pill .pill-ccy {
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.topbar .actions .wallet-pill .pill-cta {
  background: var(--brand-blue);
  color: #fff;
  padding: 7px 14px;
  border-radius: var(--r-md);
  font-size: var(--text-xs);
  font-weight: 700;
}
.topbar .actions .wallet-pill .pill-cta:hover { background: var(--brand-blue-hover); }

.topbar .actions .avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-blue), var(--brand-purple));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
}
.topbar .actions .avatar:hover { filter: brightness(1.1); }
