/* ------------------------------------------------------------------ tokens */
:root {
  --paper: #EEF1EC;
  --surface: #FFFFFF;
  --surface-sunken: #F6F8F4;
  --ink: #12211C;
  --ink-soft: #3A4B44;
  --muted: #6C7A72;
  --line: #DBE1D8;
  --line-strong: #C0CABC;

  --emerald: #16624A;
  --emerald-soft: #2E8B69;
  --mint: #E2EFE8;
  --slate: #3E6E97;
  --mustard: #D99518;
  --clay: #B4503C;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(18, 33, 28, .05), 0 8px 24px -18px rgba(18, 33, 28, .35);

  --font-display: "Bricolage Grotesque", "Instrument Sans", system-ui, sans-serif;
  --font-body: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; line-height: 1.2; }
p { margin: 0; }
ul, ol, dl, dd { margin: 0; padding: 0; list-style: none; }

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--emerald);
  outline-offset: 2px;
  border-radius: 4px;
}

.shell {
  width: min(1280px, 100% - 40px);
  margin-inline: auto;
}

/* ------------------------------------------------------------------ topbar */
.topbar {
  background: var(--ink);
  color: #EDF2EE;
  padding: 18px 0;
  margin-bottom: 26px;
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 28px;
  flex-wrap: wrap;
}

.topbar-identity { display: flex; align-items: center; gap: 14px; margin-right: auto; }

.topbar-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(150deg, var(--emerald-soft), var(--mustard));
  flex: none;
}

.topbar h1 { font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.topbar p { font-size: 13px; color: #A9BBB1; }

.topbar-meta { display: flex; gap: 26px; flex-wrap: wrap; }
.topbar-meta dt {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: #8FA79A;
  margin-bottom: 2px;
}
.topbar-meta dd { font-family: var(--font-mono); font-size: 12.5px; color: #E4EDE7; }

.btn-print {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: #E4EDE7;
  background: transparent;
  border: 1px solid rgba(228, 237, 231, .35);
  border-radius: 999px;
  padding: 8px 18px;
  cursor: pointer;
}
.btn-print:hover { background: rgba(228, 237, 231, .12); }

/* -------------------------------------------------------------------- hero */
.hero {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 28px 20px;
  margin-bottom: 16px;
}

.hero-head {
  display: flex;
  gap: 36px;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--emerald);
  margin-bottom: 10px;
}

.hero h2 {
  font-size: clamp(21px, 2.4vw, 30px);
  font-weight: 600;
  max-width: 30ch;
  letter-spacing: -.015em;
  color: var(--ink-soft);
}
.hero h2 strong { color: var(--ink); font-weight: 800; }

.hero-note { margin-top: 12px; font-size: 13.5px; color: var(--muted); max-width: 52ch; }

/* ------------------------------------------------------------------ legend */
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; max-width: 340px; }
.legend li { display: flex; align-items: center; gap: 7px; font-size: 12.5px; }
.legend-chip { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-label { color: var(--ink-soft); }
.legend-value { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); }

.legend-stack { flex-direction: column; gap: 8px; max-width: none; }
.legend-stack li { justify-content: flex-start; }
.legend-stack .legend-value { margin-left: auto; }

/* ---------------------------------------------------- shelves (unit chart) */
.shelves { border-top: 1px solid var(--line); }

.shelf {
  display: grid;
  grid-template-columns: 158px minmax(0, 1fr) 116px;
  gap: 20px;
  align-items: center;
  padding: 13px 0 11px;
  border-bottom: 1px solid var(--line);
}

.shelf-label { display: flex; flex-direction: column; gap: 2px; }
.shelf-name {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.shelf-count { font-size: 11.5px; color: var(--muted); }

.shelf-units {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding-bottom: 9px;
  border-bottom: 2px solid var(--line-strong);
}

.unit {
  width: 15px;
  height: 23px;
  border-radius: 3px;
  background: var(--unit-color, var(--emerald));
  transition: transform .16s ease;
}
.unit:hover { transform: translateY(-4px); }

.shelf-payroll { text-align: right; display: flex; flex-direction: column; gap: 1px; }
.shelf-payroll-value { font-family: var(--font-mono); font-size: 13.5px; font-weight: 600; }
.shelf-payroll-caption { font-size: 10.5px; color: var(--muted); }

/* --------------------------------------------------------------- kpi cards */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  border-top: 3px solid var(--emerald);
  padding: 16px 18px 14px;
  box-shadow: var(--shadow);
}

.kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 9px;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 23px;
  font-weight: 600;
  letter-spacing: -.02em;
  line-height: 1.1;
}
.kpi-unit { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 5px; }
.kpi-caption { margin-top: 8px; font-size: 11.5px; color: var(--muted); }

/* ----------------------------------------------------------------- filters */
.filters {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.filter-form {
  display: grid;
  grid-template-columns: minmax(180px, 1.6fr) repeat(4, minmax(120px, 1fr)) auto;
  gap: 12px;
  align-items: end;
}

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
}
.field input, .field select {
  font-family: var(--font-body);
  font-size: 13.5px;
  color: var(--ink);
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  width: 100%;
  min-width: 0;
}
.field input:focus, .field select:focus { border-color: var(--emerald-soft); outline: none; }

.filter-actions { display: flex; gap: 8px; }

.btn-primary {
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 500;
  color: #F4F8F5;
  background: var(--emerald);
  border: 1px solid var(--emerald);
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  cursor: pointer;
}
.btn-primary:hover { background: #124F3C; }

.btn-ghost {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  text-decoration: none;
  white-space: nowrap;
}
.btn-ghost:hover { background: var(--surface-sunken); }

.filter-summary {
  margin-top: 13px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}
.filter-summary strong { color: var(--ink); font-family: var(--font-mono); }

/* ------------------------------------------------------------------- cards */
.grid { display: grid; gap: 16px; margin-bottom: 16px; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-wide-side { grid-template-columns: minmax(0, 1.85fr) minmax(0, 1fr); }

.stack { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.card-head { margin-bottom: 16px; }
.card-head h3 { font-size: 15.5px; font-weight: 600; letter-spacing: -.01em; }
.card-head p { font-size: 12.5px; color: var(--muted); margin-top: 3px; }

.card-head-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

.card-note {
  margin-top: 12px;
  font-size: 11.5px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.empty {
  font-size: 13px;
  color: var(--muted);
  background: var(--surface-sunken);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 18px;
  text-align: center;
}

/* -------------------------------------------------------------------- bars */
.bars { display: flex; flex-direction: column; gap: 13px; }
.bar-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 5px; }
.bar-label { font-size: 13px; color: var(--ink-soft); }
.bar-value { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.bar-track { height: 8px; border-radius: 999px; background: var(--surface-sunken); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 999px; }

/* ------------------------------------------------------------------ charts */
.chart-area { width: 100%; height: auto; display: block; }
.chart-area-value { font-family: var(--font-mono); font-size: 11px; font-weight: 600; fill: var(--ink); }
.chart-area-label { font-family: var(--font-mono); font-size: 10.5px; fill: var(--muted); }

.donut-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.chart-donut { width: 150px; height: 150px; }
.chart-donut-value { font-family: var(--font-mono); font-size: 26px; font-weight: 600; fill: var(--ink); }
.chart-donut-caption { font-family: var(--font-body); font-size: 11px; fill: var(--muted); }
.donut-wrap .legend-stack { width: 100%; }

/* ------------------------------------------------------------- people list */
.people-list { display: flex; flex-direction: column; gap: 12px; }
.people-list li { display: flex; align-items: center; gap: 11px; }

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  flex: none;
  display: grid;
  place-items: center;
  background: var(--unit-color, var(--emerald));
  color: #fff;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
}

.people-main { display: flex; flex-direction: column; min-width: 0; }
.people-name { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.people-meta { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.people-value { margin-left: auto; font-family: var(--font-mono); font-size: 12px; color: var(--ink-soft); white-space: nowrap; }
.people-list.compact li { gap: 8px; }

/* ----------------------------------------------------------------- quality */
.quality {
  background: #FDF6E7;
  border: 1px solid #EBD9AE;
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}

.quality summary {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 20px;
  cursor: pointer;
  list-style: none;
}
.quality summary::-webkit-details-marker { display: none; }
.quality summary strong { font-size: 14px; display: block; }
.quality-sub { font-size: 12.5px; color: #8A7038; }

.quality-badge {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: var(--mustard);
  border-radius: 8px;
  padding: 4px 11px;
  flex: none;
}

.quality-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  padding: 4px 20px 20px;
  border-top: 1px solid #EBD9AE;
  padding-top: 18px;
}

.quality-group h4 {
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 9px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.quality-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: #8A7038;
  background: #F6EAC9;
  border-radius: 5px;
  padding: 1px 7px;
}
.quality-group li { display: flex; gap: 8px; font-size: 12.5px; padding: 4px 0; flex-wrap: wrap; }
.quality-row { font-family: var(--font-mono); font-size: 11px; color: #8A7038; }
.quality-name { font-weight: 500; }
.quality-detail { color: var(--muted); font-size: 11.5px; width: 100%; }

/* ------------------------------------------------------------------- table */
.table-card { padding-bottom: 8px; }
.table-scroll { overflow-x: auto; margin-inline: -22px; padding-inline: 22px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }

.data-table th {
  text-align: left;
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  padding: 0 12px 9px;
  border-bottom: 1.5px solid var(--line-strong);
  white-space: nowrap;
}
.data-table th a { text-decoration: none; }
.data-table th a:hover { color: var(--emerald); }

.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table tbody tr:hover { background: var(--surface-sunken); }

.data-table .numeric { font-family: var(--font-mono); font-size: 12px; white-space: nowrap; }
.data-table .align-right { text-align: right; }

.data-table tfoot td {
  border-bottom: none;
  border-top: 1.5px solid var(--line-strong);
  font-size: 12px;
  color: var(--muted);
  padding-top: 12px;
}

.cell-name { display: block; font-weight: 500; }
.cell-sub { display: block; font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); margin-top: 2px; }

.row-flagged { box-shadow: inset 3px 0 0 var(--mustard); }

.chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  color: var(--chip-color, var(--emerald));
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 2px 10px;
  white-space: nowrap;
}

/* ------------------------------------------------------------------- error */
.error-card { border-left: 4px solid var(--clay); }
.error-card h2 { font-size: 19px; margin-bottom: 8px; }
.error-message {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--clay);
  background: #FBEFEC;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 14px;
}
.error-steps { display: flex; flex-direction: column; gap: 7px; font-size: 13.5px; color: var(--ink-soft); }
.error-steps li { padding-left: 18px; position: relative; }
.error-steps li::before { content: "→"; position: absolute; left: 0; color: var(--emerald); }
.error-steps code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--surface-sunken);
  padding: 1px 5px;
  border-radius: 4px;
}

/* ------------------------------------------------------------------ footer */
.page-footer { padding: 26px 0 40px; }
.page-footer p { font-size: 12px; color: var(--muted); }

/* -------------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .kpi-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-form { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filter-actions { grid-column: 1 / -1; }
}

@media (max-width: 900px) {
  .grid-3, .grid-wide-side { grid-template-columns: minmax(0, 1fr); }
  .shelf { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .shelf-label { flex-direction: row; align-items: baseline; gap: 10px; }
  .shelf-payroll { text-align: left; flex-direction: row; gap: 8px; align-items: baseline; }
}

@media (max-width: 640px) {
  .shell { width: min(1280px, 100% - 24px); }
  .kpi-row, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-form { grid-template-columns: minmax(0, 1fr); }
  .topbar-meta { gap: 18px; }
  .hero { padding: 20px 18px 16px; }
  .card { padding: 18px; }
  .table-scroll { margin-inline: -18px; padding-inline: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ------------------------------------------------------------------- print */
@media print {
  body { background: #fff; }
  .topbar { background: #fff; color: var(--ink); border-bottom: 2px solid var(--ink); }
  .topbar h1, .topbar-meta dd { color: var(--ink); }
  .btn-print, .filters, .btn-ghost { display: none; }
  .card, .hero, .kpi { box-shadow: none; break-inside: avoid; }
  .quality details { display: none; }
}
