/* ==========================================================================
   MetroFood OS — Components
   Buttons, stat cards, tables, badges, empty states, modals, forms, toasts.
   ========================================================================== */

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-family: 'Instrument Sans', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .14s;
  letter-spacing: .02em;
  white-space: nowrap;
}
.btn-primary { background: var(--g); color: white; }
.btn-primary:hover { background: var(--gm); }
.btn-gold { background: var(--gold); color: white; }
.btn-gold:hover { background: var(--gold2); }
.btn-ghost { background: white; color: var(--ink2); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--g); color: var(--g); }
.btn-danger { background: var(--red); color: white; }
.btn-sm { padding: 6px 13px; font-size: 12px; }
.btn-xs { padding: 4px 9px; font-size: 11px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── STAT CARDS ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}

/* ── Period toggle (dashboard + AP stat cards) ──────────────────────────
   Two-level pill selector: primary row (All/Month/Week/Today) always visible;
   secondary row (Calendar/Rolling) appears only when Month or Week is active. */
.period-toggle {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.period-toggle:empty {
  display: none;
}
.period-pills-row {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  align-items: center;
}
.period-pills-row .period-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  padding: 0 6px 0 0;
}
.period-pill {
  background: white;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 14px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  transition: all .12s;
  white-space: nowrap;
}
.period-pill:hover {
  border-color: var(--g);
  color: var(--g);
}
.period-pill.active {
  background: #1B5E3511;
  border-color: #1B5E35;
  color: #1B5E35;
  box-shadow: 0 0 0 3px rgba(27,94,53,.08);
}
.period-pill.period-sub {
  padding: 3px 10px;
  font-size: 10px;
  font-weight: 500;
}
.period-pill.period-sub.active {
  background: var(--goldl);
  border-color: var(--gold2);
  color: var(--gold2);
  box-shadow: 0 0 0 3px rgba(201,168,76,.18);
}

/* ── Catch-weight columns (OCR review table) ───────────────────────────
   Weight + $/Weight columns stay hidden on pure grocery invoices so the
   table isn't cluttered. The moment addLineItem() detects a row with
   totalWeight or pricePerWeight populated, it adds `.show-weight` to the
   table root which unhides both columns in one pass. */
.line-items-table .weight-col { display: none; }
.line-items-table.show-weight .weight-col { display: table-cell; }
.stat-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--g);
}
.stat-card.gold::before { background: var(--gold); }
.stat-card.red::before { background: var(--red); }
.stat-card.blue::before { background: var(--blue); }
.stat-label { font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: 7px; }
.stat-val { font-family: 'DM Serif Display', serif; font-size: 28px; color: var(--g3); line-height: 1; }
.stat-val.mono { font-family: 'DM Mono', monospace; font-size: 22px; }
.stat-sub { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ── TABLES ── */
.table-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.table-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--borderl);
  flex-wrap: wrap;
}
.table-toolbar-title {
  font-family: 'DM Serif Display', serif;
  font-size: 17px;
  color: var(--g3);
  margin-right: 4px;
}
.toolbar-spacer { flex: 1; }
.search-box {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-family: 'Instrument Sans', sans-serif;
  font-size: 13px;
  color: var(--ink2);
}
.search-box input {
  border: none;
  background: none;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  outline: none;
  width: 190px;
}
.search-box input::placeholder { color: var(--muted); }
select.filter {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-family: 'Instrument Sans', sans-serif;
  font-size: 13px;
  color: var(--ink2);
  background: white;
  cursor: pointer;
  outline: none;
}
table { width: 100%; border-collapse: collapse; }
thead { background: var(--g); }
th {
  padding: 11px 14px;
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: rgba(255,255,255,.8);
  white-space: nowrap;
}
/* Light-themed table headers — when a developer overrides the thead/tr
   background to var(--cream) or white inline (Re-extract diff, Pay Multiple,
   Invoice viewer payments table, etc.), the global th { color: white }
   rule above used to win on specificity, producing white text on cream
   background. These selectors restore dark text in those cases.
   Specificity: tr/thead with inline style + th tag descendant > plain th. */
thead[style*="--cream"] th,
thead[style*="cream"] th,
thead[style*="background:#fff"] th,
thead[style*="background:white"] th,
thead tr[style*="--cream"] th,
thead tr[style*="cream"] th,
thead tr[style*="background:#fff"] th,
thead tr[style*="background:white"] th,
table tr[style*="--cream"] th,
table tr[style*="cream"] th {
  color: var(--ink);
}
td {
  padding: 12px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--borderl);
  vertical-align: middle;
  color: var(--ink2);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gll); }
.mono-cell { font-family: 'DM Mono', monospace; font-size: 12px; }
.bold-cell { font-weight: 600; color: var(--ink); }

/* ── BADGES ── */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-pending { background: var(--amberl); color: var(--amber); }
.badge-approved { background: var(--gl); color: var(--g2); }
.badge-paid { background: #e8f5e9; color: #2e7d32; }
.badge-overdue { background: var(--redl); color: var(--red); }
.badge-needs-review { background: #fef3c7; color: #b45309; border: 1px solid #fcd34d; }
.badge-new { background: var(--bluel); color: var(--blue); }
.badge-matched { background: var(--gl); color: var(--g2); }
.badge-flagged { background: var(--redl); color: var(--red); }

/* ── EMPTY STATE ── */
.empty {
  text-align: center;
  padding: 52px 20px;
  color: var(--muted);
}
.empty-icon { font-size: 44px; margin-bottom: 12px; opacity: .5; }
.empty-text { font-size: 15px; font-weight: 600; color: var(--ink2); }
.empty-sub { font-size: 13px; margin-top: 5px; }

/* ── MODAL ── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,58,31,.6);
  backdrop-filter: blur(2px);
  z-index: 900;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.overlay.open { display: flex; }
.modal {
  background: white;
  border-radius: 14px;
  padding: 30px 32px;
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  position: relative;
}
.modal-wide { max-width: 860px; }
.modal-xl { max-width: 1050px; }

/* ── SKU edit modal — premium layout ─────────────────────────────────────
   Replaces the flat form-grid look with sectioned cards. The hero uses
   the brand green gradient so it reads as a "product detail" panel
   instead of a generic dialog. Sections are subtly elevated (cream bg,
   thin border, 14px radius) to separate Identity / Classification /
   Pricing / Inventory.
   ===================================================================== */
.sku-modal {
  padding: 0;            /* hero handles top padding */
  background: #fbfaf6;   /* warmer than pure white — feels editorial */
  /* Inherits overflow-y:auto + max-height:90vh from .modal so the form
     can scroll. Don't set overflow:hidden here — that breaks scrolling.
     The hero clips its own corners via border-radius below. */
}
.sku-modal .modal-close {
  top: 14px; right: 16px;
  color: rgba(255,255,255,.85);
  background: rgba(255,255,255,.08);
  font-size: 20px;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
}
.sku-modal .modal-close:hover { background: rgba(255,255,255,.18); color: white; }
.sku-modal-hero {
  background: linear-gradient(135deg, var(--g3) 0%, var(--g) 100%);
  padding: 22px 32px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 0 0 20px;
  /* Match the parent modal's top corners so the gradient doesn't bleed
     past the rounded edge (replaces the old overflow:hidden trick). */
  border-radius: 14px 14px 0 0;
  /* Sticky header — stays visible while user scrolls through the form
     sections below. Useful since the modal can be 600+ px tall. */
  position: sticky;
  top: 0;
  z-index: 5;
}
.sku-modal-hero-icon {
  font-size: 32px;
  width: 52px; height: 52px;
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sku-modal-section {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px 14px;
  margin: 0 32px 14px;
  box-shadow: 0 1px 2px rgba(15,58,31,.04);
}
.sku-modal-section-title {
  font-family: 'DM Serif Display', serif;
  font-size: 15px;
  color: var(--g3);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--borderl);
  letter-spacing: 0.01em;
}
/* Pricing section gets a subtle tinted background to draw the eye */
.sku-modal-section.sku-modal-pricing {
  background: linear-gradient(180deg, #fffef9 0%, white 60%);
  border-color: var(--gold);
  border-width: 1px;
  box-shadow: 0 1px 4px rgba(201,168,76,.10);
}
.sku-modal-section.sku-modal-pricing .sku-modal-section-title {
  color: var(--gold2);
  border-bottom-color: rgba(201,168,76,.25);
}
/* Footer stays inside the modal but outside the section cards */
.sku-modal .modal-footer {
  margin: 18px 32px 24px;
  padding-top: 14px;
  border-top: 1px solid var(--borderl);
}
/* Tighten form-grid label sizing inside the new sections */
.sku-modal-section .lbl {
  font-size: 9.5px;
  letter-spacing: 0.09em;
}
.sku-modal-section .form-grid {
  gap: 10px 14px;
}
.modal-close {
  position: absolute;
  top: 16px; right: 18px;
  background: none;
  border: none;
  font-size: 22px;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}
.modal-close:hover { background: var(--borderl); color: var(--ink); }
.modal-title {
  font-family: 'DM Serif Display', serif;
  font-size: 22px;
  color: var(--g3);
  margin-bottom: 6px;
}
.modal-sub { font-size: 13px; color: var(--muted); margin-bottom: 22px; }
.modal-divider { height: 1px; background: var(--borderl); margin: 18px 0; }
.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding-top: 18px;
  border-top: 1px solid var(--borderl);
  margin-top: 20px;
}

/* ── FORM ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.fg { display: flex; flex-direction: column; gap: 5px; }
.fg.full { grid-column: 1/-1; }
.fg.span2 { grid-column: span 2; }
label.lbl {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}
label.lbl .req { color: var(--red); margin-left: 2px; }
input.inp, select.inp, textarea.inp {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Instrument Sans', sans-serif;
  font-size: 13px;
  color: var(--ink);
  background: var(--cream);
  transition: border .14s, background .14s;
  outline: none;
}
input.inp:focus, select.inp:focus, textarea.inp:focus {
  border-color: var(--g);
  background: white;
  box-shadow: 0 0 0 3px rgba(27,94,53,.08);
}
textarea.inp { resize: vertical; min-height: 72px; }
input.inp.mono { font-family: 'DM Mono', monospace; }

/* ── TOAST ── */
.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--g3);
  color: white;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn .2s ease;
  max-width: 340px;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--g); border-left: 3px solid var(--gold); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:.4; } }
