:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #0f766e;
  --accent-soft: #e6f4f2;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn-soft: #fff7e0;
  --radius: 12px;
  --nav-h: 64px;
  --side-w: 220px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { min-height: 100vh; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
h1 { font-size: 1.4rem; margin: 0 0 16px; }
h2 { font-size: 1.1rem; margin: 24px 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.loading { color: var(--muted); padding: 24px; }

/* Layout */
main { padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; outline: none; }
#nav { position: fixed; z-index: 10; background: var(--card); border-top: 1px solid var(--line);
  bottom: 0; left: 0; right: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); display: flex; }
#nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 0.72rem; min-height: 44px; }
#nav a.active { color: var(--accent); font-weight: 600; }
#nav a svg { width: 24px; height: 24px; }
#nav a.scan { color: #fff; }
#nav a.scan span.bubble { background: var(--accent); border-radius: 50%; width: 52px; height: 52px; display: flex;
  align-items: center; justify-content: center; margin-top: -22px; box-shadow: 0 4px 12px rgba(15, 118, 110, .35); }
#nav a.scan span.label { color: var(--accent); }
#nav .side-only { display: none; }
@media (min-width: 800px) {
  #nav { top: 0; bottom: 0; right: auto; width: var(--side-w); height: auto; flex-direction: column; border-top: 0;
    border-right: 1px solid var(--line); padding: 16px 8px; gap: 4px; }
  #nav .brand { display: block; font-weight: 700; padding: 8px 12px 16px; color: var(--text); font-size: 1.05rem; }
  #nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 12px;
    border-radius: 8px; font-size: 0.95rem; }
  #nav a.active { background: var(--accent-soft); }
  #nav a.scan span.bubble { width: 24px; height: 24px; margin: 0; box-shadow: none; background: none; color: var(--accent); }
  #nav a.more-link { display: none; }
  #nav .side-only { display: flex; }
  #nav .spacer { flex: 1; }
  main { margin-left: var(--side-w); padding: 32px 32px 48px; }
  #nav:not([hidden]) ~ main { margin-left: calc(var(--side-w) + max(0px, (100vw - var(--side-w) - 1100px) / 2)); }
}
#nav .brand { display: none; }
@media (min-width: 800px) { #nav .brand { display: block; } }

/* Cards and stats */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
@media (max-width: 480px) { .stats .stat:nth-child(2) { grid-column: 1 / -1; order: -1; } .stat .value { font-size: 1.5rem; } }
.stat .label { color: var(--muted); font-size: 0.9rem; }
.stat .value { font-size: 1.8rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.quick .btn { white-space: nowrap; }

/* Buttons */
button, .btn { font: inherit; font-size: 1rem; min-height: 44px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger, button.danger { color: var(--danger); border-color: #f3c3bd; }
button:disabled { opacity: .6; cursor: default; }
button.link { border: 0; background: none; color: var(--accent); padding: 4px; min-height: 0; }
.btn svg, button svg { width: 20px; height: 20px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }

/* Forms */
form .field { margin-bottom: 14px; }
label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.95rem; }
label .opt { font-weight: 400; color: var(--muted); }
input, select, textarea { font: inherit; font-size: 16px; width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid #cfd4dc; border-radius: 10px; background: #fff; color: var(--text); }
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--danger); }
.error { color: var(--danger); font-size: 0.88rem; margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .wide { grid-column: 1 / -1; } }
.stepper { display: flex; gap: 8px; }
.stepper button { width: 52px; flex: none; font-size: 1.3rem; padding: 0; }
.stepper input { text-align: center; font-size: 1.2rem; font-weight: 600; }
.input-with-button { display: flex; gap: 8px; }
.input-with-button button { flex: none; }
.form-actions { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); background: var(--bg);
  padding: 12px 0; display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--line); margin-top: 8px; }
@media (min-width: 800px) { .form-actions { bottom: 0; } }
.supplier-row { display: grid; grid-template-columns: 1fr 120px 44px; gap: 8px; margin-bottom: 8px; align-items: center; }
.supplier-row button { padding: 0; }

/* Banners */
.banner { border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; }
.banner.error { background: var(--danger-soft); color: var(--danger); font-size: 0.95rem; margin-top: 0; }
.banner.warn { background: var(--warn-soft); }
.banner .row { margin-top: 8px; }

/* Lists and tables */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1 1 220px; }
.toolbar .search-scan { flex: 1 1 220px; }
.toolbar .search-scan input[type=search] { flex: 1 1 auto; min-width: 0; }
.toolbar select { width: auto; flex: 0 1 220px; }
table.list { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; }
table.list th, table.list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
table.list th { font-size: 0.82rem; color: var(--muted); font-weight: 600; white-space: nowrap; user-select: none; }
table.list th.sortable { cursor: pointer; }
table.list th.num, table.list td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover { background: #fafbfc; }
table.list tr:last-child td { border-bottom: 0; }
.cards { display: none; }
.cards .item { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px; text-decoration: none; color: inherit; }
.item .top { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.item .sub { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 0.88rem; margin-top: 4px; }
.only-desktop { display: table; }
@media (max-width: 799px) {
  .only-desktop { display: none; }
  .cards { display: block; }
}
@media (min-width: 800px) { .only-mobile { display: none !important; } }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.pill { display: inline-block; font-size: 0.78rem; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.pill.grey { background: #eef0f3; color: var(--muted); }

/* Detail */
dl.details { display: grid; grid-template-columns: 140px 1fr; gap: 10px 12px; margin: 0; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; word-break: break-word; white-space: pre-wrap; }
@media (max-width: 480px) { dl.details { grid-template-columns: 1fr; gap: 2px; } dl.details dd { margin-bottom: 10px; } }
.big-qty { font-size: 2.2rem; font-weight: 700; }

/* Activity */
.activity .entry { padding: 10px 0; border-bottom: 1px solid var(--line); }
.activity .entry:last-child { border-bottom: 0; }
.activity .when { color: var(--muted); font-size: 0.85rem; }
.activity .changes { font-size: 0.9rem; margin-top: 2px; }

/* Auth pages */
.auth { max-width: 380px; margin: 10vh auto 0; }
.auth .logo { width: 56px; height: 56px; margin-bottom: 12px; }

/* Scanner */
.scanner { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 3 / 4; max-height: 60vh; width: 100%; }
@media (min-width: 800px) { .scanner { aspect-ratio: 4 / 3; max-width: 640px; } }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame { position: absolute; left: 10%; right: 10%; top: 35%; bottom: 35%; border: 3px solid rgba(255,255,255,.9);
  border-radius: 12px; box-shadow: 0 0 0 9999px rgba(0,0,0,.35); pointer-events: none; }
.scanner .torch { position: absolute; right: 12px; top: 12px; background: rgba(0,0,0,.5); color: #fff; border: 0; }
.scanner .msg { position: absolute; left: 0; right: 0; bottom: 12px; text-align: center; color: #fff; font-size: 0.95rem; text-shadow: 0 1px 2px #000; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal .panel { background: var(--card); border-radius: var(--radius); padding: 16px; width: 100%; max-width: 520px; }

/* Toast */
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  background: #1f2933; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none;
  transition: opacity .2s; z-index: 60; max-width: 90vw; }
#toast.show { opacity: 1; }
@media (min-width: 800px) { #toast { bottom: 24px; } }
@media (min-width: 800px) {
  #nav a.scan { color: var(--muted); }
  #nav a.scan span.bubble, #nav a.scan span.label { color: inherit; }
  #nav a.scan.active { color: var(--accent); }
}
@media (min-width: 800px) { #nav[hidden] ~ main { margin-left: auto; } }
