/* Inventory Control - one stylesheet, phone first (spec section 10). */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #14171a;
  --muted: #4f5964;
  --border: #c9d0d7;
  --primary: #1f5f8b;
  --primary-hover: #194e73;
  --on-primary: #ffffff;
  --focus: #2b7bb9;
  --ok-bg: #e3f3e8;
  --ok-text: #14532d;
  --ok-border: #2f8a4f;
  --err-bg: #fdeaea;
  --err-text: #7f1d1d;
  --err-border: #c24141;
  --warn-bg: #fff3d1;
  --warn-text: #5c3f00;
  --warn-border: #b7860b;
  --info-bg: #e7f0f8;
  --info-text: #123a57;
  --info-border: #3a78a8;
  --radius: 10px;
  --gap: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1316;
    --surface: #182027;
    --surface-2: #212b33;
    --text: #e9eef2;
    --muted: #a9b4be;
    --border: #3a4650;
    --primary: #6bb4ea;
    --primary-hover: #8bc5ef;
    --on-primary: #08121a;
    --focus: #9fd0f5;
    --ok-bg: #11301e;
    --ok-text: #b6ecc7;
    --ok-border: #4fb877;
    --err-bg: #3a1414;
    --err-text: #ffc9c9;
    --err-border: #e06666;
    --warn-bg: #3a2c05;
    --warn-text: #ffe39b;
    --warn-border: #d6a72a;
    --info-bg: #132a3d;
    --info-text: #cfe6f8;
    --info-border: #5d9fd1;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1316;
  --surface: #182027;
  --surface-2: #212b33;
  --text: #e9eef2;
  --muted: #a9b4be;
  --border: #3a4650;
  --primary: #6bb4ea;
  --primary-hover: #8bc5ef;
  --on-primary: #08121a;
  --focus: #9fd0f5;
  --ok-bg: #11301e;
  --ok-text: #b6ecc7;
  --ok-border: #4fb877;
  --err-bg: #3a1414;
  --err-text: #ffc9c9;
  --err-border: #e06666;
  --warn-bg: #3a2c05;
  --warn-text: #ffe39b;
  --warn-border: #d6a72a;
  --info-bg: #132a3d;
  --info-text: #cfe6f8;
  --info-border: #5d9fd1;
  color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

[hidden] { display: none !important; }

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

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ----- top bar --------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
}

.who {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}

/* ----- page ------------------------------------------------------------- */

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

h1 { font-size: 1.45rem; margin: 4px 0 12px; }
h2 { font-size: 1.15rem; margin: 20px 0 8px; }
h3 { font-size: 1rem; margin: 16px 0 6px; }

p { margin: 6px 0; }

.muted { color: var(--muted); }
.small { font-size: 0.9rem; }

.stack > * + * { margin-top: var(--gap); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.card + .card { margin-top: var(--gap); }

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.row > .grow { flex: 1 1 160px; min-width: 0; }

.kv {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  margin: 0;
}

.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 600; overflow-wrap: anywhere; }

.big-number { font-size: 2rem; font-weight: 700; line-height: 1.1; }

.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; }

/* ----- buttons ---------------------------------------------------------- */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  min-width: 48px;
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-danger { border-color: var(--err-border); color: var(--err-text); }

.btn-ghost { background: transparent; border-color: transparent; }

.btn-small { min-height: 48px; padding: 6px 12px; font-size: 0.95rem; }

.btn-block { width: 100%; }

/* The primary action sits at the bottom of the screen, full width (spec section 10). */
.actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin: 16px -16px 0;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.actions .btn { width: 100%; }

.home-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.home-grid .btn {
  min-height: 96px;
  font-size: 1.15rem;
  flex-direction: column;
}

.home-grid .btn-wide { grid-column: 1 / -1; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

/* ----- forms ------------------------------------------------------------ */

label { display: block; font-weight: 600; margin-bottom: 4px; }

.field + .field { margin-top: 12px; }

.hint { color: var(--muted); font-size: 0.9rem; margin-top: 4px; }

input[type="text"], input[type="password"], input[type="search"], input[type="date"],
input[type="number"], select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

input.qty {
  font-size: 1.8rem;
  font-weight: 700;
  text-align: center;
}

input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--err-border); border-width: 2px; }

.field-error { color: var(--err-text); font-size: 0.92rem; margin-top: 4px; }

.check { display: flex; align-items: center; gap: 10px; min-height: 48px; font-weight: 600; }
.check input { width: 24px; height: 24px; }

/* ----- messages (text label + colour, never colour alone) --------------- */

.banner-area { max-width: 560px; margin: 0 auto; padding: 0 16px; }

.msg {
  border: 1px solid;
  border-left-width: 6px;
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 12px 0 0;
}

.msg strong { margin-right: 6px; }
.msg-ok { background: var(--ok-bg); color: var(--ok-text); border-color: var(--ok-border); }
.msg-error { background: var(--err-bg); color: var(--err-text); border-color: var(--err-border); }
.msg-warn { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); }
.msg-info { background: var(--info-bg); color: var(--info-text); border-color: var(--info-border); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-off { border-style: dashed; color: var(--muted); }

/* ----- scanner ---------------------------------------------------------- */

.scanner .viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}

.scanner video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.scanner .guide {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 50%;
  height: 0;
  border-top: 3px solid rgba(255, 80, 80, 0.9);
  pointer-events: none;
}

.scanner form { margin-top: 12px; }

/* ----- lists ------------------------------------------------------------ */

.list { list-style: none; margin: 0; padding: 0; }

.list > li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  overflow-wrap: anywhere;
}

.list > li + li { margin-top: 8px; }

.list .title { font-weight: 700; }

.list-button {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 48px;
  font: inherit;
  cursor: pointer;
}

.list-button + .list-button { margin-top: 8px; }

.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.tabs .btn[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }

.step { color: var(--muted); font-weight: 600; font-size: 0.9rem; margin-bottom: 4px; }

/* Space between the blocks of a form (cards, fields, button rows). */
form > * + *:not(.actions):not(.hint) { margin-top: 12px; }
