/* ==========================================================================
   SpinTax Generator - POC UI
   Palette: cool neutrals biased toward a deep teal accent, matching the
   SpinTax Parser Handbook so the project's surfaces read as one family.

   Pinned to the light theme: it no longer follows the operating system.
   The dark palette is kept below and applies only when <html data-theme="dark">
   is set - see index.html if you want to switch back.
   ========================================================================== */

:root {
  --ground:      #f6f7f7;
  --surface:     #ffffff;
  --surface-2:   #eef1f1;
  --ink:         #14181a;
  --ink-soft:    #4a5356;
  --ink-faint:   #7c868a;
  --rule:        #e0e4e4;
  --rule-strong: #c7cfcf;
  --accent:      #0e6e5e;
  --accent-ink:  #0b564a;
  --accent-soft: #e3f0ed;
  --warn:        #9a5b06;
  --warn-soft:   #fbf1e2;
  --danger:      #a32e22;
  --danger-soft: #fbeceb;

  --font-ui: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Cascadia Mono", Consolas, "SF Mono", ui-monospace, monospace;

  --radius: 6px;
  --shadow: 0 1px 2px rgba(20, 24, 26, 0.05), 0 4px 14px rgba(20, 24, 26, 0.05);

  /* Text drawn on top of --accent (buttons, variant badges). */
  --on-accent:   #ffffff;
}

:root[data-theme="dark"] {
  --ground:      #101315;
  --surface:     #171b1d;
  --surface-2:   #1e2325;
  --ink:         #e8edec;
  --ink-soft:    #a7b2b1;
  --ink-faint:   #798484;
  --rule:        #2a3033;
  --rule-strong: #3b4347;
  --accent:      #4fc9ae;
  --accent-ink:  #7fdcc6;
  --accent-soft: #16332d;
  --warn:        #e3a957;
  --warn-soft:   #2e2411;
  --danger:      #e8776a;
  --danger-soft: #2f1917;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.3);
  --on-accent:   #0b1a17;
}

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

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.05em 0.3em;
}

/* ================= Masthead ================= */

.masthead {
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}

.masthead-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.4rem clamp(1rem, 3vw, 2rem);
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem 2rem;
  align-items: flex-end;
  justify-content: space-between;
}

.eyebrow {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.masthead h1 {
  margin: 0.15rem 0 0;
  font-size: 1.6rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.paths {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.5rem;
  margin: 0;
}

.paths div { display: flex; flex-direction: column; gap: 0.1rem; }

.paths dt {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.paths dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--ink-soft);
  max-width: 46ch;
  overflow-wrap: anywhere;
}

/* ================= Page ================= */

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(1.25rem, 3vw, 2.25rem) clamp(1rem, 3vw, 2rem) 4rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.35rem clamp(1rem, 2.5vw, 1.6rem) 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--rule);
}

.card-head h2 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-soft);
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: 100px;
  padding: 0.12rem 0.6rem;
  white-space: nowrap;
}

.badge.flash { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }

/* ================= Fields ================= */

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field-narrow { max-width: 9rem; }
.field-check { justify-content: flex-start; padding-top: 0.15rem; }

label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.optional { text-transform: none; letter-spacing: 0; font-weight: 400; font-style: italic; }

select, input[type="number"] {
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  padding: 0.5rem 0.65rem;
  width: 100%;
}

select { max-width: 34rem; font-family: var(--font-mono); font-size: 0.86rem; }

select:hover, input[type="number"]:hover { border-color: var(--ink-faint); }

.hint { margin: 0; font-size: 0.78rem; color: var(--ink-faint); }

.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
  cursor: pointer;
}

.check input { accent-color: var(--accent); width: 1rem; height: 1rem; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  align-items: flex-start;
}

.controls .btn-primary { margin-top: 1.25rem; }

/* ================= Buttons ================= */

.btn-primary, .btn-quiet {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 4px;
  padding: 0.55rem 1.4rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-ink); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-quiet {
  background: var(--surface-2);
  color: var(--ink-soft);
  border-color: var(--rule);
  font-weight: 500;
  padding: 0.32rem 0.75rem;
  font-size: 0.78rem;
}

.btn-quiet:hover { color: var(--ink); border-color: var(--rule-strong); }

/* ================= Stats ================= */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
  border-radius: 4px;
  overflow: hidden;
}

.stat {
  background: var(--surface-2);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.stat-label {
  font-size: 0.68rem;
  font-family: var(--font-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.stat-note { font-size: 0.72rem; color: var(--ink-faint); }

/* ================= Issues ================= */

.issues {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--warn-soft);
  border: 1px solid var(--warn);
  border-left-width: 3px;
  border-radius: 4px;
  padding: 0.8rem 1rem;
}

.issues h3 {
  margin: 0;
  font-size: 0.72rem;
  font-family: var(--font-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--warn);
}

.issue { font-size: 0.82rem; color: var(--ink-soft); }

.issue-badge {
  display: inline-block;
  margin-right: 0.4rem;
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: 1px;
}

.issue-error .issue-badge { background: #fbe3e3; color: #9b2c2c; }
.issue-warning .issue-badge { background: #fdf0d5; color: #8a5a00; }
.issue code { background: transparent; border: none; padding: 0; color: var(--ink-faint); }

/* ================= Status ================= */

.status { margin: 0; font-size: 0.85rem; color: var(--ink-soft); min-height: 1.2em; }
.status.error { color: var(--danger); font-weight: 500; }
.status.busy { color: var(--accent-ink); }

/* ================= Results ================= */

.results-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--rule-strong);
  margin-bottom: 1.25rem;
}

.results-head h2 { margin: 0; font-size: 1.1rem; font-weight: 650; }

.results-meta {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--ink-faint);
  overflow-wrap: anywhere;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.15rem;
}

.variation {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.variation-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--rule);
}

.variant-num {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--on-accent);
  background: var(--accent);
  border-radius: 100px;
  padding: 0.1rem 0.5rem;
  font-variant-numeric: tabular-nums;
}

.variation-file {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.chip-warn {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--warn);
  background: var(--warn-soft);
  border: 1px solid var(--warn);
  border-radius: 100px;
  padding: 0.05rem 0.45rem;
  white-space: nowrap;
}

.variation-subject {
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--rule);
  background: var(--surface-2);
  font-size: 0.85rem;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.variation-subject .subject-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* Email HTML is authored at 600px; scale it down to thumbnail width. */
.preview {
  position: relative;
  height: 300px;
  overflow: hidden;
  background: #fff;
  border-bottom: 1px solid var(--rule);
}

.preview iframe {
  width: 600px;
  height: 1400px;
  border: 0;
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: top left;
  background: #fff;
}

.preview::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 44px;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.95));
  pointer-events: none;
}

.variation-foot {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.85rem;
}

.variation-size {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-faint);
  margin-right: auto;
  font-variant-numeric: tabular-nums;
}

/* ================= Viewer dialog ================= */

#viewer {
  width: min(96vw, 700px);
  max-width: 96vw;
  height: min(92vh, 1000px);
  padding: 0;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  overflow: hidden;
}

#viewer::backdrop { background: rgba(10, 14, 15, 0.6); }

#viewer[open] { display: flex; flex-direction: column; }

.viewer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--rule);
}

.viewer-file { margin: 0; font-family: var(--font-mono); font-size: 0.8rem; color: var(--ink); }
.viewer-subject { margin: 0.1rem 0 0; font-size: 0.82rem; color: var(--ink-faint); }

#viewerFrame { flex: 1; width: 100%; border: 0; background: #fff; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

.chip-coverage {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 100px;
  padding: 0.06rem 0.5rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ================= page navigation ================= */

.pagenav { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.pagenav a {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-soft);
  text-decoration: none;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 100px;
  background: var(--surface-2);
}

.pagenav a:hover { color: var(--ink); border-color: var(--rule-strong); }

.pagenav a[aria-current="page"] {
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
}

/* ================= builder page ================= */

.controls-tight { align-items: flex-end; gap: 1rem 1.25rem; }
.controls-tight .btn-quiet { margin-bottom: 0.15rem; }

.head-actions { display: flex; gap: 0.45rem; align-items: center; }

input[type="file"] {
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  padding: 0.4rem 0.5rem;
  max-width: 22rem;
  width: 100%;
}

input[type="file"]::file-selector-button {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  padding: 0.25rem 0.7rem;
  margin-right: 0.65rem;
  cursor: pointer;
}

input[type="file"]::file-selector-button:hover { border-color: var(--ink-faint); }

textarea#editor {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.65;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  padding: 0.85rem 1rem;
  width: 100%;
  min-height: 22rem;
  resize: vertical;
  tab-size: 2;
}

textarea#editor::placeholder { color: var(--ink-faint); }
textarea#editor.drop-target { border-color: var(--accent); background: var(--accent-soft); }

.spintax-source {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.7;
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  margin: 0;
  padding: 1rem 1.15rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--ink-soft);
  max-height: 34rem;
  overflow-y: auto;
}

/* the choices the generator introduced */
.spin-group {
  background: var(--accent-soft);
  color: var(--accent-ink);
  border: 1px solid var(--accent);
  border-radius: 3px;
  padding: 0 0.15em;
  font-weight: 500;
}
