/* Every value below comes from a theme token — see themes.css. */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-ui);
  font-size: var(--size-base);
  line-height: var(--leading);
  color: var(--ink);
  background: var(--bg);
  padding: 0 1rem;
  max-width: 1040px;
  margin: 0 auto;
}

header {
  border-bottom: var(--rule-weight) solid var(--rule);
  margin-top: 3rem; /* ~two lines of space above #site-title */
  padding: 0.6rem 0;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: baseline;
  gap: 1.5rem;
  flex-wrap: wrap;
}

#site-title {
  font-weight: bold;
  font-size: 1rem;
  text-decoration: none;
  color: var(--ink);
  letter-spacing: var(--brand-tracking);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
#site-title img {
  height: 1.5rem;
  width: auto;
  mix-blend-mode: var(--logo-blend);
  background: var(--logo-plate);
  padding: var(--logo-plate-pad-sm);
  border-radius: 3px;
}

.nav-user-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.3;
}

nav a {
  text-decoration: none;
  color: var(--ink-muted);
  font-size: 0.9rem;
}
nav a:hover { text-decoration: underline; }
nav a.active { font-weight: bold; text-decoration: underline; color: var(--accent); }

#nav-logout { margin-left: auto; font-size: 0.85rem; }
#nav-logout a { color: var(--accent); }

a { color: var(--accent); }

h1 {
  font-size: 1.2rem;
  margin-bottom: 1rem;
  font-weight: bold;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.3rem;
  letter-spacing: var(--head-tracking);
}
h2 { font-size: 0.95rem; margin: 1.2rem 0 0.5rem; font-weight: bold; }

table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; font-size: 0.88rem; }
th {
  text-align: left;
  border-bottom: var(--rule-weight) solid var(--rule);
  padding: var(--pad-cell);
  color: var(--ink-muted);
}
td { border-bottom: 1px solid var(--border); padding: var(--pad-cell); vertical-align: top; }
tr:last-child td { border-bottom: none; }

.mono { font-family: var(--font-mono); font-size: 0.82rem; }

form { margin-bottom: 1rem; }

label { display: block; font-size: 0.88rem; margin-bottom: 0.6rem; }
label input, label select, label textarea { display: block; width: 100%; }

input[type=text],
input[type=email],
input[type=password],
input[type=number],
input[type=file],
select,
textarea {
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 0.3rem 0.5rem;
  font: inherit;
  font-size: 0.88rem;
  width: 100%;
  margin-top: 0.15rem;
}
input:focus-visible, select:focus-visible, textarea:focus-visible,
button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

textarea { resize: vertical; min-height: 100px; }

button {
  border: var(--border-width) solid var(--accent);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--accent);
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
  margin-right: 0.4rem;
  margin-top: 0.3rem;
}
button:hover { background: var(--accent); color: var(--accent-ink); }
button:disabled { opacity: 0.4; cursor: default; }
button:disabled:hover { background: var(--bg); color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.15); }
button.secondary { border-color: var(--border); color: var(--ink-muted); }
button.secondary:hover { background: var(--ink-muted); color: var(--bg); }
button.small { padding: 0.15rem 0.4rem; font-size: 0.8rem; }

fieldset {
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem 0.8rem;
  margin-bottom: 0.75rem;
}
legend { padding: 0 0.25rem; font-size: 0.88rem; font-weight: bold; }

details {
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
}
summary {
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  border-bottom: 1px solid transparent;
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
summary::-webkit-details-marker { display: none; }
summary::before { content: '▶'; font-size: 0.65rem; flex-shrink: 0; }
details[open] summary::before { content: '▼'; }
details[open] summary { border-bottom: 1px solid var(--border); }
.details-body { padding: 0.75rem; }

pre {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  white-space: pre-wrap;
  word-break: break-word;
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.75rem;
  background: var(--surface-alt);
}

.msg { margin-bottom: 0.75rem; font-size: 0.88rem; }
.msg:empty { display: none; }
.error, .success {
  --callout-color: var(--err);
  --callout-bg: var(--err-bg);
  color: var(--callout-color);
  border: var(--border-width) solid var(--callout-color);
  border-radius: var(--radius);
  background: var(--callout-bg);
  padding: 0.4rem 0.6rem;
}
.success {
  --callout-color: var(--ok);
  --callout-bg: var(--ok-bg);
  font-style: italic;
}
.notice { font-size: 0.85rem; color: var(--ink-muted); margin-bottom: 0.5rem; }

.profile-card { max-width: 480px; }
.profile-card h2 { margin-bottom: 0.5rem; }
.profile-fields { margin: 0; padding: 0; }
.profile-field {
  display: flex;
  flex-direction: column;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}
.profile-field:first-child { border-top: 1px solid var(--border); }
.profile-field dt {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  margin-bottom: 0.2rem;
}
.profile-field dd { margin: 0; font-size: 0.95rem; }

#user-mgmt td { vertical-align: middle; }
#user-mgmt button { margin-top: 0; }

.callout {
  --callout-color: var(--err);
  --callout-bg: var(--err-bg);
  color: var(--callout-color);
  border: var(--border-width) solid var(--callout-color);
  border-radius: var(--radius);
  background: var(--callout-bg);
  padding: 0.9rem 1rem;
  margin: 1.5rem 0;
  font-size: 1rem;
  font-weight: 500;
}
.callout.banner { margin: 3rem 0; }
.callout.green {
  --callout-color: var(--ok);
  --callout-bg: var(--ok-bg);
}
.callout.yellow {
  --callout-color: var(--warn);
  --callout-bg: var(--warn-bg);
}

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15em 0.5em;
  border-radius: var(--badge-radius);
  letter-spacing: 0.02em;
  vertical-align: middle;
  white-space: nowrap;
}
.badge-type-pdf  { background: var(--info-bg); color: var(--info); }
.badge-type-text { background: transparent; color: var(--info); box-shadow: inset 0 0 0 1px var(--info); }
.badge-status-completed  { background: var(--ok-bg); color: var(--ok); }
.badge-status-pending    { background: var(--warn-bg); color: var(--warn); }
.badge-status-draft      { background: var(--surface-alt); color: var(--ink-muted); }

/* Signature canvases stay white in every theme: the ink is always black, and the
   captured signature is stamped onto a white PDF. A themed dark ground would
   hide the stroke from the person drawing it. */
canvas {
  border: var(--border-width) solid var(--rule);
  border-radius: var(--radius);
  background: #ffffff;
  display: block;
  touch-action: none;
  cursor: crosshair;
  width: 100%;
  max-width: 600px;
  height: 180px;
}

.sig-strip {
  border-top: 3px solid var(--rule);
  margin-top: 2rem;
  padding-top: 0.5rem;
  width: 100%;
}
.sig-strip canvas {
  width: 100%;
  max-width: 100%;
  height: 120px;
  border: 1px dashed var(--ink-faint);
  display: block;
  cursor: crosshair;
  touch-action: none;
}
.sig-strip-label {
  font-size: 0.75rem;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
}

.stub-notice {
  display: inline-block;
  font-size: 0.88rem;
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  padding: 0.3rem 0.7rem;
  margin-left: 0.5rem;
  vertical-align: middle;
}

.loading { color: var(--ink-muted); font-size: 0.88rem; }

/* --- billing ------------------------------------------------------------ */
.billing-page { max-width: 760px; }
.billing-page > section { margin: 1.5rem 0; }
.billing-account {
  max-width: 440px;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.billing-balance {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: var(--rule-weight) solid var(--rule);
}
.billing-balance h2 { margin-top: 0; }
.billing-balance-value { font-size: 1.4rem; font-weight: 700; line-height: 1.2; }
.billing-balance .notice { margin: 0.35rem 0 0; }
.billing-balance button { flex-shrink: 0; }
.billing-packs { list-style: none; border-top: 1px solid var(--border); }
.billing-pack {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border);
}
.billing-pack div { display: grid; gap: 0.1rem; }
.billing-pack span { color: var(--ink-muted); font-size: 0.88rem; }
.billing-pack button { margin: 0; flex-shrink: 0; }
.billing-history { padding-top: 0.25rem; }
.billing-history h2 { margin-bottom: 0.25rem; }
.billing-table-wrap { overflow-x: auto; }
.billing-empty { max-width: 560px; border: 1px solid var(--border); padding: 0.9rem 1rem; background: var(--surface-alt); }
.billing-empty h2 { margin-top: 0; }

@media (max-width: 520px) {
  .billing-balance, .billing-pack { align-items: flex-start; flex-direction: column; gap: 0.5rem; }
  .billing-balance button, .billing-pack button { width: 100%; margin: 0; }
  .billing-history table, .billing-history thead, .billing-history tbody, .billing-history tr, .billing-history th, .billing-history td { display: block; }
  .billing-history thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .billing-history tr { padding: 0.65rem 0; border-bottom: 1px solid var(--border); }
  .billing-history td { border: 0; padding: 0.08rem 0; }
  .billing-history td::before { content: attr(data-label) ': '; color: var(--ink-muted); font-size: 0.8rem; }
}

/* --- logo --------------------------------------------------------------- */
.logo {
  mix-blend-mode: var(--logo-blend);
  background: var(--logo-plate);
  padding: var(--logo-plate-pad);
  border-radius: var(--radius);
  object-fit: contain;
}

/* QR codes must stay black on white to remain scannable, so they carry their own
   ground rather than inheriting the theme's. */
.qr {
  max-width: 180px;
  display: block;
  margin-top: 0.5rem;
  background: #ffffff;
  padding: 0.4rem;
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
}

/* --- theme picker ------------------------------------------------------- */
.theme-picker { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.5rem 0 0.75rem; }
.theme-swatch {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink-muted);
  padding: 0.35rem 0.6rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  margin: 0;
}
.theme-swatch:hover { border-color: var(--accent); }
.theme-swatch[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.theme-chip {
  width: 1.5rem;
  height: 0.9rem;
  border-radius: 2px;
  flex-shrink: 0;
  display: inline-block;
  border: 1px solid rgba(128, 128, 128, 0.45);
}

/* --- landing page ------------------------------------------------------- */
.landing { display: flex; flex-direction: column; gap: calc(var(--space) * 2.5); }

.hero {
  display: flex;
  align-items: center;
  gap: 2.5rem;
  flex-wrap: wrap;
  padding: calc(var(--space) * 1.5) 0;
}
.hero-copy { flex: 1; min-width: 300px; display: flex; flex-direction: column; gap: 0.9rem; }
.hero-copy h1 {
  font-size: clamp(1.75rem, 4.5vw, 2.6rem);
  line-height: 1.12;
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 0;
  max-width: 18ch;
  text-wrap: balance;
  letter-spacing: var(--head-tracking);
}
.hero-copy p { color: var(--ink-muted); max-width: 52ch; }
.hero-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.hero-actions button { margin-top: 0; }
.hero .logo { max-width: 200px; max-height: 200px; flex-shrink: 0; }

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 0.85rem;
}
.feature {
  background: var(--surface-alt);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.feature h2 { margin: 0; font-size: 0.95rem; }
.feature p { font-size: 0.88rem; color: var(--ink-muted); }

.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 1.25rem; }
.step { display: flex; flex-direction: column; gap: 0.3rem; }
.step-num {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-faint);
  border-bottom: var(--rule-weight) solid var(--rule);
  padding-bottom: 0.25rem;
  margin-bottom: 0.2rem;
}
.step h2 { margin: 0; font-size: 0.92rem; }
.step p { font-size: 0.88rem; color: var(--ink-muted); }

.landing-cta {
  border-top: var(--rule-weight) solid var(--rule);
  padding-top: calc(var(--space) * 1.5);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  align-items: flex-start;
}
.landing-cta h2 { margin: 0; font-size: 1.1rem; }
.landing-cta p { color: var(--ink-muted); max-width: 52ch; font-size: 0.92rem; }

.landing-foot {
  border-top: 1px solid var(--border);
  padding: 1rem 0 2rem;
  font-size: 0.8rem;
  color: var(--ink-faint);
  font-family: var(--font-mono);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

@media (max-width: 600px) {
  body { padding: 0 0.5rem; }
  header { gap: 0.75rem; }
  table { font-size: 0.8rem; }
  td, th { padding: 0.25rem 0.3rem; }
  .hero { gap: 1.25rem; }
  .hero .logo { max-width: 130px; max-height: 130px; }
}
