:root {
  --bg: #eef2f4;
  --bg-deep: #e2e8ec;
  --surface: #ffffff;
  --ink: #14323f;
  --ink-soft: #3d5a66;
  --muted: #6a818c;
  --line: #cfd8dd;
  --accent: #0f766e;
  --accent-hover: #0d635c;
  --good: #1f6b4a;
  --warn: #a16207;
  --bad: #9b2c2c;
  --sidebar: #14323f;
  --sidebar-text: #e8f0f3;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(20, 50, 63, 0.08);
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, #d7e8e6 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 0%, #d9e4ec 0%, transparent 50%),
    var(--bg);
}

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

button {
  cursor: pointer;
}

h1,
h2,
h3 {
  font-family: var(--display);
  font-weight: 650;
  letter-spacing: -0.02em;
  margin: 0;
}

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.25rem 0.5rem;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #0f766e, #115e59);
  color: #fff;
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.95rem;
}

.brand strong {
  display: block;
  font-family: var(--display);
  font-size: 1.15rem;
  line-height: 1.1;
}

.brand span {
  font-size: 0.78rem;
  opacity: 0.7;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-btn {
  text-align: left;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  opacity: 0.85;
  transition: background 0.15s, opacity 0.15s;
}

.nav-btn:hover,
.nav-btn.active {
  background: rgba(255, 255, 255, 0.1);
  opacity: 1;
}

.nav-btn.active {
  background: rgba(15, 118, 110, 0.45);
}

.nav-scan {
  margin-top: 0.5rem;
  background: rgba(15, 118, 110, 0.35);
  font-weight: 600;
}

.main {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(10px);
  background: rgba(238, 242, 244, 0.9);
  border-bottom: 1px solid rgba(207, 216, 221, 0.8);
}

.topbar h1 {
  flex: 1;
  font-size: 1.45rem;
}

.menu-btn {
  display: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  width: 40px;
  height: 40px;
}

.content {
  padding: 1.25rem;
  max-width: 1100px;
}

.view {
  display: none;
  animation: fadeIn 0.25s ease;
}

.view.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.9rem;
  margin-bottom: 1.25rem;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}

.stat .label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.stat .value {
  font-family: var(--display);
  font-size: 1.7rem;
  line-height: 1;
}

.stat.warn .value {
  color: var(--warn);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  font-size: 1.15rem;
}

.form-panel {
  padding: 1.25rem;
  max-width: 640px;
}

.pad {
  padding: 0 1.1rem 0.5rem;
}

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

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 400;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 9px;
  padding: 0.65rem 0.8rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18);
}

.panel-head .input,
.row-actions .input {
  width: min(220px, 100%);
}

.btn {
  border: 1px solid var(--line);
  background: var(--bg-deep);
  border-radius: 9px;
  padding: 0.6rem 0.95rem;
  font-weight: 600;
  transition: background 0.15s, transform 0.1s;
}

.btn:hover {
  background: #d3dde3;
}

.btn:active {
  transform: scale(0.98);
}

.btn-sm {
  padding: 0.45rem 0.75rem;
  font-size: 0.9rem;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

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

.btn-danger {
  background: #f8e8e8;
  border-color: #e3b6b6;
  color: var(--bad);
}

.btn-danger:hover {
  background: #f0d4d4;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 0.8rem 1.1rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}

tbody tr {
  cursor: pointer;
  transition: background 0.12s;
}

tbody tr:hover {
  background: rgba(26, 58, 47, 0.04);
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge.ok {
  background: #dceee4;
  color: var(--good);
}

.badge.low {
  background: #fdecc8;
  color: var(--warn);
}

.badge.out {
  background: #f8dede;
  color: var(--bad);
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.9rem;
  padding: 1rem;
}

.product-card {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 1rem;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.product-card h3 {
  font-size: 1.05rem;
}

.product-card .meta {
  font-size: 0.82rem;
  color: var(--muted);
}

.product-card .qty {
  font-family: var(--display);
  font-size: 1.5rem;
}

.product-card .actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.35rem;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  margin-top: 1rem;
}

.form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.stock-mode {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font-size: 0.88rem;
  font-weight: 600;
}

.chip.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.barcode-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.85rem;
  padding: 1rem;
}

.barcode-item {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 0.85rem;
  background: #fff;
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.barcode-item label {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  cursor: pointer;
  width: 100%;
}

.barcode-item input {
  margin-top: 0.35rem;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.barcode-preview {
  flex: 1;
  text-align: center;
}

.barcode-preview canvas,
.barcode-preview svg {
  max-width: 100%;
  height: auto;
}

.barcode-preview .name {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.scanner-wrap {
  position: relative;
  width: 100%;
  max-width: 420px;
  margin: 1rem auto;
}

.scanner {
  width: 100%;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #111;
  min-height: 260px;
}

.scanner video {
  border-radius: 12px !important;
  width: 100% !important;
}

.btn-camera {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 5;
  padding: 0.9rem 1.4rem;
  font-size: 1.05rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.btn-camera-stop {
  position: absolute;
  right: 0.6rem;
  top: 0.6rem;
  z-index: 5;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  border-color: transparent;
}

.btn-camera.hidden,
.btn-camera-stop.hidden,
.scan-hint.hidden {
  display: none;
}

.scan-hint {
  text-align: center;
  margin: 0.35rem 0 0;
}

.scan-manual {
  margin-top: 1rem;
}

.inline-form {
  display: flex;
  gap: 0.5rem;
}

.scan-result {
  margin-top: 1.25rem;
  padding: 1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
}

.scan-result.hidden {
  display: none;
}

.scan-result h3 {
  margin-bottom: 0.35rem;
}

.scan-result .big-qty {
  font-family: var(--display);
  font-size: 2.4rem;
  margin: 0.5rem 0;
}

.scan-result .details {
  display: grid;
  gap: 0.35rem;
  font-size: 0.92rem;
  color: var(--ink-soft);
}

.scan-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.9rem;
}

.modal {
  border: none;
  border-radius: 14px;
  padding: 0;
  max-width: min(480px, calc(100vw - 2rem));
  width: 100%;
  background: var(--surface);
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.25);
}

.modal::backdrop {
  background: rgba(26, 58, 47, 0.45);
}

.modal-inner {
  padding: 1.1rem;
}

.modal-inner header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.9rem;
}

.icon-btn {
  border: 0;
  background: transparent;
  font-size: 1.1rem;
  width: 36px;
  height: 36px;
  border-radius: 8px;
}

.icon-btn:hover {
  background: var(--bg-deep);
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--ink);
  color: #fff;
  padding: 0.75rem 1.1rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.92rem;
  z-index: 100;
  transition: transform 0.25s ease;
  max-width: calc(100vw - 2rem);
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.overlay {
  display: none;
}

.change-pos {
  color: var(--good);
  font-weight: 700;
}

.change-neg {
  color: var(--bad);
  font-weight: 700;
}

/* Print styles */
.print-sheet {
  display: none;
}

@media print {
  body * {
    visibility: hidden !important;
  }

  .print-sheet,
  .print-sheet * {
    visibility: visible !important;
  }

  .print-sheet {
    display: block !important;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    background: #fff;
  }

  .print-label {
    page-break-inside: avoid;
    break-inside: avoid;
    text-align: center;
    padding: 12px;
    border: 1px dashed #999;
    margin: 8px;
    display: inline-block;
    width: 220px;
    vertical-align: top;
  }

  .print-label .name {
    font-family: Arial, sans-serif;
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 4px;
  }

  .print-label .sku {
    font-family: Arial, sans-serif;
    font-size: 10px;
    color: #444;
    margin-top: 2px;
  }
}

@media (max-width: 900px) {
  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

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

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    width: min(280px, 85vw);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .menu-btn {
    display: grid;
    place-items: center;
  }

  .overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 30;
  }

  .overlay.show {
    display: block;
  }
}

@media (max-width: 560px) {
  .content {
    padding: 0.85rem;
  }

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

  .inline-form {
    flex-direction: column;
  }

  .panel-head .input,
  .row-actions .input {
    width: 100%;
  }
}
