* { box-sizing: border-box; }

:root {
  --bg: #e8e3de;
  --surface: #fbf9f7;
  --text: #474848;
  --text-muted: #5f5c56;
  --ink: #1c1c1c;
  --border: #d6cfc5;
  --ok-bg: #dde6d9;
  --ok-text: #3f5a3a;
  --low-bg: #ecd8d3;
  --low-text: #8a3d2e;
  --warn-bg: #f1e2b8;
  --warn-text: #6b5416;
}

* { -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Inter', -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 20px 64px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.4;
}

h1 {
  font-family: 'Oswald', sans-serif;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 1.4rem;
  margin: 0;
  color: var(--ink);
}

/* Visually hide content but keep it available to screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
a.sr-only:focus {
  position: fixed;
  top: 10px;
  left: 10px;
  width: auto;
  height: auto;
  padding: 10px 16px;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
  background: var(--ink);
  color: #fff;
  border-radius: 3px;
  z-index: 1000;
  font-family: 'Oswald', sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.85rem;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
.btn:focus-visible {
  outline: 3px solid #2b6cb0;
  outline-offset: 2px;
}

/* ---------- Top bar ---------- */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-areas: "title logo actions";
  align-items: center;
  gap: 12px 16px;
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.topbar-title { grid-area: title; }
.brand-mark {
  grid-area: logo;
  justify-self: center;
  flex-shrink: 0;
}
.brand-logo {
  height: 84px;
  width: 84px;
  object-fit: contain;
  display: block;
}
.header-actions {
  grid-area: actions;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

@media (max-width: 640px) {
  .topbar {
    grid-template-columns: 1fr;
    grid-template-areas: "logo" "title" "actions";
    justify-items: center;
    text-align: center;
    padding: 16px 0;
  }
  .brand-logo { height: 72px; width: 72px; }
  .header-actions { justify-content: center; }
}

.btn {
  display: inline-block;
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 3px;
  text-decoration: none;
  border: 1px solid var(--ink);
  cursor: pointer;
  font-family: 'Oswald', sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  min-height: 40px;
  line-height: 1.2;
}
.btn:hover { background: #000; }
.btn.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--ink);
}
.btn.secondary:hover { background: var(--ink); color: #fff; }
.btn.tiny { padding: 6px 10px; font-size: 0.72rem; min-height: 36px; }

.link-btn {
  background: none;
  border: none;
  color: var(--low-text);
  cursor: pointer;
  padding: 4px 0;
  font-size: 0.85rem;
  text-decoration: underline;
  min-height: 36px;
}

a { color: var(--ink); }

.flash {
  padding: 10px 14px;
  border-radius: 3px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  border: 1px solid transparent;
}
.flash.ok { background: var(--ok-bg); color: var(--ok-text); border-color: #c3d3bd; }
.flash.err { background: var(--low-bg); color: var(--low-text); border-color: #dcb9b1; }
.flash.warn { background: var(--warn-bg); color: var(--warn-text); border-color: #e2cd8a; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 14px 16px;
  margin-bottom: 16px;
}
.filter-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text);
}
.filter-field label {
  font-family: 'Oswald', sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 0.7rem;
  color: var(--text-muted);
}
.filter-field input,
.filter-field select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 0.9rem;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
  min-height: 40px;
  min-width: 160px;
}
.filter-field input:focus,
.filter-field select:focus {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
}
.filter-actions {
  display: flex;
  gap: 8px;
}

@media (max-width: 640px) {
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-field input,
  .filter-field select { min-width: 0; width: 100%; }
  .filter-actions { justify-content: stretch; }
  .filter-actions .btn { flex: 1; text-align: center; }
}

.table-scroll {
  overflow-x: auto;
  border-radius: 4px;
  border: 1px solid var(--border);
}
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}
th, td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
th {
  background: var(--bg);
  font-family: 'Oswald', sans-serif;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.75rem;
  color: var(--text-muted);
}
tr:last-child td { border-bottom: none; }
tr.low { background: #f6ece9; }

.badge {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: inline-block;
}
.badge-ok { background: var(--ok-bg); color: var(--ok-text); }
.badge-low { background: var(--low-bg); color: var(--low-text); }

.inline-form { display: inline-flex; gap: 4px; align-items: center; margin: 2px 4px 2px 0; }
.qty-input { width: 70px; padding: 6px; border: 1px solid var(--border); border-radius: 3px; background: #fff; min-height: 36px; }

.empty { text-align: center; color: var(--text-muted); padding: 28px; }

/* ---------- Mobile: table -> stacked cards ---------- */
@media (max-width: 700px) {
  .table-scroll { border: none; overflow-x: visible; }
  table, thead, tbody, th, td, tr { display: block; width: 100%; }
  thead { position: absolute; left: -9999px; top: -9999px; } /* keep for screen readers via sr-only alt below */
  tbody { display: flex; flex-direction: column; gap: 12px; }
  tr {
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    padding: 4px 12px;
  }
  tr.low { border-color: #dcb9b1; }
  td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.92rem;
  }
  td:last-child { border-bottom: none; }
  td::before {
    content: attr(data-label);
    font-family: 'Oswald', sans-serif;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-size: 0.68rem;
    color: var(--text-muted);
    flex-shrink: 0;
  }
  td.cell-stack {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  td.cell-stack::before { margin-bottom: 2px; }
  td.cell-stack .inline-form { flex-wrap: wrap; }
  .empty { padding: 20px 0; }
}

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--surface);
  padding: 22px;
  border-radius: 4px;
  border: 1px solid var(--border);
  max-width: 480px;
}
.form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
}
.form input,
.form select {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
  min-height: 42px;
}
.form input:focus,
.form select:focus { outline: 2px solid var(--ink); outline-offset: 1px; }
.form small { color: var(--text-muted); font-weight: 400; }

.help-text {
  max-width: 480px;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 18px;
}
.help-text a { color: var(--ink); }

.form details {
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 10px 12px;
  background: #fff;
}
.form details[open] { display: flex; flex-direction: column; gap: 14px; }
.form summary {
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  min-height: 36px;
  display: flex;
  align-items: center;
}
.form details label { margin-top: 10px; }

.checkbox-label { flex-direction: row !important; align-items: center; gap: 8px !important; }
.checkbox-label input { width: auto; min-height: auto; }

.qr-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 28px 22px;
  max-width: 420px;
  margin: 0 auto;
}
.qr-card img {
  width: 100%;
  max-width: 280px;
  height: auto;
  background: #fff;
  padding: 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.qr-instructions {
  font-family: 'Oswald', sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 0.95rem;
  color: var(--ink);
  margin: 6px 0 0;
}
.qr-url {
  font-size: 0.85rem;
  color: var(--text-muted);
  word-break: break-all;
  margin: 0;
}
.qr-card .help-text { margin-bottom: 0; }
