:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #0f766e;
  --primary-2: #14b8a6;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --border: #334155;
  --radius: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.app-header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 14px;
  background: var(--primary);
  color: #fff;
  padding-top: max(10px, env(safe-area-inset-top));
}
.app-title { display: flex; flex-direction: column; }
.app-title strong { font-size: 16px; }
.session-info { font-size: 12px; opacity: .85; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary-2); box-shadow: 0 0 0 3px rgba(20,184,166,.25); }

.app-main { flex: 1; overflow-y: auto; padding: 12px; padding-bottom: 84px; }
.tab { display: flex; flex-direction: column; gap: 12px; }
.hidden { display: none !important; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.card h2 { margin: 0 0 8px; font-size: 15px; }
.muted { color: var(--muted); font-size: 13px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 12px; }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.row.end { justify-content: flex-end; }
.row.spread { justify-content: space-between; }

.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); padding: 10px 14px; border-radius: 10px; font-size: 14px;
  font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn-ghost { background: transparent; }
.btn.big { font-size: 18px; padding: 16px 20px; flex: 1; justify-content: center; }

.input {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 12px; border-radius: 10px; font-size: 16px; width: 100%;
}
.input.qty { width: 84px; flex: 0 0 auto; text-align: center; }
.manual-row { display: flex; gap: 8px; align-items: center; }
.manual-row .input:first-child { flex: 1; }

.stats { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 8px 12px; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--muted); }

.conn { margin-top: 10px; border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.conn summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.conn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.conn-grid .input { font-size: 14px; padding: 10px; }
@media (max-width: 420px) { .conn-grid { grid-template-columns: 1fr; } }

.scan-hint { font-size: 12px; color: var(--muted); flex: 1; }
.last-added { min-height: 20px; font-size: 14px; color: var(--primary-2); font-weight: 600; }

.table-wrap { overflow-x: auto; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--surface); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.diff-neg td.razlika { color: #f87171; font-weight: 700; }
tr.diff-pos td.razlika { color: #4ade80; font-weight: 700; }
tr.extra { background: rgba(217,119,6,.12); }
.qtybtn { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); width: 30px; height: 30px; border-radius: 8px; font-size: 16px; font-weight: 700; }

.totals { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.totals .stat b { font-size: 18px; }
.t-manjak b { color: #f87171; }
.t-visak b { color: #4ade80; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); padding: 6px 12px; border-radius: 999px; font-size: 13px; cursor: pointer; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
}
.tabbtn { background: none; border: none; color: var(--muted); padding: 10px 4px; font-size: 12px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.tabbtn span { font-size: 20px; }
.tabbtn.active { color: var(--primary-2); }

.dialog { border: none; border-radius: var(--radius); background: var(--surface); color: var(--text); width: min(92vw, 480px); padding: 16px; }
.dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog textarea { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 10px; font-family: ui-monospace, monospace; font-size: 13px; }
.dialog h3 { margin-top: 0; }

.scan-modal { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column; }
.scan-modal video { width: 100% !important; height: 100% !important; object-fit: cover; }
#reader { width: 100%; height: 100%; }
#reader img[alt="Info icon"], #reader button { display: none; }
.scan-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.scan-box { width: 72vw; max-width: 360px; height: 32vh; border: 3px solid var(--primary-2); border-radius: 14px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
.scan-toast { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); background: rgba(15,23,42,.9); padding: 10px 16px; border-radius: 10px; font-size: 15px; font-weight: 600; max-width: 90vw; text-align: center; }
.scan-controls { position: absolute; bottom: calc(20px + var(--safe-b)); left: 0; right: 0; display: flex; gap: 10px; align-items: center; justify-content: center; }

.toast {
  position: fixed; bottom: calc(80px + var(--safe-b)); left: 50%; transform: translateX(-50%);
  background: var(--surface-2); color: var(--text); padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600; z-index: 100; border: 1px solid var(--border);
  box-shadow: 0 6px 20px rgba(0,0,0,.4); max-width: 90vw; text-align: center;
}
.toast.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.toast.err { background: var(--danger); border-color: var(--danger); color: #fff; }
