/* ============================================================
   Carded — style.css
   Built on the Graham Nessler design system (see tokens.css).
   Dark-mode first; .light overrides cascade from tokens.css.
   Mobile-first.
   ============================================================ */

/* ── 1. Reset & base ─────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
}

img, svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Generic link override for app shell (tokens.css already styles raw <a>). */
a {
  text-decoration: none;
}

/* ── 2. Accessibility utility ────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── 3. Layout ───────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 768px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--fg);
}

.brand:hover {
  color: var(--fg);
}

.brand__logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.wordmark {
  font-family: var(--font-sans);
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: var(--tracking-tight);
  color: var(--fg);
}

.header-spacer {
  flex: 1;
}

.theme-toggle {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--fg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease-standard),
              background var(--dur-fast) var(--ease-standard),
              border-color var(--dur-fast) var(--ease-standard);
}

.theme-toggle:hover {
  color: var(--fg);
  background: var(--bg-elev-2);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--brand-red);
  outline-offset: 2px;
}

.theme-toggle__icon {
  display: block;
}

/* Show the sun in dark mode (toggle to light); moon in light mode. */
.theme-toggle__icon--moon { display: none; }
.theme-toggle__icon--sun  { display: block; }
.light .theme-toggle__icon--moon { display: block; }
.light .theme-toggle__icon--sun  { display: none; }

.site-main {
  max-width: 768px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-12);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

/* ── 4. Card (base container) ────────────────────────────── */
.card {
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

/* ── 5. Buttons ──────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 44px;
  padding: 0 var(--space-5);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  border: 1px solid transparent;
  outline: none;
  transition: background var(--dur-fast) var(--ease-standard),
              color var(--dur-fast) var(--ease-standard),
              border-color var(--dur-fast) var(--ease-standard),
              opacity var(--dur-fast) var(--ease-standard);
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:focus-visible {
  outline: 2px solid var(--brand-red);
  outline-offset: 2px;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* Primary = silver-on-dark (default CTA). On light theme tokens.css inverts
   to black-on-white. */
.btn--primary {
  background: var(--action-primary-bg);
  color: var(--action-primary-fg);
  border-color: var(--action-primary-bg);
}
.btn--primary:hover:not(:disabled) {
  background: var(--action-primary-bg-hover);
  border-color: var(--action-primary-bg-hover);
  color: var(--action-primary-fg);
}

/* Destructive = brand red. Used for actions that erase data. */
.btn--destructive {
  background: var(--action-destructive-bg);
  color: var(--action-destructive-fg);
  border-color: var(--action-destructive-bg);
}
.btn--destructive:hover:not(:disabled) {
  background: var(--action-destructive-bg-hover);
  border-color: var(--action-destructive-bg-hover);
  color: var(--action-destructive-fg);
}

/* Secondary kept for backwards compat — accent (blue) variant. */
.btn--secondary {
  background: var(--action-accent-bg);
  color: var(--action-accent-fg);
  border-color: var(--action-accent-bg);
}
.btn--secondary:hover:not(:disabled) {
  background: var(--action-accent-bg-hover);
  border-color: var(--action-accent-bg-hover);
}

/* Ghost = transparent with subtle border. */
.btn--ghost {
  background: transparent;
  color: var(--fg-muted);
  border-color: var(--border);
}
.btn--ghost:hover:not(:disabled) {
  background: var(--bg-elev-2);
  color: var(--fg);
}

.btn--sm {
  height: 36px;
  padding: 0 var(--space-3);
  font-size: 0.8125rem;
  border-radius: var(--radius-sm);
}

.btn--full {
  width: 100%;
}

.btn--download {
  flex: 1;
  min-width: 140px;
}

.btn__icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ── 6. Form inputs ──────────────────────────────────────── */
.input {
  height: 44px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  color: var(--fg);
  background: var(--bg-elev-2);
  outline: none;
  transition: border-color var(--dur-fast) var(--ease-standard),
              box-shadow var(--dur-fast) var(--ease-standard);
  width: 100%;
}

.input::placeholder {
  color: var(--fg-dim);
}

.input:focus {
  border-color: var(--brand-red);
  box-shadow: 0 0 0 2px var(--ring);
}

/* ── 7. Spinner ──────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid color-mix(in srgb, var(--action-primary-fg) 25%, transparent);
  border-top-color: var(--action-primary-fg);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  flex-shrink: 0;
}

.spinner--hidden {
  display: none;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── 8. API Key section ──────────────────────────────────── */
.api-key-section--set {
  padding: var(--space-4) var(--space-6);
}

.key-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.key-indicator--hidden {
  display: none;
}

.key-indicator__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: var(--ok-bg);
  border-radius: 50%;
  color: var(--ok);
  flex-shrink: 0;
}

.key-indicator__icon svg {
  width: 14px;
  height: 14px;
}

.key-indicator__label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--fg);
}

.key-indicator__mask {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--fg-muted);
  margin-right: auto;
}

.key-entry {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.key-entry--hidden {
  display: none;
}

.key-entry__heading {
  font-family: var(--font-sans);
  font-size: var(--fs-h3);
  font-weight: 700;
  letter-spacing: var(--tracking-snug);
  color: var(--fg);
  margin: 0;
}

.key-entry__hint {
  font-size: var(--fs-small);
  color: var(--fg-muted);
  line-height: var(--lh-body);
  margin: 0;
}

.key-form__row {
  display: flex;
  gap: var(--space-2);
  align-items: stretch;
}

.key-form__input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 0.875rem;
}

/* Inline error below key form */
.key-error {
  font-size: var(--fs-small);
  color: var(--brand-red-ink);
  background: var(--bg-tint-red);
  border: 1px solid var(--brand-red);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  line-height: var(--lh-body);
}

.light .key-error {
  color: var(--brand-red-hover);
}

.key-error--hidden {
  display: none;
}

/* ── 9. Upload section ──────────────────────────────────── */
.upload-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.upload-section--hidden {
  display: none;
}

.upload-section__heading {
  font-family: var(--font-sans);
  font-size: var(--fs-h3);
  font-weight: 700;
  letter-spacing: var(--tracking-snug);
  color: var(--fg);
  margin: 0;
}

/* File drop zone */
.file-drop-zone {
  position: relative;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-elev-2);
  transition: border-color var(--dur-fast) var(--ease-standard),
              background var(--dur-fast) var(--ease-standard);
  cursor: pointer;
}

.file-drop-zone:hover,
.file-drop-zone.is-drag-over {
  border-color: var(--fg-muted);
  background: var(--bg);
}

.light .file-drop-zone:hover,
.light .file-drop-zone.is-drag-over {
  background: var(--bg-elev-1);
}

.file-drop-zone__label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-10) var(--space-6);
  cursor: pointer;
  text-align: center;
}

.file-drop-zone__icon {
  color: var(--fg-muted);
}

.file-drop-zone__primary {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--fg);
}

.file-drop-zone__secondary {
  font-size: var(--fs-small);
  color: var(--fg-muted);
}

.file-drop-zone__input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* Image preview */
.preview-area {
  position: relative;
  min-height: 88px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
}

.preview-area--hidden {
  display: none;
}

.preview-area__img {
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  display: block;
}

.preview-area__fallback {
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-5) 0 var(--space-2);
  color: var(--fg-muted);
}

.preview-area--no-image .preview-area__img {
  display: none;
}

.preview-area--no-image .preview-area__fallback {
  display: flex;
}

.preview-area__filename {
  display: none;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--fg-muted);
  padding: var(--space-2) var(--space-3);
  margin: 0;
  word-break: break-all;
}

.preview-area--no-image .preview-area__filename {
  display: block;
}

.preview-area__clear {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
}

/* Submit button layout */
.upload-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.upload-form__submit {
  display: flex;
  gap: var(--space-2);
}

/* ── 10. Error card ──────────────────────────────────────── */
.error-card {
  border-radius: var(--radius-md);
  border: 1px solid var(--brand-red);
  background: var(--bg-tint-red);
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.error-card--hidden {
  display: none;
}

.error-card__message {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--brand-red-ink);
  line-height: var(--lh-snug);
}

.error-card__detail {
  font-size: 0.8125rem;
  color: var(--brand-red-ink);
  opacity: 0.85;
  line-height: var(--lh-body);
}

.light .error-card__message,
.light .error-card__detail {
  color: var(--brand-red-hover);
}

/* ── 11. Result section ──────────────────────────────────── */
.result-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.result-section--hidden {
  display: none;
}

.result-section__heading {
  font-family: var(--font-sans);
  font-size: var(--fs-h3);
  font-weight: 700;
  letter-spacing: var(--tracking-snug);
  color: var(--fg);
  margin: 0;
}

.result-card {
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

/* Name block */
.result-name {
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--space-4);
}

.result-name__full {
  font-family: var(--font-sans);
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: var(--tracking-tight);
  color: var(--fg);
  line-height: var(--lh-snug);
}

.result-name__subtitle {
  margin-top: var(--space-1);
  font-size: 0.9375rem;
  color: var(--fg-muted);
  line-height: var(--lh-snug);
}

.result-name__department {
  margin-top: var(--space-1);
  font-size: var(--fs-small);
  color: var(--fg-muted);
}

/* Field rows */
.result-fields {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.result-field {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: var(--space-2) var(--space-4);
  align-items: baseline;
}

.result-field__label {
  font-family: var(--font-sans);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--brand-red);
  padding-top: 2px;
}

.result-field__value {
  font-size: 0.9375rem;
  color: var(--fg);
  line-height: var(--lh-snug);
  word-break: break-word;
}

.result-field__value a {
  color: var(--fg-link);
}

.result-field__value a:hover {
  color: var(--fg-link-hover);
}

/* Multi-entry rows */
.result-entries {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.result-entry {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.result-entry__text {
  font-size: 0.9375rem;
  color: var(--fg);
}

.result-entry__type {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

/* Note / aside */
.result-note {
  border-top: 1px solid var(--border);
  padding-top: var(--space-4);
}

.result-note__text {
  font-family: var(--font-serif);
  font-size: 0.9375rem;
  color: var(--fg-muted);
  font-style: italic;
  line-height: var(--lh-body);
}

/* Download actions */
.download-actions {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
}

/* ── 12. Responsive overrides (tablet+) ──────────────────── */
@media (min-width: 540px) {
  .site-main {
    padding-top: var(--space-8);
  }

  .card {
    padding: var(--space-8);
  }

  .key-form__row {
    flex-direction: row;
    gap: var(--space-3);
  }

  .result-field {
    grid-template-columns: 96px 1fr;
  }

  .btn--download {
    flex: 0 0 auto;
    min-width: 160px;
  }
}

@media (min-width: 768px) {
  .file-drop-zone__label {
    padding: var(--space-12) var(--space-8);
  }
}

/* ── 13. Footer ──────────────────────────────────────────── */
.site-footer {
  max-width: 768px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-5) var(--space-6);
  text-align: center;
}

.site-footer__version {
  font-size: var(--fs-xs);
  color: var(--fg-dim);
  letter-spacing: 0.01em;
}
