/*
   xlsx.tools — design system
   ===========================

   Single stylesheet for the whole site. Sections in order:

   01. Custom fonts
   02. Design tokens (CSS variables)
   03. Reset & base
   04. Typography
   05. Layout primitives (container, main)
   06. Site header & brand
   07. Site footer
   08. Buttons & links
   09. Forms
   10. Tables
   11. Cards & sections
   12. Notices
   13. Page: home
   14. Page: merge flow
   15. HTMX transitions
   16. Utility classes
   17. Responsive overrides
*/

/* ----------------------------------------------------------------
   01. CUSTOM FONTS
   ----------------------------------------------------------------
   The wordmark and display headings use Fraunces, a contemporary
   serif with character. If the font file isn't present, the system
   serif fallback in --f-display takes over and the design degrades
   gracefully.

   To enable: download Fraunces variable font from
   https://fonts.google.com/specimen/Fraunces and save the woff2 to
   app/static/fonts/Fraunces-VariableFont.woff2
*/

@font-face {
  font-family: "Fraunces";
  src: url("/static/fonts/Fraunces-VariableFont.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ----------------------------------------------------------------
   02. DESIGN TOKENS
   ---------------------------------------------------------------- */

:root {
  /* Surfaces */
  --c-bg: #F8FAFC;         /* Light slate */
  --c-surface: #FFFFFF;    /* Pure white */
  --c-surface-warm: #F1F5F9; /* Muted slate for secondary backgrounds */

  /* Text */
  --c-ink: #0F172A;        /* Deep slate */
  --c-ink-muted: #475569;  /* Medium slate */
  --c-ink-subtle: #94A3B8; /* Light slate */
  --c-ink-inverse: #FFFFFF;

  /* Lines */
  --c-border: #E2E8F0;
  --c-border-strong: #CBD5E1;

  /* Accent (Vibrant Indigo) */
  --c-accent: #4F46E5;
  --c-accent-hover: #4338CA;
  --c-accent-soft: #EEF2FF;
  --c-accent-ink: #FFFFFF;

  /* Semantic */
  --c-danger: #DC2626;
  --c-danger-soft: #FEF2F2;

  /* Type families */
  --f-display: "Fraunces", "Iowan Old Style", "Palatino Linotype",
    "Book Antiqua", Palatino, Georgia, serif;
  --f-body: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --f-mono: ui-monospace, "SF Mono", Menlo, "Cascadia Code",
    "Source Code Pro", Consolas, "Liberation Mono", monospace;

  /* Type sizes */
  --t-xs: 0.75rem;
  --t-sm: 0.875rem;
  --t-base: 1rem;
  --t-md: 1.0625rem;
  --t-lg: 1.25rem;
  --t-xl: 1.5rem;
  --t-2xl: 2rem;
  --t-3xl: 2.75rem;
  --t-4xl: 4rem;

  /* Line heights */
  --lh-tight: 1.1;
  --lh-snug: 1.3;
  --lh-normal: 1.55;

  /* Spacing scale (4px base) */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.25rem;
  --s-6: 1.5rem;
  --s-8: 2rem;
  --s-10: 2.5rem;
  --s-12: 3rem;
  --s-16: 4rem;
  --s-20: 5rem;

  /* Radii */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;

  /* Shadows */
  --sh-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 1px rgba(15, 23, 42, 0.03);
  --sh-md: 0 4px 8px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.04);

  /* Containers */
  --w-content: 1024px;
  --w-narrow: 768px;

  /* Motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --duration-fast: 120ms;
  --duration-normal: 200ms;
}

/* ----------------------------------------------------------------
   03. RESET & BASE
   ---------------------------------------------------------------- */

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

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

body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-ink);
  font-family: var(--f-body);
  font-size: var(--t-md);
  line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern", "liga", "calt";
}

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

hr {
  border: 0;
  height: 1px;
  background: var(--c-border);
  margin: var(--s-8) 0;
}

::selection {
  background: var(--c-accent);
  color: var(--c-accent-ink);
}

/* ----------------------------------------------------------------
   04. TYPOGRAPHY
   ---------------------------------------------------------------- */

h1, h2, h3, h4 {
  font-family: var(--f-display);
  font-weight: 500;
  line-height: var(--lh-tight);
  letter-spacing: -0.015em;
  color: var(--c-ink);
  margin: 0 0 var(--s-4) 0;
}

h1 {
  font-size: var(--t-3xl);
  font-weight: 400;
  letter-spacing: -0.025em;
}

h2 {
  font-size: var(--t-2xl);
  letter-spacing: -0.02em;
}

h3 {
  font-size: var(--t-xl);
}

h4 {
  font-size: var(--t-lg);
}

p {
  margin: 0 0 var(--s-4) 0;
}

p:last-child {
  margin-bottom: 0;
}

small {
  font-size: var(--t-sm);
  color: var(--c-ink-muted);
}

strong {
  font-weight: 600;
}

code, kbd, samp, pre {
  font-family: var(--f-mono);
  font-size: 0.92em;
}

code {
  background: var(--c-surface-warm);
  padding: 0.1em 0.4em;
  border-radius: var(--r-sm);
  color: var(--c-ink);
  border: 1px solid var(--c-border);
}

/* ----------------------------------------------------------------
   05. LAYOUT PRIMITIVES
   ---------------------------------------------------------------- */

.container {
  width: 100%;
  max-width: var(--w-content);
  margin-inline: auto;
  padding-inline: var(--s-6);
}

main {
  padding-block: var(--s-12) var(--s-16);
  min-height: calc(100vh - 200px);
}

/* ----------------------------------------------------------------
   06. SITE HEADER & BRAND
   ---------------------------------------------------------------- */

.site-header {
  background: rgba(248, 250, 252, 0.85); /* Matches --c-bg with opacity */
  border-bottom: 1px solid var(--c-border);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: saturate(140%) blur(6px);
}

.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-6);
  padding-block: var(--s-4);
  max-width: var(--w-content);
  margin-inline: auto;
  padding-inline: var(--s-6);
}

.site-brand {
  font-family: var(--f-display);
  font-size: var(--t-lg);
  font-weight: 500;
  text-decoration: none;
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: baseline;
}

.site-brand-name {
  color: var(--c-ink);
}

.site-brand-ext {
  font-family: var(--f-mono);
  font-size: 0.78em;
  font-weight: 400;
  color: var(--c-accent);
  letter-spacing: 0;
}

.site-nav {
  display: flex;
  gap: var(--s-6);
}

.site-nav a {
  font-size: var(--t-sm);
  color: var(--c-ink-muted);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease);
}

.site-nav a:hover {
  color: var(--c-accent);
}

/* ----------------------------------------------------------------
   07. SITE FOOTER
   ---------------------------------------------------------------- */

.site-footer {
  border-top: 1px solid var(--c-border);
  padding-block: var(--s-8);
  font-size: var(--t-sm);
  color: var(--c-ink-subtle);
}

.site-footer-inner {
  max-width: var(--w-content);
  margin-inline: auto;
  padding-inline: var(--s-6);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s-4);
  flex-wrap: wrap;
}

/* ----------------------------------------------------------------
   08. BUTTONS & LINKS
   ---------------------------------------------------------------- */

a {
  color: var(--c-accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: color var(--duration-fast) var(--ease);
}

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

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-5);
  font-family: var(--f-body);
  font-size: var(--t-base);
  font-weight: 500;
  line-height: 1.2;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: var(--c-accent);
  color: var(--c-accent-ink);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--duration-fast) var(--ease),
              transform var(--duration-fast) var(--ease),
              box-shadow var(--duration-fast) var(--ease);
}

button:hover,
.btn:hover {
  background: var(--c-accent-hover);
  color: var(--c-accent-ink);
  box-shadow: var(--sh-sm);
}

button:active,
.btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

button:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 2px;
}

.btn-secondary {
  background: var(--c-surface);
  color: var(--c-ink);
  border-color: var(--c-border-strong);
}

.btn-secondary:hover {
  background: var(--c-surface-warm);
  color: var(--c-ink);
  border-color: var(--c-ink-muted);
}

.btn-ghost {
  background: transparent;
  color: var(--c-ink-muted);
  padding-inline: var(--s-2);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

.btn-ghost:hover {
  background: transparent;
  color: var(--c-accent);
  box-shadow: none;
}

/* ----------------------------------------------------------------
   09. FORMS
   ---------------------------------------------------------------- */

form {
  display: flex;
  flex-direction: column;
  gap: var(--s-10);
}

fieldset {
  border: 0;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

legend {
  font-family: var(--f-display);
  font-size: var(--t-lg);
  font-weight: 500;
  color: var(--c-ink);
  letter-spacing: -0.01em;
  margin-bottom: var(--s-1);
  padding: 0;
}

.field-help {
  font-size: var(--t-sm);
  color: var(--c-ink-muted);
  line-height: var(--lh-snug);
  margin: 0 0 var(--s-2) 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

label {
  font-size: var(--t-sm);
  color: var(--c-ink-muted);
  line-height: var(--lh-snug);
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="file"],
select,
textarea {
  width: 100%;
  padding: var(--s-3) var(--s-4);
  background: var(--c-surface);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-md);
  font-family: var(--f-body);
  font-size: var(--t-base);
  color: var(--c-ink);
  transition: border-color var(--duration-fast) var(--ease),
              box-shadow var(--duration-fast) var(--ease);
}

input[type="file"] {
  padding: var(--s-3);
  cursor: pointer;
}

input[type="file"]::file-selector-button {
  margin-right: var(--s-3);
  padding: var(--s-2) var(--s-4);
  background: var(--c-surface-warm);
  color: var(--c-ink);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-sm);
  font-family: var(--f-body);
  font-size: var(--t-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease);
}

input[type="file"]::file-selector-button:hover {
  background: var(--c-accent-soft);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px var(--c-accent-soft);
}

/* Dynamic chevron color matching the indigo accent (#4F46E5) */
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='8' viewBox='0 0 14 8'%3E%3Cpath fill='none' stroke='%234F46E5' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' d='M1 1l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s-4) center;
  padding-right: var(--s-10);
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--c-accent);
  width: 1.05em;
  height: 1.05em;
  margin: 0;
  flex-shrink: 0;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) 0;
  cursor: pointer;
}

.option input {
  margin-top: 0.2em;
}

.option-text {
  font-size: var(--t-base);
  color: var(--c-ink);
  line-height: var(--lh-snug);
}

.option-stack > .option + .option {
  border-top: 1px solid var(--c-border);
}

.key-pair {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: var(--s-3);
  align-items: center;
}

.key-pair-separator {
  font-size: var(--t-sm);
  color: var(--c-ink-muted);
  font-style: italic;
}

/* ----------------------------------------------------------------
   10. TABLES
   ---------------------------------------------------------------- */

.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--t-sm);
  font-variant-numeric: tabular-nums;
}

thead {
  background: var(--c-surface-warm);
}

th {
  text-align: left;
  font-family: var(--f-mono);
  font-weight: 500;
  color: var(--c-ink-muted);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--c-border-strong);
  font-size: var(--t-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

td {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--c-border);
  color: var(--c-ink);
  vertical-align: top;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: var(--c-surface-warm);
}

.source-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.15em 0.55em;
  border-radius: var(--r-sm);
  font-family: var(--f-mono);
  font-size: var(--t-xs);
  font-weight: 500;
  white-space: nowrap;
  text-transform: lowercase;
  letter-spacing: 0;
}

.source-tag-matched {
  background: var(--c-accent-soft);
  color: var(--c-accent);
}

.source-tag-only {
  background: var(--c-surface-warm);
  color: var(--c-ink-muted);
}

/* ----------------------------------------------------------------
   11. CARDS & SECTIONS
   ---------------------------------------------------------------- */

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--s-8);
}

.section {
  margin-bottom: var(--s-12);
}

/* ----------------------------------------------------------------
   12. NOTICES
   ---------------------------------------------------------------- */

.notice {
  padding: var(--s-4) var(--s-5);
  border-radius: var(--r-md);
  border: 1px solid var(--c-border);
  background: var(--c-surface-warm);
  color: var(--c-ink);
  font-size: var(--t-sm);
}

.notice-error {
  background: var(--c-danger-soft);
  border-color: var(--c-danger);
  color: var(--c-danger);
}

/* ----------------------------------------------------------------
   13. PAGE: HOME
   ---------------------------------------------------------------- */

.hero {
  padding-block: var(--s-12) var(--s-10);
  border-bottom: 1px solid var(--c-border);
  margin-bottom: var(--s-10);
}

.hero-eyebrow {
  font-family: var(--f-mono);
  font-size: var(--t-xs);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--c-accent);
  margin-bottom: var(--s-5);
}

.hero-title {
  font-size: clamp(var(--t-3xl), 6vw, var(--t-4xl));
  letter-spacing: -0.03em;
  line-height: 1.05;
  font-weight: 400;
  margin-bottom: var(--s-6);
  max-width: 16ch;
}

.hero-lead {
  font-size: var(--t-lg);
  color: var(--c-ink-muted);
  line-height: var(--lh-snug);
  max-width: 50ch;
  margin: 0;
}

.tools-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s-4);
}

.tool-card {
  display: block;
  padding: var(--s-6);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  text-decoration: none;
  color: inherit;
  transition: border-color var(--duration-normal) var(--ease),
              transform var(--duration-normal) var(--ease),
              box-shadow var(--duration-normal) var(--ease);
}

.tool-card:hover {
  border-color: var(--c-accent);
  box-shadow: var(--sh-md);
  transform: translateY(-1px);
  color: inherit;
}

.tool-card-title {
  font-family: var(--f-display);
  font-size: var(--t-xl);
  font-weight: 500;
  color: var(--c-ink);
  margin: 0 0 var(--s-2) 0;
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
}

.tool-card-arrow {
  font-family: var(--f-mono);
  font-size: var(--t-base);
  color: var(--c-accent);
  margin-left: auto;
  transition: transform var(--duration-normal) var(--ease);
}

.tool-card:hover .tool-card-arrow {
  transform: translateX(3px);
}

.tool-card-desc {
  color: var(--c-ink-muted);
  font-size: var(--t-base);
  margin: 0;
}

/* ----------------------------------------------------------------
   14. PAGE: MERGE FLOW
   ---------------------------------------------------------------- */

.page-header {
  margin-bottom: var(--s-8);
}

.page-title {
  font-family: var(--f-display);
  font-size: var(--t-2xl);
  font-weight: 500;
  margin: 0 0 var(--s-2) 0;
  letter-spacing: -0.02em;
}

.page-subtitle {
  color: var(--c-ink-muted);
  font-size: var(--t-base);
  margin: 0;
}

.merge-flow {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--s-8);
  box-shadow: var(--sh-sm); /* Added a subtle shadow to lift the form off the slate background */
}

.file-summary {
  display: grid;
  gap: var(--s-2);
  padding: var(--s-4) var(--s-5);
  background: var(--c-surface-warm);
  border-radius: var(--r-md);
  font-size: var(--t-sm);
  margin-bottom: var(--s-8);
}

.file-summary-line {
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
  flex-wrap: wrap;
}

.file-summary-label {
  color: var(--c-ink-muted);
  min-width: 5em;
}

.file-summary-value {
  font-family: var(--f-mono);
  color: var(--c-ink);
  font-weight: 500;
}

.file-summary-sheet {
  color: var(--c-ink-subtle);
  font-size: var(--t-xs);
}

.counts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-bottom: var(--s-6);
}

.count-pill {
  display: inline-flex;
  align-items: baseline;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-4);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  font-size: var(--t-sm);
}

.count-pill-label {
  color: var(--c-ink-muted);
}

.count-pill-value {
  font-family: var(--f-mono);
  font-weight: 600;
  color: var(--c-ink);
}

.count-pill-matched {
  background: var(--c-accent-soft);
  border-color: var(--c-accent);
}

.count-pill-matched .count-pill-label,
.count-pill-matched .count-pill-value {
  color: var(--c-accent);
}

.preview-note {
  font-size: var(--t-sm);
  color: var(--c-ink-muted);
  margin: var(--s-6) 0 var(--s-3) 0;
  font-style: italic;
}

.actions {
  display: flex;
  gap: var(--s-3);
  align-items: center;
  margin-top: var(--s-6);
  flex-wrap: wrap;
}

/* ----------------------------------------------------------------
   15. HTMX TRANSITIONS
   ---------------------------------------------------------------- */

.htmx-swapping {
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease);
}

.htmx-settling {
  opacity: 0;
}

#merge-flow {
  transition: opacity var(--duration-normal) var(--ease);
}

/* ----------------------------------------------------------------
   16. UTILITY CLASSES
   ---------------------------------------------------------------- */

.muted { color: var(--c-ink-muted); }
.subtle { color: var(--c-ink-subtle); }
.mono { font-family: var(--f-mono); }
.text-sm { font-size: var(--t-sm); }
.text-xs { font-size: var(--t-xs); }

/* ----------------------------------------------------------------
   17. RESPONSIVE
   ---------------------------------------------------------------- */

@media (max-width: 640px) {
  :root {
    --t-3xl: 2.25rem;
    --t-4xl: 3rem;
  }

  main {
    padding-block: var(--s-8) var(--s-12);
  }

  .site-header-inner,
  .container,
  .site-footer-inner {
    padding-inline: var(--s-4);
  }

  .merge-flow {
    padding: var(--s-5);
    border-radius: var(--r-md);
  }

  .key-pair {
    grid-template-columns: 1fr;
    gap: var(--s-2);
  }

  .key-pair-separator {
    text-align: center;
  }

  .hero {
    padding-block: var(--s-8) var(--s-6);
  }

  .file-summary-line {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--s-1);
  }

  .actions {
    flex-direction: column;
    align-items: stretch;
  }

  .actions .btn,
  .actions button {
    width: 100%;
  }
}