/* marketcat.co auth modal (docs/design-handoff/auth-modal). Tokens only, logical properties only. */
.am[hidden], .am [hidden] { display: none !important; }
html.am-locked, html.am-locked body { overflow: hidden; }

.am {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-4);
  font-family: var(--font-sans); color: var(--text);
  font-size: var(--text-sm); line-height: var(--lh-sm);
}
.am-overlay { position: absolute; inset: 0; background: var(--overlay); }
.am-dialog {
  position: relative; box-sizing: border-box;
  display: flex; flex-direction: column;
  width: 100%; max-width: 420px; max-height: calc(100dvh - 2 * var(--space-4)); overflow: hidden;
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  animation: am-in var(--duration) ease-out;
}
.am *, .am *::before, .am *::after { box-sizing: border-box; }
@keyframes am-in { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
@keyframes am-spin { to { transform: rotate(360deg); } }

/* Header */
.am-head { flex-shrink: 0; display: flex; align-items: center; gap: var(--space-2); min-height: 36px; padding-block: var(--space-3) 0; padding-inline: var(--space-6) var(--space-4); }
.am-brand { display: flex; align-items: center; flex: 1; min-width: 0; }
.am-brand img { display: block; width: auto; height: 24px; max-width: 100%; }
.am-icon-btn {
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 32px; height: 32px; border: 0; border-radius: var(--radius-md);
  background: transparent; color: var(--text-secondary); cursor: pointer; text-decoration: none;
}
.am-icon-btn:hover { background: var(--bg-muted); color: var(--text); }
.am-back { margin-inline-start: calc(var(--space-2) * -1); }
[dir="rtl"] .am-flip { transform: scaleX(-1); }

/* Fixed top (heading + tabs), then the only scrolling region, then the fixed footer */
.am-top { flex-shrink: 0; display: flex; flex-direction: column; gap: var(--space-4); padding-block: var(--space-2) 0; padding-inline: var(--space-6); }
.am-scroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: var(--space-4);
  padding-block: var(--space-4) var(--space-5); padding-inline: var(--space-6);
}
/* Thin scrollbar without arrow buttons, inset from the rounded corners. Chromium and Safari
   use the ::-webkit-scrollbar rules (the standard properties would override them there). */
.am-scroll::-webkit-scrollbar { width: 6px; }
.am-scroll::-webkit-scrollbar-button { display: none; }
.am-scroll::-webkit-scrollbar-track { margin-block: var(--space-2); background: transparent; }
.am-scroll::-webkit-scrollbar-thumb { border-radius: var(--radius-full); background: var(--border-strong); }
.am-scroll::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }
@supports not selector(::-webkit-scrollbar) {
  .am-scroll { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
}
.am-heading { display: flex; flex-direction: column; gap: var(--space-1); }
.am-title { margin: 0; font-size: var(--text-xl); line-height: var(--lh-xl); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-tight); }
.am-subtitle { margin: 0; font-size: var(--text-sm); color: var(--text-secondary); text-wrap: pretty; }

/* Segmented control */
.am-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px; border-radius: var(--radius-md); background: var(--bg-muted); }
.am-tab {
  display: flex; align-items: center; justify-content: center; height: 32px;
  border-radius: calc(var(--radius-md) - 2px); color: var(--text-secondary);
  font-size: var(--text-sm); font-weight: var(--weight-medium); text-decoration: none; cursor: pointer;
}
.am-tab[aria-selected="true"] { background: var(--surface-raised); box-shadow: var(--shadow-sm); color: var(--text); }

/* Alerts */
.am-alert { display: flex; gap: 10px; padding: 10px var(--space-3); border-radius: var(--radius-md); font-size: var(--text-sm); }
.am-alert .am-svg { flex-shrink: 0; margin-block-start: 3px; }
.am-alert--danger { background: var(--danger-subtle); color: var(--danger); }
.am-alert--success { background: var(--success-subtle); color: var(--success); }

/* Form */
.am-form { display: flex; flex-direction: column; gap: var(--space-3); margin: 0; }
.am-field { display: flex; flex-direction: column; gap: var(--space-1); }
.am-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-2); }
.am-label { font-size: var(--text-sm); font-weight: var(--weight-medium); }
.am-link, .am-foot a { color: var(--accent-text); font-size: var(--text-sm); text-decoration: none; }
.am-link:hover, .am-foot a:hover { text-decoration: underline; }
.am-control { position: relative; display: flex; }
.am-input {
  flex: 1; min-width: 0; height: calc(var(--control-md) + var(--space-0)); margin: 0; padding-block: 0; padding-inline: var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--surface); color: var(--text); font: inherit; font-size: var(--text-base);
}
.am-input::placeholder { color: var(--text-tertiary); }
.am-input--password { padding-inline-end: 40px; }
.am-input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.am-input[aria-invalid="true"] { border-color: var(--danger); }
.am-eye {
  position: absolute; inset-block: 0; inset-inline-end: 3px; margin-block: auto; width: 28px; height: 28px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-tertiary); cursor: pointer;
}
.am-eye::before { content: ""; position: absolute; inset: -8px; }
.am-eye:hover { color: var(--text); background: var(--bg-hover); }
.am-eye .am-eye-off, .am-eye[aria-pressed="true"] .am-eye-on { display: none; }
.am-eye[aria-pressed="true"] .am-eye-off { display: block; }
.am-error { display: flex; align-items: center; gap: 6px; font-size: var(--text-xs); color: var(--danger); }
.am-error .am-svg { flex-shrink: 0; }
.am-error--indent { padding-inline-start: var(--space-6); }

/* Strength meter: 0-4, --border -> --danger -> --warning -> --success */
.am-meter { display: flex; flex-direction: column; gap: var(--space-1); }
.am-meter-bars { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-1); }
.am-meter-bars span { height: 3px; border-radius: 2px; background: var(--border); transition: background var(--duration-fast) var(--ease); }
.am-meter[data-score="1"] .am-meter-bars span:nth-child(-n+1) { background: var(--danger); }
.am-meter[data-score="2"] .am-meter-bars span:nth-child(-n+2) { background: var(--warning); }
.am-meter[data-score="3"] .am-meter-bars span:nth-child(-n+3),
.am-meter[data-score="4"] .am-meter-bars span { background: var(--success); }
.am-meter-text { font-size: var(--text-xs); color: var(--text-tertiary); }

/* Checkboxes */
.am-check { display: flex; align-items: center; gap: var(--space-2); min-height: 24px; font-size: var(--text-sm); color: var(--text-secondary); cursor: pointer; }
.am-check--top { align-items: flex-start; }
.am-check input { flex-shrink: 0; width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.am-check--top input { margin-block-start: var(--space-0); }
.am-field--terms .am-check { font-size: var(--text-xs); line-height: var(--lh-xs); }
.am-field--terms .am-check input { margin-block-start: 0; }
.am-field--terms .am-link { font-size: inherit; }
.am-check span { text-wrap: pretty; }

/* Buttons */
.am-submit, .am-btn {
  display: flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: calc(var(--control-md) + var(--space-0)); margin: 0; border-radius: var(--radius-md);
  font: inherit; font-size: var(--text-sm); font-weight: var(--weight-medium); text-decoration: none; cursor: pointer;
}
.am-submit, .am-btn--primary { border: 0; background: var(--accent); color: var(--accent-contrast); }
/* Stays reachable while the body scrolls; the band hides the fields passing underneath. */
.am-submit { position: sticky; inset-block-end: 0; z-index: 1; flex-shrink: 0; box-shadow: 0 0 0 var(--space-3) var(--surface-raised), 0 var(--space-2) 0 var(--space-3) var(--surface-raised); }
.am-submit:hover, .am-btn--primary:hover { background: var(--accent-hover); }
.am-submit[aria-busy="true"] { cursor: progress; opacity: .8; }
.am-spinner { display: none; width: 14px; height: 14px; border: 2px solid currentColor; border-inline-end-color: transparent; border-radius: 50%; animation: am-spin .7s linear infinite; }
.am-submit[aria-busy="true"] .am-spinner { display: block; }
.am-btn--secondary { padding-inline: 14px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); }
.am-btn--secondary:hover { background: var(--bg-subtle); }
.am-btn--secondary:disabled { color: var(--text-tertiary); cursor: default; }
.am-submit:focus-visible { outline: none; box-shadow: var(--focus-ring), 0 0 0 var(--space-3) var(--surface-raised), 0 var(--space-2) 0 var(--space-3) var(--surface-raised); }
.am-btn:focus-visible, .am-icon-btn:focus-visible, .am-tab:focus-visible,
.am-eye:focus-visible, .am-link:focus-visible, .am-foot a:focus-visible, .am-check input:focus-visible, .am-choice input:focus-visible {
  outline: none; box-shadow: var(--focus-ring);
}

/* Agency picker */
.am-choices { margin: 0; padding: 0; border: 0; min-width: 0; }
.am-choice-list { display: flex; flex-direction: column; gap: var(--space-2); }
.am-choice {
  display: flex; align-items: center; gap: 10px; min-height: var(--control-lg); padding-block: var(--space-2); padding-inline: var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--surface);
  font-weight: var(--weight-medium); cursor: pointer;
}
.am-choice:hover { background: var(--bg-subtle); }
.am-choice:has(input:checked) { border-color: var(--accent); }
.am-choice input { margin: 0; accent-color: var(--accent); }
.am-choice span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.am-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Confirmation screens */
.am-sent { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-4); }
.am-sent-icon { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 50%; background: var(--accent-subtle); color: var(--accent-text); }
.am-sent-text { margin: 0; font-size: var(--text-sm); color: var(--text-secondary); text-wrap: pretty; }
.am-sent-text strong { color: var(--text); font-weight: var(--weight-medium); overflow-wrap: anywhere; }
.am-sent-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); width: 100%; margin: 0; }
.am-sent-actions .am-btn--primary { flex: 1; padding-inline: 14px; }
.am-sent-field { flex-basis: 100%; }

/* Footer */
.am-foot { flex-shrink: 0; padding-block: var(--space-3); padding-inline: var(--space-6); border-block-start: 1px solid var(--border); font-size: var(--text-sm); color: var(--text-secondary); text-align: center; }
.am-foot a { font-weight: var(--weight-medium); }

/* Full-screen sheet under 640 px: roomier touch targets, 16 px inputs so iOS does not zoom */
@media (max-width: 639.98px) {
  .am { align-items: stretch; padding: 0; }
  .am-dialog { max-width: none; height: 100dvh; max-height: 100dvh; border: 0; border-radius: 0; }
  .am-input, .am-submit, .am-btn { height: var(--control-lg); }
  .am-input { font-size: var(--text-md); }
}
@media (prefers-reduced-motion: reduce) {
  .am-dialog, .am-spinner { animation: none; }
}
