:root {
  --canvas: #0A0D0C;
  --surface: #121716;
  --raised: #171D1B;
  --selected: #16352B;
  --emerald: #2ED99B;
  --emerald-hover: #53E2AF;
  --ink: #082419;
  --text: #E8EFEC;
  --muted: #A7B6AF;
  --subtle: #8FA198;
  --separator: #2B3933;
  --control-border: #647A70;
  --danger: #FF9797;
  --danger-bg: #381D21;
  --radius: 4px;
  --touch: 44px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.875rem;
  line-height: 1.25rem;
}

.top, main {
  padding: 16px;
}

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  padding-bottom: 0;
  background: var(--canvas);
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 2rem;
  font-weight: 600;
}

h2 {
  margin: 0 0 8px;
  font-size: 1.125rem;
  line-height: 1.5rem;
  font-weight: 600;
}

.subtitle { margin: 4px 0 0; color: var(--muted); }

.tabs {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  overflow-x: auto;
  border-bottom: 1px solid var(--separator);
}

.tab {
  min-height: var(--touch);
  padding: 8px 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  white-space: nowrap;
}

.tab[aria-selected="true"] {
  color: var(--emerald);
  border-bottom-color: var(--emerald);
  font-weight: 600;
}

.tab-count {
  margin-left: 4px;
  font-variant-numeric: tabular-nums;
}

.selection {
  position: fixed;
  z-index: 30;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--canvas);
  border-bottom: 1px solid var(--separator);
}

.selection[hidden] { display: none; }

.selection-name {
  margin: 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selection .subtitle { margin: 0; }

.selection-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.selection-actions button { flex: 1 1 140px; }

#print-barcode { flex-basis: 100%; }

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}

.toolbar .status { margin: 0; }

.task { cursor: default; }

.task.linked { cursor: pointer; }

.qty small {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 400;
}

.qty.missing { color: var(--danger); }

.notification-kind {
  margin: 0 0 4px;
  color: var(--danger);
  font-weight: 600;
}

.search-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.search-row .search { flex: 1; min-width: 0; }

.search-row input { width: 100%; }

.search, .category, dialog label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.75rem;
}

input, select, button {
  font: inherit;
  color: var(--text);
}

input, select {
  min-height: var(--touch);
  padding: 8px 12px;
  background: var(--raised);
  border: 1px solid var(--control-border);
  border-radius: var(--radius);
}

input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--emerald);
  outline-offset: 2px;
}

.status { color: var(--muted); }

.error {
  margin: 12px 0 0;
  padding: 12px;
  color: var(--danger);
  background: var(--danger-bg);
  border-radius: var(--radius);
  white-space: pre-line;
}

.list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

.card {
  position: relative;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 12px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: 6px;
}

.card.selected {
  background: var(--selected);
  border-color: var(--emerald);
}

.card.selected::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 3px;
  background: var(--emerald);
  border-radius: 6px 0 0 6px;
}

.card img, .thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  background: var(--raised);
  border-radius: var(--radius);
}

.photo-zoom {
  position: fixed;
  width: 192px;
  height: 192px;
  object-fit: contain;
  pointer-events: none;
  z-index: 50;
  background: var(--raised);
  border: 1px solid var(--separator);
  border-radius: var(--radius);
}

.photo-lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(10, 13, 12, 0.82);
}

.photo-lightbox img {
  width: min(100%, 320px);
  height: min(80vh, 320px);
  object-fit: contain;
  background: var(--raised);
  border: 1px solid var(--separator);
  border-radius: var(--radius);
}

.card h2 { margin: 0; font-size: 0.875rem; line-height: 1.25rem; }

.card p { margin: 2px 0 0; color: var(--subtle); font-size: 0.75rem; overflow-wrap: anywhere; }

.qty {
  min-width: 72px;
  color: var(--text);
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.empty { color: var(--muted); }

dialog {
  width: min(100% - 32px, 420px);
  padding: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: 8px;
}

dialog h2 { overflow-wrap: anywhere; }

dialog.wide {
  width: min(100% - 32px, 560px);
  max-height: calc(100vh - 32px);
  overflow: hidden;
}

dialog.wide[open] {
  display: flex;
  flex-direction: column;
  height: min(720px, calc(100dvh - 32px));
}

#card-scroll {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

.card-tabs { max-width: 100%; }

dialog.wide .actions { flex: none; }

.card-photo-missing {
  display: grid;
  place-items: center;
  width: 80px;
  height: 80px;
  margin: 0 auto 12px;
  color: var(--muted);
  background: var(--raised);
  border-radius: var(--radius);
  font-size: 0.75rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-top: 8px;
  padding: 4px 8px;
  border: 1px solid var(--separator);
  border-radius: var(--radius);
  font-size: 0.75rem;
  line-height: 1rem;
}

.badge.success {
  color: var(--emerald);
  border-color: var(--emerald);
}

.value { color: var(--text); }

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.metric {
  padding: 8px 12px;
  background: var(--raised);
  border: 1px solid var(--separator);
  border-radius: 6px;
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1rem;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.metric small { margin-top: 4px; color: var(--subtle); }

.stock-balances {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stock-balance-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: baseline;
}

.stock-balance-row span {
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.25rem;
}

.stock-balance-row strong {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.card-section {
  margin-top: 16px;
  padding: 12px;
  background: var(--raised);
  border: 1px solid var(--separator);
  border-radius: 6px;
}

.section-title {
  margin: 0 0 8px;
  font-size: 1.125rem;
  line-height: 1.5rem;
  font-weight: 600;
}

.fields { margin: 8px 0 0; }

.fields div {
  display: grid;
  grid-template-columns: minmax(7rem, 9.5rem) minmax(0, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.fields dt { color: var(--muted); font-size: 0.75rem; }

.fields dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 4px 8px;
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius);
}

.component {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.component p { margin: 0; }

.component .name { font-weight: 600; }

.record {
  padding: 12px 0;
  border-bottom: 1px solid var(--separator);
}

.record:last-child { border-bottom: 0; }

.record-head {
  display: flex;
  gap: 12px;
  align-items: baseline;
  justify-content: space-between;
}

.record-head span { color: var(--muted); font-size: 0.75rem; }

.record-head strong {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.record p { margin: 2px 0 0; color: var(--muted); font-size: 0.75rem; }

.record .record-title {
  margin-top: 4px;
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
}

/* Four times the list thumbnail. */
.editor-photo {
  display: block;
  width: 192px;
  height: 192px;
  margin: 0 auto 12px;
  object-fit: contain;
  background: var(--raised);
  border-radius: var(--radius);
}

.editor-photo[hidden] { display: none; }

/* Keeps the calculator and the save button on short phone screens without scrolling. */
@media (max-height: 760px) {
  .editor-photo { width: 96px; height: 96px; }
}

.scanner-view {
  position: relative;
  margin-top: 12px;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  background: var(--raised);
  border-radius: var(--radius);
}

.scanner-view video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Aiming frame shaped like a linear barcode. */
.scanner-view::after {
  content: "";
  position: absolute;
  inset: 30% 12%;
  border: 2px solid var(--emerald);
  border-radius: var(--radius);
  pointer-events: none;
}

.calc-display {
  display: block;
  min-height: var(--touch);
  padding: 8px 12px;
  color: var(--text);
  background: var(--raised);
  border: 1px solid var(--control-border);
  border-radius: var(--radius);
  font-size: 1.5rem;
  line-height: 2rem;
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.calc-result {
  min-height: 1.25rem;
  margin: 4px 0 0;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.calc-keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.calc-keys button {
  padding: 8px;
  font-size: 1.125rem;
  font-variant-numeric: tabular-nums;
}

.calc-keys .op { color: var(--emerald); }

.calc-keys .equals {
  grid-row: span 2;
  color: var(--ink);
  background: var(--emerald);
  border-color: var(--emerald);
  font-weight: 600;
}

.calc-keys .zero { grid-column: span 3; }

dialog::backdrop { background: rgba(0, 0, 0, 0.64); }

dialog.login {
  width: min(100% - 32px, 360px);
}

dialog.login .actions {
  margin-top: 16px;
  justify-content: stretch;
}

dialog.login .actions .primary {
  width: 100%;
}

dialog.login[open] {
  display: block;
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

button {
  min-height: var(--touch);
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--control-border);
  background: var(--raised);
}

.primary {
  flex: 1;
  color: var(--ink);
  background: var(--emerald);
  border-color: var(--emerald);
  font-weight: 600;
}

.primary:hover { background: var(--emerald-hover); }

.secondary { background: transparent; }

button:disabled { opacity: 0.6; }
