:root {
  --bg: #f4f7f5;
  --card: #ffffff;
  --ink: #17211f;
  --ink-muted: #5c6e68;
  --primary: #0f6a4a;
  --primary-strong: #0b4d36;
  --danger: #b93737;
  --warn: #9f7400;
  --ok: #166636;
  --line: #d6e2dd;
  --radius: 14px;
  --shadow: 0 14px 30px rgba(16, 43, 36, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, #d9efe4 0 28%, transparent 40%),
    radial-gradient(circle at 90% 85%, #d9e9ef 0 26%, transparent 38%),
    var(--bg);
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
}

.bg-shape {
  position: fixed;
  z-index: -1;
  border-radius: 999px;
  filter: blur(45px);
  opacity: 0.5;
}

.bg-shape-a {
  width: 220px;
  height: 220px;
  background: #88d3b0;
  top: -60px;
  left: -50px;
}

.bg-shape-b {
  width: 280px;
  height: 280px;
  background: #88b3d3;
  bottom: -90px;
  right: -70px;
}

.app-shell {
  width: min(860px, 100%);
  margin: 0 auto;
  padding: 20px 14px 34px;
}

.app-header {
  margin-bottom: 14px;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(1.4rem, 4vw, 2rem);
  letter-spacing: 0.02em;
}

.app-header p {
  margin: 4px 0 0;
  color: var(--ink-muted);
}

.status {
  margin-bottom: 12px;
  padding: 11px 12px;
  border-radius: 10px;
  font-size: 0.95rem;
  border: 1px solid transparent;
}

.status-info {
  color: #175174;
  background: #e6f4fb;
  border-color: #bddff2;
}

.status-error {
  color: #751a1a;
  background: #fdeeee;
  border-color: #efc5c5;
}

.status-success {
  color: #154f2b;
  background: #ebf8ef;
  border-color: #c2e8cc;
}

.status-hidden {
  display: none;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid #edf3f0;
  padding: 14px;
}

.stack {
  display: grid;
  gap: 10px;
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.row > * {
  flex: 1;
  min-width: 170px;
}

label {
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  width: fit-content;
  max-width: 100%;
  white-space: nowrap;
}

.checkbox-inline input[type="checkbox"] {
  width: auto;
  margin: 0;
  padding: 0;
  flex: 0 0 auto;
}

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

input,
select,
textarea {
  width: 100%;
  margin-top: 4px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}

.editable-combo {
  position: relative;
  display: block;
  margin-top: 4px;
}

.editable-combo input {
  margin-top: 0;
  padding-right: 48px;
}

.editable-combo::after {
  content: "▾";
  position: absolute;
  top: 1px;
  right: 1px;
  width: 42px;
  height: calc(100% - 2px);
  display: grid;
  place-items: center;
  border-left: 1px solid var(--line);
  border-radius: 0 9px 9px 0;
  background: #f8fbfa;
  color: var(--ink-muted);
  pointer-events: none;
}

.editable-combo-picker {
  position: absolute;
  top: 0;
  right: 0;
  width: 42px;
  height: 100%;
  min-height: 42px;
  margin-top: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}

.editable-combo-picker option {
  color: var(--ink);
}

textarea {
  min-height: 220px;
  resize: vertical;
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.86rem;
}

/* Reports: stretch output area down near system nav/home controls */
#reportText {
  min-height: 320px;
  height: max(320px, calc(100dvh - 250px - env(safe-area-inset-bottom)));
}

button {
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.6;
  cursor: default;
}

.primary-btn {
  background: linear-gradient(130deg, var(--primary), var(--primary-strong));
  color: #fff;
  font-weight: 600;
}

.ghost-btn {
  background: #f2f6f4;
  color: var(--ink);
  border: 1px solid var(--line);
}

.warn-btn {
  background: var(--warn);
  color: #fff;
}

.danger-btn {
  background: var(--danger);
  color: #fff;
}

.icon-btn {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 9px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f2f6f4;
}

.icon-btn img {
  width: 22px;
  height: 22px;
  display: block;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.menu-grid-single {
  grid-template-columns: 1fr;
}

.menu-grid-two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.menu-grid-three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.block-title {
  margin: 0;
}

.hidden {
  display: none !important;
}

.scanner-wrap {
  display: grid;
  gap: 8px;
}

.scanner-video-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 10px;
}

.scanner-wrap video {
  width: 100%;
  max-height: 300px;
  border-radius: 10px;
  background: #111;
  object-fit: cover;
  aspect-ratio: 3 / 4;
}

.scanner-controls {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.72);
}

.scanner-control-label {
  display: grid;
  gap: 5px;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.zap-external-code-info {
  min-height: 32px;
}

.zap-external-code-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.zap-external-code-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 18px;
  line-height: 22px;
  cursor: pointer;
}

.scanner-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: grid;
  place-items: center;
}

.scanner-frame {
  width: min(58vw, 180px);
  height: min(58vw, 180px);
  max-width: calc(100% - 24px);
  max-height: calc(100% - 24px);
  border: 2px solid rgba(53, 255, 177, 0.95);
  border-radius: 16px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.28);
  position: relative;
  overflow: hidden;
}

.bag-card-details {
  display: grid;
  gap: 4px;
}

.bag-card-details p {
  margin: 0;
}

.scanner-line {
  position: absolute;
  left: 10px;
  right: 10px;
  height: 2px;
  background: linear-gradient(90deg, rgba(53, 255, 177, 0), rgba(53, 255, 177, 1), rgba(53, 255, 177, 0));
  animation: scannerLineMove 2s linear infinite;
}

.current-stock-list {
  display: grid;
  gap: 10px;
}

.stock-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fff;
  display: grid;
  gap: 4px;
}

.stock-item p {
  margin: 0;
}

.stock-item-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 8px;
}

.history-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 4px;
}

.history-edit-btn {
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 7px;
}

.history-edit-btn img {
  width: 20px;
  height: 20px;
}

.inventory-summary-num {
  font-weight: 700;
}

.inventory-summary-total {
  color: #111111;
}

.inventory-summary-scanned {
  color: #166636;
}

.inventory-summary-missing {
  color: #b93737;
}

.stock-open-card-btn {
  white-space: nowrap;
}

@keyframes scannerLineMove {
  0% {
    top: 8px;
  }
  100% {
    top: calc(100% - 8px);
  }
}

.app-footer {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}

@media (max-width: 650px) {
  .app-shell {
    padding: 14px 10px 26px;
  }

  .card {
    padding: 12px;
  }

  .menu-grid {
    grid-template-columns: 1fr;
  }

  .menu-grid-two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .menu-grid-three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #warehouseGrid.menu-grid-three {
    grid-template-columns: 1fr;
  }

  .account-actions-grid.menu-grid-two {
    grid-template-columns: 1fr;
  }

  #reportText {
    height: max(340px, calc(100dvh - 220px - env(safe-area-inset-bottom)));
  }
}
