/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: var(--font);
  background: var(--gray-100);
  color: var(--gray-900);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ===== Header ===== */
#app-header {
  background: var(--primary-dark);
  color: var(--white);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 20px;
  padding: 10px 24px;
  min-height: 68px;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 3px solid var(--accent);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.header-logo {
  height: 44px;
  width: 44px;
  object-fit: contain;
  border-radius: 50%;
  background: var(--white);
  padding: 2px;
}

.header-title {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.header-logo-link { line-height: 0; border-radius: 50%; }
.header-logo-link:focus-visible { outline: 2px solid rgba(255,255,255,.7); outline-offset: 2px; }

.title-main {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--white);
  letter-spacing: -.01em;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}
.title-main:hover { text-decoration: none; }

.title-sub {
  font-size: 0.7rem;
  color: rgba(255,255,255,.55);
  letter-spacing: .02em;
  text-transform: uppercase;
  text-decoration: none;
}
.title-sub:hover { color: rgba(255,255,255,.55); }

/* ===== Scan Input (Header Center) ===== */
.header-center { flex: 1; min-width: 0; }

.scan-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.scan-input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255,255,255,.5);
  pointer-events: none;
  display: flex;
}

#scan-input {
  width: 100%;
  background: rgba(255,255,255,.1);
  border: 2px solid rgba(255,255,255,.2);
  border-radius: var(--radius);
  color: var(--white);
  font-size: 1rem;
  font-family: var(--font);
  padding: 10px 42px 10px 44px;
  outline: none;
  transition: background .15s, border-color .15s;
}

#scan-input::placeholder { color: rgba(255,255,255,.4); }

#scan-input:focus {
  background: rgba(255,255,255,.15);
  border-color: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(196,98,42,.25);
}

.scan-clear-btn {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  color: rgba(255,255,255,.5);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  transition: color .15s;
  line-height: 1;
}
.scan-clear-btn:hover { color: var(--white); }

/* ===== Mode Nav ===== */
.header-right { flex-shrink: 0; }

.mode-nav {
  display: flex;
  gap: 8px;
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: var(--radius);
  color: rgba(255,255,255,.7);
  cursor: pointer;
  font-size: 0.82rem;
  font-family: var(--font);
  font-weight: 600;
  padding: 8px 14px;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}

.mode-btn:hover {
  background: rgba(255,255,255,.18);
  color: var(--white);
}

.mode-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--white);
  box-shadow: 0 2px 6px rgba(196,98,42,.4);
}

#btn-menu-toggle[aria-expanded="true"] {
  background: rgba(255,255,255,.25);
  border-color: rgba(255,255,255,.45);
  box-shadow: inset 0 1px 3px rgba(0,0,0,.2);
}

.mode-btn svg { width: 15px; height: 15px; flex-shrink: 0; }


/* ===== Main Content ===== */
#app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px;
  min-width: 0;       /* prevent flex blowout */
  overflow-y: auto;   /* main content scrolls independently from sidebar */
}

/* ===== View Sections ===== */
.view { display: none; }
.view.active { display: flex; flex-direction: column; flex: 1; }

/* ===== Idle / Ready State ===== */
#view-idle {
  align-items: center;
  justify-content: center;
  flex: 1;
}

.idle-content {
  text-align: center;
  animation: fadeIn .4s ease;
}

.scan-indicator {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scan-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid var(--primary);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: .8; }
  50%       { transform: scale(1.12); opacity: .3; }
}

.scan-icon-large {
  width: 64px;
  height: 64px;
  color: var(--primary);
  position: relative;
  z-index: 1;
}

.idle-content h2 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--gray-800);
  margin-bottom: 8px;
}

.idle-content p {
  color: var(--gray-500);
  font-size: 1rem;
}

/* ===== Loading State ===== */
#view-loading {
  align-items: center;
  justify-content: center;
}

.loading-content {
  text-align: center;
  animation: fadeIn .2s ease;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-content p {
  color: var(--gray-500);
  font-size: 1rem;
}

/* ===== Error State ===== */
.error-card {
  background: var(--red-bg);
  border: 1px solid #fca5a5;
  border-radius: var(--radius-lg);
  padding: 28px;
  text-align: center;
  max-width: 480px;
  margin: 60px auto;
  animation: fadeIn .3s ease;
}

.error-card .error-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.error-card h3 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--red);
  margin-bottom: 8px;
}

.error-card p {
  color: var(--gray-700);
  margin-bottom: 20px;
  font-size: 0.92rem;
}

/* ===== Search Results ===== */
.search-results-wrap {
  animation: fadeIn .3s ease;
}

.search-results-wrap h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 12px;
}

.search-result-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-result-item {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 14px 18px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: border-color .15s, box-shadow .15s;
}

.search-result-item:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.search-result-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--gray-900);
}

.search-result-meta {
  font-size: 0.8rem;
  color: var(--gray-500);
  margin-top: 2px;
}

/* ===== Toast Notifications ===== */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  background: var(--gray-900);
  color: var(--white);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 0.88rem;
  font-weight: 500;
  min-width: 220px;
  max-width: 360px;
  box-shadow: var(--shadow-lg);
  animation: slideUp .25s ease;
  display: flex;
  align-items: center;
  gap: 10px;
}

.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }
.toast.info    { background: var(--primary); }

@keyframes slideUp {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ===== Utility ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes menuOpen {
  from { clip-path: inset(0 0 100% 0 round 8px); }
  to   { clip-path: inset(0 0 0%   0 round 8px); }
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font);
  font-weight: 600;
  padding: 9px 18px;
  font-size: 0.88rem;
  transition: background .15s, transform .1s, box-shadow .15s;
}
.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--primary);
  color: var(--white);
}
.btn-primary:hover { background: var(--primary-light); }

.btn-accent {
  background: var(--accent);
  color: var(--white);
}
.btn-accent:hover { background: var(--accent-light); }

.btn-ghost {
  background: var(--gray-100);
  color: var(--gray-700);
  border: 1px solid var(--gray-200);
}
.btn-ghost:hover { background: var(--gray-200); }

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid #fca5a5;
}
.btn-danger:hover { background: #fecaca; }

/* ===== Label Generation View ===== */
.label-gen-wrap {
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  animation: fadeIn .3s ease;
}

.label-gen-wrap h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--gray-800);
}

.label-search-row {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
}

.label-search-row input {
  flex: 1;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.95rem;
  font-family: var(--font);
  outline: none;
  transition: border-color .15s;
}
.label-search-row input:focus { border-color: var(--primary); }

/* ===== User Menu (header-right) ===== */
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-right: 14px;
  border-right: 1px solid rgba(255,255,255,.15);
}

.user-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: rgba(255,255,255,.9);
  white-space: nowrap;
}

.user-role-badge {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 1px 7px;
  border-radius: 99px;
  background: rgba(255,255,255,.15);
  color: rgba(255,255,255,.7);
  white-space: nowrap;
}

/* Distinct colour per role */
.user-role-badge[data-role="superduperadmin"] { background: var(--accent);     color: #fff; }
.user-role-badge[data-role="admin"]           { background: var(--primary-light); color: #fff; }
.user-role-badge[data-role="tech"]            { background: rgba(255,255,255,.2); color: rgba(255,255,255,.85); }
.user-role-badge[data-role="client"]          { background: rgba(255,255,255,.1); color: rgba(255,255,255,.6); }

.btn-logout {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.7);
  cursor: pointer;
  font-size: 0.8rem;
  font-family: var(--font);
  font-weight: 600;
  padding: 6px 11px;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}

.btn-logout svg { width: 14px; height: 14px; flex-shrink: 0; }

.btn-logout:hover {
  background: rgba(185,28,28,.3);
  border-color: rgba(252,165,165,.3);
  color: #fca5a5;
}

/* ===== Header button divider ===== */
.header-btn-divider {
  display: block;
  width: 1px;
  height: 24px;
  background: rgba(255,255,255,.15);
  flex-shrink: 0;
}

/* ===== App Menu Dropdown ===== */
.app-menu-wrap {
  position: relative;
  filter: drop-shadow(0 12px 28px rgba(0,0,0,.18)) drop-shadow(0 3px 8px rgba(0,0,0,.10));
}

.app-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  background: var(--white);
  border-radius: var(--radius-lg);
  min-width: 210px;
  z-index: 500;
  overflow: hidden;
  animation: menuOpen .2s ease;
}

.app-menu[hidden] { display: none; }

.app-menu-user {
  padding: 14px 16px;
  background: var(--primary);
  border-bottom: 2px solid var(--accent);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.app-menu-user .user-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--white);
}

.app-menu-divider {
  height: 1px;
  background: var(--gray-100);
  margin: 4px 0;
}

.app-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--gray-700);
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  transition: background .1s, color .1s;
}

.app-menu-item:hover { background: var(--gray-50); color: var(--gray-900); }

.app-menu-item svg {
  width: 15px;
  height: 15px;
  color: var(--gray-400);
  flex-shrink: 0;
  transition: color .1s;
}

.app-menu-item:hover svg { color: var(--gray-600); }

.app-menu-item-danger { color: var(--red); }
.app-menu-item-danger svg { color: var(--red); opacity: .7; }
.app-menu-item-danger:hover { background: var(--red-bg); color: var(--red); }
.app-menu-item-danger:hover svg { color: var(--red); opacity: 1; }

/* Active state inside the menu (e.g. timer ON) */
.app-menu-item.active { color: var(--accent); font-weight: 600; }
.app-menu-item.active svg { color: var(--accent); opacity: 1; }
.app-menu-item.active:hover { background: var(--accent-50); color: var(--accent-dark); }

/* ===== Search Autocomplete Dropdown ===== */
.search-autocomplete {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0,0,0,.22), 0 2px 8px rgba(0,0,0,.12);
  overflow: hidden;
  max-height: 360px;
  overflow-y: auto;
  animation: fadeIn .12s ease;
}

.search-autocomplete[hidden] { display: none; }

.ac-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  cursor: pointer;
  transition: background .1s;
  border-bottom: 1px solid var(--gray-100);
}

.ac-item:last-child { border-bottom: none; }

.ac-item:hover,
.ac-item.ac-active {
  background: var(--primary-50);
}

.ac-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  color: var(--gray-400);
}

.ac-item-body { min-width: 0; }

.ac-item-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--gray-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ac-item-meta {
  font-size: 0.75rem;
  color: var(--gray-500);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.ac-item-syncro {
  font-size: 0.85rem;
  color: var(--gray-600);
  background: var(--gray-50);
  border-top: 1px solid var(--gray-200);
}

.ac-item-syncro:hover,
.ac-item-syncro.ac-active {
  background: var(--accent-50);
  color: var(--accent-dark);
}

.ac-item-syncro .ac-icon { color: var(--gray-400); }

.ac-item-syncro em {
  font-style: normal;
  font-weight: 600;
  color: var(--accent);
}

@media (max-width: 900px) {
  .user-info { display: none; }
}

/* ── Camera scan overlay ──────────────────────────────────────────────────── */

.camera-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.camera-overlay[hidden] {
  display: none;
}

.camera-overlay-inner {
  background: #1a1a1a;
  border-radius: var(--radius-lg);
  overflow: hidden;
  width: min(92vw, 480px);
  display: flex;
  flex-direction: column;
}

.camera-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #333;
}

.camera-title {
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
}

.camera-close-btn {
  background: none;
  border: none;
  color: #aaa;
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}

.camera-close-btn:hover {
  color: #fff;
}

.camera-viewport {
  position: relative;
  background: #000;
  aspect-ratio: 4 / 3;
}

#camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Targeting reticle — pure CSS, no images */
.camera-reticle {
  position: absolute;
  inset: 20%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  pointer-events: none;
}

/* Corner accents — top-left and bottom-right */
.camera-reticle::before,
.camera-reticle::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  border-style: solid;
  border-color: rgba(255, 255, 255, 0.75);
  transition: border-color 0.15s;
}
.camera-reticle::before {
  top: -1px; left: -1px;
  border-width: 3px 0 0 3px;
  border-radius: 4px 0 0 0;
}
.camera-reticle::after {
  bottom: -1px; right: -1px;
  border-width: 0 3px 3px 0;
  border-radius: 0 0 4px 0;
}

/* Scan line — hidden by default, shown on detection */
.camera-scan-line {
  display: none;
}

/* Flash green when a barcode is detected */
.camera-overlay.detected .camera-reticle {
  border-color: rgba(74, 222, 128, 0.5);
}
.camera-overlay.detected .camera-reticle::before,
.camera-overlay.detected .camera-reticle::after {
  border-color: #4ade80;
}
.camera-overlay.detected .camera-scan-line {
  display: block;
  position: absolute;
  left: 4px; right: 4px;
  height: 2px;
  top: 50%;
  background: linear-gradient(90deg, transparent 0%, #4ade80 50%, transparent 100%);
  border-radius: 1px;
}

.camera-status {
  padding: 10px 16px;
  color: #ccc;
  font-size: 0.875rem;
  text-align: center;
  min-height: 2.5em;
  margin: 0;
}

.camera-status.error {
  color: #ff6b6b;
}

/* ── Client role: hide write controls and scan-only UI ──────────────────── */
.role-client #btn-scan-mode,
.role-client #btn-scan-mode-toggle,
.role-client #btn-timer-toggle,
.role-client #btn-label-center,
.role-client #sidebar-refresh,
.role-client #action-toggle-possession,
.role-client #action-lifecycle,
.role-client #action-change-owner,
.role-client #action-remove-user,
.role-client #action-sign-out,
.role-client #action-infrastructure,
.role-client #action-print-label,
.role-client #action-add-to-queue { display: none; }

/* Show Quick View button only for client role */
#btn-quick-view { display: none; }
.role-client #btn-quick-view { display: inline-flex; }

/* Search bar: show magnifying glass icon for clients, barcode for staff */
.icon-search { display: none; }
.role-client .icon-barcode { display: none; }
.role-client .icon-search  { display: inline; }

/* Quick View dashboard layout */
#view-quick-view { padding: 1.5rem; overflow-y: auto; }

/* Card — matches .admin-section from admin panel */
.qv-section {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
  overflow: hidden;
}
.qv-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--gray-200);
}
.qv-card-header h2 { font-size: 1rem; font-weight: 700; color: var(--gray-800); margin: 0; }
.qv-card-count { font-size: 0.8rem; color: var(--gray-500); }

/* Table */
.qv-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.qv-table th {
  text-align: center; padding: 0.5rem 0.75rem;
  background: var(--gray-50); color: var(--gray-600);
  font-weight: 600; border-bottom: 1px solid var(--gray-200);
}
.qv-table th:first-child { text-align: left; padding-left: 24px; }
.qv-table td {
  text-align: center; padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--gray-200);
}
.qv-table td:first-child { text-align: left; font-weight: 500; color: var(--gray-800); padding-left: 24px; }
.qv-table tbody tr:last-child td { border-bottom: none; }
.qv-table tfoot td {
  font-weight: 600; border-top: 2px solid var(--gray-200);
  border-bottom: none; background: var(--gray-50);
  padding-top: 0.6rem; padding-bottom: 0.6rem;
}
.qv-cell-link {
  display: inline-block; min-width: 2rem; padding: 0.2rem 0.4rem;
  border-radius: 4px; cursor: pointer; transition: background 0.15s;
  color: var(--accent, #3b82f6);
}
.qv-cell-link:hover { background: var(--gray-100); text-decoration: underline; }
.qv-cell-zero { color: var(--gray-400); }
.qv-empty { padding: 1.5rem 24px; color: var(--gray-500); font-size: 0.875rem; }
.qv-loading { padding: 1.5rem 24px; color: var(--gray-400); font-size: 0.875rem; }
