/* Thurn — Design System */
:root {
  --teal: #0d6e6e;
  --teal-dark: #094d4d;
  --teal-light: #e0f2f1;
  --gold: #c8a951;
  --bg: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --border: #e5e7eb;
  --border-focus: #0d6e6e;
  --text: #111827;
  --text-muted: #6b7280;
  /* Darkened from #9ca3af to #6b7280 so small-text uses of --text-light
     (form hints, audit metadata, preview empty state) clear WCAG 1.4.3
     AA on a white background. */
  --text-light: #6b7280;
  --red: #dc2626;
  --green: #16a34a;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius: 8px;
}

/* Dark mode — applied via .dark class on <html> (set by JS) */
html.dark {
  --teal: #2dd4bf;
  --teal-dark: #14b8a6;
  --teal-light: rgba(45, 212, 191, 0.1);
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #0f172a;
  --border: #334155;
  --border-focus: #2dd4bf;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  /* Lightened from #64748b to #94a3b8 for WCAG 1.4.3 AA on dark bg. */
  --text-light: #94a3b8;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}
/* Auto dark mode when no manual preference is stored */
@media (prefers-color-scheme: dark) {
  html:not(.light) {
    --teal: #2dd4bf;
    --teal-dark: #14b8a6;
    --teal-light: rgba(45, 212, 191, 0.1);
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #0f172a;
    --border: #334155;
    --border-focus: #2dd4bf;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --text-light: #94a3b8;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Universal keyboard-focus ring. Applied only on keyboard focus
   (:focus-visible) so mouse users don't see a ring after every click.
   Inputs/selects/textareas keep their richer custom ring via the
   input:focus rule below. */
:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Reduced-motion users: disable non-essential transitions and animations. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}

/* Visually hidden but accessible to screen readers — used for off-screen
   labels on admin toolbar inputs and skip links that only appear on focus. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 9999;
  padding: 0.5rem 1rem;
  background: var(--bg-card);
  color: var(--text);
  border: 2px solid var(--border-focus);
  border-radius: 4px;
  text-decoration: none;
}
.skip-link:focus {
  left: 1rem;
  top: 1rem;
}

/* Marketing landing (#102) */
.landing {
  background: linear-gradient(180deg, var(--bg-card), var(--bg));
  border-bottom: 1px solid var(--border);
  padding: 2.5rem 1.25rem 2rem;
}
.landing-inner {
  max-width: 880px;
  margin: 0 auto;
  text-align: center;
}
.landing-title {
  margin: 0 0 0.5rem;
  font-size: 1.875rem;
  font-weight: 700;
  line-height: 1.2;
}
.landing-sub {
  margin: 0 0 1.25rem;
  color: var(--text-muted);
  font-size: 1.05rem;
}
.landing-cta {
  display: inline-block;
  margin-bottom: 2rem;
}
.landing-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  list-style: none;
  counter-reset: step;
  margin: 0 0 1.25rem;
  padding: 0;
  text-align: left;
}
.landing-steps li {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.875rem 1rem 0.875rem 2.5rem;
  position: relative;
  counter-increment: step;
}
.landing-steps li::before {
  content: counter(step);
  position: absolute;
  left: 0.75rem;
  top: 0.75rem;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  background: var(--accent, #0d9488);
  color: white;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.landing-steps strong { display: block; font-size: 0.95rem; margin-bottom: 0.125rem; }
.landing-steps span { font-size: 0.85rem; color: var(--text-muted); }
@media (max-width: 640px) {
  .landing { padding: 1.5rem 1rem 1.25rem; }
  .landing-title { font-size: 1.4rem; }
  .landing-steps { grid-template-columns: 1fr; }
}

/* Outage banner (#95) — operator-set, site-wide */
.site-banner {
  background: #fff8e1;
  color: #5d4037;
  border-bottom: 1px solid #ffd54f;
  padding: 0.6rem 1.25rem;
  font-size: 0.9rem;
  text-align: center;
}
/* #132: belt-and-suspenders. Same fix as the partner-hero (#120)
   in case a future rule defeats the HTML hidden attribute. */
.site-banner[hidden] { display: none; }
:root.dark .site-banner {
  background: #3a2e10;
  color: #ffe082;
  border-bottom-color: #6a5210;
}

/* Partner co-branded hero (#106) */
.partner-hero {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
/* #120: HTML `hidden` is `display: none`, but the rule above wins
   on specificity; this restores it. The hero stays invisible until
   hydratePartnerHero un-hides it via hero.hidden = false. */
.partner-hero[hidden] { display: none; }
.partner-hero-logo {
  max-height: 40px;
  max-width: 160px;
  object-fit: contain;
}
.partner-hero-text { flex: 1; min-width: 0; }
.partner-hero-text h1 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
}
.partner-hero-text p {
  margin: 0.125rem 0 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.partner-hero-by {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}
@media (max-width: 640px) {
  .partner-hero { flex-wrap: wrap; }
  .partner-hero-by { order: 3; margin-left: auto; }
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  position: sticky;
  top: 0;
  z-index: 100;
}
.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 1.125rem;
}
.logo img { width: 32px; height: 32px; }
.header-right { display: flex; align-items: center; gap: 0.75rem; }

/* Language switcher — globe button matches .theme-toggle, popover lists languages */
.lang-switcher { position: relative; }
.lang-toggle .lang-icon { display: block; }
.lang-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  list-style: none;
  margin: 0;
  padding: 0.25rem;
  min-width: 5rem;
  z-index: 110;
}
.lang-menu[hidden] { display: none; }
.lang-menu-item {
  background: none;
  border: 0;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  min-height: 36px;
}
.lang-menu-item:hover { background: var(--teal-light); color: var(--teal); }
.lang-menu-item[aria-current="true"] { color: var(--teal); }
html.dark .lang-menu { box-shadow: 0 4px 12px rgba(0,0,0,0.4); }
@media (prefers-color-scheme: dark) {
  html:not(.light) .lang-menu { box-shadow: 0 4px 12px rgba(0,0,0,0.4); }
}

/* Main layout */
.main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr auto;
  gap: 0;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}
.pay-col {
  padding: 0 1.25rem 1.25rem;
  grid-column: 1; /* under form column on desktop */
}
.form-col {
  padding: 1.25rem;
  overflow-y: auto;
  max-height: calc(100vh - 50px);
}
.preview-col {
  border-left: 1px solid var(--border);
  background: var(--bg);
  padding: 1.25rem;
  max-height: calc(100vh - 50px);
  overflow-y: auto;
}
.preview-sticky {
  position: sticky;
  top: 0;
}
.preview-sticky h2,
.form-col > h2 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.form-col > h2 {
  scroll-margin-top: 60px; /* clear sticky header when jumping via #main-form */
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow);
}
.card h2, .card h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Form */
label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
input, select, textarea {
  width: 100%;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: var(--font);
  background: var(--bg-input);
  color: var(--text);
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(13, 110, 110, 0.1);
}
html.dark input:focus, html.dark select:focus, html.dark textarea:focus {
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.15);
}
@media (prefers-color-scheme: dark) {
  html:not(.light) input:focus, html:not(.light) select:focus, html:not(.light) textarea:focus {
    box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.15);
  }
}
textarea {
  resize: vertical;
  min-height: 180px;
  line-height: 1.5;
}
.form-group { margin-bottom: 0.75rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.form-meta { font-size: 0.75rem; color: var(--text-light); margin-top: 0.25rem; display: block; }
/* Live char counter warning tiers (#letter-body limit). 90% → amber
   hint, 100% → red so the user sees the cap before and when they
   hit it, without the textarea going silent on them. */
.form-meta--warn { color: #b45309; font-weight: 600; }
.form-meta--over { color: #991b1b; font-weight: 600; }
html.dark .form-meta--warn { color: #fbbf24; }
html.dark .form-meta--over { color: #fca5a5; }
@media (prefers-color-scheme: dark) {
  html:not(.light) .form-meta--warn { color: #fbbf24; }
  html:not(.light) .form-meta--over { color: #fca5a5; }
}

/* Formatting toolbar */
.fmt-toolbar {
  display: flex;
  gap: 2px;
  margin-bottom: 4px;
}
.fmt-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.fmt-btn:hover { border-color: var(--teal); color: var(--teal); }

/* Toggle */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text);
}
.toggle-row input[type="checkbox"] { width: auto; }

/* Options */
.options-row {
  display: flex;
  gap: 1rem;
  align-items: stretch;
  flex-wrap: wrap;
}
.options-row > div { flex: 1 1 0; min-width: 0; }
.option-group { display: flex; gap: 3px; }
.options-row .option-group { width: 100%; }
.option-btn {
  padding: 0 0.85rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.options-row .option-btn { flex: 1 1 0; min-width: 0; }
.option-btn.active {
  background: var(--teal-light);
  color: var(--teal);
  border-color: var(--teal);
}
.option-btn:hover { border-color: var(--teal); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}
.btn--primary { background: var(--teal); color: white; }
.btn--primary:hover { opacity: 0.9; }
.btn--full { width: 100%; }
.btn--large { padding: 0.875rem 1.5rem; font-size: 1.05rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Price box */
.pay-card { text-align: center; }
.price-box { margin-bottom: 0.75rem; }
.price-amount {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--teal);
}
.price-detail {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Preview */
.preview-container {
  position: relative;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.preview-canvas-wrap {
  position: relative;
  aspect-ratio: 210 / 297;
  overflow: hidden;
  background: white;
}
.preview-canvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: 100%;
}
.preview-chin {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.3rem 0.5rem;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.8rem;
}
.preview-chin-spacer { flex: 1; }
.preview-chin-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0.35rem;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  line-height: 0;
}
.preview-chin-btn:hover:not(:disabled) {
  background: var(--border);
  color: var(--text);
}
.preview-chin-btn:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
}
.preview-chin-btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.preview-page-indicator {
  min-width: 5rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding: 0 0.25rem;
}
.preview-empty {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: #6b7280;
  font-size: 0.9rem;
  padding: 2rem;
  pointer-events: none;
}

/* Address autocomplete */
.address-ac-wrap { position: relative; }
.ac-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0 0 6px 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  z-index: 50;
  max-height: 200px;
  overflow-y: auto;
}
html.dark .ac-dropdown { box-shadow: 0 4px 12px rgba(0,0,0,0.4); }
@media (prefers-color-scheme: dark) {
  html:not(.light) .ac-dropdown { box-shadow: 0 4px 12px rgba(0,0,0,0.4); }
}
.ac-item {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.active { background: var(--teal-light); }
.link-small {
  font-size: 0.75rem;
  color: var(--teal);
  text-decoration: none;
  margin-top: 0.25rem;
  display: inline-block;
}
.link-small:hover { text-decoration: underline; }

/* Alerts */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
}
.alert--success { background: #d1fae5; color: #065f46; }
.alert--error { background: #fee2e2; color: #991b1b; }
html.dark .alert--success { background: rgba(16, 185, 129, 0.15); color: #6ee7b7; }
html.dark .alert--error { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }
@media (prefers-color-scheme: dark) {
  html:not(.light) .alert--success { background: rgba(16, 185, 129, 0.15); color: #6ee7b7; }
  html:not(.light) .alert--error { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }
}

/* Inline field error: rendered by showFormError() next to the offending
   input so the user sees the specific hint without scrolling back up to
   the #form-errors summary. See #271. */
.field-error {
  display: block;
  margin-top: 0.35rem;
  color: #991b1b;
  font-size: 0.8rem;
  line-height: 1.3;
}
html.dark .field-error { color: #fca5a5; }
@media (prefers-color-scheme: dark) {
  html:not(.light) .field-error { color: #fca5a5; }
}
input[aria-invalid="true"],
textarea[aria-invalid="true"],
select[aria-invalid="true"] {
  border-color: #991b1b;
}
html.dark input[aria-invalid="true"],
html.dark textarea[aria-invalid="true"],
html.dark select[aria-invalid="true"] { border-color: #fca5a5; }
@media (prefers-color-scheme: dark) {
  html:not(.light) input[aria-invalid="true"],
  html:not(.light) textarea[aria-invalid="true"],
  html:not(.light) select[aria-invalid="true"] { border-color: #fca5a5; }
}

/* Status badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge--pending { background: #fef3c7; color: #92400e; }
.badge--paid { background: #dbeafe; color: #1e40af; }
.badge--shipped { background: #d1fae5; color: #065f46; }
.badge--failed { background: #fee2e2; color: #991b1b; }

/* Sticky footer (#polish-pass-1).
   body is display:flex column + min-height:100vh. Every direct child
   that isn't the header or footer gets flex:1 so the content takes
   all remaining space, pinning the footer to the viewport bottom on
   short pages (tracking, delete data, request data). Two pages use
   <main>, most use <section class="container">, admin uses a <div>;
   cover all three. flex-shrink:0 on header/footer so neither
   collapses when content overflows. */
body > .container,
body > main,
body > .admin-wrap,
body > .main {
  flex: 1 0 auto;
}
body > .header,
body > .footer {
  flex-shrink: 0;
}
.footer {
  border-top: 1px solid var(--border);
  padding: 1rem 1.25rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg-card);
}
.footer a {
  color: var(--text-muted);
  text-decoration: underline;
  margin: 0 0.5rem;
}
.footer a:hover { color: var(--teal); }

/* Responsive: stack on narrow screens */
@media (max-width: 900px) {
  .main {
    grid-template-columns: 1fr;
  }
  .form-col {
    max-height: none;
    overflow-y: visible;
  }
  .preview-col {
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: none;
    overflow-y: visible;
  }
  /* No max-height on .preview-container here: it's a flex-column
   * wrapping .preview-canvas-wrap (aspect-ratio 210/297) + the chin
   * toolbar, and any outer height cap shrinks the wrap below its
   * aspect ratio, which is exactly how the preview went back to
   * looking square after the PDF.js switch in #248. On mobile the
   * grid collapses to a single column and the preview sits below
   * the form, so letting it take its natural A4 height is fine. */
  /* Mobile order: Form → Preview → Pay */
  .form-col { order: 1; }
  .preview-col { order: 2; }
  .pay-col { order: 3; padding: 0 1.25rem 1.25rem; }
}

@media (max-width: 480px) {
  .form-row { grid-template-columns: 1fr; }
  .options-row { flex-direction: column; align-items: stretch; }
  .options-row > div { width: 100%; }
  /* WCAG: minimum 44px touch targets */
  input, select, textarea { padding: 0.75rem; font-size: 1rem; }
  .btn { padding: 0.75rem 1.25rem; }
}

/* Theme toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 0.5rem;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: var(--text-muted);
  transition: all 0.15s;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.theme-toggle:hover { border-color: var(--teal); color: var(--teal); }
/* Show moon in light mode, sun in dark mode */
.theme-icon-dark { display: none; }
html.dark .theme-icon-light { display: none; }
html.dark .theme-icon-dark { display: inline; }
@media (prefers-color-scheme: dark) {
  html:not(.light) .theme-icon-light { display: none; }
  html:not(.light) .theme-icon-dark { display: inline; }
}

/* Signature pad */
.sig-pad-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: white;
  overflow: hidden;
}
.sig-pad-canvas {
  display: block;
  width: 100%;
  height: 150px;
  cursor: crosshair;
  touch-action: none;
}
.sig-actions {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-top: 0.5rem;
}
.sig-hint { display: block; margin-top: 0.25rem; margin-bottom: 0.25rem; }

/* Track page container (used on track.html) */
.container { max-width: 680px; margin: 0 auto; padding: 0 1.5rem; }
.container-padded { padding-top: 2rem; padding-bottom: 4rem; }
