/* Swish chart extractor — brand tokens + page-shell layout */

:root {
  --bone: #F5F1E8;
  --cream: #FBF7EE;
  --forest: #1E3A2F;
  --forest-ink: #F5F1E8;
  --sandstone: #C9A66B;
  --sandstone-soft: rgba(201, 166, 107, 0.18);
  --ink: #1A1A1A;
  --stone: #6B6B66;
  --soft-stone: #E5DFD0;

  --font-display: 'Newsreader', Georgia, 'Times New Roman', serif;
  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;

  --page-max: 1200px;
  --page-pad-x: clamp(20px, 5vw, 64px);
  --section-gap: clamp(48px, 7vw, 96px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bone);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: inherit;
}

/* ---------- Header ---------- */

.site-header {
  background: var(--bone);
  border-bottom: 1px solid var(--soft-stone);
}

.site-header__inner {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 24px var(--page-pad-x) 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.site-header__wordmark {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: 20px;
  letter-spacing: 0.01em;
  color: var(--ink);
  text-decoration: none;
}

.site-header__reset {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--sandstone);
  padding-bottom: 1px;
  transition: color 120ms ease;
}

.site-header__reset:hover {
  color: var(--forest);
}

.site-header__eyebrow {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 4px var(--page-pad-x) 20px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--stone);
}

/* ---------- Page + sections ---------- */

.page {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 var(--page-pad-x);
}

.section {
  padding: var(--section-gap) 0;
  border-top: 1px solid var(--soft-stone);
}

.section:first-of-type {
  border-top: none;
}

.section--bone {
  background: var(--bone);
}

.section--cream {
  background: var(--cream);
  /* extend cream beyond page padding by negative margin trick if we wanted full-bleed —
     keeping in-page for simple layout */
}

/* 7:5 grid for the section header */
.section__header {
  display: grid;
  grid-template-columns: 7fr 5fr;
  gap: clamp(20px, 4vw, 48px);
  align-items: end;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--soft-stone);
  margin-bottom: 28px;
}

.section__title {
  display: flex;
  align-items: baseline;
  gap: 14px;
  font-family: var(--font-display);
  color: var(--ink);
  line-height: 1;
}

.section__numeral {
  font-size: clamp(48px, 7vw, 64px);
  font-weight: 400;
  color: var(--sandstone);
}

.section__slash {
  font-size: clamp(36px, 5vw, 48px);
  font-weight: 400;
  color: var(--soft-stone);
}

.section__label {
  font-size: clamp(24px, 3.5vw, 32px);
  font-weight: 400;
  color: var(--ink);
}

.section__lede {
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 400;
  color: var(--stone);
  margin: 0;
  line-height: 1.55;
  padding-bottom: 8px;
}

@media (max-width: 720px) {
  .section__header {
    grid-template-columns: 1fr;
    gap: 12px;
    align-items: start;
  }
  .section__lede {
    padding-bottom: 0;
  }
}

.section__body {
  min-height: 80px;
}

/* Locked / inactive sections — dimmed scaffold */
.section[data-state="locked"] {
  opacity: 0.45;
  pointer-events: none;
  user-select: none;
}

.section[data-state="locked"] .section__lede {
  color: var(--stone);
}

/* ---------- Placeholder / skeleton shapes (visual only) ---------- */

.placeholder {
  display: block;
}

.placeholder__row {
  height: 56px;
  border-top: 1px solid var(--soft-stone);
}

.placeholder--rows .placeholder__row:last-child {
  border-bottom: 1px solid var(--soft-stone);
}

.placeholder--split {
  display: grid;
  grid-template-columns: 7fr 5fr;
  gap: clamp(20px, 4vw, 40px);
}

.placeholder__frame {
  aspect-ratio: 4 / 3;
  background: var(--soft-stone);
  opacity: 0.5;
}

.placeholder__table .placeholder__row {
  height: 40px;
}

.placeholder--canvas {
  aspect-ratio: 16 / 9;
  width: 100%;
  max-width: 900px;
  background: var(--soft-stone);
  opacity: 0.5;
}

/* ---------- Footer ---------- */

.site-footer {
  background: var(--forest);
  color: var(--forest-ink);
  margin-top: var(--section-gap);
}

.site-footer__inner {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 40px var(--page-pad-x);
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.site-footer__cta {
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  color: var(--forest-ink);
  text-decoration: none;
  padding: 10px 18px;
  border: 1px solid rgba(245, 241, 232, 0.4);
  transition: background 140ms ease, color 140ms ease;
}

.site-footer__cta:hover {
  background: var(--forest-ink);
  color: var(--forest);
}

/* ---------- Shared UI primitives later features may use ---------- */

.btn {
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  padding: 12px 20px;
  border: 1px solid var(--forest);
  background: var(--forest);
  color: var(--forest-ink);
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: opacity 120ms ease;
}

.btn:hover {
  opacity: 0.9;
}

.btn[disabled] {
  cursor: default;
  opacity: 0.55;
}

.btn--secondary {
  background: transparent;
  color: var(--forest);
}

.eyebrow {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--stone);
}

/* ---------- Section 01 — search form ---------- */

.search-form {
  display: block;
  max-width: 760px;
}

.search-form__row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: end;
}

.search-form__label {
  display: block;
  min-width: 0;
}

.search-form__eyebrow {
  display: block;
  margin-bottom: 8px;
}

.search-form__input {
  width: 100%;
  display: block;
  font-family: var(--font-display);
  font-size: clamp(20px, 2.6vw, 28px);
  font-weight: 400;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--ink);
  padding: 8px 0 10px;
  line-height: 1.2;
  outline: none;
  transition: border-color 120ms ease;
}

.search-form__input::placeholder {
  color: var(--stone);
  font-style: italic;
  opacity: 0.7;
}

.search-form__input:focus {
  border-bottom-color: var(--forest);
}

.search-form__input--invalid,
.search-form__input--invalid:focus {
  border-bottom-color: var(--sandstone);
}

.search-form__input:disabled {
  color: var(--stone);
  opacity: 0.7;
}

.search-form__submit {
  white-space: nowrap;
  align-self: end;
}

.search-form__error {
  margin: 14px 0 0;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--sandstone);
}

.search-progress {
  position: relative;
  display: block;
  height: 1px;
  margin-top: 18px;
  background: var(--soft-stone);
  overflow: hidden;
}

.search-progress__strip {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 30%;
  background: var(--forest);
}

.search-progress.is-active .search-progress__strip {
  animation: search-progress-slide 1.4s linear infinite;
}

@keyframes search-progress-slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(420%); }
}

@media (max-width: 560px) {
  .search-form__row {
    grid-template-columns: 1fr;
  }
  .search-form__submit {
    justify-self: start;
  }
}

/* ---------- Section 02 — minimal placeholders used by search-section fallbacks ---------- */

.results__error {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: flex-start;
  padding: 16px 0;
}

.results__error-msg {
  margin: 0;
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--ink);
}

.results__retry {
  font-size: 13px;
  padding: 10px 16px;
}

.results__empty {
  margin: 0;
  padding: 16px 0;
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--ink);
}

.results__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.results__row {
  padding: 14px 0;
  border-top: 1px solid var(--soft-stone);
}

.results__row:last-child {
  border-bottom: 1px solid var(--soft-stone);
}

.results__title {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--ink);
  line-height: 1.3;
}

.results__url {
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--stone);
  margin-top: 4px;
}

/* ---------- Section 02 — result rows + chart-match badges ---------- */

.result-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.result-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "title  badge"
    "source badge"
    "url    badge";
  column-gap: 24px;
  row-gap: 4px;
  padding: 18px 0 18px 14px;
  border-top: 1px solid var(--soft-stone);
  border-left: 2px solid transparent;
  cursor: pointer;
  transition: background-color 140ms ease, opacity 160ms ease,
    border-left-color 140ms ease;
}

.result-row:last-child {
  border-bottom: 1px solid var(--soft-stone);
}

.result-row__title {
  grid-area: title;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.3;
}

.result-row__source {
  grid-area: source;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--stone);
}

.result-row__url {
  grid-area: url;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--stone);
  opacity: 0.85;
  word-break: break-all;
}

.result-row__badge {
  grid-area: badge;
  align-self: center;
  justify-self: end;
  min-width: 140px;
  text-align: right;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--stone);
  white-space: nowrap;
}

.result-row__badge--loading {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  letter-spacing: 0;
}

.result-row__badge-skeleton {
  display: inline-block;
  width: 120px;
  height: 12px;
  background: var(--soft-stone);
  opacity: 0.7;
  animation: badge-pulse 1.2s ease-in-out infinite;
}

@keyframes badge-pulse {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 0.85;
  }
}

.result-row__badge--chart {
  color: var(--forest);
}

.result-row__badge--chart::before {
  content: "✓ ";
  color: var(--sandstone);
}

.result-row__badge--related {
  color: var(--forest);
}

.result-row__badge--related::before {
  content: "◯ ";
  color: var(--sandstone);
}

.result-row__badge--none {
  color: var(--stone);
}

.result-row__badge--none::before {
  content: "— ";
  color: var(--stone);
}

.result-row__badge--unfetchable {
  color: var(--stone);
  font-family: var(--font-display);
  font-style: italic;
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

.result-row--enabled:hover {
  background: rgba(201, 166, 107, 0.06);
}

.result-row--enabled:focus-visible {
  outline: 2px solid var(--sandstone);
  outline-offset: -2px;
}

.result-row--selected {
  border-left-color: var(--sandstone);
  background: rgba(201, 166, 107, 0.05);
}

.result-row--disabled {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}

/* ---------- Section 03 — fallback EXTRACTING state ---------- */
/* Used briefly by results.js before extraction.js claims swish.startExtraction. */

.preview-extracting {
  display: block;
}

.preview-extracting__eyebrow {
  margin: 0 0 16px;
  color: var(--sandstone);
}

.preview-extracting__note {
  margin: 18px 0 0;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 14px;
  color: var(--stone);
  word-break: break-all;
}

/* ---------- Section 03 — preview-extraction renderer ---------- */

.preview {
  display: block;
}

.preview__eyebrow {
  margin: 0 0 18px;
  color: var(--sandstone);
}

.preview__eyebrow--error,
.preview__eyebrow--unsupported {
  color: var(--sandstone);
}

.preview__extracting-lede {
  margin: 0 0 24px;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 14px;
  color: var(--stone);
  word-break: break-all;
}

.preview__split {
  display: grid;
  grid-template-columns: 7fr 5fr;
  gap: clamp(24px, 4vw, 48px);
  align-items: start;
}

@media (max-width: 860px) {
  .preview__split {
    grid-template-columns: 1fr;
  }
}

.preview__left {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.preview__right {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.preview__image-wrap {
  display: block;
  width: 100%;
  background: var(--bone);
  border: 1px solid var(--soft-stone);
  padding: 8px;
  min-height: 200px;
}

.preview__image {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  background: var(--bone);
  min-height: 180px;
}

.preview__image--loading {
  opacity: 0.85;
}

.preview__image--broken {
  min-height: 220px;
  background:
    repeating-linear-gradient(
      45deg,
      var(--soft-stone),
      var(--soft-stone) 8px,
      var(--bone) 8px,
      var(--bone) 16px
    );
}

.preview__image-placeholder {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--soft-stone);
  opacity: 0.5;
}

.preview__source {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 8px;
}

.preview__source-label {
  margin: 0;
  color: var(--stone);
}

.preview__source-url {
  display: block;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--sandstone);
  word-break: break-all;
  padding-bottom: 1px;
  align-self: flex-start;
}

.preview__source-url:hover {
  color: var(--forest);
}

.preview__skeleton {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.preview__skeleton-row {
  height: 36px;
  background: var(--soft-stone);
  opacity: 0.5;
}

.preview__fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.preview__field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.preview__field-label {
  margin: 0;
  color: var(--stone);
}

.preview__title-input {
  font-family: var(--font-display);
  font-size: clamp(20px, 2.4vw, 26px);
  font-weight: 400;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--ink);
  padding: 6px 0 8px;
  outline: none;
  width: 100%;
  transition: border-color 120ms ease;
}

.preview__title-input:focus {
  border-bottom-color: var(--forest);
}

.preview__axes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

@media (max-width: 520px) {
  .preview__axes {
    grid-template-columns: 1fr;
  }
}

.preview__axis-input {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--soft-stone);
  padding: 6px 0 6px;
  outline: none;
  width: 100%;
  transition: border-color 120ms ease;
}

.preview__axis-input:focus {
  border-bottom-color: var(--forest);
}

.preview__table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: 13px;
  table-layout: fixed;
}

.preview__th {
  text-align: left;
  border-bottom: 1px solid var(--ink);
  padding: 8px 6px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--stone);
  background: transparent;
  vertical-align: bottom;
}

.preview__series-name {
  width: 100%;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 1px dashed transparent;
  padding: 2px 0;
  outline: none;
}

.preview__series-name:focus {
  border-bottom-color: var(--sandstone);
}

.preview__row {
  border-bottom: 1px solid var(--soft-stone);
}

.preview__cell {
  padding: 6px 6px;
  vertical-align: middle;
}

.preview__cell--label {
  width: 35%;
}

.preview__label-input {
  width: 100%;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 1px dashed transparent;
  padding: 4px 4px;
  outline: none;
}

.preview__label-input:focus {
  border-bottom-color: var(--sandstone);
}

.preview__value-input {
  width: 100%;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  padding: 6px 8px;
  outline: none;
  text-align: right;
  transition: border-color 120ms ease, background-color 120ms ease;
}

.preview__value-input:focus {
  border-color: var(--forest);
}

/* r7 — low-confidence cell highlight: sandstone-soft (~18% opacity)
   background + 1px hairline border. Removed on input by the JS handler. */
.preview__value--low-conf {
  background: var(--sandstone-soft);
  border: 1px solid var(--sandstone);
}

.preview__cta-row {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.preview__render-cta {
  white-space: nowrap;
}

.preview__error-msg {
  margin: 0;
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--ink);
  max-width: 480px;
}

.preview__unsupported-msg {
  margin: 0;
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--ink);
  line-height: 1.4;
}

/* ---------- Section 04 — branded chart + downloads ---------- */

.branded {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.branded__eyebrow {
  margin: 0;
  color: var(--sandstone);
}

.branded__frame {
  display: block;
  width: 100%;
  max-width: 900px;
  aspect-ratio: 16 / 9;
  background: var(--bone);
  border: 1px solid var(--soft-stone);
  padding: 16px;
  position: relative;
  min-height: 320px;
  box-sizing: border-box;
}

.branded__canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  max-width: 100%;
}

.branded__cta-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.branded__cta {
  white-space: nowrap;
}

.branded__source {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  padding-top: 16px;
  border-top: 1px solid var(--soft-stone);
}

.branded__source-label {
  margin: 0;
  color: var(--stone);
}

.branded__source-url {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--sandstone);
  word-break: break-all;
  padding-bottom: 1px;
}

.branded__source-url:hover {
  color: var(--forest);
}

.branded__source-date {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--stone);
  white-space: nowrap;
}

@media (max-width: 560px) {
  .branded__source {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}

/* ---------- Cross-cutting: extract error + low-confidence banner ---------- */

.preview--error {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 640px;
  padding: 16px 0;
}

.preview__eyebrow--error {
  color: var(--sandstone);
}

.preview__error-msg {
  font-family: var(--font-display);
  font-size: clamp(20px, 2.4vw, 26px);
  font-weight: 400;
  color: var(--ink);
  margin: 0;
  line-height: 1.3;
}

.preview__error-cta-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.preview__back-to-results {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
}

.preview__error-retry {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  background: transparent;
  border: none;
  color: var(--ink);
  border-bottom: 1px solid var(--sandstone);
  padding: 6px 0;
  cursor: pointer;
  text-decoration: none;
}

.preview__error-retry:hover {
  color: var(--forest);
}

.preview__render-cta--disabled {
  opacity: 0.4;
  pointer-events: none;
}

.preview__low-conf-banner {
  background: var(--sandstone-soft);
  border-left: 3px solid var(--sandstone);
  padding: 12px 14px;
  margin: 0 0 16px;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--ink);
  line-height: 1.45;
}

.preview__low-conf-banner strong {
  font-weight: 600;
  letter-spacing: 0.02em;
}

.preview__low-conf-banner-rest {
  color: var(--stone);
}
