:root {
  --bg:         #080c18;
  --surface:    #0e1528;
  --card:       #131c32;
  --border:     #1c2845;
  --border2:    #253358;
  --accent:     #8b5cf6;
  --accent-lt:  #a78bfa;
  --accent-dim: #2d1f5e;
  --blue:       #3b82f6;
  --blue-dim:   #1a3060;
  --text:       #e2e8f8;
  --muted:      #4a5a80;
  --danger:     #f87171;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; background: var(--bg); font-family: 'Plus Jakarta Sans', sans-serif; color: var(--text); overscroll-behavior: none; overflow-x: hidden; }

input, button { font-family: inherit; }
input::placeholder { color: var(--muted); }
input { caret-color: var(--accent); }
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

#app { width: 100%; max-width: 1200px; margin: 0 auto; height: 100%; display: flex; flex-direction: column; }

/* ── TOP BAR ── */
#topbar { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 14px; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
#topbar-left { display: flex; align-items: center; gap: 10px; }
#topbar-icon { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, var(--accent), var(--blue)); display: flex; align-items: center; justify-content: center; }
#topbar-title { font-size: 16px; font-weight: 700; }
#topbar-hub-link {
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-decoration: none; letter-spacing: 0.1em; text-transform: uppercase;
  transition: color 0.2s;
}
#topbar-hub-link:hover { color: var(--accent-lt); }
#back-btn { background: none; border: none; color: var(--muted); cursor: pointer; padding: 6px; display: none; align-items: center; }

/* ── CONTENT ── */
#content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; position: relative; }
.view { display: none; padding: 24px 20px; animation: fadeIn .18s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── PIN VIEW ── */
#view-pin { display: none; flex-direction: column; align-items: center; padding: 60px 20px 20px; }
#view-pin.active { display: flex; }
#pin-lock { width: 56px; height: 56px; border-radius: 50%; background: var(--accent-dim); border: 1px solid var(--accent); display: flex; align-items: center; justify-content: center; color: var(--accent-lt); margin-bottom: 20px; }
#pin-heading { font-size: 13px; color: var(--muted); margin-bottom: 28px; letter-spacing: .12em; }
#pin-dots { display: flex; gap: 14px; margin-bottom: 8px; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: transparent; border: 2px solid var(--border2); transition: all .15s; }
.dot.filled { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 10px #8b5cf680; }
#pin-error { color: var(--danger); font-size: 12px; margin-bottom: 12px; letter-spacing: .08em; display: none; }
#numpad { margin-top: 24px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: 260px; }
.nk { background: var(--card); border: 1px solid var(--border2); border-radius: 14px; padding: 18px 0; color: var(--text); font-size: 22px; font-weight: 600; cursor: pointer; font-family: monospace; transition: background .15s; }
.nk:active { background: var(--border2); }
.nk.empty { background: transparent; border: none; cursor: default; }

/* ── BOTTOM NAV ── */
#bottomnav { display: flex; border-top: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.nav-btn { flex: 1; padding: 13px 0 10px; background: none; border: none; border-top: 2px solid transparent; color: var(--muted); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 10px; letter-spacing: .1em; font-family: inherit; transition: color .2s, border-color .2s; }
.nav-btn.active { color: var(--accent-lt); border-top-color: var(--accent); }

/* ── SEARCH ── */
.search-wrap { position: relative; margin-bottom: 28px; }
.search-wrap input { width: 100%; background: var(--card); border: 1px solid var(--border2); border-radius: 14px; padding: 14px 46px 14px 18px; color: var(--text); font-size: 15px; outline: none; }
.search-icon { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }

/* ── SCANNER & MANUAL ── */
#scan-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
#scan-card { background: var(--card); border: 1px solid var(--border2); border-radius: 20px; padding: 32px 20px; text-align: center; cursor: pointer; transition: all .25s; height: 100%; }
#scan-card.scanning { background: linear-gradient(135deg, var(--accent-dim), var(--blue-dim)); border-color: var(--accent); }
#scan-icon-wrap { width: 64px; height: 64px; border-radius: 50%; background: linear-gradient(135deg, var(--accent-dim), var(--blue-dim)); display: flex; align-items: center; justify-content: center; margin: 0 auto 16px; color: var(--accent-lt); border: 1px solid var(--border2); }
#reader-wrap { display: none; width: 200px; height: 200px; margin: 0 auto 16px; border: 2px solid var(--accent); border-radius: 16px; overflow: hidden; position: relative; }
#reader-wrap.on { display: block; }
#html5-qr-reader { width: 100%; height: 100%; }
#scan-line { position: absolute; left: 12px; right: 12px; height: 2px; background: linear-gradient(90deg, transparent, var(--accent), transparent); top: 45%; animation: scanAnim 2s ease-in-out infinite; }
@keyframes scanAnim { 0%, 100% { top: 20%; opacity: .4; } 50% { top: 75%; opacity: 1; } }
.corner { position: absolute; width: 22px; height: 22px; }
.corner.tl { top: 8px; left: 8px; border-top: 3px solid var(--accent); border-left: 3px solid var(--accent); }
.corner.tr { top: 8px; right: 8px; border-top: 3px solid var(--accent); border-right: 3px solid var(--accent); }
.corner.bl { bottom: 8px; left: 8px; border-bottom: 3px solid var(--accent); border-left: 3px solid var(--accent); }
.corner.br { bottom: 8px; right: 8px; border-bottom: 3px solid var(--accent); border-right: 3px solid var(--accent); }

#manual-card { background: var(--card); border: 1px solid var(--border2); border-radius: 16px; padding: 18px 20px; display: flex; flex-direction: column; justify-content: center; height: 100%; }
.slabel { font-size: 11px; color: var(--muted); letter-spacing: .12em; margin-bottom: 14px; }
#manual-row { display: flex; gap: 10px; align-items: stretch; justify-content: center; }
#manual-input { width: 150px; flex-shrink: 0; background: var(--bg); border: 1px solid var(--border2); border-radius: 12px; padding: 14px 0; color: var(--accent-lt); font-size: 32px; font-weight: 800; text-align: center; outline: none; letter-spacing: .2em; font-family: monospace; transition: border-color .2s; }
#manual-input.rdy { border-color: var(--accent); }
#manual-go { width: 52px; flex-shrink: 0; background: var(--surface); border: none; border-radius: 12px; color: var(--muted); font-size: 22px; cursor: pointer; font-weight: 700; transition: all .2s; }
#manual-go.rdy { background: linear-gradient(135deg, var(--accent), var(--blue)); color: #fff; }

/* ── SEARCH RESULTS ── */
#search-results { display: none; margin-bottom: 24px; }
#results-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px;
}
.r-item { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.r-item:active { opacity: .7; }
.r-desc { font-size: 14px; color: var(--text); }
.r-box { font-size: 11px; color: var(--muted); margin-top: 3px; }
.r-code { background: var(--accent-dim); border-radius: 8px; padding: 5px 11px; font-size: 15px; font-weight: 700; color: var(--accent-lt); font-family: monospace; flex-shrink: 0; }
.no-results { color: var(--muted); text-align: center; padding: 48px 0; font-size: 14px; }

/* ── BOX VIEW ── */
#box-hero {
  background: linear-gradient(135deg, var(--accent-dim), var(--blue-dim));
  border-radius: 28px;
  padding: 48px 24px;
  text-align: center;
  margin-bottom: 24px;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
#box-hero::before {
  content: '';
  position: absolute;
  top: -50%; left: -50%; width: 200%; height: 200%;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.1) 0%, transparent 70%);
  pointer-events: none;
}
#box-code-display { 
  font-size: 88px; 
  font-weight: 800; 
  color: var(--accent-lt); 
  letter-spacing: 0.05em; 
  font-family: monospace; 
  line-height: 1;
  text-shadow: 0 0 30px rgba(139, 92, 246, 0.3);
}

.hero-badge-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
}

#box-location-display {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border2);
  border-radius: 12px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}
#box-location-display:hover { background: rgba(255, 255, 255, 0.1); border-color: var(--accent); }

#box-size-display {
  background: var(--accent-dim);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: 10px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 800;
  color: var(--accent-lt);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
  text-transform: uppercase;
}
#box-size-display:hover { transform: scale(1.05); border-color: var(--accent); }

/* ── QR CODE ── */
#qr-toggle-btn { width: 100%; background: var(--card); border: 1px solid var(--border2); border-radius: 12px; padding: 13px 16px; color: var(--muted); font-size: 13px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 20px; font-family: inherit; }
#qr-panel { display: none; background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 24px; text-align: center; margin-bottom: 16px; }
#qr-panel.on { display: block; }
#qrcode-el { display: flex; justify-content: center; }
#qrcode-el canvas, #qrcode-el img { border-radius: 8px; }
#qr-hint { font-size: 11px; color: var(--muted); margin-top: 12px; letter-spacing: .1em; }
#qr-close { background: none; border: none; color: var(--muted); font-size: 12px; cursor: pointer; margin-top: 8px; font-family: inherit; }

/* ── ITEMS ── */
#items-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
#items-count { font-size: 11px; color: var(--muted); letter-spacing: .12em; }
#delete-box-btn { background: none; border: 1px solid #7f1d1d; border-radius: 8px; padding: 4px 10px; color: var(--danger); font-size: 11px; cursor: pointer; font-family: inherit; }
#items-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 10px;
}
@media (max-width: 400px) {
  #items-list { grid-template-columns: 1fr; }
}
.item-row { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 13px 16px; display: flex; justify-content: space-between; align-items: center; }
.item-inner { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.item-text { font-size: 14px; color: var(--text); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.item-edit-input { width: 100%; background: var(--surface); border: 1px solid var(--accent); border-radius: 6px; padding: 6px 8px; color: var(--text); font-size: 14px; outline: none; font-family: inherit; }
.item-del { background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 6px; display: flex; flex-shrink: 0; margin-left: 8px; }
#add-item-row { display: flex; gap: 10px; margin-top: 16px; }
#new-item-input { flex: 1; background: var(--card); border: 1px solid var(--accent); border-radius: 10px; padding: 13px 14px; color: var(--text); font-size: 14px; outline: none; font-family: inherit; }
#add-item-btn { background: linear-gradient(135deg, var(--accent), var(--blue)); border: none; border-radius: 10px; padding: 0 16px; color: #fff; cursor: pointer; font-size: 22px; }

/* ── NEW BOX FAB ── */
/* ── NEW BOX FAB ── */
#new-box-fab { display: none; position: fixed; bottom: 80px; right: 20px; width: 52px; height: 52px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--blue)); border: none; color: #fff; font-size: 26px; cursor: pointer; box-shadow: 0 4px 20px #8b5cf640; align-items: center; justify-content: center; z-index: 10; }
@media (min-width: 1240px) {
  #new-box-fab { right: calc(50% - 600px + 20px); }
}

/* ── BOX LIST ── */
#list-count { font-size: 11px; color: var(--muted); letter-spacing: .12em; margin-bottom: 16px; }
#boxes-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}

.location-header {
  grid-column: 1 / -1;
  font-size: 12px;
  color: var(--accent-lt);
  letter-spacing: .12em;
  margin: 24px 0 8px 4px;
  font-weight: 800;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 10px;
}
.location-header::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.box-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}
.box-tile:hover {
  border-color: var(--accent);
  transform: translateY(-4px);
  background: var(--surface);
}
.box-tile:active {
  transform: scale(0.96);
}

.tile-code {
  font-size: 42px;
  font-weight: 800;
  color: var(--accent-lt);
  font-family: monospace;
  line-height: 1;
  margin-bottom: 16px;
  letter-spacing: 0.05em;
  text-shadow: 0 0 20px rgba(139, 92, 246, 0.2);
}

.tile-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}
.tile-info-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.tile-info-item svg {
  color: var(--muted);
  opacity: 0.7;
}

.tile-size-badge {
  margin-top: 4px;
  padding: 2px 8px;
  background: var(--accent-dim);
  border-radius: 6px;
  color: var(--accent-lt);
  font-weight: 700;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid rgba(139, 92, 246, 0.2);
}

/* ── LOADING / TOAST ── */
#toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--card); border: 1px solid var(--border2); border-radius: 12px; padding: 10px 20px; font-size: 13px; color: var(--text); opacity: 0; transition: all .3s; pointer-events: none; white-space: nowrap; z-index: 100; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border2); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── MODAL ── */
#modal-overlay { display: none; position: fixed; inset: 0; background: #00000080; z-index: 1000; align-items: center; justify-content: center; }
#modal-overlay.on { display: flex; }
#modal { background: var(--surface); border: 1px solid var(--border2); border-radius: 20px; padding: 28px 24px 32px; width: 90%; max-width: 430px; }
#modal h3 { font-size: 17px; font-weight: 700; margin-bottom: 20px; }
.modal-field { margin-bottom: 14px; }
.modal-field label { font-size: 11px; color: var(--muted); letter-spacing: .1em; display: block; margin-bottom: 8px; }
.modal-field input { width: 100%; background: var(--card); border: 1px solid var(--border2); border-radius: 10px; padding: 13px 14px; color: var(--text); font-size: 15px; outline: none; font-family: inherit; }
.modal-field input:focus { border-color: var(--accent); }
#modal-code-input { font-size: 28px; font-weight: 800; text-align: center; letter-spacing: .2em; font-family: monospace; color: var(--accent-lt); }
.modal-row { display: flex; gap: 12px; margin-top: 20px; }
.btn-cancel { flex: 1; background: var(--card); border: 1px solid var(--border2); border-radius: 12px; padding: 14px; color: var(--muted); cursor: pointer; font-size: 14px; font-family: inherit; }
.btn-confirm { flex: 2; background: linear-gradient(135deg, var(--accent), var(--blue)); border: none; border-radius: 12px; padding: 14px; color: #fff; cursor: pointer; font-size: 14px; font-weight: 700; font-family: inherit; }
