* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* ===================== TOKENS ===================== */
:root {
  --ink:   #1d1d1f;
  --ink-2: #6e6e73;
  --ink-3: #aeaeb2;
  --line:        rgba(60,60,67,.13);
  --line-strong: rgba(60,60,67,.22);

  /* glass cards */
  --card:    rgba(255,255,255,.78);
  --card-hov: rgba(255,255,255,.92);
  --paper-2: rgba(255,255,255,.48);

  /* accent — sky blue */
  --accent:     #5ac8fa;
  --accent-2:   #70d0fc;
  --accent-ink: #0a3356;

  /* box tags */
  --boxtag:     #5ac8fa;
  --boxtag-dark:#32ade6;
  --boxtag-ink: #0a3356;

  /* semantic */
  --good:    #34c759;
  --good-bg: rgba(52,199,89,.14);
  --warn:    #ff9500;
  --warn-bg: rgba(255,149,0,.12);
  --danger:  #ff3b30;
  --danger-bg: rgba(255,59,48,.12);

  /* sidebar */
  --sidebar-glass:  rgba(255,255,255,.88);
  --sidebar-ink:    #1d1d1f;
  --sidebar-ink-2:  #8e8e93;
  --sidebar-hover:  rgba(90,200,250,.12);
  --sidebar-active: #5ac8fa;

  --shadow-sm: 0 2px 8px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.04);
  --shadow-md: 0 4px 24px rgba(0,0,0,.09), 0 2px 6px rgba(0,0,0,.05);
  --shadow-lg: 0 16px 48px rgba(0,0,0,.13), 0 4px 14px rgba(0,0,0,.07);

  --radius:    10px;
  --radius-lg: 14px;

  --safe-top:    env(safe-area-inset-top,    0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left,   0px);
  --safe-right:  env(safe-area-inset-right,  0px);
  --tap: 44px;
}

[data-theme="dark"] {
  --ink:   #f5f5f7;
  --ink-2: rgba(235,235,245,.65);
  --ink-3: rgba(235,235,245,.30);
  --line:        rgba(255,255,255,.10);
  --line-strong: rgba(255,255,255,.18);

  --card:    rgba(44,44,46,.75);
  --card-hov: rgba(58,58,60,.85);
  --paper-2: rgba(255,255,255,.06);

  --accent:     #0a84ff;
  --accent-2:   #409cff;
  --accent-ink: #ffffff;

  --boxtag:     #0a84ff;
  --boxtag-dark:#0066cc;
  --boxtag-ink: #ffffff;

  --good:    #30d158;
  --good-bg: rgba(48,209,88,.14);
  --warn:    #ffd60a;
  --warn-bg: rgba(255,214,10,.12);
  --danger:  #ff453a;
  --danger-bg: rgba(255,69,58,.14);

  --sidebar-glass:  rgba(18,18,20,.90);
  --sidebar-ink:    #f5f5f7;
  --sidebar-ink-2:  #8e8e93;
  --sidebar-hover:  rgba(255,255,255,.07);
  --sidebar-active: #0a84ff;

  --shadow-sm: 0 2px 8px rgba(0,0,0,.45);
  --shadow-md: 0 4px 24px rgba(0,0,0,.50);
  --shadow-lg: 0 16px 48px rgba(0,0,0,.65);
}

/* ===================== BASE ===================== */
/* Pastel gradient background — makes glass pop */
html {
  margin: 0; padding: 0;
  min-height: 100%;
  background: #e8f1f8;
}
html[data-theme="dark"] {
  background: #0d1117;
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display',
               'Helvetica Neue', Arial, sans-serif;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  margin: 0; padding: 0;
  background: transparent;
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

.mono { font-family: 'SF Mono', ui-monospace, Menlo, Monaco, monospace; }

/* ===================== SIDEBAR (desktop) ===================== */
.sidebar {
  background: var(--sidebar-glass);
  backdrop-filter: blur(40px) saturate(200%);
  -webkit-backdrop-filter: blur(40px) saturate(200%);
  color: var(--sidebar-ink);
  border-right: 1px solid rgba(255,255,255,.60);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  padding-top: calc(20px + var(--safe-top));
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  z-index: 20;
}
[data-theme="dark"] .sidebar {
  border-right-color: rgba(255,255,255,.10);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 20px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.logo {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 8px;
  font-size: 20px;
  font-weight: 700;
  flex-shrink: 0;
}

.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.brand-sub  { font-size: 11px; color: var(--sidebar-ink-2); text-transform: uppercase; letter-spacing: .08em; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  min-height: var(--tap);
  background: transparent;
  border: none;
  color: var(--sidebar-ink);
  font: inherit;
  font-weight: 500;
  text-align: left;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s ease;
}
.nav-item:hover { background: var(--sidebar-hover); }
.nav-item[hidden] { display: none !important; }
.nav-item.active {
  background: rgba(90,200,250,.28);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(90,200,250,.50);
  color: #0a3356;
}
.nav-item.active .nav-count { background: rgba(90,200,250,.40); color: #0a3356; }

.nav-icon  { font-size: 17px; opacity: .85; }
.nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-count {
  font-family: 'SF Mono', ui-monospace, Menlo, monospace;
  font-size: 11px;
  background: rgba(0,0,0,.08);
  color: var(--sidebar-ink-2);
  padding: 2px 8px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}
[data-theme="dark"] .nav-count { background: rgba(255,255,255,.10); }

.sidebar-footer {
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-info {
  font-size: 12px;
  color: var(--sidebar-ink-2);
  padding: 2px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#btn-logout {
  font-size: 12px;
  color: var(--sidebar-ink-2);
  justify-content: flex-start;
}

.theme-toggle {
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--sidebar-ink);
  padding: 8px 12px;
  min-height: var(--tap);
  min-width: var(--tap);
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  transition: background .12s ease;
}
.theme-toggle:hover { background: var(--sidebar-hover); }

/* ===================== MAIN ===================== */
.main {
  padding: 28px 36px 60px;
  padding-left:  calc(36px + var(--safe-left));
  padding-right: calc(36px + var(--safe-right));
  max-width: 1400px;
  min-width: 0;
}

.panel { display: none; }
.panel.active { display: block; animation: fade .18s ease; }

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

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.panel-head h1 {
  margin: 0 0 4px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.02em;
}
.subtitle { margin: 0; color: var(--ink-2); font-size: 13px; }
.panel-head .actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ===================== FILTERS ===================== */
.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  align-items: center;
}

.search {
  position: relative;
  flex: 1;
  min-width: 260px;
}
.search-icon {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--ink-3);
  font-size: 16px;
  pointer-events: none;
}
.search input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  min-height: var(--tap);
  border: 1px solid rgba(255,255,255,.70);
  border-radius: var(--radius);
  background: rgba(255,255,255,.72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  transition: border-color .12s;
}
[data-theme="dark"] .search input {
  background: rgba(255,255,255,.09);
  border-color: rgba(255,255,255,.14);
}
.search input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

select {
  padding: 10px 12px;
  min-height: var(--tap);
  border: 1px solid rgba(255,255,255,.70);
  border-radius: var(--radius);
  background: rgba(255,255,255,.72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  cursor: pointer;
  transition: border-color .12s;
}
[data-theme="dark"] select {
  background: rgba(255,255,255,.09);
  border-color: rgba(255,255,255,.14);
}
select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

.filter-toggle { display: none; position: relative; }
.filter-badge {
  position: absolute;
  top: -4px; right: -4px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  display: grid;
  place-items: center;
}
.filter-badge[hidden] { display: none !important; }

.filter-set {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.result-count {
  font-size: 12px;
  color: var(--ink-3);
  margin-bottom: 10px;
  font-family: 'SF Mono', ui-monospace, Menlo, monospace;
}

/* ===================== BUTTONS ===================== */
.btn {
  font: inherit;
  font-weight: 500;
  padding: 10px 14px;
  min-height: var(--tap);
  border: 1px solid rgba(255,255,255,.65);
  border-radius: var(--radius);
  background: rgba(255,255,255,.72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--ink);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .08s ease;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
[data-theme="dark"] .btn {
  background: rgba(255,255,255,.10);
  border-color: rgba(255,255,255,.16);
}
.btn:hover {
  background: rgba(255,255,255,.92);
  border-color: rgba(60,60,67,.25);
}
[data-theme="dark"] .btn:hover {
  background: rgba(255,255,255,.18);
  border-color: rgba(255,255,255,.25);
}
.btn:active { transform: scale(.97); }

.btn.primary {
  background: rgba(90,200,250,.28);
  backdrop-filter: blur(14px) saturate(200%);
  -webkit-backdrop-filter: blur(14px) saturate(200%);
  border: 1px solid rgba(90,200,250,.55);
  color: #0a3356;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.6), 0 2px 8px rgba(90,200,250,.25);
}
.btn.primary:hover {
  background: rgba(90,200,250,.42);
  border-color: rgba(90,200,250,.75);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.7), 0 4px 12px rgba(90,200,250,.35);
}
[data-theme="dark"] .btn.primary {
  background: rgba(90,200,250,.22);
  border-color: rgba(90,200,250,.45);
  color: #d0f0ff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.15), 0 2px 8px rgba(90,200,250,.20);
}
[data-theme="dark"] .btn.primary:hover {
  background: rgba(90,200,250,.35);
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
  backdrop-filter: none;
  color: var(--ink-2);
}
.btn.ghost:hover {
  background: rgba(0,0,0,.06);
  color: var(--ink);
  border-color: transparent;
}
[data-theme="dark"] .btn.ghost:hover { background: rgba(255,255,255,.08); }

.btn.danger {
  background: transparent;
  backdrop-filter: none;
  color: var(--danger);
  border-color: var(--danger);
}
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.sm { padding: 6px 12px; min-height: auto; font-size: 12.5px; }

.icon-btn {
  background: rgba(255,255,255,.72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,.65);
  color: var(--ink-2);
  min-width: 38px;
  min-height: 38px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: inline-grid;
  place-items: center;
  transition: background .1s ease, border-color .1s ease, color .1s ease, transform .08s ease;
}
[data-theme="dark"] .icon-btn {
  background: rgba(255,255,255,.10);
  border-color: rgba(255,255,255,.16);
}
.icon-btn:hover {
  background: rgba(255,255,255,.95);
  border-color: rgba(60,60,67,.28);
  color: var(--ink);
}
[data-theme="dark"] .icon-btn:hover {
  background: rgba(255,255,255,.20);
  border-color: rgba(255,255,255,.30);
}
.icon-btn:active { transform: scale(.94); }
.icon-btn.danger {
  color: var(--danger);
  border-color: rgba(255,59,48,.40);
  background: var(--danger-bg);
  backdrop-filter: none;
}
.icon-btn.danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }


tr:hover:not(:has(button:hover)) .icon-btn,
.cat-card:hover:not(:has(button:hover)) .icon-btn {
  border-color: rgba(60,60,67,.28);
}
[data-theme="dark"] tr:hover:not(:has(button:hover)) .icon-btn,
[data-theme="dark"] .cat-card:hover:not(:has(button:hover)) .icon-btn {
  border-color: rgba(255,255,255,.28);
}

/* ===================== TABLE ===================== */
.table-wrap {
  background: var(--card);
  backdrop-filter: blur(20px) saturate(200%);
  -webkit-backdrop-filter: blur(20px) saturate(200%);
  border: 1px solid rgba(255,255,255,.65);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
[data-theme="dark"] .table-wrap {
  border-color: rgba(255,255,255,.10);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.data-table thead th {
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-3);
  padding: 10px 14px;
  background: rgba(255,255,255,.50);
  border-bottom: 1px solid var(--line);
}
[data-theme="dark"] .data-table thead th {
  background: rgba(255,255,255,.05);
}

.data-table tbody tr {
  border-bottom: 1px solid var(--line);
  transition: background .08s ease;
}
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: rgba(90,200,250,.07); }
[data-theme="dark"] .data-table tbody tr:hover { background: rgba(255,255,255,.04); }

.data-table td {
  padding: 10px 14px;
  vertical-align: middle;
}

.col-name  { width: 28%; font-weight: 500; }
.col-desc  { width: 28%; color: var(--ink-2); font-size: 13px; }
.col-box   { width: 12%; }
.col-loc   { width: 14%; }
.col-cat   { width: 14%; }
.col-act   { width: 108px; text-align: right; white-space: nowrap; }

/* Boxes table */
.col-code  { width: 14%; }
.col-count { width: 10%; font-size: 13px; color: var(--ink-2); }

.cell-muted { color: var(--ink-3); font-style: italic; font-size: 12px; }

.box-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: 'SF Mono', ui-monospace, Menlo, monospace;
  font-weight: 700;
  font-size: 12.5px;
  background: rgba(90,200,250,.26);
  backdrop-filter: blur(10px) saturate(180%);
  -webkit-backdrop-filter: blur(10px) saturate(180%);
  color: #0a3356;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(90,200,250,.52);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.55);
  cursor: pointer;
  transition: transform .1s ease, background .1s;
}
.box-tag:hover {
  transform: translateY(-1px);
  background: rgba(90,200,250,.40);
}
[data-theme="dark"] .box-tag {
  background: rgba(90,200,250,.18);
  border-color: rgba(90,200,250,.38);
  color: #d0f0ff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.10);
}

.loc-tag { font-size: 12.5px; color: var(--ink-2); }
.loc-tag::before { content: "◈ "; color: var(--accent); }

.cat-tag {
  display: inline-block;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--good-bg);
  color: var(--good);
  font-weight: 500;
}

/* ===================== BOX GRID ===================== */
.box-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.box-card {
  background: var(--card);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255,255,255,.65);
  border-radius: var(--radius-lg);
  padding: 0;
  overflow: hidden;
  transition: transform .1s ease, box-shadow .12s ease;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
}
[data-theme="dark"] .box-card { border-color: rgba(255,255,255,.10); }
.box-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.box-card:active { transform: translateY(0); }

.box-card-head {
  background: linear-gradient(135deg, var(--boxtag) 0%, var(--boxtag-dark) 100%);
  padding: 16px 16px 14px;
  color: var(--boxtag-ink);
  position: relative;
}
.box-card-head::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: repeating-linear-gradient(90deg, transparent 0 6px, rgba(0,0,0,.15) 6px 10px);
}

.box-code {
  font-family: 'SF Mono', ui-monospace, Menlo, monospace;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: .02em;
  line-height: 1;
  margin-bottom: 6px;
  word-break: break-all;
}

.box-card-body {
  padding: 12px 16px 14px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.box-location {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
}
.box-location::before { content: "◈"; color: var(--boxtag-ink); opacity: .7; }

.box-desc {
  font-size: 12.5px;
  color: var(--ink-2);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  min-height: 32px;
}

.box-card-foot {
  border-top: 1px solid var(--line);
  padding: 6px 8px 6px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-3);
}
.box-item-count { font-family: 'SF Mono', ui-monospace, Menlo, monospace; font-weight: 600; color: var(--ink-2); }
.box-actions { display: flex; gap: 2px; }

/* ===================== CATEGORIES ===================== */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.profile-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow: hidden;
  max-width: 480px;
}
.profile-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  gap: 12px;
}
.profile-row:last-child { border-bottom: none; }
.profile-label { color: var(--ink-2); flex-shrink: 0; }
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; }
.cat-card {
  background: var(--card);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255,255,255,.65);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .12s;
}
[data-theme="dark"] .cat-card { border-color: rgba(255,255,255,.10); }
.cat-card:hover { box-shadow: var(--shadow-md); }
.cat-name { font-weight: 600; font-size: 14px; }
.cat-meta { font-size: 12px; color: var(--ink-3); font-family: 'SF Mono', ui-monospace, Menlo, monospace; }

/* ===================== EMPTY STATE ===================== */
.empty { text-align: center; padding: 60px 20px; color: var(--ink-3); }
.empty-icon { font-size: 40px; margin-bottom: 8px; opacity: .5; }

/* ===================== MODAL ===================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  backdrop-filter: blur(10px) saturate(160%);
  -webkit-backdrop-filter: blur(10px) saturate(160%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal.hidden { display: none; }

.modal-content {
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(40px) saturate(220%);
  -webkit-backdrop-filter: blur(40px) saturate(220%);
  border: 1px solid rgba(255,255,255,.75);
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  animation: pop .15s ease;
}
[data-theme="dark"] .modal-content {
  background: rgba(28,28,30,.92);
  border-color: rgba(255,255,255,.12);
}
@keyframes pop {
  from { opacity: 0; transform: scale(.97); }
  to   { opacity: 1; transform: none; }
}

.drag-handle { display: none; }

.modal-content > header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-content > header h2 { margin: 0; font-size: 16px; font-weight: 600; }

#modal-body { padding: 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ===================== BOX PICKER ===================== */
.box-picker { position: relative; }
.box-picker-input {
  width: 100%;
  padding: 11px 12px;
  min-height: var(--tap);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255,255,255,.60);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}
[data-theme="dark"] .box-picker-input { background: rgba(255,255,255,.08); }
.box-picker-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.box-picker-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: rgba(255,255,255,.95);
  backdrop-filter: blur(20px) saturate(200%);
  -webkit-backdrop-filter: blur(20px) saturate(200%);
  border: 1px solid rgba(255,255,255,.70);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-height: 220px;
  overflow-y: auto;
  z-index: 200;
}
[data-theme="dark"] .box-picker-dropdown {
  background: rgba(36,36,38,.96);
  border-color: rgba(255,255,255,.12);
}
.box-picker-dropdown.open { display: block; }
.box-picker-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
  transition: background .08s;
}
.box-picker-item:last-child { border-bottom: none; }
.box-picker-item:hover, .box-picker-item.selected { background: rgba(90,200,250,.14); }
.bpi-code {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  min-width: 70px;
}
.bpi-loc {
  font-size: 15px;
  color: var(--ink-2);
}

/* ===================== ITEM QUEUE ===================== */
.queue-section {
  display: none;
  margin-bottom: 14px;
  padding: 10px 12px;
  background: rgba(90,200,250,.10);
  border: 1px solid rgba(90,200,250,.30);
  border-radius: var(--radius-lg);
}
.queue-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-3);
  margin-bottom: 8px;
}
.queue-list { display: flex; flex-direction: column; gap: 4px; }
.queue-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  background: rgba(255,255,255,.65);
  border: 1px solid rgba(90,200,250,.25);
  border-radius: var(--radius);
  font-size: 13px;
}
[data-theme="dark"] .queue-item { background: rgba(255,255,255,.07); }
.queue-item-name { flex: 1; font-weight: 500; }
.queue-item-box {
  font-size: 11px;
  background: var(--boxtag);
  color: var(--boxtag-ink);
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid var(--boxtag-dark);
}
.queue-item .icon-btn {
  min-width: 26px;
  min-height: 26px;
  padding: 3px;
  font-size: 13px;
}

/* ===================== FORMS ===================== */
.form-row { margin-bottom: 14px; }
.form-row label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 6px;
}
.form-row label .req { color: var(--accent); margin-left: 2px; }

.form-row input,
.form-row select,
.form-row textarea {
  width: 100%;
  padding: 11px 12px;
  min-height: var(--tap);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255,255,255,.60);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}
[data-theme="dark"] .form-row input,
[data-theme="dark"] .form-row select,
[data-theme="dark"] .form-row textarea {
  background: rgba(255,255,255,.08);
}
.form-row textarea { min-height: 80px; resize: vertical; font-family: inherit; }
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  margin-top: 8px;
}

.discard-banner {
  background: var(--danger-bg);
  border: 1px solid rgba(255,59,48,.25);
  border-radius: var(--radius);
  padding: 12px 14px 4px;
  margin-bottom: 8px;
}

.bulk-rows { display: grid; gap: 8px; margin-bottom: 8px; }
.bulk-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr auto;
  gap: 6px;
  align-items: center;
}
.bulk-row-num {
  font-family: 'SF Mono', ui-monospace, Menlo, monospace;
  font-size: 11px;
  color: var(--ink-3);
  text-align: center;
}
.bulk-row input {
  padding: 9px 10px;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255,255,255,.60);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  min-width: 0;
}
[data-theme="dark"] .bulk-row input { background: rgba(255,255,255,.08); }

/* ===================== FAB ===================== */
.fab {
  display: none;
  position: fixed;
  right: calc(16px + var(--safe-right));
  bottom: calc(82px + var(--safe-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: rgba(90,200,250,.35);
  backdrop-filter: blur(14px) saturate(200%);
  -webkit-backdrop-filter: blur(14px) saturate(200%);
  border: 1px solid rgba(90,200,250,.60);
  color: #0a3356;
  font-size: 28px;
  line-height: 1;
  font-weight: 300;
  box-shadow: 0 4px 20px rgba(90,200,250,.45), 0 2px 6px rgba(0,0,0,.12);
  cursor: pointer;
  z-index: 30;
  transition: transform .12s ease, box-shadow .12s ease;
}
.fab:active { transform: scale(.94); box-shadow: 0 2px 10px rgba(90,200,250,.45); }

/* ===================== PAGINATION ===================== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
  padding: 4px;
  flex-wrap: wrap;
}
.pagination[hidden] { display: none; }
.page-size {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-2);
}
.page-size label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-3);
  font-weight: 600;
}
.page-size select {
  padding: 6px 10px;
  min-height: 36px;
  font-size: 14px;
  min-width: 0;
  width: auto;
}
.page-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}
.page-nav .btn {
  min-width: 36px;
  min-height: 36px;
  padding: 6px 10px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
}
.page-nav .btn:disabled {
  opacity: .4;
  cursor: not-allowed;
  pointer-events: none;
}
#page-info, #boxes-page-info {
  padding: 0 10px;
  font-size: 13px;
  color: var(--ink-2);
  min-width: 120px;
  text-align: center;
}

/* ===================== BOX POPOVER ===================== */
.box-popover {
  position: fixed;
  background: rgba(255,255,255,.90);
  backdrop-filter: blur(24px) saturate(200%);
  -webkit-backdrop-filter: blur(24px) saturate(200%);
  border: 1px solid rgba(255,255,255,.75);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 12px 14px;
  min-width: 220px;
  max-width: 320px;
  max-height: 360px;
  overflow-y: auto;
  z-index: 60;
  font-size: 13px;
  pointer-events: none;
  animation: popover-in .12s ease;
}
[data-theme="dark"] .box-popover {
  background: rgba(40,40,42,.92);
  border-color: rgba(255,255,255,.12);
}
@keyframes popover-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: none; }
}
.box-popover h4 {
  margin: 0 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-3);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.box-popover h4 .count { font-family: 'SF Mono', ui-monospace, Menlo, monospace; color: var(--ink-2); }
.box-popover ul { list-style: none; padding: 0; margin: 0; }
.box-popover li {
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}
.box-popover li:last-child { border-bottom: none; }
.box-popover .pop-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.box-popover .pop-cat {
  font-size: 11px;
  color: var(--good);
  background: var(--good-bg);
  padding: 1px 7px;
  border-radius: 999px;
  font-weight: 500;
  flex-shrink: 0;
}
.box-popover .pop-empty { color: var(--ink-3); font-style: italic; font-size: 12.5px; }

/* ===================== CONFIRM / TOAST ===================== */
.confirm-msg { margin: 0 0 6px; font-size: 14.5px; line-height: 1.5; color: var(--ink); }
.confirm-sub { margin: 0 0 4px; font-size: 13px; color: var(--ink-2); }

.toast {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(29,29,31,.88);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  color: #f5f5f7;
  border: 1px solid rgba(255,255,255,.15);
  padding: 10px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 200;
  font-size: 13.5px;
  font-weight: 500;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.hidden { display: none; }
.toast.error   { background: var(--danger); color: #fff; border-color: transparent; }
.toast.success { background: var(--good);   color: #fff; border-color: transparent; }

/* filter-backdrop není potřeba */
.filter-backdrop { display: none !important; }

/* ===================== LOGIN ===================== */
body.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  min-height: 100dvh;
}
.auth-card {
  background: var(--card);
  backdrop-filter: blur(40px) saturate(220%);
  -webkit-backdrop-filter: blur(40px) saturate(220%);
  border: 1px solid rgba(255,255,255,.65);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
}
[data-theme="dark"] .auth-card { border-color: rgba(255,255,255,.10); }
.auth-card .logo {
  margin: 0 auto 12px;
  width: 56px; height: 56px;
  font-size: 28px;
}
.auth-card h1 {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  margin: 0 0 4px;
  letter-spacing: -.01em;
}
.auth-card .subtitle { text-align: center; margin: 0 0 24px; }
.auth-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(255,59,48,.30);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13.5px;
  margin-bottom: 14px;
}
.auth-error[hidden] { display: none; }

/* ===================== ADMIN PANEL ===================== */
.admin-section { margin-bottom: 28px; }
.admin-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 10px;
  gap: 12px;
}
.admin-section-head h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -.01em;
}
.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--line-strong);
  color: var(--ink-2);
  font-weight: 500;
}
.badge.owner      { background: rgba(90,200,250,.25); color: #0a3356; }
.badge.superadmin { background: rgba(255,149,0,.20); color: #7a4500; }
[data-theme="dark"] .badge.owner      { color: #d0f0ff; }
[data-theme="dark"] .badge.superadmin { color: #ffb84d; }

/* =============================================================
   MOBILE (≤ 768px)
   ============================================================= */
@media (max-width: 768px) {
  body {
    grid-template-columns: 1fr;
    padding-bottom: calc(64px + var(--safe-bottom));
  }

  /* Bottom tab bar — glass */
  .sidebar {
    position: fixed;
    top: auto; bottom: 0; left: 0; right: 0;
    width: 100%; height: auto;
    flex-direction: row;
    padding: 6px 6px calc(6px + var(--safe-bottom));
    border-top: 1px solid var(--line);
    border-right: none;
    background: rgba(255,255,255,.85);
    backdrop-filter: blur(40px) saturate(200%);
    -webkit-backdrop-filter: blur(40px) saturate(200%);
    box-shadow: 0 -1px 0 var(--line), 0 -4px 16px rgba(0,0,0,.06);
    z-index: 40;
    transition: transform .3s ease;
  }
  .sidebar--hidden {
    transform: translateY(100%);
  }
  [data-theme="dark"] .sidebar {
    background: rgba(18,18,20,.88);
  }

  .brand, .sidebar-footer { display: none; }

  /* Superadmins only have the Administration tab — no point showing a
     one-button bottom bar on mobile. Hide the whole sidebar and reclaim the
     bottom safe-area padding. */
  body.is-superadmin { padding-bottom: var(--safe-bottom); }
  body.is-superadmin .sidebar { display: none; }

  .nav { flex-direction: row; flex: 1; gap: 0; }

  .nav-item {
    flex: 1;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    justify-items: center;
    gap: 2px;
    padding: 5px 3px;
    min-height: 38px;
    text-align: center;
    border-radius: 0;
    font-size: 11px;
    font-weight: 500;
    color: var(--ink);
  }
  .nav-item:hover { background: transparent; }
  .nav-item.active {
    background: rgba(90,200,250,.18);
    border-radius: 10px;
    color: #0a3356;
  }
  .nav-item.active .nav-icon { color: #32ade6; }
  .nav-item.active .nav-count { background: rgba(90,200,250,.40); color: #0a3356; }
  .nav-icon { font-size: 20px; }
  .nav-label { font-size: 11px; }
  .nav-count {
    position: absolute;
    top: 2px; right: 50%;
    transform: translateX(24px);
    font-size: 10px;
    padding: 1px 6px;
    min-width: 18px;
  }
  .nav-item { position: relative; }

  .main {
    padding: 16px calc(14px + var(--safe-left)) 20px calc(14px + var(--safe-right));
    max-width: none;
  }

  .panel-head { flex-direction: column; gap: 2px; margin-bottom: 10px; }
  .panel-head h1 { font-size: 20px; }
  .subtitle { font-size: 12px; }
  .panel-head .actions { display: none; }

  /* Sticky filters — glass */
  .filters {
    position: sticky;
    top: 0;
    background: rgba(232,241,248,.95);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    z-index: 10;
    padding: 8px 0;
    margin: -8px 0 6px;
    gap: 6px;
  }
  [data-theme="dark"] .filters {
    background: rgba(13,17,23,.95);
  }
  .search { min-width: 0; }
  .search input { padding: 8px 10px 8px 34px; min-height: 40px; }
  .result-count { font-size: 11px; margin-bottom: 6px; }

  .filter-toggle { display: inline-flex; }

  /* Filter order on mobile: Filtry, then drawer (filter-set), then Vyčistit
     visually inside the drawer (only shown when drawer is open). */
  .filter-toggle { order: 1; }
  .filter-set    { order: 2; }
  .filter-clear  { order: 3; display: none; }
  .filter-set.open ~ .filter-clear {
    display: inline-flex;
    width: 100%;
    flex: 0 0 100%;
  }

  /* Expandable filter panel */
  .filter-set {
    position: static;
    transform: none;
    transition: none;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    flex: 0 0 100%;
    background: transparent;
    backdrop-filter: none;
    border: none;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
  }
  .filter-set::before { display: none; }
  .filter-set.open { display: flex; }
  .filter-set select { width: 100%; font-size: 16px; }
  .filter-set .btn { width: 100%; }

  /* Mobile table → cards */
  .table-wrap {
    background: transparent;
    backdrop-filter: none;
    border: none;
    box-shadow: none;
    border-radius: 0;
    overflow: visible;
  }
  .data-table,
  .data-table thead,
  .data-table tbody,
  .data-table tr { display: block; width: 100%; }
  .data-table td { display: block; }
  .data-table thead { display: none; }

  .data-table tbody tr {
    background: var(--card);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(255,255,255,.65);
    border-radius: var(--radius-lg);
    margin-bottom: 6px;
    padding: 10px 12px;
    padding-right: 94px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 4px 8px;
    position: relative;
  }
  [data-theme="dark"] .data-table tbody tr { border-color: rgba(255,255,255,.10); }
  .data-table tbody tr:hover { background: var(--card); }
  .data-table td { width: auto; padding: 0; border: none; flex-shrink: 0; }

  .col-name, .col-code {
    flex: 1 1 100%;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
    font-weight: 600;
  }

  .col-act {
    position: absolute;
    right: 8px; top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 4px;
    align-items: center;
  }

  .col-desc { display: none; }
  .col-loc  { display: none; }
  .col-cat:has(.cell-muted) { display: none; }

  .col-box, .col-cat, .col-count { flex: 0 0 auto; }

  .data-table .box-tag { font-size: 11.5px; padding: 2px 7px; gap: 4px; }
  .data-table .cat-tag { font-size: 11.5px; padding: 2px 8px; }
  .col-count {
    font-size: 11.5px;
    color: var(--ink-3);
    font-family: 'SF Mono', ui-monospace, Menlo, monospace;
  }

  #boxes-table tbody tr { padding-right: 134px; }

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

  .fab { display: grid; place-items: center; }

  /* Modal as bottom sheet */
  .modal { align-items: flex-end; padding: 0; }
  .modal-content {
    max-width: 100%;
    max-height: 92dvh;
    border-radius: 18px 18px 0 0;
    animation: slideUp .24s ease;
  }
  @keyframes slideUp {
    from { transform: translateY(100%); }
    to   { transform: none; }
  }
  .drag-handle {
    display: block;
    width: 44px; height: 4px;
    background: var(--line-strong);
    border-radius: 2px;
    margin: 8px auto 0;
  }
  .modal-content > header { padding: 8px 16px 12px; }
  #modal-body { padding: 12px 16px calc(16px + var(--safe-bottom)); }

  .form-actions { flex-direction: column-reverse; gap: 8px; }
  .form-actions .btn { width: 100%; }

  .result-count { margin-left: 2px; }

  .bulk-row {
    grid-template-columns: 24px 1fr auto;
    row-gap: 4px;
  }
  .bulk-row input:nth-of-type(1) { grid-column: 2 / 3; }
  .bulk-row input:nth-of-type(2) { grid-column: 2 / 3; }
  .bulk-row .icon-btn { grid-column: 3 / 4; grid-row: 1 / 3; align-self: center; }
  .bulk-row-num { grid-row: 1 / 3; align-self: center; }

  .toast { bottom: calc(88px + var(--safe-bottom)); }

  .pagination { gap: 10px; justify-content: center; }
  .page-size { order: 2; }
  .page-nav  { order: 1; width: 100%; justify-content: center; }
  #page-info, #boxes-page-info { min-width: 80px; font-size: 12px; }

  .box-popover { display: none !important; }
}

@media (max-width: 360px) {
  .nav-label { display: none; }
  .nav-item  { grid-template-rows: 1fr; }
  .nav-count { position: static; transform: none; }
}
