/* Refer & Earn: connect with an emailed code (ADR-089).
   Built by static/js/features/hub-gdrive.js (createElement only). Matches the
   #ref-connect-account banner: same gradient, border, radius and input style.
   Phone layout from 1024px or a coarse pointer (portal rule): 44px targets,
   16px inputs (no iOS zoom), stacked actions.
   Local tokens (never a --pb-* redefinition): --ref-err for error text and
   invalid borders (a light red only works on dark), --ref-focus for focus
   rings (the portal --pb-focus where defined). */

#referArea {
  --ref-err: #f87171;
  --ref-focus: var(--pb-focus, var(--pb-blue, #2a93c1));
}
[data-theme="light"] #referArea {
  --ref-err: #b91c1c;
  --ref-focus: var(--pb-focus, var(--pb-blue-dark, #1a6a8f));
}
[data-theme="girly"] #referArea { --ref-err: #b91c1c; }

#ref-code-connect {
  background: linear-gradient(135deg, rgba(42,147,193,0.12), rgba(212,168,67,0.08));
  border: 1px solid var(--pb-blue, #2a93c1);
  border-radius: var(--pb-radius, 12px);
  padding: 20px;
  margin-bottom: 24px;
  max-width: 560px;
}
#ref-code-connect .ref-cc-title {
  font-size: 0.9rem; font-weight: 700; color: var(--pb-blue, #2a93c1); margin: 0 0 6px;
}
#ref-code-connect .ref-cc-lead {
  font-size: 0.82rem; color: var(--pb-text, #e6edf3); margin: 0 0 4px; line-height: 1.45;
}
#ref-code-connect .ref-cc-lead b { font-weight: 600; }
#ref-code-connect .ref-cc-note {
  font-size: 0.75rem; color: var(--pb-text-muted, #7d8fa3); margin: 0 0 14px; line-height: 1.45;
}
#ref-code-connect form { display: grid; gap: 12px; margin: 0; }
#ref-code-connect .ref-cc-field { display: grid; gap: 6px; }
#ref-code-connect label {
  font-size: 0.75rem; font-weight: 600; color: var(--pb-text-muted, #7d8fa3);
}
#ref-code-connect input {
  width: 100%; box-sizing: border-box; min-height: 40px;
  background: var(--pb-surface, #0d1117); border: 1px solid var(--pb-border);
  border-radius: var(--pb-radius-sm, 8px); padding: 10px 14px;
  color: var(--pb-text); font-size: 0.85rem; font-family: inherit;
}
#ref-code-connect input#ref-code-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.18em; max-width: 220px; /* the panel JS uppercases the value */
}
#ref-code-connect input:focus-visible {
  outline: 2px solid var(--ref-focus); outline-offset: 2px; border-color: var(--ref-focus);
}
#ref-code-connect input[aria-invalid="true"] { border-color: var(--ref-err); }
#ref-code-connect .ref-cc-pwrow { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
#ref-code-connect .ref-cc-hint { font-size: 0.75rem; color: var(--pb-text-muted, #7d8fa3); margin: -4px 0 0; }
#ref-code-connect .ref-cc-submit {
  justify-self: start; min-height: 40px;
  background: var(--pb-blue, #2a93c1); color: #fff; border: none; border-radius: var(--pb-radius-sm, 8px);
  padding: 10px 22px; cursor: pointer; font-size: 0.82rem; font-weight: 600; white-space: nowrap;
}
#ref-code-connect .ref-cc-submit:disabled { opacity: 0.6; cursor: default; }
#ref-code-connect .ref-cc-submit:focus-visible,
#ref-code-connect .ref-cc-linkbtn:focus-visible {
  outline: 2px solid var(--ref-focus); outline-offset: 2px;
}
#ref-code-connect .ref-cc-msg {
  font-size: 0.78rem; line-height: 1.45; margin: 0; display: none;
}
#ref-code-connect .ref-cc-msg.is-error { color: var(--ref-err); display: block; }
#ref-code-connect .ref-cc-msg.is-info { color: var(--pb-text-muted, #7d8fa3); display: block; }
#ref-code-connect .ref-cc-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--pb-border);
}
.ref-cc-linkbtn {
  background: none; border: none; padding: 0; min-height: 40px; cursor: pointer;
  color: var(--pb-blue, #2a93c1); font-size: 0.78rem; font-weight: 600; font-family: inherit;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-color: rgba(42,147,193,0.45);
}
.ref-cc-linkbtn:hover { text-decoration-color: currentColor; }
.ref-cc-linkbtn:disabled {
  color: var(--pb-text-muted, #7d8fa3); text-decoration: none; cursor: default; font-variant-numeric: tabular-nums;
}
#ref-code-connect .ref-cc-site { font-size: 0.75rem; color: var(--pb-text-muted, #7d8fa3); margin-top: 6px; }
#ref-code-connect .ref-cc-site a { white-space: nowrap; }
/* Reconnect needed (refresh refused or password migration failed) */
#ref-code-connect .ref-cc-reconnect {
  font-size: 0.82rem; line-height: 1.45; margin: 0 0 12px; padding: 10px 12px;
  border-radius: var(--pb-radius-sm, 8px); border: 1px solid var(--pb-border);
  background: var(--pb-surface, #0d1117); color: var(--pb-text, #e6edf3);
}
#ref-code-connect .ref-cc-send {
  justify-self: start; min-height: 40px; margin: 0 0 12px;
  background: var(--pb-blue, #2a93c1); color: #fff; border: none; border-radius: var(--pb-radius-sm, 8px);
  padding: 10px 22px; cursor: pointer; font-size: 0.82rem; font-weight: 600; font-family: inherit;
}
#ref-code-connect .ref-cc-send:disabled { opacity: 0.6; cursor: default; }
#ref-code-connect .ref-cc-send:focus-visible { outline: 2px solid var(--ref-focus); outline-offset: 2px; }

/* Password form (#ref-connect-account): wraps instead of overflowing */
#ref-connect-account .ref-pw-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
#ref-connect-account .ref-pw-row input {
  flex: 1 1 220px; min-width: 0; min-height: 40px; box-sizing: border-box;
  background: var(--pb-surface, #0d1117); border: 1px solid var(--pb-border); border-radius: 8px;
  padding: 10px 14px; color: var(--pb-text); font-size: 0.85rem; font-family: inherit;
}
#ref-connect-account .ref-pw-row button {
  min-height: 40px; background: var(--pb-blue, #2a93c1); color: #fff; border: none; border-radius: 8px;
  padding: 10px 18px; cursor: pointer; font-size: 0.82rem; font-weight: 600; white-space: nowrap; font-family: inherit;
}
#ref-connect-account .ref-pw-row button:disabled { opacity: 0.6; cursor: default; }
#ref-connect-account input:focus-visible,
#ref-connect-account button:focus-visible,
#ref-connect-account a:focus-visible,
#ref-link-bar input:focus-visible,
#ref-link-bar button:focus-visible { outline: 2px solid var(--ref-focus); outline-offset: 2px; }

/* Password form: same width as the code form; the error sits right after the
   input in the markup and, on desktop, drops below the row */
#ref-connect-account { max-width: 560px; box-sizing: border-box; }
#ref-connect-msg { order: 3; flex-basis: 100%; margin: 0; }

/* Header: referral site link + Refresh (moved out of inline styles) */
#ref-view-link {
  display: inline-flex; align-items: center;
  font-size: 0.8rem; color: var(--pb-blue, #2a93c1); text-decoration: none; white-space: nowrap;
}
#ref-refresh-btn {
  display: inline-flex; align-items: center;
  background: var(--pb-surface-2, #1a1d2e); color: var(--pb-text-muted, #7d8fa3);
  border: 1px solid var(--pb-border); border-radius: 8px; padding: 6px 14px;
  cursor: pointer; font-size: 0.8rem; font-family: inherit;
}
#ref-view-link:focus-visible,
#ref-refresh-btn:focus-visible { outline: 2px solid var(--ref-focus); outline-offset: 2px; }

/* Stats grid and link bar */
#ref-stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
#ref-link-bar .ref-link-row { flex-wrap: wrap; }
#ref-link-bar .ref-link-row input { flex: 1 1 200px; min-width: 0; }
/* Copy Link is secondary: Request Payout is the one filled primary */
#ref-copy-btn {
  background: transparent; color: var(--pb-text, #e6edf3);
  border: 1px solid var(--pb-border); border-radius: 8px; padding: 12px 20px;
  cursor: pointer; font-size: 0.85rem; font-weight: 600; white-space: nowrap; font-family: inherit;
}
#ref-copy-btn:hover { border-color: var(--pb-blue, #2a93c1); }

/* "Send me a code instead" under the password form */
#ref-connect-code-row { margin-top: 8px; font-size: 0.78rem; color: var(--pb-text-muted, #7d8fa3); }
#ref-connect-code-row .ref-cc-linkbtn { margin-left: 4px; }
/* Success notice after connecting */
#ref-connect-success {
  display: none; margin-bottom: 20px; padding: 12px 16px; border-radius: var(--pb-radius-sm, 8px);
  border: 1px solid rgba(34,197,94,0.45); background: rgba(34,197,94,0.10);
  color: var(--pb-text, #e6edf3); font-size: 0.82rem; line-height: 1.45;
}
#ref-connect-success b { color: var(--pb-green-text, #22c55e); font-weight: 700; }

@media (max-width: 1024px), (pointer: coarse) {
  #ref-code-connect { padding: 16px; max-width: none; }
  #ref-code-connect input { min-height: 44px; font-size: 16px; }
  #ref-code-connect input#ref-code-input { max-width: none; }
  #ref-code-connect .ref-cc-submit { min-height: 44px; width: 100%; justify-self: stretch; font-size: 0.9rem; }
  #ref-code-connect .ref-cc-send { min-height: 44px; width: 100%; justify-self: stretch; font-size: 0.9rem; }
  .ref-cc-linkbtn { min-height: 44px; }
  #ref-connect-account { padding: 16px !important; max-width: none; }
  #ref-connect-msg { order: 0; }
  #ref-refresh-btn,
  #ref-view-link { min-height: 44px; }
  #ref-refresh-btn { padding: 0 16px; }
  #ref-connect-account .ref-pw-row input { min-height: 44px; font-size: 16px; flex-basis: 100%; }
  #ref-connect-account .ref-pw-row button { min-height: 44px; width: 100%; font-size: 0.9rem; }
  #ref-link-bar .ref-link-row input { min-height: 44px; font-size: 16px; flex-basis: 100%; }
  #ref-link-bar .ref-link-row button { min-height: 44px; flex: 1 1 100%; }
}
@media (max-width: 560px) {
  #ref-stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #ref-code-connect .ref-cc-pwrow { grid-template-columns: 1fr; }
  #ref-code-connect .ref-cc-actions { flex-direction: column; align-items: flex-start; gap: 0; }
}
