:root {
  --bg: #0a0b12;
  --bg-2: #0f111c;
  --panel: rgba(255, 255, 255, 0.04);
  --panel-solid: #14162200;
  --stroke: rgba(255, 255, 255, 0.08);
  --stroke-strong: rgba(255, 255, 255, 0.16);
  --text: #eef0f7;
  --muted: #9aa0b5;
  --faint: #666c85;
  --accent: #6d6bff;
  --accent-2: #22d3ee;
  --accent-3: #f472b6;
  --good: #34d399;
  --bad: #fb7185;
  --warn: #fbbf24;
  --radius: 18px;
  --shadow: 0 20px 60px -20px rgba(0, 0, 0, 0.7);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 12% -10%, rgba(109, 107, 255, 0.22), transparent 60%),
    radial-gradient(1000px 700px at 100% 0%, rgba(34, 211, 238, 0.14), transparent 55%),
    radial-gradient(900px 700px at 50% 120%, rgba(244, 114, 182, 0.12), transparent 55%),
    var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font-family: inherit; }
::selection { background: rgba(109, 107, 255, 0.4); }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); border-radius: 20px; }

/* ---------------- Login ---------------- */
.lock {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 50;
  background:
    radial-gradient(900px 600px at 30% 10%, rgba(109,107,255,.25), transparent 60%),
    radial-gradient(700px 600px at 80% 90%, rgba(34,211,238,.16), transparent 55%),
    var(--bg);
}
.lock.hidden { display: none; }
.lock-card {
  width: min(400px, 100%);
  background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.02));
  border: 1px solid var(--stroke);
  border-radius: 24px;
  padding: 38px 32px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  text-align: center;
  animation: rise .5s cubic-bezier(.2,.8,.2,1);
}
.lock-logo {
  width: 64px; height: 64px;
  margin: 0 auto 18px;
  border-radius: 18px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 12px 30px -8px rgba(109,107,255,.6);
}
.lock-logo svg { width: 34px; height: 34px; stroke: #fff; }
.lock h1 { margin: 0 0 6px; font-size: 22px; letter-spacing: -.02em; }
.lock p { margin: 0 0 24px; color: var(--muted); font-size: 14px; }
.pw-row { position: relative; }
.pw-row input {
  width: 100%;
  padding: 15px 16px;
  border-radius: 14px;
  border: 1px solid var(--stroke-strong);
  background: rgba(0,0,0,.25);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  text-align: center;
  letter-spacing: .12em;
}
.pw-row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(109,107,255,.18);
}
.pw-show {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 12px; cursor: pointer;
  color: var(--muted); font-size: 13.5px; font-weight: 500;
  user-select: none; transition: color .2s;
}
.pw-show:hover { color: var(--text); }
.pw-show input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.lock button {
  margin-top: 14px;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #8b5cff);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s, box-shadow .2s, filter .2s;
  box-shadow: 0 12px 26px -10px rgba(109,107,255,.7);
}
.lock button:hover { filter: brightness(1.07); }
.lock button:active { transform: translateY(1px) scale(.995); }
.lock-error {
  margin-top: 14px; min-height: 18px;
  color: var(--bad); font-size: 13.5px; font-weight: 500;
}
.shake { animation: shake .4s; }

/* ---------------- App shell ---------------- */
.app { max-width: 1180px; margin: 0 auto; padding: 22px 22px 80px; }
.app.hidden { display: none; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 22px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .mark {
  width: 42px; height: 42px; border-radius: 13px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 24px -10px rgba(109,107,255,.7);
}
.brand .mark svg { width: 24px; height: 24px; stroke: #fff; }
.brand h1 { font-size: 18px; margin: 0; letter-spacing: -.02em; }
.brand small { color: var(--faint); font-size: 12px; }
.spacer { flex: 1; }

.logout {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: 11px;
  border: 1px solid var(--stroke);
  background: var(--panel); color: var(--muted);
  font-size: 13px; cursor: pointer;
  transition: color .2s, border-color .2s, background .2s;
}
.logout:hover { color: var(--text); border-color: var(--stroke-strong); background: rgba(255,255,255,.06); }

/* Tabs */
.tabs {
  display: inline-flex; padding: 5px; gap: 4px;
  background: var(--panel); border: 1px solid var(--stroke);
  border-radius: 14px; margin-bottom: 26px;
  backdrop-filter: blur(10px);
}
.tab {
  border: none; background: transparent; color: var(--muted);
  padding: 10px 20px; border-radius: 10px; cursor: pointer;
  font-size: 14px; font-weight: 500; letter-spacing: -.01em;
  display: inline-flex; align-items: center; gap: 9px;
  transition: color .2s, background .2s;
}
.tab svg { width: 17px; height: 17px; }
.tab:hover { color: var(--text); }
.tab.active {
  color: #fff;
  background: linear-gradient(135deg, rgba(109,107,255,.9), rgba(139,92,255,.85));
  box-shadow: 0 10px 24px -12px rgba(109,107,255,.8);
}
.tab .badge {
  font-size: 11px; font-weight: 700;
  background: rgba(0,0,0,.28); padding: 2px 8px; border-radius: 20px;
}

.view { display: none; animation: fade .35s ease; }
.view.active { display: block; }

/* Panels / cards */
.panel {
  background: linear-gradient(180deg, rgba(255,255,255,.045), rgba(255,255,255,.015));
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 22px;
  backdrop-filter: blur(10px);
}
.panel + .panel { margin-top: 22px; }
.panel-title {
  display: flex; align-items: center; gap: 10px;
  font-size: 15px; font-weight: 600; margin: 0 0 18px;
}
.panel-title .dot { width: 8px; height: 8px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.panel-title .count { margin-left: auto; color: var(--faint); font-size: 13px; font-weight: 500; }

/* Forms */
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 7px; font-weight: 500; }
.input {
  width: 100%; padding: 13px 14px; border-radius: 12px;
  border: 1px solid var(--stroke-strong);
  background: rgba(0,0,0,.22); color: var(--text);
  font-size: 15px; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(109,107,255,.16); }
.input::placeholder { color: var(--faint); }

.add-form { display: flex; flex-direction: column; gap: 16px; }
.add-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 620px) { .add-fields { grid-template-columns: 1fr; } }
.add-form .btn-primary { width: 100%; }

/* Dropzone */
.drop {
  position: relative;
  border: 1.5px dashed var(--stroke-strong);
  border-radius: 12px;
  min-height: 92px;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 14px; cursor: pointer;
  transition: border-color .2s, background .2s;
  color: var(--muted);
}
.drop:hover, .drop.over { border-color: var(--accent); background: rgba(109,107,255,.07); }
.drop input[type=file] { display: none; }
.drop .thumb {
  width: 66px; height: 66px; border-radius: 10px; object-fit: cover;
  background: rgba(255,255,255,.05); flex: none;
  border: 1px solid var(--stroke);
}
.drop .thumb.empty { display: grid; place-items: center; }
.drop .thumb.empty svg { width: 26px; height: 26px; stroke: var(--faint); }
.drop .drop-text b { color: var(--text); font-weight: 600; display: block; font-size: 13.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.drop .drop-text span { font-size: 12px; color: var(--faint); }

/* PDF picker */
.pdfdrop .pdf-ic {
  width: 66px; height: 66px; border-radius: 10px; flex: none;
  display: grid; place-items: center;
  background: rgba(251,113,133,.08); border: 1px solid rgba(251,113,133,.2);
  color: var(--bad);
}
.pdfdrop .pdf-ic svg { width: 30px; height: 30px; }
.pdfdrop.has-file { border-style: solid; border-color: rgba(52,211,153,.4); background: rgba(52,211,153,.05); }
.pdfdrop.has-file .pdf-ic { background: rgba(52,211,153,.1); border-color: rgba(52,211,153,.3); color: var(--good); }
.pdfdrop.has-file .drop-text b { color: var(--good); }
.drop-text { min-width: 0; }

/* PDF download button on card */
.pdf-dl {
  width: 100%; margin-bottom: 10px;
  background: rgba(251,113,133,.1); color: #ff9db0; border: 1px solid rgba(251,113,133,.22);
  text-decoration: none;
}
.pdf-dl:hover { background: rgba(251,113,133,.18); color: #ffb3c2; border-color: rgba(251,113,133,.35); }

/* PDF block in edit modal */
.pdf-current { margin-bottom: 10px; }
.pdf-link {
  display: inline-flex; align-items: center; gap: 8px;
  color: #ff9db0; text-decoration: none; font-size: 13.5px; font-weight: 600;
  padding: 8px 12px; border-radius: 10px;
  background: rgba(251,113,133,.1); border: 1px solid rgba(251,113,133,.22);
  transition: background .2s, color .2s;
}
.pdf-link:hover { background: rgba(251,113,133,.18); color: #ffb3c2; }
.pdf-none { font-size: 13px; color: var(--faint); font-style: italic; }

/* Buttons */
.btn {
  border: none; cursor: pointer; font-weight: 600; font-size: 14px;
  padding: 13px 22px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  transition: transform .12s, filter .2s, background .2s, border-color .2s, color .2s;
  white-space: nowrap;
}
.btn svg { width: 17px; height: 17px; }
.btn:active { transform: translateY(1px) scale(.99); }
.btn-primary {
  color: #fff; background: linear-gradient(135deg, var(--accent), #8b5cff);
  box-shadow: 0 12px 26px -12px rgba(109,107,255,.8);
  height: 48px;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost {
  background: var(--panel); color: var(--muted); border: 1px solid var(--stroke);
}
.btn-ghost:hover { color: var(--text); border-color: var(--stroke-strong); background: rgba(255,255,255,.05); }
.btn-danger { background: rgba(251,113,133,.12); color: var(--bad); border: 1px solid rgba(251,113,133,.25); }
.btn-danger:hover { background: rgba(251,113,133,.2); }
.btn-warn { background: rgba(251,191,36,.12); color: var(--warn); border: 1px solid rgba(251,191,36,.25); }
.btn-warn:hover { background: rgba(251,191,36,.2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { padding: 8px 12px; font-size: 12.5px; border-radius: 10px; }

/* Barcode grid */
.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.card {
  background: linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,.02));
  border: 1px solid var(--stroke); border-radius: 16px;
  overflow: hidden; transition: transform .18s, border-color .2s, box-shadow .2s;
  animation: rise .4s ease both;
  display: flex; flex-direction: column;
}
.card:hover { transform: translateY(-3px); border-color: var(--stroke-strong); box-shadow: var(--shadow); }
.card .photo {
  aspect-ratio: 4 / 3; width: 100%; object-fit: cover; display: block;
  background: repeating-conic-gradient(rgba(255,255,255,.03) 0% 25%, transparent 0% 50%) 50% / 22px 22px;
}
.card .photo.empty { display: grid; place-items: center; color: var(--faint); }
.card .photo.empty svg { width: 40px; height: 40px; stroke: currentColor; }
.card .body { padding: 13px 14px 14px; flex: 1; display: flex; flex-direction: column; }
.card .pname {
  font-size: 14.5px; font-weight: 600; letter-spacing: -.01em;
  margin-bottom: 5px; line-height: 1.3; min-height: 2.6em;
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.card .pname-empty { color: var(--faint); font-weight: 500; font-style: italic; }
.card .code {
  font-family: "SF Mono", ui-monospace, "Cascadia Code", monospace;
  font-size: 13px; font-weight: 600; letter-spacing: .01em;
  color: var(--muted);
  word-break: break-all; margin-bottom: 12px;
}
.card .actions { display: flex; gap: 8px; margin-top: auto; }
.card .actions .btn-sm { flex: 1; }

/* Empty state */
.empty-state {
  text-align: center; padding: 46px 20px; color: var(--faint);
}
.empty-state svg { width: 46px; height: 46px; stroke: currentColor; opacity: .6; margin-bottom: 12px; }
.empty-state b { display: block; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.empty-state span { font-size: 13px; }

/* ---------------- Picking ---------------- */
.scan-label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; font-weight: 500; }
.scan-row { display: flex; gap: 12px; align-items: stretch; }
.scan-row .scan-input { flex: 1; }
.scan-row .btn { flex: none; height: 52px; }
@media (max-width: 640px) { .scan-row { flex-direction: column; } .scan-row .btn { width: 100%; } }
.scan-input {
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 18px; letter-spacing: .04em; height: 52px;
}
.scan-hint { font-size: 12px; color: var(--faint); margin-top: 10px; display: flex; align-items: center; gap: 6px; }
.scan-hint svg { width: 14px; height: 14px; stroke: var(--good); }

.pick-cols { display: grid; grid-template-columns: 320px 1fr; gap: 22px; align-items: stretch; margin-top: 22px; }
@media (max-width: 900px) { .pick-cols { grid-template-columns: 1fr; align-items: start; } }

/* log panel fills column height so both panels line up; toolbar pinned to bottom */
.log-panel { display: flex; flex-direction: column; }
.log-panel .log { flex: 1 1 0; min-height: 140px; }
@media (max-width: 900px) { .log-panel .log { flex: none; min-height: 0; max-height: 440px; } }

/* scan log */
.log { overflow: auto; margin: 0 -6px; padding: 2px 6px; }
.log-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 11px;
  border: 1px solid var(--stroke);
  background: rgba(255,255,255,.02);
  margin-bottom: 8px;
  animation: slideIn .3s ease both;
}
.log-item.dupe-flash { animation: flashHit .5s ease; }
.log-item .num {
  width: 30px; height: 30px; flex: none; border-radius: 9px;
  display: grid; place-items: center; font-size: 12.5px; font-weight: 700;
  background: rgba(109,107,255,.14); color: #b7b6ff;
}
.log-item .lmeta { flex: 1; min-width: 0; }
.log-item .lname { font-size: 13.5px; font-weight: 600; line-height: 1.25; margin-bottom: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-item .lcode {
  font-family: "SF Mono", ui-monospace, monospace; font-size: 13px;
  color: var(--muted); word-break: break-all;
}
.log-item .unknown {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--warn); background: rgba(251,191,36,.12);
  padding: 3px 7px; border-radius: 6px; flex: none;
}

/* summary table */
.tbl-wrap { overflow-x: auto; }
table.summary { width: 100%; border-collapse: collapse; font-size: 14px; }
table.summary th {
  text-align: left; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--faint); font-weight: 600;
  padding: 0 14px 12px; border-bottom: 1px solid var(--stroke);
}
table.summary td { padding: 12px 14px; border-bottom: 1px solid var(--stroke); vertical-align: middle; }
table.summary tr:last-child td { border-bottom: none; }
table.summary .t-photo img,
table.summary .t-photo .noimg {
  width: 54px; height: 54px; border-radius: 10px; object-fit: cover;
  border: 1px solid var(--stroke); background: rgba(255,255,255,.04);
  display: block;
}
table.summary .t-photo .noimg { display: grid; place-items: center; color: var(--faint); }
table.summary .t-photo .noimg svg { width: 22px; height: 22px; stroke: currentColor; }
table.summary .t-name { font-weight: 600; font-size: 14px; letter-spacing: -.01em; }
table.summary .t-name-empty { color: var(--faint); font-weight: 500; }
table.summary .t-code { font-family: "SF Mono", ui-monospace, monospace; font-weight: 600;
  font-size: 13px; color: var(--muted); word-break: break-all; }
table.summary .t-code .warn-tag { display: inline-block; margin-left: 8px; font-family: var(--font);
  font-size: 10px; font-weight: 700; color: var(--warn); background: rgba(251,191,36,.12);
  padding: 2px 7px; border-radius: 6px; vertical-align: middle; }
table.summary .t-qty { text-align: right; }
.qty-pill {
  display: inline-flex; align-items: center; justify-content: center; min-width: 44px;
  padding: 6px 12px; border-radius: 10px; font-weight: 700; font-size: 15px;
  background: linear-gradient(135deg, rgba(52,211,153,.16), rgba(34,211,238,.16));
  color: #7ff2c9; border: 1px solid rgba(52,211,153,.22);
}
table.summary tfoot td {
  padding-top: 16px; font-weight: 700; font-size: 15px; border-top: 2px solid var(--stroke-strong);
}
table.summary tfoot .total-num { color: var(--accent-2); font-size: 20px; }

.pick-toolbar { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.pick-toolbar .btn { width: 100%; }

.stat-row { display: flex; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.stat {
  flex: 1; min-width: 120px;
  background: linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,.015));
  border: 1px solid var(--stroke); border-radius: 14px; padding: 14px 16px;
}
.stat .k { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.stat.accent .v { background: linear-gradient(135deg, var(--accent-2), var(--good)); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------------- Modal ---------------- */
.modal-back {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(4,5,10,.6); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 20px;
  animation: fade .2s ease;
}
.modal-back.hidden { display: none; }
.modal {
  width: min(440px, 100%);
  background: linear-gradient(180deg, #171a28, #12141f);
  border: 1px solid var(--stroke-strong); border-radius: 20px;
  padding: 24px; box-shadow: var(--shadow);
  animation: rise .3s cubic-bezier(.2,.8,.2,1);
}
.modal h3 { margin: 0 0 18px; font-size: 17px; }
.modal .field + .field, .modal .field + .drop-wrap { margin-top: 16px; }
.modal .modal-actions { display: flex; gap: 10px; margin-top: 22px; }
.modal .modal-actions .btn { flex: 1; }

/* Toasts */
.toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 10px; z-index: 90; align-items: center; }
.toast {
  padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 500;
  background: #1b1e2e; border: 1px solid var(--stroke-strong); color: var(--text);
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 10px;
  animation: toastIn .3s ease both;
}
.toast.ok { border-color: rgba(52,211,153,.4); }
.toast.ok svg { stroke: var(--good); }
.toast.err { border-color: rgba(251,113,133,.4); }
.toast.err svg { stroke: var(--bad); }
.toast svg { width: 18px; height: 18px; flex: none; }
.toast.hide { animation: toastOut .3s ease both; }

/* ---------------- Hover zoom preview ---------------- */
img[data-zoom] { cursor: zoom-in; }
.zoom-layer {
  position: fixed; top: 0; left: 0; z-index: 100;
  pointer-events: none; opacity: 0; visibility: hidden;
  transform: scale(.9); transform-origin: center;
  transition: opacity .14s ease, transform .14s ease;
  padding: 8px; border-radius: 18px;
  background: linear-gradient(180deg, rgba(30,33,48,.96), rgba(18,20,30,.96));
  border: 1px solid var(--stroke-strong);
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.85);
  backdrop-filter: blur(8px);
}
.zoom-layer.show { opacity: 1; visibility: visible; transform: scale(1); }
.zoom-layer img {
  display: block; border-radius: 11px;
  width: clamp(220px, 34vw, 420px); height: auto;
  max-height: 74vh; object-fit: contain;
}

/* Animations */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%,60%{transform:translateX(-8px)} 40%,80%{transform:translateX(8px)} }
@keyframes flashHit { 0%{ background: rgba(52,211,153,.25); } 100%{ background: rgba(255,255,255,.02); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(16px); } }
