/* ============================================================
   components.css — buttons, cards, chips, inputs, toggles,
   tables, badges, modals. Reused on every page.
   ============================================================ */

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  padding: 12px 18px; border-radius: var(--r-md);
  font-size: 13.5px; font-weight: 700; white-space: nowrap;
  border: 1px solid transparent; transition: filter .12s, border-color .12s, background .12s, transform .08s;
}
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--grad); color: #fff; box-shadow: var(--shadow-btn); }
.btn--primary:hover { filter: brightness(1.08); }
.btn--ghost { background: var(--card); border-color: var(--line); color: var(--ink); }
.btn--ghost:hover { border-color: #C9B8FF; color: var(--purple-deep); }
.btn--quiet { background: var(--card); border-color: var(--line); color: var(--mut); }
.btn--quiet:hover { border-color: #C9B8FF; color: var(--purple-deep); }
.btn--danger { background: var(--danger-bg); border-color: var(--danger-line); color: var(--danger); }
.btn--lg { padding: 15px 24px; font-size: 14.5px; border-radius: 14px; }
.btn--sm { padding: 9px 14px; font-size: 12.5px; border-radius: 11px; }
.btn--block { width: 100%; }
.btn--busy, .btn:disabled { background: #C3B5F0; box-shadow: none; cursor: default; }
.btn--done { background: var(--teal-tint); border-color: var(--teal-line); color: var(--teal-text); box-shadow: none; }
.btn--link { padding: 0; font-size: 12.5px; font-weight: 700; color: #6D34E8; }
.btn--link:hover { color: var(--brand-teal); }

/* ---------- Cards ---------- */
.card {
  border: 1px solid var(--hair); border-radius: var(--r-lg);
  background: var(--card); box-shadow: var(--shadow-card);
}
.card--pad { padding: 20px; }
.card--tint { border-color: #E7E3F8; background: linear-gradient(180deg, #F9F6FF, #FFFFFF); box-shadow: none; }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--rule); }
.card__title { font-size: 15.5px; font-weight: 700; }
.card__body { padding: 18px 20px; }

.stat { padding: 18px; }
.stat__top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.stat__icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 15px; flex-shrink: 0; background: var(--purple-tint); color: var(--purple-deep); }
.stat__icon--teal { background: var(--teal-tint); color: var(--teal-text); }
.stat__label { font-size: 13px; color: var(--mut); font-weight: 600; }
.stat__value { font-size: 27px; font-weight: 800; letter-spacing: -.035em; margin-bottom: 6px; }
.stat__note { font-size: 12px; color: var(--faint); }

/* ---------- Chips / badges / pills ---------- */
.chip {
  padding: 8px 13px; border-radius: 99px; font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--line); background: var(--card); color: var(--mut);
}
.chip:hover { border-color: #C9B8FF; }
.chip.is-on { background: var(--grad); border-color: transparent; color: #fff; font-weight: 700; }

.badge { font-size: 11px; font-weight: 700; padding: 5px 10px; border-radius: 99px; white-space: nowrap; border: 1px solid var(--rule); background: var(--sunken); color: var(--mut); }
.badge--teal { background: var(--teal-tint); border-color: var(--teal-line); color: var(--teal-text); }
.badge--purple { background: var(--purple-tint); border-color: var(--purple-line); color: var(--purple-deep); }
.badge--grad { background: var(--grad); border-color: transparent; color: #fff; letter-spacing: .08em; font-size: 10px; padding: 3px 7px; border-radius: 6px; }

.segmented { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--card); }
.segmented button { padding: 8px 14px; border-radius: 9px; font-size: 12.5px; font-weight: 600; color: var(--mut); }
.segmented button.is-on { background: var(--grad); color: #fff; font-weight: 700; }
.segmented--fill button { flex: 1; }

/* ---------- Inputs ---------- */
.field { display: block; font-size: 12px; color: var(--mut); margin-bottom: 8px; }
.input, .select, .textarea {
  width: 100%; padding: 14px 16px; border-radius: var(--r-md);
  background: var(--sunken); border: 1px solid var(--line); font-size: 14px;
}
.input:focus, .select:focus, .textarea:focus { border-color: #C9B8FF; background: #fff; }
.select { padding: 11px 12px; font-size: 13px; font-weight: 600; }
.textarea { padding: 13px; font-size: 13px; line-height: 1.6; resize: vertical; }
.range { width: 100%; accent-color: var(--purple); }
.range-label { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--mut); margin-bottom: 8px; }
.range-label b { color: var(--ink); font-weight: 700; }

.swatch { width: 32px; height: 32px; border-radius: var(--r-sm); border: 1px solid var(--line); }
.swatch.is-on { border: 2px solid var(--purple-deep); box-shadow: 0 0 0 3px var(--purple-tint); }

.toggle-row {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); font-size: 12.5px; font-weight: 600; color: var(--mut);
}
.toggle-row.is-on { border-color: #E7E3F8; background: #F9F6FF; color: var(--purple-deep); }

.switch { width: 46px; height: 26px; border-radius: 99px; background: #E0E2EC; padding: 3px; display: flex; justify-content: flex-start; flex-shrink: 0; transition: background .15s; position: relative; }
/* The track is only 26px tall — extend the hit area to a comfortable 44px
   for thumbs without changing how the switch looks. */
.switch::after { content: ''; position: absolute; left: 0; right: 0; top: 50%; height: 44px; transform: translateY(-50%); }
.switch.is-on { background: var(--grad); justify-content: flex-end; }
.switch span { width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(20, 20, 40, .2); display: block; }

/* ---------- Lists ---------- */
.list-row {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 20px; border-bottom: 1px solid #F5F6FA; text-align: left; width: 100%;
}
.list-row:hover { background: #FAFAFE; }
.list-row:last-child { border-bottom: none; }
.list-row__thumb { width: 52px; height: 38px; border-radius: 9px; background: var(--stage); color: rgba(255, 255, 255, .5); font-size: 9px; font-weight: 700; display: grid; place-items: center; flex-shrink: 0; }
.list-row__name { display: block; font-size: 13.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row__meta { display: block; font-size: 11.5px; color: var(--faint); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.feed-item { display: flex; gap: 12px; align-items: flex-start; }
.feed-item__icon { width: 32px; height: 32px; border-radius: var(--r-sm); display: grid; place-items: center; font-size: 13px; flex-shrink: 0; background: var(--purple-tint); color: var(--purple-deep); box-shadow: inset 0 0 0 1px var(--purple-line); }
.feed-item__icon--teal { background: var(--teal-tint); color: var(--teal-text); box-shadow: inset 0 0 0 1px var(--teal-line); }
.feed-item__text { font-size: 12.5px; line-height: 1.45; }
.feed-item__when { font-size: 11px; color: var(--faint); margin-top: 3px; }

.inset-row { display: flex; justify-content: space-between; font-size: 12.5px; padding: 10px 13px; border-radius: 11px; background: var(--sunken); }

.empty { padding: 34px 20px; text-align: center; }
.empty__title { font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.empty__body { font-size: 12.5px; color: var(--mut); margin-bottom: 14px; }

.alert { padding: 12px 14px; border-radius: 12px; font-size: 12.5px; font-weight: 600; line-height: 1.45; }
.alert--error { background: var(--danger-bg); border: 1px solid var(--danger-line); color: var(--danger); }
.alert--info { background: #F9F6FF; border: 1px solid #E7E3F8; color: var(--purple-deep); }

.notice {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: center;
  border: 1px solid var(--teal-line); border-radius: var(--r-lg); padding: 18px 20px;
  background: linear-gradient(135deg, #EEFCFD, #F9F6FF);
}

/* ---------- Modals ---------- */
.modal-scrim {
  position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 20px;
  background: rgba(20, 20, 40, .42); backdrop-filter: blur(6px);
}
.modal { width: 100%; max-width: 420px; border-radius: 24px; background: var(--card); padding: 26px; box-shadow: var(--shadow-pop); }
.modal--narrow { max-width: 400px; text-align: center; }
.modal__title { font-size: 18px; font-weight: 800; letter-spacing: -.025em; }
.modal__sub { font-size: 13px; color: var(--mut); line-height: 1.55; }

.ring { position: relative; width: 104px; height: 104px; margin: 0 auto 18px; }
.ring svg { width: 100%; height: 100%; display: block; }
.ring__track { fill: none; stroke: #F1F0F9; stroke-width: 9; }
.ring__bar { fill: none; stroke: var(--purple); stroke-width: 9; stroke-linecap: round; stroke-dasharray: 264; transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset .3s ease; }
.ring__pct { position: absolute; inset: 0; display: grid; place-items: center; font-size: 21px; font-weight: 800; letter-spacing: -.03em; }

.steps { display: flex; flex-direction: column; gap: 12px; text-align: left; padding: 16px; border-radius: 16px; background: #FAFAFE; border: 1px solid var(--rule); }
.step { display: flex; align-items: center; gap: 11px; font-size: 12.5px; font-weight: 500; color: var(--faint); }
.step__dot { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; flex-shrink: 0; background: #F3F4FA; border: 1px solid var(--rule); color: var(--purple-deep); }
.step.is-active { color: var(--ink); font-weight: 700; }
.step.is-active .step__dot { background: var(--purple-tint); border-color: var(--purple-line); }
.step.is-done { color: var(--teal-text); font-weight: 700; }
.step.is-done .step__dot { background: var(--teal-tint); border-color: var(--teal-line); color: var(--teal-text); }

.tick { width: 60px; height: 60px; border-radius: 50%; background: var(--teal-tint); color: var(--teal-text); display: grid; place-items: center; font-size: 24px; margin: 0 auto 16px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 99px;
  font-size: 13px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 90;
}
.toast.is-on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Shown when the browser refused to auto-open the file picker — the user
   has to click once, so make the button impossible to miss. */
@keyframes wait-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(139, 92, 255, .55); }
  50%      { box-shadow: 0 0 0 9px rgba(139, 92, 255, 0); }
}
.is-waiting { animation: wait-pulse 1.5s ease-out infinite; }
@media (prefers-reduced-motion: reduce) { .is-waiting { animation: none; outline: 2px solid var(--purple); outline-offset: 2px; } }

/* Legal links at the foot of the app sidebar. The studio pages have no
   <footer> of their own, and Privacy/Terms/Refunds/Contact have to be
   reachable from every page. */
.sidebar__legal { display: flex; flex-wrap: wrap; gap: 4px 10px; padding: 12px 4px 2px; }
.sidebar__legal a { font-size: 11px; color: var(--faint); }
.sidebar__legal a:hover { color: var(--purple-deep); }

/* ---- Touch input sizing --------------------------------------------------
   Safari on iOS zooms the viewport when you focus a field whose font-size is
   below 16px, and there is no way to undo that zoom without a reload. The
   design's 13-14px fields did exactly that on every form. Only touch devices
   get the bump, so the desktop typography is untouched. */
@media (pointer: coarse) {
  .input, .select, .textarea { font-size: 16px; }
  .select { padding: 12px 12px; }
  .textarea { padding: 13px; }
}

/* ---- Touch target sizes --------------------------------------------------
   A .btn measured ~40px tall and a .chip ~32px; the accessibility floor is
   44px (Apple) / 48px (Google). Anything below that is a target people miss
   and re-tap, which reads as the site being broken rather than small.
   min-height rather than more padding, so the desktop proportions hold. */
@media (pointer: coarse) {
  :root { --tap-min: 44px; }
  /* Everything the browser measured under 44px at 360px wide: buttons,
     chips, the segmented toggles, footer and nav links, the brand lockup,
     and the inline text buttons. */
  .btn, .chip, .nav-item, .dl-row, .line-row, .list-row, .segmented > button,
  .site-nav__link, .site-nav__brand, .land-foot__links a, .btn--link,
  .faq-item__q, .tile, .tpl-card__body .btn {
    min-height: var(--tap-min);
  }
  /* a short label like "1:1" left the segmented button 41px wide */
  .segmented > button { min-width: var(--tap-min); }
  .btn, .chip, .segmented > button, .site-nav__link, .land-foot__links a, .btn--link {
    display: inline-flex; align-items: center;
  }
  /* the brand is an image link; give it a tappable box without resizing the mark */
  .site-nav__brand { display: inline-flex; align-items: center; padding: 0 4px; }
  .btn--sm { min-height: 40px; }
  /* icon-only controls need width as well as height */
  .site-nav__burger, .topbar__burger, .sidebar__close, .nav-drawer__close, .cap-resize {
    min-width: var(--tap-min); min-height: var(--tap-min);
  }
  /* a range slider's thumb is the target — the default is tiny */
  .range { height: var(--tap-min); }
}

/* ---- Touch targets, second pass ------------------------------------------
   What a real browser still measured under 44px at 360px after the first
   round. Footer links become full-width rows rather than word-width ones,
   because a 40px-wide target in a column of links is easy to miss even when
   it is tall enough. */
@media (pointer: coarse) {
  /* footer link columns: the whole row is the target, not just the word */
  /* The footer columns are shrink-to-fit, so a full-width link was still
     only as wide as the longest word in that column (40px for "About").
     A floor on the column makes every link a 44x44 target. */
  .land-foot__links > div { min-width: var(--tap-min); }
  .land-foot__links a { display: flex; align-items: center; width: 100%; }

  /* the copyright line carries a mailto link */
  .site-foot a, .land-foot span a { display: inline-flex; align-items: center; min-height: var(--tap-min); }

  /* sign-in page: the legal row and the brand lockup */
  .legal-row { line-height: 1.9; }
  .legal-row a {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: var(--tap-min); padding: 0 8px;
  }
  .auth__aside a { display: inline-flex; align-items: center; min-height: var(--tap-min); }

  /* skip link is itself a control, and was 40px */
  .skip-link { min-height: var(--tap-min); display: inline-flex; align-items: center; }
}

/* The referral link field: small mono on desktop, but it used to set that
   size inline, which no stylesheet can override — so it zoomed iOS on focus. */
.mono-sm { font-family: var(--mono); font-size: 12.5px; }

/* ---- Touch targets, third pass — the signed-in pages ---------------------
   Measured on the real app pages at 360px. .btn--sm was capped at 40px by
   the previous pass, which is still under the floor; the sidebar's sign-out
   control measured 13x20. */
@media (pointer: coarse) {
  .btn--sm { min-height: var(--tap-min); }
  .mono-sm { font-size: 16px; }
  .range { font-size: 16px; }
  /* the icon-only controls inside the sidebar footer and topbar */
  .who button, .topbar button, .sidebar__foot button, .credit-card .btn {
    min-width: var(--tap-min); min-height: var(--tap-min);
  }
  .who button { display: inline-flex; align-items: center; justify-content: center; }
}
