/* ============================================================
   STICKY BOOKS — COMPONENT STYLES
   Loads after tokens.css. Every rule reads SEMANTIC tokens only.
   ============================================================ */

/* ---------- Page shell ----------
   Scoped wrapper (not `body`) so the brand system can be dropped
   onto the public landing page without reskinning the rest of the
   app, which still runs on the plain Tailwind look. */
.sb-page {
  background: var(--bg-page);
  color: var(--text-body);
  font-family: var(--font-body);
  min-height: 100vh;
}

/* ---------- Headings ----------
   Applied globally (not just on .sb-page) so every h1-h6 picks up the
   display face, including pages that haven't adopted the rest of the
   brand system yet — inline font-family styles on individual headings
   still win where they're set, this is just the fallback. */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
}

/* ---------- Button ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-body);
  font-weight: var(--weight-bold);
  font-size: var(--text-base);
  line-height: 1;
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-pill);
  border: var(--border-width) solid var(--action-border);
  background: var(--action-bg);
  color: var(--text-on-honey);
  box-shadow: var(--action-shadow);
  text-decoration: none;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
}
.btn:hover  { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--border-ink); }
.btn:active { transform: translate(2px, 2px);  box-shadow: 2px 2px 0 var(--border-ink); }
.btn:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 3px; }
.btn--ghost { background: transparent; box-shadow: none; }

/* ---------- Card ---------- */
.card {
  background: var(--bg-surface);
  border: var(--border-width) solid var(--border-ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sticker);
  padding: var(--space-6);
  /* Grid/flex items default to min-width: auto, which refuses to shrink
     below an unbreakable child's full width (e.g. a long .numeric value)
     and lets it overflow into the next cell instead of wrapping. */
  min-width: 0;
}
.card--honey { background: var(--bg-highlight); }
.card--grape { background: var(--bg-accent); color: var(--text-on-accent); }
.card__header { margin-bottom: var(--space-4); }
.card--grape .card__body { color: color-mix(in srgb, var(--cream) 88%, transparent); }

/* ---------- Status pill ---------- */
.status-pill {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  border: 2px solid var(--border-ink);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.status-pill[data-state="open"]  { background: var(--status-open);  color: var(--status-open-text); }
.status-pill[data-state="cured"] { background: var(--status-cured); color: var(--status-cured-text); }
.status-pill[data-state="empty"] { background: var(--status-empty); color: var(--status-empty-text); }

/* ---------- Order card ---------- */
.order-card__top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-3);
}
.order-card__po { font-size: var(--text-sm); color: var(--grape); }
.order-card__title {
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  font-size: var(--text-lg);
}
.order-card__vendor { font-size: var(--text-sm); color: var(--text-muted); }
.order-card__lines { list-style: none; margin: var(--space-4) 0 0; padding: 0; }
.order-card__line {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: var(--text-sm);
  padding: var(--space-2) 0;
  border-top: 1.5px solid var(--hairline);
}
.order-card__line-row { display: flex; justify-content: space-between; }
.order-card__line-detail { font-size: var(--text-xs); color: var(--text-muted); }
.order-card__sku { font-size: var(--text-xs); color: var(--text-muted); }
.order-card__total {
  display: flex;
  justify-content: space-between;
  margin-top: var(--space-3);
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  font-size: var(--text-lg);
}

/* ---------- Data rule ---------- */
.numeric { font-family: var(--font-mono); font-weight: var(--weight-bold); overflow-wrap: anywhere; }

/* ---------- Flag row (inventory urgency, e.g. days-on-hand running low) --- */
.flag-row[data-flag="critical"] { background: var(--flag-critical); color: var(--flag-critical-text); }
.flag-row[data-flag="warning"]  { background: var(--flag-warning);  color: var(--flag-warning-text); }

/* ---------- Filter field (dashboard-style select/label pairs) ---------- */
.field label {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}
.field select {
  width: 100%;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-3);
  border: var(--border-width) solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-body);
}
.field select:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; border-color: var(--border-ink); }

/* ---------- Checkbox dropdown (multi-select filters, e.g. dashboard) ---------- */
.checkbox-dropdown { position: relative; }
.checkbox-dropdown__trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-3);
  border: var(--border-width) solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-body);
  cursor: pointer;
}
.checkbox-dropdown__trigger:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; border-color: var(--border-ink); }
/* Long joined selections (e.g. two location names) truncate with an
   ellipsis instead of wrapping -- wrapping would make this trigger taller
   than its sibling fields and break the filter bar's row alignment. */
.checkbox-dropdown__trigger-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.checkbox-dropdown__panel {
  position: absolute;
  top: calc(100% + var(--space-1));
  left: 0;
  right: 0;
  z-index: 20;
  max-height: 14rem;
  overflow-y: auto;
  background: var(--bg-surface);
  border: var(--border-width) solid var(--border-ink);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sticker);
  padding: var(--space-2);
}
.checkbox-dropdown__option {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-sm);
  border-radius: var(--radius-md);
  cursor: pointer;
}
.checkbox-dropdown__option:hover { background: var(--cream); }

/* ---------- Text input (auth/marketing forms) ---------- */
.text-field-label {
  display: block;
  font-weight: var(--weight-bold);
  font-size: var(--text-sm);
  margin-bottom: var(--space-1);
}
.text-field {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: var(--border-width) solid var(--border-ink);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-body);
  font-family: var(--font-body);
  font-size: var(--text-sm);
}
.text-field:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 1px; }

/* ---------- Data table ---------- */
.data-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.data-table th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: var(--space-2) var(--space-4);
  border-bottom: var(--border-width) solid var(--border-ink);
  /* Sticky header for long tables -- needs its own opaque background or
     scrolled rows show through underneath it. */
  position: sticky;
  top: 0;
  background: var(--bg-surface);
}
/* nowrap overrides .numeric's own overflow-wrap: anywhere (above) for table
   cells specifically -- a numeric value or header label breaking
   mid-character (e.g. "$28.00" splitting to "$28." / "00") once a column
   gets tight is worse than the column (or its .overflow-x-auto wrapper)
   running a little wide. */
.data-table th.numeric, .data-table td.numeric { text-align: right; white-space: nowrap; }
.data-table td { padding: var(--space-2) var(--space-4); border-bottom: 1px solid var(--hairline); }
.data-table tbody:last-of-type tr:last-child td { border-bottom: none; }
/* Column grid lines -- the main cue that reads "spreadsheet" rather than
   "card list". Right border on every cell, dropped on the last column so
   the table doesn't get a stray line against its own edge. */
.data-table th, .data-table td { border-right: 1px solid var(--hairline); }
.data-table th:last-child, .data-table td:last-child { border-right: none; }

/* ---------- Spreadsheet chrome: row numbers, column letters, formula bar ----------
   Opt-in on top of .data-table (add .sheet) for the one table per page that's
   meant to read as the primary spreadsheet, not every .data-table -- the
   Dashboard's action-items table, for instance, stays plain. */
.formula-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: var(--border-width) solid var(--border-ink);
  border-bottom: none;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: var(--bg-surface);
}
.formula-bar .fx {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-style: italic;
  font-weight: var(--weight-bold);
  color: var(--grape);
}
.formula-bar .formula-text { font-size: var(--text-sm); color: var(--text-muted); }

/* table-layout: fixed + the <colgroup> in _product_form.html.erb -- auto
   layout falls apart once rows disagree on colspan (the main row's 8 plain
   cells vs. the preference sub-lines' colspan="3" product picker vs. the
   note row's colspan="6"): browsers' column-width algorithm gets unreliable
   across mismatched colspans with no explicit widths, producing collapsed/
   near-zero columns and digit-by-digit wrapping in whichever cell loses the
   fight. Fixed layout makes every row -- any colspan, any tbody -- resolve
   against the same 8 explicit column tracks instead. */
.data-table.sheet { border: var(--border-width) solid var(--border-ink); border-collapse: separate; border-spacing: 0; table-layout: fixed; }
.data-table.sheet .col-letters th {
  /* Overrides .data-table th's sticky/background -- only one header row
     should stick while scrolling, and it's the labels below this one. */
  position: static;
  background: var(--hairline);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: var(--weight-regular);
  text-transform: none;
  letter-spacing: normal;
  text-align: center;
  padding: 2px var(--space-2);
  border-bottom: 1px solid var(--border-ink);
}
.data-table.sheet .col-labels th {
  background: var(--bg-highlight);
  padding: var(--space-1) var(--space-3);
}
.data-table.sheet .rownum {
  /* Width comes from the <colgroup> in _product_form.html.erb now that the
     table is table-layout: fixed -- a per-cell width here would be inert. */
  background: var(--hairline);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-align: center;
  user-select: none;
}
/* Same cell padding as a plain .data-table -- an earlier, tighter pass
   (space-1/space-3, 4px field padding) read as cramped once real content
   filled every row; the grid lines/mono header already carry the
   "spreadsheet" read without also pinching the padding. */
.data-table.sheet td { padding: var(--space-2) var(--space-4); }
.data-table.sheet select, .data-table.sheet input[type="number"], .data-table.sheet input[type="text"] {
  padding-top: var(--space-2);
  padding-bottom: var(--space-2);
}

/* ---------- Spec-row grouping ----------
   Each spec line is its own <tbody> (main row + its note/preference
   sub-rows -- see _product_form.html.erb). Thicken the border between
   tbody groups so a whole line item reads as one unit, and shade its
   own sub-rows so they read as nested under the main row above them
   rather than as a sibling line. */
.data-table.sheet tbody + tbody { border-top: 2px solid var(--border-ink); }
.data-table.sheet tr.sub-row td { background: var(--app-surface-hover); }

/* ---------- Primary button (authenticated-app raw-Tailwind buttons) ----------
   Covers the color handling only for the repeated "bg-gray-900 text-white
   hover:bg-gray-700" button pattern -- padding/radius/font-size/cursor
   stay plain Tailwind at each call site. Deliberately thin (no sticker
   border/shadow) -- that look is owned by Ui::ButtonComponent, not this. */
.btn-primary { background: var(--app-btn-primary-bg); color: var(--app-btn-primary-text); }
.btn-primary:hover { background: var(--app-btn-primary-bg-hover); }

/* ---------- Badge (authenticated-app status/response/payment/match pills) ----------
   See PurchaseOrdersHelper -- tone hashes feed data-tone here instead of
   returning raw Tailwind classes directly. */
.badge { display: inline-block; padding: 0.125rem 0.5rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 500; }
.badge[data-tone="gray"]   { background: var(--app-tone-gray-bg);   color: var(--app-tone-gray-text); }
.badge[data-tone="red"]    { background: var(--app-tone-red-bg);    color: var(--app-tone-red-text); }
.badge[data-tone="amber"]  { background: var(--app-tone-amber-bg);  color: var(--app-tone-amber-text); }
.badge[data-tone="green"]  { background: var(--app-tone-green-bg);  color: var(--app-tone-green-text); }
.badge[data-tone="blue"]   { background: var(--app-tone-blue-bg);   color: var(--app-tone-blue-text); }
.badge[data-tone="purple"] { background: var(--app-tone-purple-bg); color: var(--app-tone-purple-text); }
.badge[data-tone="indigo"] { background: var(--app-tone-indigo-bg); color: var(--app-tone-indigo-text); }
