/* ─── Design tokens ─── */
:root {
  --accent: #2563eb;
  --accent-light: #eff6ff;
  --accent-hover: #1d4ed8;
  --soft: #f8fafc;
  --surface: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --line: #e2e8f0;
  --line-light: #f1f5f9;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.06), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --sidebar-w: 272px;
  --topbar-h: 60px;
}

/* ─── Base reset ─── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--soft);
  color: var(--text-primary);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.6;
  font-size: 0.9375rem;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.3;
}

/* ─── Layout ─── */
.app-main {
  margin-left: var(--sidebar-w);
  padding: 28px 32px 40px;
  min-height: 100vh;
}

/* ─── Sidebar (desktop: fixed, mobile: offcanvas) ─── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

/* Desktop only: pin sidebar to the left */
@media (min-width: 992px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1040;
  }
}

.sidebar-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 36px 16px 32px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text-primary);
  margin-bottom: 10px;
  padding: 20px 15px;
}

.sidebar-brand strong {
  font-size: 1rem;
  font-weight: 700;
}

/* ─── Brand mark ─── */
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: inline-grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #059669);
  font-weight: 800;
  font-size: 1rem;
  flex-shrink: 0;
}

.brand-mark-sm {
  width: 34px;
  height: 34px;
  font-size: 0.85rem;
  border-radius: 8px;
}

/* ─── Sidebar links ─── */
.sidebar-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.sidebar-links a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-links a:hover {
  background: var(--line-light);
  color: var(--text-primary);
}

.sidebar-links a.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-links a.active i {
  color: var(--accent);
}

.sidebar-links i {
  font-size: 1.15rem;
  width: 22px;
  text-align: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

.sidebar-links a:hover i {
  color: var(--text-secondary);
}

/* ─── Sidebar footer ─── */
.sidebar-footer {
  margin-top: auto;
  padding: 20px 15px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--soft);
}

.user-chip-avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.user-chip-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-chip-info span {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-chip-info small {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

/* ─── Mobile top bar ─── */
.mobile-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1030;
}

.mobile-menu-btn {
  border: 1px solid var(--line);
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  padding: 0;
  color: var(--text-primary);
}

/* Hide the old floating toggle */
.sidebar-toggle {
  display: none;
}

/* ─── Scan hero section ─── */
.scan-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 460px);
  gap: 28px;
  align-items: center;
  padding: 28px 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--accent-light) 0%, var(--surface) 60%);
  box-shadow: var(--shadow-xs);
}

/* ─── Cards, panels, metrics ─── */
.scanner-box,
.panel,
.metric {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
}

.scanner-box:hover,
.panel:hover,
.metric:hover {
  box-shadow: var(--shadow-md);
}

.scanner-box,
.panel {
  padding: 22px;
}

.barcode-input {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.barcode-input:focus {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
  border-color: var(--accent);
  outline: none;
}

/* ─── Metric cards ─── */
.metric {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 120px;
  justify-content: center;
}

.metric i {
  font-size: 1.6rem;
  color: var(--accent);
  margin-bottom: 2px;
}

.metric span {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric strong {
  font-size: clamp(1.35rem, 2.5vw, 2rem);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

/* ─── Panels ─── */
.panel-title {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line-light);
}

.list-row:last-child {
  border-bottom: none;
}

.list-row span {
  display: grid;
}

.list-row small {
  color: var(--text-muted);
  font-size: 0.8125rem;
}

/* ─── Toolbar ─── */
.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 220px 160px auto auto;
  gap: 10px;
  align-items: center;
}

/* ─── Product/media elements ─── */
.thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.barcode-mini {
  max-width: 130px;
  height: 40px;
  object-fit: contain;
  display: block;
}

.preview-strip {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.preview-strip img {
  width: 80px;
  height: 66px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.product-card {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 14px;
  align-items: center;
}

.product-card img {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.lookup-card {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
}

.lookup-card img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--soft);
}

/* ─── Checkout / Invoice ─── */
.checkout-panel {
  position: sticky;
  top: 88px;
}

.totals {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-light);
}

.invoice {
  max-width: 860px;
  margin: auto;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.invoice-total {
  text-align: right;
  font-size: 1.4rem;
  font-weight: 800;
  margin: 24px 0;
}

/* ─── Login page ─── */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #eff6ff 0%, #f8fafc 50%, #f0fdf4 100%);
  padding: 20px;
}

.login-shell {
  width: min(380px, 100%);
}

.login-panel {
  padding: 40px 32px 32px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.08), 0 1px 3px rgba(0, 0, 0, 0.04);
  border: 1px solid var(--line);
}

.brand-mark-lg {
  width: 52px;
  height: 52px;
  font-size: 1.25rem;
  border-radius: 14px;
  display: inline-grid;
}

.login-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 0;
}

.login-input-group .input-group-text {
  background: var(--soft);
  border-color: var(--line);
  color: var(--text-muted);
  padding: 0 14px;
}

.login-input-group .form-control {
  border-color: var(--line);
  font-size: 0.95rem;
  padding: 12px 14px;
}

.login-input-group .form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.login-input-group .form-control::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

.login-btn {
  font-size: 1rem;
  font-weight: 600;
  padding: 12px;
  border-radius: 10px;
  background: var(--accent);
  border-color: var(--accent);
  transition: background 0.2s ease, transform 0.1s ease;
}

.login-btn:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.login-btn:active {
  transform: scale(0.98);
}

.login-footer-text {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 24px;
  margin-bottom: 0;
}

/* ─── Misc ─── */
.empty-state {
  min-height: 60vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
}

.user-summary {
  display: flex;
  align-items: center;
  gap: 14px;
}

.user-summary small {
  display: block;
  color: var(--text-muted);
}

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
  font-size: 1.35rem;
}

.navbar {
  backdrop-filter: blur(12px);
}

/* ─── Responsive: Tablet / small laptop ─── */
@media (max-width: 1200px) {
  .app-main {
    padding: 24px 20px;
  }

  .scan-hero {
    grid-template-columns: 1fr;
    padding: 24px;
  }
}

/* ─── Responsive: Mobile (< 992px) ─── */
@media (max-width: 991.98px) {
  .app-main {
    margin-left: 0;
    padding: 16px;
    padding-top: calc(var(--topbar-h) + 16px) !important;
  }

  /* Offcanvas overrides — solid white, proper z-index */
  .sidebar.offcanvas-lg {
    background: var(--surface) !important;
    width: 280px !important;
    z-index: 1055;
  }

  .sidebar .offcanvas-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
  }

  .sidebar-body {
    min-height: auto;
    padding: 20px 16px;
    background: var(--surface);
  }

  .sidebar-links a {
    padding: 12px 14px;
    font-size: 0.95rem;
    min-height: 48px;
    position: relative;
    z-index: 1;
  }

  .sidebar-footer {
    padding: 16px;
  }

  .user-chip {
    margin-top: 8px;
  }
}

/* ─── Responsive: Small mobile (< 768px) ─── */
@media (max-width: 768px) {
  .app-main {
    padding: 12px;
    padding-top: calc(var(--topbar-h) + 12px) !important;
  }

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

  .lookup-card {
    grid-template-columns: 1fr;
  }

  .lookup-card img {
    width: 100%;
    height: auto;
    max-height: 220px;
  }

  .metric {
    padding: 16px;
    min-height: 100px;
  }

  .metric strong {
    font-size: 1.3rem;
  }

  .scanner-box,
  .panel {
    padding: 16px;
  }

  .scan-hero {
    padding: 16px;
    gap: 16px;
  }
}

/* ─── Print ─── */
@media print {

  .mobile-topbar,
  .sidebar,
  .no-print {
    display: none !important;
  }

  .app-main {
    margin-left: 0;
    padding: 0;
  }

  body {
    background: #fff;
  }

  .invoice {
    border: 0;
    box-shadow: none;
  }
}