:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #38bdf8;
  --primary-dark: #0284c7;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}

.hidden { display: none !important; }

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #1e293b;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
}

.brand img { width: 28px; height: 28px; border-radius: 6px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.btn-chip {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--surface-2);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-chip.danger { color: #fca5a5; border-color: rgba(239, 68, 68, 0.4); }

/* Layout */
.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 14px 90px;
}

/* Login */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 16px;
  max-width: 420px;
  margin: 0 auto;
}

.card {
  background: var(--surface);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.login-head { text-align: center; margin-bottom: 20px; }
.login-head img { width: 64px; height: 64px; margin-bottom: 10px; }
.login-head h1 { margin: 0 0 6px; font-size: 1.4rem; }
.login-head p { margin: 0; color: var(--muted); font-size: 0.92rem; }

/* Inputs & Buttons */
.input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 10px;
  border: 1px solid var(--surface-2);
  background: #0b1220;
  color: var(--text);
  font-size: 1rem;
  outline: none;
}

.input:focus { border-color: var(--primary); }

.btn {
  width: 100%;
  padding: 13px 16px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary { background: var(--primary); color: #082f49; }
.btn-primary:active { background: var(--primary-dark); color: #fff; }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-danger { background: rgba(239, 68, 68, 0.18); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.35); }
.btn-sm { padding: 8px 12px; font-size: 0.85rem; width: auto; }

/* Status bar */
.status-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.78rem;
}

.badge-online { background: rgba(34, 197, 94, 0.15); color: #86efac; }
.badge-offline { background: rgba(245, 158, 11, 0.15); color: #fcd34d; }
.badge-admin { background: rgba(56, 189, 248, 0.15); color: #7dd3fc; }

/* Tabs */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.tab-btn {
  padding: 11px;
  border-radius: 10px;
  border: 1px solid var(--surface-2);
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--primary);
  color: #082f49;
  border-color: var(--primary);
}

/* Scanner */
#reader {
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  margin-bottom: 10px;
}

.scan-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

/* Search results */
.search-list {
  margin-top: 10px;
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.search-item {
  width: 100%;
  text-align: start;
  background: #0b1220;
  border: 1px solid var(--surface-2);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.search-item small { color: var(--muted); display: block; margin-top: 2px; font-family: monospace; }
.search-price { font-weight: 700; color: var(--primary); white-space: nowrap; }

/* Product Detail Card */
.product-title { margin: 0 0 4px; font-size: 1.25rem; line-height: 1.3; }
.product-barcode { font-family: monospace; color: var(--muted); font-size: 0.9rem; margin-bottom: 14px; }

.price-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.metric {
  background: #0b1220;
  border: 1px solid var(--surface-2);
  border-radius: 12px;
  padding: 12px;
}

.metric.full { grid-column: 1 / -1; }
.metric-label { font-size: 0.78rem; color: var(--muted); margin-bottom: 4px; }
.metric-value { font-size: 1.35rem; font-weight: 800; }
.metric-sell { color: var(--primary); }
.metric-buy { color: #fbbf24; }
.metric-margin-pos { color: var(--success); }
.metric-margin-neg { color: var(--danger); }

.meta-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-top: 1px solid rgba(148, 163, 184, 0.14);
  font-size: 0.92rem;
}

.meta-row span:first-child { color: var(--muted); }

/* History */
.history-item {
  padding: 10px;
  border-radius: 10px;
  background: #0b1220;
  border: 1px solid var(--surface-2);
  margin-top: 8px;
  font-size: 0.86rem;
}

.history-date { color: var(--muted); font-size: 0.78rem; margin-bottom: 4px; }

/* Switches & Admin Staff */
.staff-card {
  background: #0b1220;
  border: 1px solid var(--surface-2);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}

.staff-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.perm-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-top: 1px solid rgba(148, 163, 184, 0.12);
  font-size: 0.9rem;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--surface-2);
  border-radius: 999px;
  transition: 0.2s;
}

.slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}

.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider::before { transform: translateX(20px); }

.form-group { margin-bottom: 10px; }
.form-group label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 5px; }
.row-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #020617;
  color: #fff;
  border: 1px solid var(--primary);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 50;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.error-box {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fecaca;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  margin-top: 10px;
}