:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c1f26;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2f6f4f;
  --primary-dark: #234f38;
  --danger: #c0392b;
  --warn-bg: #fff4e5;
  --warn-text: #92400e;
  --radius: 10px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  row-gap: 8px;
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar .brand { font-weight: 700; font-size: 1.05rem; color: #fff; white-space: nowrap; }
.topbar .brand:hover { text-decoration: none; }

.topbar nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 14px;
}

.topbar nav a {
  color: #eafff2;
  font-size: 0.92rem;
  white-space: nowrap;
}

.topbar nav a.active { font-weight: 700; text-decoration: underline; }

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 16px;
  width: 100%;
}

/* Tablet portrait and phones: let the nav wrap onto its own full-width row
   instead of squeezing every link onto one line. */
@media (max-width: 780px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
  .topbar nav {
    width: 100%;
    gap: 8px 12px;
  }
}

/* Small phones: tighten up spacing so content isn't cramped against the edges. */
@media (max-width: 420px) {
  .container { padding: 12px; }
  .card { padding: 12px; }
  .btn { padding: 10px 14px; font-size: 0.9rem; }
  .stat { min-width: 100px; padding: 10px; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.stats-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.stat {
  flex: 1;
  min-width: 120px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: center;
}

.stat .num { font-size: 1.4rem; font-weight: 700; }
.stat .label { font-size: 0.8rem; color: var(--muted); }

.btn {
  display: inline-block;
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 0.95rem;
  cursor: pointer;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--primary-dark); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn.block { width: 100%; }
.btn.big { padding: 16px; font-size: 1.1rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

input, select, textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  margin-bottom: 10px;
  background: #fff;
  color: var(--text);
}

label { font-size: 0.85rem; color: var(--muted); display: block; margin-bottom: 4px; }

.field { margin-bottom: 12px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }

/* Wrap any data table in <div class="table-scroll"> so it scrolls
   horizontally on narrow phone screens instead of squashing columns. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
  padding: 0 4px;
}
.table-scroll table { min-width: 560px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: #eef2f0;
  color: var(--primary-dark);
}
.badge.low { background: var(--warn-bg); color: var(--warn-text); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 0.9rem; }
.flash.success { background: #e7f6ec; color: #1e6b3f; }
.flash.error { background: #fdecea; color: #a02622; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input, .filters select { width: auto; margin-bottom: 0; }

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

.login-wrap {
  max-width: 360px;
  width: 100%;
  margin: 15vh auto 0;
  padding: 24px;
}

@media (max-width: 480px), (max-height: 700px) {
  .login-wrap { margin-top: 6vh; padding: 20px; }
}

.scan-box {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 8px;
  margin-bottom: 14px;
  background: #000;
}

/* On tablets/laptops the camera box doesn't need to span the full width. */
@media (min-width: 700px) {
  .scan-box { max-width: 480px; margin-left: auto; margin-right: auto; }
}

#reader { width: 100%; border-radius: 8px; overflow: hidden; }

.result-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: #fff;
}

.result-card h2 { margin: 0 0 4px; }
.qty-display { font-size: 2rem; font-weight: 700; margin: 8px 0; }

.qty-controls { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.qty-controls button {
  width: 46px; height: 46px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; font-size: 1.3rem; cursor: pointer;
}
.qty-controls input[type=number] { text-align: center; margin-bottom: 0; }

.label-sheet { display: flex; flex-wrap: wrap; gap: 10px; }
.label {
  border: 1px solid #999;
  border-radius: 6px;
  width: 220px;
  padding: 8px;
  text-align: center;
}
.label img { width: 100%; }
.label .lname { font-weight: 700; font-size: 0.85rem; margin-bottom: 2px; }
.label .lprice { font-size: 0.85rem; color: var(--muted); }

@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .label { break-inside: avoid; }
}

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

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