:root, [data-theme="light"] {
  --bg: #f2f6f8;
  --card: #ffffff;
  --ink: #14202b;
  --muted: #64748b;
  --primary: #1596d0;        /* Ekaru blue (links, focus, accents) */
  --primary-dark: #1180b6;
  --border: #e3e8ee;
  --danger: #c0392b;
  --warn: #d97706;
  --success: #1f9e4e;        /* Ekaru green (buttons, positive) */
  --success-dark: #187f3e;
  --input-bg: #ffffff;
  --hover: #f1f6fa;
  --shadow: 0 1px 2px rgba(16,42,67,0.06);
  --shadow-lg: 0 12px 32px rgba(16,42,67,0.16);
  --sidebar-bg: #1ca0db;     /* bright Ekaru blue */
  --sidebar-ink: #eaf7fd;
  --sidebar-ink-strong: #ffffff;
  --sidebar-active: #1f9e4e; /* Ekaru green highlight */
}

[data-theme="dark"] {
  --bg: #0a1620;
  --card: #10202e;
  --ink: #e6eef5;
  --muted: #93a7b8;
  --primary: #37b7ef;
  --primary-dark: #1596d0;
  --border: #223546;
  --danger: #f87171;
  --warn: #fbbf24;
  --success: #2eb45c;
  --success-dark: #23924a;
  --input-bg: #0c1a26;
  --hover: #15293a;
  --shadow: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.55);
  --sidebar-bg: #0c6f9c;     /* deep Ekaru blue for dark mode */
  --sidebar-ink: #cdeaf7;
  --sidebar-ink-strong: #ffffff;
  --sidebar-active: #1f9e4e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

.container {
  max-width: 940px;
  margin: 0 auto;
  padding: 24px 24px 80px;
}
.container.plain { max-width: 900px; }

/* ============ Sidebar layout ============ */
.sidebar-toggle { display: none; }
.layout { min-height: 100vh; }

.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 240px;
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  z-index: 60;
  transition: transform 0.25s ease;
}
.sidebar-brand {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  padding: 4px 8px 20px; text-decoration: none;
}
.sidebar-brand .brand-logo-img {
  display: block; width: 100%; max-width: 168px; height: auto;
  background: #fff; padding: 8px 12px; border-radius: 10px;
}
.sidebar-brand .brand-sub { color: var(--sidebar-ink-strong); font-size: 0.78rem; font-weight: 600; letter-spacing: 0.02em; padding-left: 2px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 3px; flex: 1; overflow-y: auto; }
.navitem {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 9px;
  color: var(--sidebar-ink); text-decoration: none; font-size: 0.95rem; font-weight: 500;
}
.navitem svg { width: 20px; height: 20px; flex: 0 0 20px; opacity: 0.9; }
.navitem:hover { background: rgba(255,255,255,0.18); color: var(--sidebar-ink-strong); }
.navitem.active { background: var(--sidebar-active); color: #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.15); }
.navitem.active svg { opacity: 1; }

.sidebar-foot { border-top: 1px solid rgba(255,255,255,0.22); padding-top: 12px; margin-top: 8px; }
.theme-toggle {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: rgba(255,255,255,0.06); border: none; color: var(--sidebar-ink);
  padding: 10px 12px; border-radius: 9px; cursor: pointer; font: inherit; font-size: 0.9rem;
  margin-bottom: 10px;
}
.theme-toggle:hover { background: rgba(255,255,255,0.12); color: var(--sidebar-ink-strong); }
.theme-ico { font-size: 1rem; line-height: 1; }
.theme-ico-dark { display: none; }
[data-theme="dark"] .theme-ico-light { display: none; }
[data-theme="dark"] .theme-ico-dark { display: inline; }
.sidebar-user { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 6px; }
.sidebar-user .who { color: var(--sidebar-ink-strong); font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linkbtn { background: none; border: none; cursor: pointer; font: inherit; color: #93c5fd; padding: 0; }
.linkbtn:hover { color: #bfdbfe; }

.main-area { margin-left: 240px; min-height: 100vh; }

/* Top bar (holds the mobile menu button; hidden on desktop) */
.topbar {
  display: none;
  align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}
.topbar-spacer { flex: 1; }
.burger { display: inline-flex; flex-direction: column; gap: 5px; padding: 6px; cursor: pointer; }
.burger span { width: 22px; height: 2px; background: var(--ink); border-radius: 2px; }
.theme-toggle.compact { width: auto; margin: 0; padding: 8px 10px; background: transparent; color: var(--ink); }
.theme-toggle.compact:hover { background: var(--hover); }

.scrim { display: none; }

/* Mobile: sidebar becomes a slide-in drawer */
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar-toggle:checked ~ .layout .sidebar { transform: translateX(0); }
  .main-area { margin-left: 0; }
  .topbar { display: flex; }
  .scrim {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.45);
    opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 55;
  }
  .sidebar-toggle:checked ~ .layout .scrim { opacity: 1; pointer-events: auto; }
}

/* ---- Cards ---- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.section-title { margin: 24px 0 12px; }
.cat-header { margin: 18px 0 8px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); border-bottom: 1px solid var(--border); padding-bottom: 6px; }

h1 { font-size: 1.5rem; margin: 8px 0 16px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }

.muted { color: var(--muted); }
main a { color: var(--primary); }
.right { text-align: right; }
.danger { color: var(--danger); font-weight: 700; }
.warn { color: var(--warn); font-weight: 700; }

/* ---- Forms ---- */
label { display: block; margin-bottom: 12px; font-weight: 600; font-size: 0.9rem; }
input, textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--ink);
}
input:focus, textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }

.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-form .full { grid-column: 1 / -1; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input { width: auto; flex: 1 1 220px; margin-top: 0; }
.inline { display: inline; }

/* Checkbox groups (permissions / email subscriptions) */
.field-label { font-weight: 600; font-size: 0.9rem; margin: 14px 0 6px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-bottom: 8px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin-bottom: 0; }
.check input { width: auto; margin: 0; }
.send-buttons { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.recipient-row .recipient-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
@media (max-width: 560px) {
  .send-buttons { flex-direction: column; }
  .send-buttons .btn-secondary { width: 100%; }
}

/* ---- Buttons ---- */
button, .btn-primary, .btn-secondary, .btn-small, .btn-link {
  font-family: inherit;
  cursor: pointer;
}
.btn-primary {
  background: var(--success);
  color: #fff;
  border: none;
  padding: 11px 18px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  min-height: 44px;
}
.btn-primary:hover { background: var(--success-dark); }
.btn-primary.big { width: 100%; padding: 16px; font-size: 1.15rem; margin-top: 8px; }
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--border);
  color: var(--ink);
  border: none;
  padding: 11px 18px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  min-height: 44px;
}
.btn-small {
  background: #eef2ff;
  color: var(--primary-dark);
  border: 1px solid #c7d2fe;
  padding: 9px 14px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
}
.btn-link { background: var(--hover); border-color: var(--border); color: var(--ink); }
.danger-btn { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.row-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }

/* ---- Tables ---- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
td.actions { white-space: nowrap; }

/* Responsive tables: on phones, each row becomes a stacked card with labels
   (the th text is echoed via data-label on each td) instead of overflowing. */
@media (max-width: 640px) {
  table.responsive thead { display: none; }
  table.responsive,
  table.responsive tbody,
  table.responsive tr,
  table.responsive td { display: block; width: 100%; }
  table.responsive tr {
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 12px;
    padding: 6px 14px;
  }
  table.responsive td {
    border: none;
    padding: 7px 0;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 14px;
    text-align: right;
  }
  table.responsive td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    text-align: left;
    flex: 0 0 auto;
  }
  table.responsive td:empty { display: none; }
  table.responsive td.right { text-align: right; }
}

/* ---- Stats ---- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 10px;
  text-align: center;
}
.stat .num { display: block; font-size: 1.8rem; font-weight: 700; }
.stat .num.pos { color: var(--success); }
.stat .num.danger { color: var(--danger); }
.stat .lbl { color: var(--muted); font-size: 0.85rem; }
@media (max-width: 480px) {
  .stats { gap: 8px; }
  .stat { padding: 14px 6px; }
  .stat .num { font-size: 1.5rem; }
  .stat .lbl { font-size: 0.75rem; }
}

/* ---- Flash / errors ---- */
.flash {
  background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46;
  padding: 10px 14px; border-radius: 8px;
}
.errors {
  background: #fef2f2; border: 1px solid #fecaca; color: var(--danger);
  padding: 10px 14px; border-radius: 8px; list-style-position: inside;
}
.warning {
  background: #fffbeb; border: 1px solid #fde68a; color: #92400e;
  padding: 10px 14px; border-radius: 8px;
}
.badge {
  display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 2px 8px;
  border-radius: 999px; background: #e5e7eb; color: #374151; vertical-align: middle;
}
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.danger-badge { background: #fee2e2; color: #b91c1c; }

.product-row.low { border-left: 4px solid var(--warn); }

/* ---- Product list: collapsed line items that expand to edit (<details>) ---- */
.product-item { padding: 0; overflow: hidden; }
.product-item.low { border-left: 4px solid var(--warn); }
.product-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 18px;
  min-height: 44px;
}
.product-summary::-webkit-details-marker { display: none; }
.product-summary:hover { background: var(--hover); }
.ps-main { display: flex; flex-direction: column; min-width: 0; }
.ps-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ps-brand { color: var(--ink); font-size: 0.85rem; font-weight: 500; }
.ps-sku { color: var(--muted); font-size: 0.82rem; }
.ps-meta { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.ps-qty { color: var(--muted); font-size: 0.9rem; white-space: nowrap; }
.ps-chevron { color: var(--muted); font-size: 0.9rem; transition: transform 0.2s; }
.product-item[open] .ps-chevron { transform: rotate(90deg); }
.product-edit { padding: 6px 18px 18px; border-top: 1px solid var(--border); }
.product-item[open] .product-summary { background: var(--hover); }

/* ---- Toolbar (import / export buttons) ---- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; align-items: flex-start; }
.dropdown { position: relative; }
.dropdown > summary {
  list-style: none;
  cursor: pointer;
}
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown-panel {
  margin-top: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.dropdown-panel code {
  background: var(--hover); padding: 1px 6px; border-radius: 4px; font-size: 0.85em;
}
.import-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.import-form input[type="file"] {
  flex: 1 1 240px; min-width: 0; margin-top: 0; padding: 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--input-bg); color: var(--ink);
}

/* Collapsible section summary styled as a heading toggle */
.import-summary { cursor: pointer; font-weight: 700; font-size: 1.05rem; list-style: none; }
.import-summary::-webkit-details-marker { display: none; }
.import-summary::before { content: '\25B8'; color: var(--muted); margin-right: 8px; display: inline-block; }
details[open] > .import-summary::before { content: '\25BE'; }
.import-body { margin-top: 14px; }
.import-body code { background: var(--hover); padding: 1px 6px; border-radius: 4px; font-size: 0.85em; }

/* Batch manual entry rows */
.batch-row { position: relative; border: 1px solid var(--border); border-radius: 10px; padding: 14px 14px 2px; margin-bottom: 12px; background: var(--hover); }
.batch-remove {
  position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; line-height: 1;
  border: 1px solid var(--border); background: var(--card); color: var(--muted);
  border-radius: 6px; font-size: 1.1rem; cursor: pointer;
}
.batch-remove:hover { color: var(--danger); border-color: var(--danger); }
.batch-controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.ps-price { color: var(--ink); font-size: 0.9rem; font-weight: 600; white-space: nowrap; }

/* Restock table inputs stay compact even inside the responsive layout */
.restock-table input { max-width: 130px; margin-top: 0; text-align: right; display: inline-block; }
.num-override { max-width: 100px; margin-top: 0; text-align: right; display: inline-block; }
.totals-row td { border-top: 2px solid var(--border); }
@media (max-width: 640px) {
  .restock-table input { max-width: 55%; }
}
@media (max-width: 560px) {
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar > .dropdown, .toolbar > .dropdown > summary, .toolbar > .btn-secondary { width: 100%; }
  .import-form { flex-direction: column; align-items: stretch; }
  .import-form input[type="file"] { flex: 0 0 auto; width: 100%; }
  .import-form .btn-primary { width: 100%; }
}

/* ---- Scan (mobile-first technician page) ---- */
.scan-card { max-width: 460px; margin: 24px auto; }
.scan-card .product-name { font-size: 1.6rem; }
.scan-card .brand-model { font-size: 1.15rem; font-weight: 600; color: var(--ink); margin: -6px 0 0; }
.scan-card .sku { color: var(--muted); margin-top: 2px; }
.scan-card .description { font-size: 1.05rem; margin: 12px 0 18px; }
.scan-form label { font-size: 1rem; }
.scan-form input { padding: 14px; font-size: 1.1rem; }
.scan-card.success { text-align: center; }
.checkmark {
  width: 64px; height: 64px; line-height: 64px; margin: 0 auto 12px;
  background: var(--success); color: #fff; border-radius: 50%; font-size: 2rem;
}

.login-card { max-width: 360px; margin: 60px auto; }
.login-card .btn-primary { width: 100%; margin-top: 8px; }
.login-logo { width: 160px; max-width: 70%; height: auto; display: block; margin-bottom: 6px; }
.narrow-card { max-width: 460px; }
.back-link { margin: 0 0 6px; }
.back-link a { color: var(--muted); text-decoration: none; font-size: 0.9rem; }
.back-link a:hover { color: var(--primary); }

/* Settings hub cards */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-top: 16px; }
.settings-card {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 22px; text-decoration: none; color: var(--ink);
  box-shadow: var(--shadow); transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
}
.settings-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--primary); }
.settings-ico {
  width: 46px; height: 46px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(21,150,208,0.12); color: var(--primary);
}
.settings-ico svg { width: 24px; height: 24px; }
.settings-title { font-weight: 700; font-size: 1.1rem; }
.settings-desc { color: var(--muted); font-size: 0.9rem; }

/* Modal dialog (temp password) */
dialog.modal {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  max-width: 420px;
  width: calc(100% - 32px);
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}
dialog.modal::backdrop { background: rgba(0,0,0,0.5); }
dialog.modal h3 { margin: 0 0 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }

.pager { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }

/* ---- QR print page ---- */
.qr-page { background: #fff; text-align: center; padding: 30px; }
.qr-label { display: inline-block; border: 2px solid #111; border-radius: 12px; padding: 24px 28px; max-width: 380px; }
.qr-img { width: 100%; max-width: 340px; height: auto; display: block; margin: 0 auto; }
.qr-label h1 { font-size: 1.4rem; margin: 14px 0 4px; }
.qr-label .description { color: #333; }
.qr-label .scan-url { font-size: 0.75rem; color: #888; word-break: break-all; margin-top: 10px; }
.qr-actions { margin-top: 20px; display: flex; gap: 10px; justify-content: center; }

@media print {
  .no-print { display: none !important; }
  .qr-page { padding: 0; }
  .qr-label { border-color: #000; }
}

@media (max-width: 560px) {
  .grid-form { grid-template-columns: 1fr; }
  .container { padding: 16px 14px 60px; }
  h1 { font-size: 1.35rem; }

  /* Stack "add recipient / add admin" forms and make the button full width */
  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form input { width: 100%; flex: none; }
  .inline-form .btn-primary { width: 100%; }

  /* Product edit cards: actions become full-width, easy-to-tap buttons */
  .row-actions { flex-direction: column; align-items: stretch; }
  .row-actions .btn-small,
  .row-actions .btn-link { width: 100%; }
  .product-edit .danger-btn { width: 100%; margin-top: 4px; }

  /* Email report header on the dashboard */
  .card-head { flex-direction: column; align-items: stretch; }
  .card-head .btn-primary { width: 100%; }
}
