/* RD Stock. Layout from the SEL app; colors from the RD Hub (navy and orange). */
:root {
  --bg: #f5f5f4;
  --card: #ffffff;
  --text: #1c1917;
  --muted: #57534e;
  --border: #d6d3d1;
  --brand: #0b162a;
  --accent: #c83803;
  --accent-text: #ffffff;
  --bad: #b91c1c;
  --ok: #15803d;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --warn-text: #78350f;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
  accent-color: var(--accent);
}

/* Dark mode: data-theme is set on <html> by the script at the top of index.html. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b162a;
  --card: #15233d;
  --text: #f5f5f4;
  --muted: #a8b3c7;
  --border: #2b3b5a;
  --accent: #d9480f;
  --bad: #f87171;
  --ok: #16a34a;
  --warn: #f59e0b;
  --warn-bg: #422006;
  --warn-text: #fde68a;
}

* {
  box-sizing: border-box;
}

button,
input,
select,
textarea {
  font-family: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 1.0625rem;
}

.shell {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px 32px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.brand img {
  border-radius: 9px;
}

h1 {
  margin: 0;
  font-size: 1.5rem;
}

h2 {
  margin: 0;
  font-size: 1.25rem;
}

h3 {
  margin: 0;
  font-size: 1.05rem;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.9rem;
}

.mono {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.card p {
  margin: 0;
}

label {
  font-weight: 600;
}

input {
  width: 100%;
  padding: 14px 12px;
  font-size: 1.25rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

#code {
  letter-spacing: 0.3em;
  text-align: center;
}

button {
  min-height: 52px;
  padding: 12px 16px;
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  border: none;
  border-radius: 8px;
}

button:disabled {
  opacity: 0.6;
}

button.secondary {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
}

button.link {
  min-height: 44px;
  padding: 8px 0;
  color: var(--accent);
  background: none;
  font-weight: 500;
}

/* A link that looks like a button */
a.button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 12px 16px;
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 8px;
}

a.button.primary {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

.links {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.error {
  color: var(--bad);
}

.error:empty,
.status:empty {
  display: none;
}

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.push-right {
  margin-left: auto;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.stack:empty {
  margin-top: 0;
}

.warn-box {
  padding: 10px 12px;
  color: var(--bad);
  border: 1px solid var(--bad);
  border-radius: 8px;
}

.tag {
  align-self: flex-start;
  padding: 2px 8px;
  font-size: 0.8rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.tag.warn {
  color: var(--bad);
  border-color: var(--bad);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.kv {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0;
}

.kv > span:last-child {
  text-align: right;
  overflow-wrap: anywhere;
}

.kv.warn-row > span:last-child {
  color: var(--bad);
  font-weight: 600;
}

/* Home */
#home {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#home > p {
  margin: 0;
}

.search-card {
  gap: 8px;
}

.item-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  min-height: 0;
  padding: 12px 14px;
  text-align: left;
  font-weight: 500;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
}

.item-top,
.item-sub {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.item-name {
  font-weight: 600;
}

.item-qty {
  flex: none;
  font-variant-numeric: tabular-nums;
}

.item-qty.bad {
  color: var(--bad);
  font-weight: 700;
}

.item-photo {
  display: block;
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  border-radius: 8px;
  background: var(--bg);
}

.notes {
  white-space: pre-wrap;
  color: var(--muted);
}

/* Connect JobTread */
.connect-card {
  gap: 8px;
  border-left: 6px solid var(--accent);
}

.connect-card button.link {
  align-self: center;
  min-height: 36px;
  padding: 4px 0;
}

.jt-status {
  margin: 8px 0 0;
  text-align: right;
}

.jt-status button.link {
  min-height: 0;
  padding: 0;
  font-size: inherit;
}

/* Footer */
.footer-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 20px;
}

.account {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin-top: 8px;
  text-align: right;
}

.account p {
  margin: 0;
}

.theme-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0;
  padding: 0;
  border: none;
}

.theme-switch legend {
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

.theme-switch button {
  min-height: 44px;
  font-weight: 500;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0;
}

.theme-switch button:first-of-type {
  border-radius: 8px 0 0 8px;
}

.theme-switch button:last-of-type {
  border-radius: 0 8px 8px 0;
}

.theme-switch button + button {
  border-left: none;
}

.theme-switch button[aria-pressed="true"] {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

/* Admin */
#admin {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#admin > p {
  margin: 0;
}

details.admin-panel > summary {
  font-size: 1.05rem;
  font-weight: 700;
  min-height: 32px;
  cursor: pointer;
}

.refresh-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.refresh-buttons button {
  min-height: 44px;
  font-size: 0.95rem;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

label.field input {
  font-size: 1rem;
  padding: 10px;
  min-height: 44px;
}

select {
  width: 100%;
  min-height: 44px;
  padding: 8px;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.user {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.user:first-child {
  border-top: none;
  padding-top: 0;
}

.user p {
  margin: 0;
}

.user.inactive {
  opacity: 0.6;
}

.user-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

/* Scan button (home) */
.scan-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 64px;
  font-size: 1.2rem;
}

/* Camera scanner: full screen over everything */
.scanner {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: #000;
}

.scanner video {
  flex: 1;
  width: 100%;
  min-height: 0;
  object-fit: cover;
}

/* The guide box: wide and short, the shape of a label's barcode */
.scanner-frame {
  position: absolute;
  top: 38%;
  left: 50%;
  width: min(82vw, 420px);
  height: min(30vw, 150px);
  transform: translate(-50%, -50%);
  border: 3px solid #fff;
  border-radius: 12px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.scanner-bar {
  position: relative; /* above the guide box shading */
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
  color: #fff;
  background: #0b162a;
}

.scanner-bar p {
  margin: 0;
  text-align: center;
}

.scanner-buttons {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 10px;
}

.scanner-buttons button.secondary {
  color: #fff;
  border-color: #64748b;
}

body.scanning {
  overflow: hidden;
}

/* Pulls */
.send-button {
  width: 100%;
  min-height: 60px;
  font-size: 1.15rem;
}

.qty-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.qty-input {
  width: 8.5rem;
  flex: none;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.warn-text {
  color: var(--bad);
}

button.warn-button {
  color: var(--bad);
  border-color: var(--bad);
}

button.danger-link {
  margin-left: auto;
  color: var(--bad);
}

.job-card .pull-job {
  font-size: 1.1rem;
  font-weight: 700;
}

.job-buttons {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

.job-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 6px;
  min-height: 0;
  padding: 12px 14px;
  text-align: left;
  font-weight: 500;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
}

.job-sub {
  flex-basis: 100%;
}

#job-search,
#link-search {
  margin-bottom: 4px;
}

/* The pull list badge, pinned to the bottom */
.pull-badge {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 20;
  width: min(448px, calc(100% - 32px));
  transform: translateX(-50%);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

body:has(#pull-badge:not([hidden])) .shell {
  padding-bottom: 96px;
}

.count {
  margin-left: 6px;
  padding: 2px 8px;
  font-size: 0.85rem;
  color: var(--accent-text);
  background: var(--bad);
  border-radius: 999px;
}

.pull-card.highlight {
  border-left: 6px solid var(--ok);
}

.pull-line-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.pull-line-row.status-returned,
.pull-line-row.status-moved {
  opacity: 0.6;
}

.line-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
}

.line-actions button.link {
  min-height: 40px;
}

/* Admin: confirm catalog links */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

button.tab {
  min-height: 44px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
}

button.tab.active {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

.link-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.link-row p {
  margin: 0;
}

.link-row .suggestion {
  font-weight: 600;
}

.link-row.done {
  opacity: 0.6;
}
