/* ============================================================
   BankLink — shared styles for the user-facing linking flow
   Faithful reproduction of the Plaid Link modal from reference
   screenshots. Colors read from brand.js via inline CSS vars set
   on :root by js/brand-apply.js.
   ============================================================ */

:root {
  --blue: #0A85EA;        /* primary accent (spinner, links, focus) */
  --navy: #0A2540;        /* CTA + logo tile */
  --teal: #00D4B1;        /* progress bar active + input focus glow */
  --ink: #111826;         /* headings */
  --body: #4B5563;        /* body text */
  --muted: #8A94A6;       /* captions, placeholders */
  --line: #E4E7EC;        /* borders/dividers */
  --panel: #F7F9FC;       /* footer legal band */
  --card: #FFFFFF;
  --radius-modal: 24px;
  --radius-field: 10px;
  --radius-tile: 14px;
  --shadow-modal: 0 24px 60px rgba(16, 24, 40, 0.16);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* Backdrop the modal floats on (host page would be behind this) */
body.link-stage {
  min-height: 100vh;
  background: #EEF1F6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* ---------- Modal shell ---------- */
.modal {
  width: 100%;
  max-width: 400px;
  height: 640px;              /* fixed frame — body scrolls inside it */
  max-height: calc(100vh - 48px);
  background: var(--card);
  border-radius: var(--radius-modal);
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* ---------- Header ---------- */
.modal-header {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
}
.modal-brand {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.06em;
  color: var(--ink);
}
.modal-brand svg { color: var(--ink); }

.hdr-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  color: var(--ink);
  display: flex;
  border-radius: 8px;
}
.hdr-btn:hover { background: #F2F4F7; }
.hdr-btn.back { left: 12px; }
.hdr-btn.close { right: 12px; }
.hdr-btn[hidden] { display: none; }

/* ---------- Progress bar ---------- */
.progress {
  height: 3px;
  width: 100%;
  background: var(--line);
  display: flex;
  flex-shrink: 0;
}
.progress span {
  height: 100%;
  flex: 1;
  background: transparent;
  transition: background 0.3s ease;
}
.progress span.done { background: var(--teal); }
.progress span.active { background: var(--blue); }

/* ---------- Step sections fill the modal so footers pin to bottom ---------- */
.step {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.step[hidden] { display: none; }

/* ---------- Body / content ---------- */
.modal-body {
  flex: 1;
  min-height: 0;              /* allow the flex child to actually scroll */
  padding: 28px 28px 20px;
  overflow-y: auto;
  scrollbar-width: none;       /* Firefox: hide scrollbar, keep scroll */
  -ms-overflow-style: none;    /* old Edge */
}
.modal-body::-webkit-scrollbar { width: 0; height: 0; display: none; } /* Chrome/Safari */
.modal-body h1 {
  font-size: 26px;
  line-height: 1.2;
  font-weight: 700;
  margin: 8px 0 0;
  color: var(--ink);
}
.modal-body p.sub {
  font-size: 16px;
  line-height: 1.5;
  color: var(--body);
  margin: 12px 0 0;
}

/* ---------- Footer ---------- */
.modal-footer {
  flex-shrink: 0;
  padding: 16px 20px 20px;
  background: var(--panel);
}
.legal {
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--muted);
  margin: 0 0 14px;
  text-align: center;
}
.legal a { color: var(--muted); text-decoration: underline; }

/* ---------- Primary CTA ---------- */
.btn {
  width: 100%;
  height: 52px;
  border: none;
  border-radius: 28px;
  background: var(--navy);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.btn:hover { opacity: 0.92; }
.btn:disabled {
  background: #EAECF0;
  color: #A6ADBB;
  cursor: not-allowed;
}

/* ---------- Intro screen (opening) ---------- */
.intro-body {
  display: flex;
  flex-direction: column;
  padding-top: 40px;
}
.intro-pair {
  display: flex;
  align-items: center;
  margin-bottom: 32px;
}
.intro-pair .pair-tile {
  width: 58px;
  height: 58px;
  border-radius: 15px;
  object-fit: cover;
  box-shadow: 0 2px 6px rgba(16, 24, 40, 0.14);
}
/* the aggregator tile overlaps the merchant tile (handshake look) */
.intro-pair .pair-tile + .pair-tile {
  margin-left: -12px;
  position: relative;
  z-index: 1;
}
.intro-h1 {
  font-size: 27px;
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0;
  max-width: 15ch;
}

/* ---------- Search field ---------- */
.search {
  position: relative;
  margin-bottom: 20px;
}
.search input {
  width: 100%;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: var(--radius-field);
  padding: 0 44px 0 44px;
  font-size: 16px;
  font-family: var(--font);
  color: var(--ink);
  outline: none;
}
.search input:focus { border-color: var(--blue); }
.search .icon-search {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.search .icon-clear {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 4px;
  display: none;
}
.search .icon-clear.show { display: flex; }

/* ---------- Institution tile grid (empty state) ---------- */
.bank-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.bank-tile {
  height: 88px;
  border: 1px solid var(--line);
  border-radius: var(--radius-tile);
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 16px;
  transition: box-shadow 0.15s ease, transform 0.05s ease;
}
.bank-tile:hover { box-shadow: 0 6px 16px rgba(16, 24, 40, 0.10); }
.bank-tile:active { transform: scale(0.99); }
.bank-tile img { max-width: 130px; max-height: 44px; object-fit: contain; }
.bank-tile .name-fallback {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
}

/* ---------- Institution search results (list state) ---------- */
.bank-list { display: none; }
.bank-list.show { display: block; }
.bank-grid.hide { display: none; }

.bank-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 4px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.bank-row:hover { background: #FAFBFC; }
.bank-row .logo-circle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #F2F4F7;
  color: var(--muted);
}
.bank-row .logo-circle img { width: 100%; height: 100%; object-fit: cover; }
.bank-row .rtext { min-width: 0; }
.bank-row .rname {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.3;
}
.bank-row .rdomain { font-size: 13px; color: var(--muted); margin-top: 2px; }
.bank-empty { padding: 32px 4px; text-align: center; color: var(--muted); font-size: 15px; }

/* ---------- "Why is X involved" link ---------- */
.why-link {
  display: block;
  width: 100%;
  text-align: center;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  padding: 20px 0 8px;
  cursor: pointer;
}
.why-link:hover { color: var(--body); }

/* ---------- Login screen ---------- */
.bank-badge {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #EFEFFE;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--blue);
  box-shadow: 0 0 0 6px #F6F6FF;
  margin-bottom: 20px;
}
.field {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius-field);
  padding: 12px 16px;
  margin-top: 16px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field.focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0, 212, 177, 0.16);
}
.field label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 2px;
}
.field input {
  width: 100%;
  border: none;
  outline: none;
  font-size: 17px;
  font-family: var(--font);
  color: var(--ink);
  background: transparent;
  padding: 0;
}
.field .eye {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink);
  padding: 4px;
}
.field-error {
  color: #D92D20;
  font-size: 13.5px;
  margin-top: 8px;
  display: none;
}
.field-error.show { display: block; }

/* ---------- OTP boxes ---------- */
.otp-row {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.otp-row input {
  width: 100%;
  height: 60px;
  text-align: center;
  font-size: 24px;
  font-weight: 600;
  border: 1px solid var(--line);
  border-radius: var(--radius-field);
  outline: none;
  font-family: var(--font);
  color: var(--ink);
}
.otp-row input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0, 212, 177, 0.16);
}

/* ---------- Spinner overlay ---------- */
.spinner-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(2px);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.spinner-overlay.show { display: flex; }
.spinner {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 4px solid #E4E7EC;
  border-top-color: var(--blue);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-text {
  margin-top: 18px;
  font-size: 15px;
  color: var(--body);
  font-weight: 500;
}

/* ---------- Success ---------- */
.success-wrap {
  text-align: center;
  padding-top: 20px;
}
.success-check {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--blue);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  margin-bottom: 20px;
}

/* ---------- Content fade for in-place morph ---------- */
.morph { transition: opacity 0.2s ease, transform 0.2s ease; }
.morph.out { opacity: 0; transform: translateY(6px); }

/* ---------- About sheet (rises over institution step) ---------- */
.about-sheet {
  position: absolute;
  inset: 0;
  z-index: 30;
}
.about-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 24, 40, 0.28);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.about-sheet.show .about-backdrop { opacity: 1; }
.about-card {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: #fff;
  border-radius: 24px 24px var(--radius-modal) var(--radius-modal);
  padding: 28px 28px 24px;
  text-align: center;
  transform: translateY(100%);
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.about-sheet.show .about-card { transform: translateY(0); }
.about-mark { margin-bottom: 16px; }
.about-mark img { border-radius: 14px; }
.about-card h2 { font-size: 22px; font-weight: 700; margin: 0 0 12px; color: var(--ink); }
.about-card p { font-size: 15px; line-height: 1.55; color: var(--body); margin: 0 0 22px; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 1.6s; }
  .morph { transition: none; }
}
