:root {
  --primary: #0f766e;
  --primary-dark: #0d5f58;
  --accent: #f59e0b;
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --danger: #dc2626;
  --success: #16a34a;
  --border: #e5e7eb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { text-decoration: none; color: inherit; }

.layout { display: flex; min-height: 100vh; }

/* ============================================================
   SIDEBAR - KUFICHA/KUONYESHA (dynamic toggle)
   ------------------------------------------------------------
   "Rail" nyembamba (42px) inabaki DAIMA kwenye mstari wa flex
   (siyo "fixed/floating") ili kitufe cha kufungua kisigongane na
   maudhui ya ukurasa (h1, topbar, n.k.) wakati sidebar imefichwa -
   badala yake .main inapanuka/kupungua kiasili kupitia flex:1.
   Hali inahifadhiwa kwenye localStorage (angalia base.html) ili
   ibaki hivyo hivyo mtumiaji akipitia ukurasa mwingine.
   ============================================================ */
.sidebar-rail {
  width: 42px;
  flex-shrink: 0;
  background: var(--primary-dark);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 16px;
}
.sidebar-rail .rail-btn {
  background: rgba(255,255,255,0.14);
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sidebar-rail .rail-btn:hover { background: rgba(255,255,255,0.3); }
body.sidebar-collapsed .sidebar { display: none; }

.sidebar {
  width: 220px;
  background: linear-gradient(180deg, var(--primary), var(--primary-dark));
  color: #fff;
  padding: 20px 0;
  flex-shrink: 0;
}
.sidebar h2 {
  padding: 0 20px 16px;
  font-size: 18px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  margin: 0 0 12px;
}
.sidebar a {
  display: block;
  padding: 10px 20px 4px;
  color: rgba(255,255,255,0.88);
  font-size: 14px;
}
.sidebar a:hover, .sidebar a.active {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border-left: 3px solid var(--accent);
}
.menu-desc {
  display: block;
  padding: 0 20px 10px 20px;
  margin-top: -4px;
  font-size: 11px;
  line-height: 1.3;
  color: rgba(255,255,255,0.55);
}
.sidebar .user-box {
  padding: 12px 20px;
  font-size: 12px;
  color: rgba(255,255,255,0.7);
  border-top: 1px solid rgba(255,255,255,0.15);
  margin-top: 12px;
}

.main { flex: 1; padding: 22px 28px; max-width: 100%; overflow-x: auto; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.topbar h1 { font-size: 22px; margin: 0; }

.cards { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.card {
  background: var(--card);
  border-radius: 10px;
  padding: 18px 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  flex: 1;
  min-width: 180px;
}
.card .label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.card .value { font-size: 24px; font-weight: 700; }
.card.warn .value { color: var(--danger); }
.card.good .value { color: var(--success); }

.panel {
  background: var(--card);
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  margin-bottom: 20px;
}
.panel h3 { margin-top: 0; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tr:hover { background: #fafafa; }

.btn {
  display: inline-block;
  padding: 9px 16px;
  border-radius: 6px;
  border: none;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  text-align: center;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #e5e7eb; color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.accent { background: var(--accent); color: #1f2937; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

input, select, textarea {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  width: 100%;
}
label { font-size: 13px; color: var(--muted); margin-bottom: 4px; display: block; }
.form-row { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 14px;
}
.alert-success { background: #dcfce7; color: #166534; }
.alert-danger { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef9c3; color: #854d0e; }

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge.low { background: #fee2e2; color: #991b1b; }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.pending { background: #fef9c3; color: #854d0e; }

.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: linear-gradient(135deg, var(--primary), var(--primary-dark));
}
.login-box {
  background: #fff; padding: 36px; border-radius: 12px; width: 340px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.login-box h2 { text-align: center; color: var(--primary); margin-top: 0; }

/* POS SCREEN */
.pos-layout { display: flex; gap: 18px; }
.pos-left { flex: 2; }
.pos-right { flex: 1; min-width: 320px; }
.scan-box input { font-size: 18px; padding: 14px; }
.scan-mode-toggle { display: flex; gap: 8px; }
.scan-mode-toggle .btn { white-space: nowrap; }
#reader video { border-radius: 8px; }
#reader__scan_region { border-radius: 8px; }
.cart-table td, .cart-table th { padding: 8px 6px; font-size: 13px; }
.cart-qty { width: 60px; }
.total-box { font-size: 26px; font-weight: 700; color: var(--primary); text-align: right; margin: 10px 0; }

.receipt {
  max-width: 340px; margin: 0 auto; font-family: 'Courier New', monospace;
  background: #fff; padding: 16px; border: 1px dashed #999;
}
.receipt h3 { text-align: center; margin: 4px 0; }
.receipt .center { text-align: center; }
.receipt table { font-size: 12px; }
.receipt hr { border: none; border-top: 1px dashed #999; }

/* ============================================================
   BARCODE LABEL - muundo wa kisasa (modern) kwa sticker za bidhaa.
   Muundo: jina la bidhaa (juu, mstari mwembamba wa kutenganisha),
   barcode yenye nafasi safi pande zote (muhimu kwa usomaji mzuri wa
   scanner - "quiet zone"), namba ya barcode ndogo chini yake, na bei
   ikiwa kwenye "pill/badge" nyeusi yenye herufi nyeupe - mtindo
   unaofanana na tag za maduka ya kisasa (H&M, Uniqlo, n.k), unaobaki
   mweusi-na-mweupe safi kwenye printa za kawaida/thermal.
   ============================================================ */
.barcode-label {
  display: inline-flex; flex-direction: column; align-items: center;
  border: 1px solid #e2e2e2; border-radius: 8px;
  padding: 10px 8px 8px; margin: 4px; width: 190px;
  background: #fff; font-family: Calibri, Arial, sans-serif;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.bl-name {
  font-size: 12.5px; font-weight: 700; color: #111;
  text-align: center; width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding-bottom: 5px; margin-bottom: 6px;
  border-bottom: 1px solid #eee;
}
.bl-barcode-wrap {
  width: 100%; padding: 2px 4px; background: #fff;
}
.barcode-label img { width: 100%; display: block; }
.bl-code {
  font-size: 10px; letter-spacing: 1.5px; color: #666;
  font-family: Consolas, 'Courier New', monospace; margin-top: 1px;
}
.bl-price-row { margin-top: 6px; }
.bl-price {
  display: inline-block; background: #14251f; color: #fff;
  font-weight: 700; font-size: 12px; letter-spacing: 0.3px;
  padding: 3px 12px; border-radius: 12px;
}

/* Grid ya screen (kabla ya kuchapisha) - kwa ajili ya kuona muundo wa
   label sheet kwenye onyesho la kawaida la browser. */
.label-sheet {
  display: flex; flex-wrap: wrap; gap: 6px;
}

@media print {
  .sidebar-rail { display: none; }
  .no-print { display: none !important; }
  .sidebar { display: none; }
  .main { padding: 0; }

  /* Kurasa ya print inayotumika kwa rolls za thermal (mf. 50mm x 25mm au
     58mm) au sticker sheets za kawaida (A4). Tunatumia grid inayojirudia
     (auto-fill) badala ya idadi maalum ya columns, ili chochote size ya
     karatasi/roll iliyowekwa kwenye printer, label zijipange vizuri bila
     kukatwa (clipping) wala kuvunjika vibaya kati ya kurasa (bad
     page-breaks).

     MUHIMU (Septemba 2026): thamani za 40mm/20mm hapa chini ni DEFAULT
     PEKEE - label_print.html ina kisanduku "Ukubwa wa Sticker (mm)"
     kinachozidisha (override) values hizi kwa <style> ya inline, NA
     kinatuma ukubwa huo huo kwa Flask kukokotoa module_width sahihi ya
     kila barcode (angalia barcode_module_width_for() kwenye app.py).
     USIBADILISHE max-width/max-height hapa moja kwa moja ukitaka sticker
     ndogo - fanya hivyo kwenye ukurasa wa "Chapisha Barcode" badala yake,
     vinginevyo picha ya barcode itabanwa na CSS bila Flask kujua, na
     bars zitakuwa nyembamba mno kusomeka na scanner/kamera (hii ndiyo
     hasa hitilafu iliyowahi kutokea kabla ya marekebisho haya). */
  .label-sheet {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40mm, 1fr));
    gap: 1.5mm;
    width: 100%;
  }

  .barcode-label {
    width: auto;
    max-width: 40mm;
    min-height: 20mm;
    margin: 0;
    padding: 1.2mm 1mm 1mm;
    border: 1px dashed #999;
    border-radius: 0.8mm;
    box-shadow: none;
    box-sizing: border-box;
    /* Epuka kukata label moja katikati ya ukurasa mmoja hadi mwingine -
       kila label inabaki kwenye ukurasa/roll segment mmoja tu. */
    break-inside: avoid;
    page-break-inside: avoid;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }

  .bl-name { font-size: 6.5px; padding-bottom: 0.6mm; margin-bottom: 0.6mm; }
  .bl-barcode-wrap {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .bl-code {
    font-size: 5px;
    letter-spacing: 0.2px;
    width: 100%;
    text-align: center;
    box-sizing: border-box;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: clip;
  }
  .bl-price { font-size: 6px; padding: 0.3mm 1.4mm; border-radius: 1.6mm; }
  .bl-price-row { margin-top: 0.6mm; }

  .barcode-label img {
    width: 90%;
    max-height: 9mm;
    object-fit: contain;
    display: block;
    margin: 0 auto;
  }

  /* Roll ya thermal ya 58mm/50mm-25mm kwa kawaida haina "pages" za A4 -
     tunaondoa margin ya default ya browser ili kila sticker ianze mara
     moja bila nafasi tupu ya juu/pembeni. */
  @page {
    margin: 2mm;
  }
}

@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .sidebar-rail { width: 100%; flex-direction: row; justify-content: flex-start; padding: 6px 10px; }
  .sidebar { width: 100%; display: flex; overflow-x: auto; padding: 8px 0; }
  .sidebar h2 { display: none; }
  .sidebar a { padding: 10px 14px; white-space: nowrap; border-left: none !important; }
  .sidebar .user-box { display: none; }
  .menu-desc { display: none; }
  .pos-layout { flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  .cards { flex-direction: column; }
  .scan-box > div:first-child { flex-direction: column; align-items: stretch !important; gap: 8px; }
  .scan-mode-toggle { flex-direction: column; }
}

/* ============================================================
   PWA INSTALL BANNER
   ============================================================ */
.pwa-install-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 2000;
  background: var(--primary-dark);
  color: #fff;
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  max-width: 480px;
  margin: 0 auto;
}
.pwa-install-text { flex: 1; font-size: 13px; line-height: 1.4; min-width: 200px; }
.pwa-install-actions { display: flex; align-items: center; gap: 8px; }
.pwa-install-close {
  background: transparent;
  border: none;
  color: rgba(255,255,255,.85);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
}
.pwa-install-banner .btn.primary {
  background: var(--accent);
  color: #1f2937;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

/* ============================================================
   ONBOARDING TOUR (Mwongozo wa Kwanza)
   ============================================================ */
.onboarding-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(15,23,42,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.onboarding-modal {
  background: var(--card);
  border-radius: 12px;
  max-width: 420px;
  width: 100%;
  padding: 24px;
  box-shadow: 0 12px 40px rgba(0,0,0,.3);
}
.onboarding-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 16px;
}
.onboarding-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border);
}
.onboarding-dot.active { background: var(--primary); width: 18px; border-radius: 4px; }
.onboarding-title { font-size: 18px; margin: 0 0 10px; color: var(--text); }
.onboarding-body { font-size: 14px; line-height: 1.6; color: var(--muted); min-height: 70px; }
.onboarding-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 18px;
  gap: 10px;
  flex-wrap: wrap;
}
.onboarding-nav { display: flex; gap: 8px; }
.onboarding-actions .btn {
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  border: none;
}
.onboarding-actions .btn.primary { background: var(--primary); color: #fff; }
.onboarding-actions .btn.secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }

@media (max-width: 480px) {
  .onboarding-actions { flex-direction: column-reverse; align-items: stretch; }
  .onboarding-nav { justify-content: space-between; }
}
