/* ===================================================================
   Receipt Coding — finance-grade operations console
   Warm paper surfaces · ink text · deep "ledger" green accent
   Fraunces (display) + IBM Plex Sans (UI) · tabular money figures
   =================================================================== */

:root {
  --paper:        #f5f2ea;   /* app background (warm) */
  --surface:      #fffdf8;   /* cards, inputs, tables */
  --surface-sunk: #f0ece1;   /* table headers, subtle wells */
  --ink:          #1c211e;   /* primary text */
  --ink-soft:     #5a615b;   /* secondary text */
  --line:         #e3ddd0;   /* hairline borders */
  --line-strong:  #cfc8b8;

  --accent:        #1b4d3e;  /* deep ledger green — primary actions, links */
  --accent-strong: #123a2e;  /* hover / nav bar */
  --accent-ink:    #f4f1e8;  /* text on green */
  --accent-haze:   #e8efe9;  /* tinted hover surface */

  --danger:       #9a2828;
  --focus:        #c98a2b;   /* warm gold focus ring — visible on green & paper */

  --radius:    10px;
  --radius-sm: 7px;
  --shadow:    0 1px 2px rgba(28, 33, 30, 0.05), 0 8px 24px -16px rgba(28, 33, 30, 0.25);

  --maxw: 66rem;
}

/* ── Reset-ish ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ── Typography ────────────────────────────────────────────────────── */
h1, h2, h3 {
  font-family: "Fraunces", Georgia, "Times New Roman", serif;
  font-weight: 560;
  line-height: 1.15;
  color: var(--ink);
  letter-spacing: -0.01em;
  margin: 0 0 0.6rem;
}
h1 { font-size: clamp(1.9rem, 1.3rem + 2vw, 2.6rem); }
h2 {
  font-size: 1.3rem;
  margin-top: 2.2rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--line);
}
h2 small { font-family: "IBM Plex Sans", sans-serif; font-size: 0.78rem; font-weight: 400; color: var(--ink-soft); }
h3 { font-size: 1.05rem; }

p { margin: 0.5rem 0 1rem; }

a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  text-underline-offset: 3px;
}
a:hover { text-decoration: underline; }

/* ── Header / nav ──────────────────────────────────────────────────── */
nav[role="navigation"] {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding: 0.85rem clamp(1rem, 4vw, 2.5rem);
  background: var(--accent-strong);
  color: var(--accent-ink);
  box-shadow: 0 1px 0 rgba(0,0,0,0.15);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--accent-ink);
  font-family: "Fraunces", Georgia, serif;
  font-weight: 560;
  font-size: 1.18rem;
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; opacity: 0.92; }
.brand-mark {
  width: 1.05rem; height: 1.05rem;
  border-radius: 4px;
  background: linear-gradient(150deg, #e7c873, #1b4d3e 65%);
  border: 1px solid rgba(255,255,255,0.35);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.12);
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.nav-links a {
  color: var(--accent-ink);
  font-weight: 500;
  font-size: 0.93rem;
  padding: 0.35rem 0.7rem;
  border-radius: var(--radius-sm);
  opacity: 0.82;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.nav-links a:hover { opacity: 1; text-decoration: none; background: rgba(255,255,255,0.08); }
.nav-links a[aria-current="page"] {
  opacity: 1;
  background: rgba(255,255,255,0.12);
  box-shadow: inset 0 -2px 0 var(--focus);
}
.nav-links form { display: inline; margin: 0; }
.nav-links form button {
  background: transparent;
  color: var(--accent-ink);
  border: 1px solid rgba(255,255,255,0.35);
  font-size: 0.9rem;
  padding: 0.35rem 0.85rem;
  opacity: 0.9;
}
.nav-links form button:hover { background: rgba(255,255,255,0.12); transform: none; }

/* ── Layout ────────────────────────────────────────────────────────── */
main {
  flex: 1 0 auto;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(1.5rem, 1rem + 2vw, 3rem) clamp(1rem, 4vw, 2.5rem) 3rem;
  animation: rise 0.4s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.site-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  padding: 1.25rem;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.82rem;
}
.site-footer p { margin: 0; }

/* ── Forms ─────────────────────────────────────────────────────────── */
form > div { margin-bottom: 1.05rem; max-width: 30rem; }

label {
  display: block;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--ink);
  margin-bottom: 0.3rem;
}

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="file"], input:not([type]),
select, textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:hover, select:hover, textarea:hover { border-color: var(--ink-soft); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-haze);
}
textarea { min-height: 4.5rem; resize: vertical; }
input[type="file"] { padding: 0.45rem; background: var(--surface-sunk); cursor: pointer; }

.error { display: block; color: var(--danger); font-size: 0.85rem; margin-top: 0.3rem; }

/* ── Buttons ───────────────────────────────────────────────────────── */
button {
  font: inherit;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.55rem 1.1rem;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.08s ease, box-shadow 0.15s ease;
}
button:hover { background: var(--accent-strong); border-color: var(--accent-strong); transform: translateY(-1px); }
button:active { transform: translateY(0); }

/* Destructive actions (the only buttons carrying a JS confirm) read as danger. */
button[onclick] {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, var(--line-strong));
}
button[onclick]:hover { background: color-mix(in srgb, var(--danger) 8%, transparent); border-color: var(--danger); transform: none; }

/* ── Tables ────────────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  font-variant-numeric: tabular-nums;
  margin: 0.5rem 0 1.25rem;
}
thead th {
  background: var(--surface-sunk);
  text-align: left;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--line);
}
tbody td { padding: 0.7rem 0.85rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.12s ease; }
tbody tr:hover { background: var(--accent-haze); }

tr.uncategorized { background: #fcf8e8; }
tr.low-confidence { background: #fdf6ec; }
tr.uncategorized:hover, tr.low-confidence:hover { background: #f6efdc; }

/* table cells holding their own forms/controls shouldn't stack-space */
td form { display: inline; margin: 0; }
td form button, td > a { font-size: 0.88rem; }
td button { padding: 0.35rem 0.7rem; }

/* ── Definition list (receipt detail) ──────────────────────────────── */
dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.5rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.3rem;
  box-shadow: var(--shadow);
  margin: 0.5rem 0 1.25rem;
}
dt { font-size: 0.85rem; color: var(--ink-soft); font-weight: 500; }
dd { margin: 0; font-variant-numeric: tabular-nums; }

/* ── Lists (audit trail, company selector) ─────────────────────────── */
main ul { padding-left: 1.1rem; }
main ul li { margin: 0.3rem 0; }
.company-list, ul.bare { list-style: none; padding: 0; }

/* ── Flash messages ────────────────────────────────────────────────── */
[role="status"] { margin-bottom: 1.25rem; }
.flash {
  padding: 0.7rem 0.95rem;
  margin: 0.5rem 0;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  border-left-width: 4px;
  font-size: 0.93rem;
}
.flash-error   { background: #fdece9; border-color: #d9534f; color: #7a1f1c; }
.flash-success { background: #e7f4ec; border-color: #2a8a4a; color: #1c5733; }
.flash-info    { background: var(--accent-haze); border-color: var(--accent); color: var(--accent-strong); }
.flash-warning { background: #fbf2e3; border-color: #b9772a; color: #5e3a12; }

.alert-warning {
  padding: 0.9rem 1.1rem;
  margin: 1rem 0 1.25rem;
  background: #fbf2e3;
  border: 1px solid #d9b676;
  border-left: 4px solid #b9772a;
  border-radius: var(--radius-sm);
  color: #5e3a12;
}
.alert-warning button { margin-left: 0.5rem; padding: 0.3rem 0.8rem; font-size: 0.88rem; }

/* ── Badges (states; icon/text + aria-label, never color-only) ─────── */
.badge {
  display: inline-block;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  border: 1px solid currentColor;
  white-space: nowrap;
}
.badge-low-confidence { color: #7a3d00; background: #fff4e5; }  /* 7.7:1 — WCAG AA */
.badge-duplicate      { color: #8a1a1a; background: #fdecea; }
.badge-uncategorized  { color: #5a4a00; background: #fdfae5; }

/* ── Page meta line (count / subtitle beneath h1) ─────────────────── */
.page-meta {
  color: var(--ink-soft);
  font-size: 0.9rem;
  margin: -0.1rem 0 0.75rem;
}

/* ── Queue filter tabs ─────────────────────────────────────────────── */
.queue-filters {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin: 1rem 0 1.25rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.6rem;
}
.queue-filters a {
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  color: var(--ink-soft);
  font-weight: 500;
  font-size: 0.92rem;
}
.queue-filters a:hover { background: var(--surface-sunk); text-decoration: none; }
.queue-filters a[aria-current="page"] {
  background: var(--accent);
  color: var(--accent-ink);
}

/* ── Decision actions (receipt detail) ─────────────────────────────── */
.receipt-actions {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  flex-wrap: wrap;
  padding: 1.1rem 1.3rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.receipt-actions form { margin: 0; }
.receipt-actions textarea { display: block; min-width: 18rem; margin: 0.3rem 0 0.6rem; }

/* ── Empty states ──────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}
.empty-state a { font-weight: 600; }

/* ── Upload drop zone (progressive enhancement only) ───────────────── */
.dropzone {
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 1.75rem;
  margin: 0.5rem 0;
  background: var(--surface-sunk);
  color: var(--ink-soft);
  text-align: center;
}
.dropzone.dragover { border-color: var(--accent); background: var(--accent-haze); color: var(--accent-strong); }

/* ── Accessibility helpers ─────────────────────────────────────────── */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 100;
}
.skip-link:focus { left: 0; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Always-visible keyboard focus ring (WCAG 2.4.7). */
a:focus-visible, button:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}

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