:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #0284c7;
  --accent-contrast: #ffffff;
  --ok: #16a34a;
  --warn: #b45309;
  --danger: #dc2626;
  --radius: 8px;
  --sidebar-w: 252px;
  --sidebar-w-collapsed: 60px;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel2: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-contrast: #082f49;
  --ok: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: width 0.15s ease;
  z-index: 20;
}
body.sidebar-collapsed #sidebar { width: var(--sidebar-w-collapsed); }
body.sidebar-collapsed #sidebar .label { display: none; }
body.sidebar-collapsed .sidebar-top { flex-direction: column; justify-content: center; gap: 6px; }
body.sidebar-collapsed .brand { display: none; }
body.sidebar-collapsed #nav a { justify-content: center; padding: 9px 0; }
body.sidebar-collapsed #userbox { align-items: center; }
body.sidebar-collapsed .user-row { justify-content: center; }

.sidebar-top {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}
#sidebar-toggle {
  background: none;
  color: var(--text);
  padding: 6px;
  font-size: 1rem;
  flex-shrink: 0;
}
#sidebar-toggle:hover { background: var(--panel2); }

.brand { font-weight: 700; font-size: 1rem; display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }

#theme-toggle, #lang-toggle {
  background: none;
  color: var(--text);
  padding: 6px 8px;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}
#theme-toggle { font-size: 1rem; padding: 6px; }
#theme-toggle:hover, #lang-toggle:hover { background: var(--panel2); }

#mobile-menu-btn {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 25;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
}

#sidebar-backdrop { display: none; }

#nav { display: flex; flex-direction: column; gap: 2px; padding: 8px; flex: 1; overflow-y: auto; }
#nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  text-decoration: none;
  padding: 9px 10px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
}
#nav a .icon { flex-shrink: 0; width: 1.2em; text-align: center; }
#nav a.active, #nav a:hover { background: var(--panel2); color: var(--text); }

.nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  color: var(--muted);
  text-decoration: none;
  padding: 9px 10px;
  border-radius: var(--radius);
  border: none;
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: inherit;
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
}
.nav-group-toggle:hover { background: var(--panel2); color: var(--text); }
.nav-group-toggle .icon { flex-shrink: 0; width: 1.2em; text-align: center; }
.nav-group-toggle .label { flex: 1; text-align: left; }
.nav-group-toggle .chevron { flex-shrink: 0; transition: transform 0.15s ease; }
.nav-group.open .nav-group-toggle .chevron { transform: rotate(90deg); }

.nav-children { display: none; flex-direction: column; gap: 2px; padding-left: 14px; margin-top: 2px; }
.nav-group.open .nav-children { display: flex; }
.nav-children a {
  display: flex;
  align-items: center;
  color: var(--muted);
  text-decoration: none;
  padding: 7px 10px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  border-left: 2px solid var(--border);
}
.nav-children a.active, .nav-children a:hover { background: var(--panel2); color: var(--text); border-left-color: var(--accent); }

body.sidebar-collapsed .nav-group-toggle .label,
body.sidebar-collapsed .nav-group-toggle .chevron { display: none; }
body.sidebar-collapsed .nav-group-toggle { justify-content: center; padding: 9px 0; }
body.sidebar-collapsed .nav-children { display: none !important; }

#userbox {
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border);
}
#userbox a, #userbox .user-row { display: flex; align-items: center; gap: 8px; text-decoration: none; color: inherit; }
#userbox .icon { flex-shrink: 0; width: 1.2em; text-align: center; }
#userbox button { font-size: 0.8rem; display: flex; align-items: center; gap: 8px; justify-content: center; width: 100%; }

.app-version {
  font-size: 0.7rem;
  color: var(--muted);
  opacity: 0.7;
  text-align: center;
  padding: 6px 10px 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
body.sidebar-collapsed .app-version { display: none; }

#app { flex: 1; min-width: 0; padding: 16px; max-width: 1100px; margin: 0 auto; width: 100%; }

@media (max-width: 860px) {
  #mobile-menu-btn { display: block; }
  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 240px;
    transform: translateX(-100%);
    box-shadow: 2px 0 16px rgba(0,0,0,0.25);
  }
  body.sidebar-collapsed #sidebar { width: 240px; }
  body.sidebar-collapsed #sidebar .label { display: initial; }
  body.sidebar-collapsed .brand { display: flex; }
  body.sidebar-collapsed #nav a { justify-content: flex-start; padding: 9px 10px; }
  body.sidebar-collapsed .nav-group-toggle { justify-content: flex-start; padding: 9px 10px; }
  body.sidebar-collapsed .nav-group-toggle .label,
  body.sidebar-collapsed .nav-group-toggle .chevron { display: initial; }
  body.sidebar-collapsed .nav-group.open .nav-children { display: flex !important; }
  body.sidebar-open #sidebar { transform: translateX(0); }
  #sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 15;
  }
  body.sidebar-open #sidebar-backdrop { display: block; }
  body.sidebar-open #mobile-menu-btn { display: none; }
  #app { padding-top: 56px; }
}

h1 { font-size: 1.3rem; margin: 0 0 12px; }
h2 { font-size: 1.05rem; margin: 20px 0 8px; }
h3 { font-size: 0.95rem; margin: 12px 0 6px; color: var(--muted); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

/* Dashboard quick actions: big thumb-sized shortcuts (Scan / Stock Cart /
   Movements / Print Queue) so the day-to-day scan -> putaway/pick loop
   doesn't require opening the sidebar first, especially on a phone where
   that's an extra tap into a hamburger menu. */
.quick-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.quick-tile {
  flex: 1 1 130px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 84px;
  padding: 16px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  font-size: 0.85rem;
  text-align: center;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.quick-tile:hover { border-color: var(--accent); }
.quick-tile:active { transform: scale(0.97); }
.quick-tile .qt-icon { font-size: 1.7rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; }
tr:hover td { background: var(--panel2); }
.table-wrap { overflow-x: auto; }

label { display: block; font-size: 0.85rem; color: var(--muted); margin: 8px 0 3px; }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}
textarea { min-height: 70px; resize: vertical; }

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 8px 14px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
  font-size: 0.9rem;
}
button.secondary { background: var(--panel2); color: var(--text); }
button.danger { background: var(--danger); color: var(--accent-contrast); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button + button { margin-left: 6px; }

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

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge.ok { background: rgba(74,222,128,0.15); color: var(--ok); }
.badge.warn { background: rgba(251,191,36,0.15); color: var(--warn); }
.badge.danger { background: rgba(248,113,113,0.15); color: var(--danger); }
.badge.muted { background: rgba(148,163,184,0.15); color: var(--muted); }
a.badge { text-decoration: none; transition: background 0.15s ease; }
a.badge.muted:hover { background: rgba(148,163,184,0.3); color: var(--text); }

.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }

.zone-map { display: flex; flex-direction: column; gap: 14px; }
.zone-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--panel2);
}
.zone-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-weight: 700;
  font-size: 1rem;
  padding-bottom: 8px;
  cursor: pointer;
}
details[open] > .zone-header { margin-bottom: 10px; border-bottom: 1px dashed var(--border); }
.zone-icon { font-size: 1.1rem; }
.zone-grid { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; }

.rack-block {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--panel);
  min-width: 130px;
}
.rack-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-weight: 600;
  font-size: 0.82rem;
}
details.rack-block[open] > .rack-header { margin-bottom: 6px; }
.rack-children { display: flex; flex-wrap: wrap; gap: 6px; }

/* zone-header/rack-header double as <summary> when their block is
   collapsible -- suppress the native disclosure marker in favor of the
   ▸/▾ .disclosure span so the two block types (collapsible vs a plain leaf
   card with a photo) look the same either way. */
summary.zone-header, summary.rack-header { list-style: none; }
summary.zone-header::-webkit-details-marker, summary.rack-header::-webkit-details-marker { display: none; }
.disclosure {
  display: inline-block;
  transition: transform 0.15s ease;
  color: var(--muted);
  flex-shrink: 0;
}
details[open] > summary .disclosure { transform: rotate(90deg); }

.loc-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.78rem;
  white-space: nowrap;
}

/* Lives inside .zone-header/.rack-header, which are flex + flex-wrap --
   flex-basis:100% forces it onto its own full-width row instead of sitting
   inline with the code/badge/edit-button text, and order:-1 puts that row
   first regardless of where the <img> falls in the markup. */
.loc-thumb {
  display: block;
  width: 100%;
  height: 100px;
  object-fit: cover;
  border-radius: 4px;
  flex: 0 0 100%;
  order: -1;
}
/* Once expanded, the full-resolution .loc-photo (right below the summary)
   shows the same photo bigger and sharper -- keeping the thumbnail visible
   too would just be the same image twice. */
details[open] > summary .loc-thumb { display: none; }

.loc-photo {
  display: block;
  width: 100%;
  max-height: 140px;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 8px;
}
#loc-edit-preview .loc-photo { max-height: 180px; }

.loc-edit-btn {
  margin-left: auto;
  padding: 2px 6px;
  font-size: 0.75rem;
  line-height: 1.4;
  flex-shrink: 0;
}
.loc-chip .loc-edit-btn { margin-left: 2px; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 200;
}
.modal-card { width: 100%; max-width: 420px; margin: 0; max-height: calc(100vh - 32px); overflow-y: auto; }
#scan-modal-video { width: 100%; border-radius: var(--radius); background: #000; }

.scan-highlight { outline: 2px solid var(--accent); outline-offset: 2px; transition: outline-color 0.3s ease; }

.muted { color: var(--muted); }
.error-box { background: rgba(248,113,113,0.1); border: 1px solid var(--danger); color: var(--danger); padding: 10px; border-radius: var(--radius); margin-bottom: 12px; }

#toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; z-index: 100;
}
.toast-msg {
  padding: 10px 16px; border-radius: var(--radius); background: var(--panel2);
  border: 1px solid var(--border); font-size: 0.9rem; box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.toast-msg.error { border-color: var(--danger); color: var(--danger); }
.toast-msg.success { border-color: var(--ok); color: var(--ok); }

#scanner-video { width: 100%; max-width: 400px; border-radius: var(--radius); background: #000; }
.scan-result { margin-top: 12px; }

.login-wrap { max-width: 340px; margin: 60px auto; }
.settings-page { max-width: 640px; margin: 0 auto; }

.stat { text-align: center; padding: 10px; }
.stat .num { font-size: 1.6rem; font-weight: 700; }
.stat .label { font-size: 0.8rem; color: var(--muted); }
a.stat { display: block; text-decoration: none; color: inherit; cursor: pointer; transition: border-color 0.15s ease; }
a.stat:hover { border-color: var(--accent); }

.pager { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 12px 0; flex-wrap: wrap; }

.item-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.item-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  text-decoration: none;
  color: inherit;
  flex-wrap: wrap;
}
a.item-card:hover { border-color: var(--accent); }
.item-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.item-title { font-weight: 600; font-size: 0.92rem; }
.item-title .item-sub { font-weight: 400; }
.item-sub { font-size: 0.8rem; color: var(--muted); }
.item-meta { display: flex; align-items: center; gap: 6px; flex-shrink: 0; flex-wrap: wrap; }
.item-actions { display: flex; gap: 6px; flex-shrink: 0; }

@media (max-width: 600px) {
  .item-card { flex-direction: column; align-items: stretch; }
  .item-meta, .item-actions { justify-content: flex-start; }
}

/* Floating suggestion list for wireProductCombobox() (components.js) --
   absolutely positioned against the caller's position:relative wrapper. */
.combo-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 20;
  margin-top: 2px;
  max-height: 240px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.combo-item { padding: 8px 10px; cursor: pointer; font-size: 0.85rem; }
.combo-item + .combo-item { border-top: 1px solid var(--border); }
.combo-item:hover, .combo-item.active { background: var(--bg); }
