/* Shared styles for the customer-facing portal (/customer) and post-checkout
   thank-you page (/thank-you). Keep both pages visually identical by editing
   here rather than duplicating <style> blocks per page.

   Built on top of the RH Tools design system (/assets/ds/ds.css, loaded before this
   file in every page's <head>) — colors and radii below are read from its scheme-1
   and token custom properties rather than hand-picked hex, so this portal stays in
   sync with the main site's palette. */

:root {
  color-scheme: dark;
  /* These map onto the design system's own scheme-1 (dark) palette — see its
     @theme tokens in _ds_bundle.css — without requiring the "scheme-1" utility
     class itself, since --color-scheme-* is only defined inside that class. */
  --bg: var(--color-neutral-darkest, #000000);
  --surface: var(--color-neutral-darker, #191919);
  --surface2: color-mix(in srgb, var(--color-neutral-darker, #191919), white 8%);
  --border: var(--color-white-10, rgba(255, 255, 255, 0.1));
  --accent: var(--color-amber, #ffc000);
  --accent-dim: color-mix(in srgb, var(--color-amber, #ffc000) 22%, black);
  --text: var(--color-white, #ffffff);
  --muted: var(--color-neutral, #7f7f7f);
  --ok-bg: #0e2e1a; --ok-fg: #4ade80;
  --bad-bg: #2e1010; --bad-fg: #f87171;
  --radius-sm: 4px;
  --radius-md: var(--radius-button, 6px);
  --radius-lg: var(--radius-card, 8px);
  --radius-form: var(--radius-form, 6px);
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

#loadingBar { height: 2px; background: var(--accent); position: fixed; top: 0; left: 0; width: 0; z-index: 300; transition: width 0.3s; }

/* ── Full-page loader — shown while we check a stored session/token, so we never flash the
   sign-in card or an empty portal shell before we know which one is correct. Visible by
   default (before JS decides) so a slow script load never exposes the wrong screen either. ── */
#pageLoader { min-height: 70vh; display: flex; align-items: center; justify-content: center; }

/* ── Fade-in for content that swaps in once we know the real state ── */
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeUp 0.3s ease; }

/* ── Skeleton placeholders (shimmer sweep over a surface2-toned block) ── */
.skeleton { position: relative; overflow: hidden; background: var(--surface2); }
.skeleton::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.07), transparent);
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }
.skeleton-line { height: 0.8em; border-radius: 4px; margin: 0.3em 0; }
.skeleton-line.w-60 { width: 60%; } .skeleton-line.w-40 { width: 40%; } .skeleton-line.w-80 { width: 80%; }
@media (prefers-reduced-motion: reduce) { .skeleton::after { animation: none; } .fade-in { animation: none; } }

/* ── Topbar ── */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 1.5rem; border-bottom: 1px solid var(--border); position: sticky; top: 0;
  background: rgba(0,0,0,0.9); backdrop-filter: blur(6px); z-index: 50;
}
#logoWrap { display: flex; align-items: center; gap: 0.7rem; text-decoration: none; color: inherit; }
#logoWrap:hover { text-decoration: none; opacity: 0.85; }
#logoImg { height: 26px; width: auto; display: none; }
#logoFallback {
  height: 26px; width: 26px; display: none; align-items: center; justify-content: center;
  background: var(--accent-dim); border-radius: var(--radius-md); font-weight: 700; letter-spacing: 0.04em;
  color: var(--accent); font-size: 0.8rem;
}
#logoTitle { font-weight: 500; font-size: 0.92rem; color: var(--text); }
#topbar .topbar-right { display: flex; align-items: center; gap: 0.6rem; }

/* ── Buttons ── */
button, .btn {
  font-family: inherit; background: var(--accent); color: #000; border: none; border-radius: var(--radius-md);
  padding: 0.55rem 1rem; cursor: pointer; font-size: 0.85rem; font-weight: 500;
  transition: opacity 0.15s, transform 0.1s; display: inline-flex; align-items: center; gap: 0.4rem;
  white-space: nowrap;
}
button:hover, .btn:hover { opacity: 0.88; text-decoration: none; }
button:active, .btn:active { transform: scale(0.98); }
button:disabled { opacity: 0.55; cursor: default; }
.secondary, .btn-secondary { background: var(--surface2); color: var(--text); }
button.danger { background: #3a1414; color: #fca5a5; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.78rem; }

/* ── Copy button: icon morphs clipboard → check, label crossfades, on copy ── */
.copy-btn-icon { display: grid; width: 13px; height: 13px; flex-shrink: 0; }
.copy-btn-icon svg { grid-area: 1/1; width: 13px; height: 13px; transition: opacity 0.15s ease, transform 0.15s ease; }
.copy-btn-icon .icon-check { opacity: 0; transform: scale(0.5); color: var(--ok-fg); }
.copy-key-btn.copied .copy-btn-icon .icon-copy { opacity: 0; transform: scale(0.6); }
.copy-key-btn.copied .copy-btn-icon .icon-check {
  opacity: 1; transform: scale(1); transition: opacity 0.15s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.copy-btn-label { position: relative; display: grid; }
.copy-btn-label span { grid-area: 1/1; white-space: nowrap; transition: opacity 0.15s ease, transform 0.15s ease; }
.copy-btn-label .label-copied { opacity: 0; transform: translateY(3px); }
.copy-key-btn.copied .copy-btn-label .label-idle { opacity: 0; transform: translateY(-3px); }
.copy-key-btn.copied .copy-btn-label .label-copied { opacity: 1; transform: translateY(0); color: var(--ok-fg); }
@media (prefers-reduced-motion: reduce) {
  .copy-btn-icon svg, .copy-btn-label span { transition: none; }
}

/* ── Spinner ── */
.spinner {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.25); border-top-color: #000;
  animation: spin 0.7s linear infinite; flex-shrink: 0;
}
.secondary .spinner, button.danger .spinner { border: 2px solid rgba(255,255,255,0.25); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }
.inline-loading { display: flex; align-items: center; gap: 0.5rem; color: var(--muted); font-size: 0.85rem; padding: 0.5rem 0; }
.inline-loading .spinner { border: 2px solid color-mix(in srgb, var(--accent), transparent 75%); border-top-color: var(--accent); }
.spinner-lg {
  width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; margin: 0 auto 1.1rem;
}

/* ── Layout ── */
main { max-width: 960px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
body.page-thankyou main { max-width: 720px; padding-top: 2rem; }

.card {
  background: var(--surface); box-shadow: 0 0 0 1px var(--border); border-radius: var(--radius-lg);
  padding: 1.35rem 1.5rem; margin-bottom: 1.25rem;
}
.card h2 { font-size: 1rem; font-weight: 600; margin: 0 0 1rem; }
.card-sub { color: var(--muted); font-size: 0.8rem; margin: -0.6rem 0 1.1rem; }

/* ── Forms ── */
label { display: block; font-size: 0.76rem; color: var(--muted); margin-bottom: 0.3rem; font-weight: 500; }
input {
  width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-form);
  color: var(--text); padding: 0.6rem 0.7rem; font-size: 0.88rem; margin-bottom: 0.9rem;
  font-family: inherit; transition: border-color 0.15s;
}
input:focus { outline: none; border-color: var(--accent); }
input:disabled { opacity: 0.6; }

#status { color: var(--muted); font-size: 0.82rem; margin-top: 0.4rem; }
#error { color: var(--bad-fg); font-size: 0.82rem; margin-top: 0.4rem; display: none; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.9rem; }
@media (max-width: 560px) { .field-row { grid-template-columns: 1fr; } }
#profileSaveRow { display: flex; align-items: center; gap: 0.8rem; margin-top: 0.2rem; }
#profileStatus { font-size: 0.8rem; color: var(--ok-fg); opacity: 0; transition: opacity 0.2s; }
#profileStatus.show { opacity: 1; }

/* ── Code / pills ── */
code {
  font-family: "SF Mono", ui-monospace, monospace; font-size: 0.8em; background: var(--bg);
  padding: 0.15em 0.45em; border-radius: var(--radius-sm);
}
.pill { padding: 0.14rem 0.55rem; border-radius: 999px; font-size: 0.7rem; font-weight: 600; display: inline-block; }
.ok { background: var(--ok-bg); color: var(--ok-fg); }
.bad { background: var(--bad-bg); color: var(--bad-fg); }
.muted { color: var(--muted); }

/* ── App icon (sizing scoped per page — dashboard tiles are larger than thank-you line items) ── */
.app-icon, .app-icon-fallback { border-radius: var(--radius-lg); }
.app-icon { object-fit: cover; background: var(--bg); }
.app-icon-fallback { background: var(--accent-dim); color: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; }
body.page-customer .app-icon, body.page-customer .app-icon-fallback { width: 52px; height: 52px; }
body.page-customer .app-icon-fallback { font-size: 1.3rem; }
body.page-thankyou .app-icon, body.page-thankyou .app-icon-fallback { width: 34px; height: 34px; }
body.page-thankyou .app-icon-fallback { font-size: 0.95rem; }

/* ── Toast ── */
#toastArea { position: fixed; bottom: 1.25rem; right: 1.25rem; z-index: 200; display: flex; flex-direction: column; gap: 0.5rem; align-items: flex-end; }
.toast { background: var(--surface2); box-shadow: 0 0 0 1px var(--border); border-radius: var(--radius-lg); padding: 0.6rem 1rem; font-size: 0.82rem; max-width: 320px; animation: fadeSlide 0.2s ease; color: var(--text); }
.toast.err { box-shadow: 0 0 0 1px rgba(248,113,113,0.5); color: var(--bad-fg); }
@keyframes fadeSlide { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ══════════════════════════ /customer dashboard ══════════════════════════ */

#requestCard { display: none; max-width: 420px; margin: 4rem auto 0; text-align: center; }
#requestCard h1 { font-size: 1.3rem; margin: 0 0 0.3rem; }
#requestCard p.tagline { color: var(--muted); font-size: 0.85rem; margin: 0 0 1.5rem; }
#portalCard { display: none; }

#welcomeHero { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; }
#welcomeText { flex: 1; min-width: 0; }
#welcomeHero h1 { font-size: 1.4rem; margin: 0 0 0.15rem; }
#welcomeHero .muted-line { color: var(--muted); font-size: 0.85rem; }
#welcomeStats { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.stat-chip {
  background: var(--surface2); color: var(--muted); font-size: 0.72rem; font-weight: 500;
  padding: 0.22rem 0.6rem; border-radius: 999px;
}

/* ── Tabs (Licenses / Account) ── */
#portalTabs { display: flex; gap: 1.5rem; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem; }
#portalTabs .tab {
  padding: 0 0 0.75rem; font-size: 0.86rem; font-weight: 500; color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color 0.15s;
}
#portalTabs .tab:hover { color: var(--text); }
#portalTabs .tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

#appsGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.9rem; }
.app-square {
  background: var(--surface2); border-radius: var(--radius-lg);
  padding: 1.1rem 0.9rem; display: flex; flex-direction: column; align-items: center; gap: 0.6rem;
  text-align: center; cursor: pointer; transition: box-shadow 0.15s, transform 0.12s;
}
.app-square:hover { box-shadow: 0 0 0 1px rgba(255,192,0,0.4); transform: translateY(-2px); }
body.page-customer .app-name { font-weight: 600; font-size: 0.86rem; }
.app-meta { font-size: 0.72rem; color: var(--muted); }

/* ── Empty states (no apps / no licenses yet) ── */
.empty-state { text-align: center; padding: 2rem 1rem; }
.empty-icon {
  width: 44px; height: 44px; border-radius: 50%; background: var(--surface2); color: var(--muted);
  display: flex; align-items: center; justify-content: center; margin: 0 auto 0.85rem; font-size: 1.1rem;
}
.empty-state p { margin: 0; }

details.license-card {
  background: var(--surface2); border-radius: var(--radius-lg);
  padding: 0.9rem 1rem; margin-bottom: 0.75rem;
}
details.license-card summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; flex-wrap: wrap;
}
details.license-card summary::-webkit-details-marker { display: none; }
.license-summary-main { display: flex; align-items: center; gap: 0.7rem; min-width: 0; }
.license-icon { display: flex; flex-shrink: 0; }
body.page-customer .license-card .app-icon, body.page-customer .license-card .app-icon-fallback { width: 36px; height: 36px; }
body.page-customer .license-card .app-icon-fallback { font-size: 0.95rem; }
.license-title-block { display: flex; flex-direction: column; min-width: 0; text-align: left; }
.license-title { font-weight: 600; font-size: 0.92rem; }
.license-type { color: var(--muted); font-size: 0.76rem; }
.license-summary-side { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.chevron { color: var(--muted); font-size: 0.75rem; transition: transform 0.2s; }
details.license-card[open] .chevron { transform: rotate(180deg); }
.license-meta { margin-top: 0.9rem; padding-top: 0.9rem; border-top: 1px solid var(--border); font-size: 0.8rem; color: var(--muted); }

.table-wrap { overflow-x: auto; margin-top: 0.7rem; }
table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
th, td { text-align: left; padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }

/* ══════════════════════════ /thank-you page ══════════════════════════ */

.checkmark {
  width: 56px; height: 56px; border-radius: 50%; background: var(--accent-dim);
  display: flex; align-items: center; justify-content: center; margin: 0 auto 1rem; font-size: 1.6rem; color: var(--accent);
}
.hero { text-align: center; margin-bottom: 2rem; }
.hero h1 { font-size: 1.5rem; margin: 0 0 0.4rem; }
.hero p { color: var(--muted); font-size: 0.9rem; margin: 0; }

.center-state { text-align: center; padding: 3rem 1rem; }
.center-state p { color: var(--muted); font-size: 0.88rem; margin: 0; }
.center-state h3 { font-size: 1.05rem; margin: 0 0 0.5rem; }

.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem 1.5rem; font-size: 0.85rem; }
@media (max-width: 520px) { .info-grid { grid-template-columns: 1fr; } }
.info-item .info-label { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 0.15rem; }
.info-item .info-val { font-weight: 500; }

.license-item {
  background: var(--surface2); border-radius: var(--radius-lg);
  padding: 1rem 1.1rem; margin-bottom: 0.85rem; display: flex; flex-direction: column; gap: 0.55rem;
}
.license-item:last-child { margin-bottom: 0; }
.license-item-head { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; flex-wrap: wrap; }
.license-app { display: flex; align-items: center; gap: 0.6rem; }
body.page-thankyou .app-name { font-weight: 600; font-size: 0.92rem; }
.app-type { color: var(--muted); font-size: 0.76rem; }

.key-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
body.page-thankyou code { font-size: 0.85rem; padding: 0.4rem 0.6rem; flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; }
.license-sub { color: var(--muted); font-size: 0.78rem; }

.notice { font-size: 0.85rem; color: var(--muted); line-height: 1.5; }
.notice strong { color: var(--text); }
.feedback-line { font-size: 0.85rem; }
