/*
 * Sand + Fog approval app.
 *
 * Plain CSS, no build step (importmap app). Palette, type, and spacing
 * choices are explained in docs/design.md. Organized top to bottom:
 * tokens, reset, layout, nav, typography, forms, buttons, queue cards,
 * status, tables, flash/errors, utilities.
 */

/* ---------- Tokens ---------- */

:root {
  --ink: #1a1a1a;
  --ink-muted: #605e5a;
  --maroon: #652c2c;
  --maroon-dark: #4a2020;
  --forest: #354d39;
  --sand: #d0c9b7;
  --sand-deep: #c0906b;
  --stone: #c9c5bf;
  --paper: #f9f9f9;
  --white: #ffffff;
  --danger: #8b2e2e;
  --danger-dark: #6e2323;

  --font-display: Georgia, "Times New Roman", serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
  --space-6: 48px;

  --radius: 4px;
  --border: 1px solid var(--stone);
}

/* ---------- Reset ---------- */

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

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

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
}

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

a { color: var(--maroon); }
a:hover { color: var(--maroon-dark); }

:focus-visible {
  outline: 3px solid var(--sand-deep);
  outline-offset: 2px;
}

/* ---------- Layout ---------- */

.page {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-4) var(--space-6);
}

.page > .flash:first-child {
  margin-top: 0;
}

/* ---------- Nav ---------- */

.site-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-2) var(--space-4);
  background: var(--white);
  border-bottom: var(--border);
  margin-bottom: var(--space-4);
}

.brand-mark {
  font-family: var(--font-display);
  font-size: 1.25rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
  margin-right: auto;
}

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

.site-nav__links {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.site-nav a.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  text-decoration: none;
  padding: var(--space-1) 0;
  border-bottom: 2px solid transparent;
}

.site-nav a.nav-link:hover,
.site-nav a.nav-link[aria-current="page"] {
  color: var(--ink);
  border-bottom-color: var(--maroon);
}

.site-nav form { margin: 0; }

.site-nav .button--quiet {
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ---------- Typography ---------- */

h1 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  margin: 0 0 var(--space-4);
}

h2 {
  font-size: 1.15rem;
  margin: 0 0 var(--space-2);
}

h3 {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 var(--space-1);
}

p { margin: 0 0 var(--space-2); }

.lede {
  color: var(--ink-muted);
  max-width: 48ch;
}

/* ---------- Buttons ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 600;
  padding: var(--space-2) var(--space-4);
  min-height: 44px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
}

.button--primary {
  background: var(--maroon);
  color: var(--white);
}
.button--primary:hover { background: var(--maroon-dark); }

.button--secondary {
  background: var(--white);
  color: var(--ink);
  border-color: var(--stone);
}
.button--secondary:hover { border-color: var(--ink-muted); }

.button--danger {
  background: var(--white);
  color: var(--danger);
  border-color: var(--danger);
}
.button--danger:hover { background: var(--danger); color: var(--white); }

.button--quiet {
  background: transparent;
  color: var(--ink-muted);
  border-color: var(--stone);
  min-height: 44px;
  padding: var(--space-1) var(--space-3);
}
.button--quiet:hover { color: var(--ink); border-color: var(--ink-muted); }

/* A smaller footprint for actions that repeat on every queue card -- still
   >=44px tall for a tappable target at 375 (#50 finding 1 requirement). */
.button--compact {
  padding: var(--space-1) var(--space-3);
  font-size: 0.85rem;
  min-height: 44px;
}

.button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Forms ---------- */

.form {
  max-width: 420px;
}

.field {
  margin-bottom: var(--space-3);
}

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--ink-muted);
  margin-bottom: var(--space-1);
}

.field input[type="text"],
.field input[type="email"],
.field input[type="password"] {
  width: 100%;
  font-family: var(--font-ui);
  font-size: 1rem;
  padding: var(--space-2) var(--space-2);
  min-height: 44px;
  border: 1px solid var(--stone);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink);
}

.field input:focus-visible { outline-offset: 0; }

.form-card {
  background: var(--white);
  border: var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
}

.form-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  margin-top: var(--space-4);
}

.form-note {
  margin-top: var(--space-3);
  font-size: 0.9rem;
}

/* Field-level and form-level errors (markup is ready even where the
   controller does not currently populate errors; see docs/design.md). */
.error-summary {
  background: #fcebea;
  border: 1px solid var(--danger);
  color: var(--danger-dark);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
}

.error-summary h2 {
  font-size: 0.9rem;
  margin-bottom: var(--space-1);
}

.field-error {
  color: var(--danger-dark);
  font-size: 0.85rem;
  margin-top: var(--space-1);
}

.field--invalid input {
  border-color: var(--danger);
}

/* ---------- Flash ---------- */

.flash {
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-4);
  font-size: 0.95rem;
}

.flash--notice {
  background: #eaf1ea;
  border: 1px solid var(--forest);
  color: var(--forest);
}

.flash--alert {
  background: #fcebea;
  border: 1px solid var(--danger);
  color: var(--danger-dark);
}

/* ---------- Queue ---------- */

.queue-card {
  background: var(--white);
  border: var(--border);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-4);
  margin-bottom: var(--space-2);
}

/* Record type + status on the left, the three actions on the right, on one
   line -- so Approve is visible the moment the card is (#50 finding 1). */
.queue-card__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
}

.queue-card__title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.queue-card__title h2 { margin: 0; font-size: 1.05rem; }

.queue-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.queue-card__actions form { margin: 0; }

.queue-card__summary {
  font-weight: 600;
  margin: 0 0 var(--space-1);
}

.queue-card__email {
  margin: 0 0 var(--space-1);
  font-size: 0.9rem;
}

.queue-card__meta {
  margin: 0 0 var(--space-1);
  font-size: 0.95rem;
}

.queue-card__meta strong {
  color: var(--ink-muted);
  font-weight: 600;
  margin-right: var(--space-1);
}

.queue-card__email-meta {
  color: var(--ink-muted);
  margin-left: var(--space-1);
}

.queue-card__attachments {
  list-style: none;
  padding: 0;
  margin: var(--space-1) 0 0;
}

.queue-card__decided {
  color: var(--ink-muted);
  font-size: 0.9rem;
  margin: var(--space-2) 0 0;
}

/* Approved but going nowhere until an admin turns its category's switch
   on (#58) -- muted, not an error, but visibly different from a plain
   "decided" line. */
.queue-card__decided.execution-off {
  color: var(--danger-dark);
}

/* ---------- Status ---------- */

.status {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: var(--space-1) var(--space-2);
  border-radius: 999px;
  background: var(--sand);
  color: var(--ink);
}

.status--proposed { background: var(--sand); color: var(--ink); }
.status--approved,
.status--edited,
.status--written { background: #e4ece4; color: var(--forest); }
.status--declined,
.status--failed { background: #f5e3e1; color: var(--danger-dark); }

/* ---------- Empty state ---------- */

.empty-state {
  background: var(--white);
  border: 1px dashed var(--stone);
  border-radius: var(--radius);
  padding: var(--space-5);
  text-align: center;
  color: var(--ink-muted);
}

.empty-state p { margin: 0; }

/* ---------- Decision log: a list, not a grid (#50 finding 3) ---------- */

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

.decision-row {
  background: var(--white);
  border: var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
}

.decision-row__subject {
  margin: 0 0 var(--space-1);
  font-size: 1.05rem;
}

.decision-row__subject a { text-decoration: none; }
.decision-row__subject a:hover { text-decoration: underline; }

.decision-row__meta {
  margin: 0 0 var(--space-2);
  font-size: 0.85rem;
  color: var(--ink-muted);
}

.decision-row__outcome {
  margin: 0 0 var(--space-1);
  font-weight: 600;
}

.decision-row__summary {
  margin: 0;
  color: var(--ink-muted);
}

.filter-tabs {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

.filter-tabs a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--ink-muted);
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--stone);
  border-radius: 999px;
}

.filter-tabs a:hover,
.filter-tabs a[aria-current="page"] {
  color: var(--white);
  background: var(--maroon);
  border-color: var(--maroon);
}

/* ---------- Write detail page (#53) ---------- */

.write-detail__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.write-detail__title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.write-detail__title h1 { margin: 0; }

.write-detail__columns {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-5);
  margin-top: var(--space-4);
}

.write-detail__col {
  /* A grid track's implicit min-width is the content's max-content size,
     which lets a wide table blow out the grid instead of scrolling inside
     its own .table-wrap. min-width: 0 lets the column shrink to the track
     and overflow-x: auto do its job. */
  min-width: 0;
}

.write-detail__block {
  margin-bottom: var(--space-4);
}

.write-detail__email-body {
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: var(--border);
  color: var(--ink-muted);
  font-size: 0.95rem;
}

.write-detail__write h3 {
  margin-top: var(--space-4);
}

.write-detail__write h3:first-of-type {
  margin-top: 0;
}

.write-detail__read-error {
  color: var(--danger-dark);
  font-size: 0.9rem;
  margin-top: var(--space-2);
}

@media (min-width: 1024px) {
  .write-detail__columns {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

/* ---------- Field tables (#53) -- plain: thin rules, left-aligned,
   monospace for codes, nothing collapsible, nothing animated. ---------- */

.table-wrap {
  overflow-x: auto;
  background: var(--white);
  border: var(--border);
  border-radius: var(--radius);
  margin-bottom: var(--space-3);
}

.field-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.field-table th,
.field-table td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--border);
  vertical-align: top;
}

.field-table th {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  background: var(--paper);
  white-space: nowrap;
}

.field-table tbody tr:last-child td { border-bottom: none; }

.field-table code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
}

.field-table td.value--changed del {
  color: var(--ink-muted);
  text-decoration-color: var(--danger);
}

.value--unset {
  color: var(--ink-muted);
}

/* ---------- Inline editing (#56) ---------- */

/* Looks like plain text until hovered or focused -- a transparent border
   reserves the space so focusing/hovering doesn't shift the row. */
.proposed-input {
  width: 100%;
  min-width: 8ch;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: var(--space-1) var(--space-2);
  margin: calc(var(--space-1) * -1) calc(var(--space-2) * -1);
}

.proposed-input:hover {
  border-color: var(--stone);
}

.proposed-input:focus-visible {
  border-color: var(--maroon);
  background: var(--white);
  outline: none;
}

select.proposed-input {
  cursor: pointer;
}

input.proposed-input[type="number"] {
  width: 10ch;
}

input.proposed-input[type="date"] {
  width: 16ch;
}

.agent-value-note {
  margin: var(--space-1) 0 0;
  font-size: 0.78rem;
  color: var(--ink-muted);
  font-style: italic;
}

.write-detail__write .form-actions {
  margin-top: var(--space-4);
}

/* Sticky "you have unsaved changes" bar -- JS-enhanced only (#56); without
   JavaScript the under-table Save button is the only way to save, and it
   always works. */
.unsaved-bar {
  position: sticky;
  bottom: var(--space-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--ink);
  color: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.unsaved-bar__actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* .unsaved-bar's own display: flex has the same specificity as the
   browser's [hidden] { display: none } default and comes later, so it
   would win and show the bar even while hidden is set -- this explicit
   [hidden] rule (higher specificity) keeps hidden actually meaning hidden. */
.unsaved-bar[hidden] {
  display: none;
}

/* ---------- Footer: Acumatica status ---------- */

.site-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-4) var(--space-5);
  border-top: var(--border);
}

.site-footer__status {
  font-size: 0.8rem;
  color: var(--ink-muted);
}

/* ---------- Auth pages ---------- */

.auth-page {
  display: flex;
  justify-content: center;
  padding-top: var(--space-6);
}

.auth-page .form-card {
  width: 100%;
  max-width: 380px;
}

.auth-page .brand-mark {
  display: block;
  text-align: center;
  margin: 0 0 var(--space-5);
}

/* ---------- Digest (#14) ---------- */

.digest-stats {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin: var(--space-4) 0;
}

.digest-stats__item {
  background: var(--white);
  border: var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  min-width: 10rem;
}

.digest-stats__item dt {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  margin: 0 0 var(--space-1);
}

.digest-stats__item dd {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--ink);
}

/* ---------- Responsive ---------- */

@media (max-width: 480px) {
  .page { padding: 0 var(--space-3) var(--space-5); }
  .site-nav { padding: var(--space-2) var(--space-3); }
  .queue-card { padding: var(--space-3); }
  .queue-card__actions { width: 100%; }
  .queue-card__actions .button { flex: 1 1 auto; }
  h1 { font-size: 1.4rem; }
}
