:root {
  --bg: #0f172a;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #1e40af;
  --primary-600: #2563eb;
  --primary-50: #eff6ff;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.15);
  font-family: -apple-system, "Segoe UI", "Rubik", "Assistant", Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
/* רשת ביטחון: שום מסך (קיים או עתידי) לא יכול לדחוף את רוחב העמוד מעבר למסך —
   מונע "בריחה מהמסגרת" גם אם אלמנט בודד רחב מדי בטעות. */
html, body { max-width: 100%; overflow-x: hidden; }
body {
  background: var(--surface-2);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
#app { min-height: 100vh; }

/* ---------- כלליים ---------- */
button { font-family: inherit; cursor: pointer; }
input, select, textarea {
  font-family: inherit; font-size: 16px; width: 100%;
  padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary-600);
  box-shadow: 0 0 0 3px var(--primary-50);
}
label { display: block; font-size: 13px; font-weight: 600;
        color: var(--muted); margin: 0 0 6px; }
.field { margin-bottom: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 18px; border: none; border-radius: 12px;
  background: var(--primary-600); color: #fff; font-size: 16px; font-weight: 600;
  width: 100%; transition: filter .15s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn.secondary { background: var(--surface); color: var(--text);
                 border: 1px solid var(--border); }
.btn.green { background: var(--green); }
.btn.red { background: var(--red); }
.btn.ghost { background: transparent; color: var(--primary-600); width: auto;
             padding: 8px 12px; }
.btn.sm { padding: 8px 12px; font-size: 14px; width: auto; }

.card { background: var(--surface); border-radius: var(--radius);
        box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.center { text-align: center; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px;
         font-size: 12px; font-weight: 600; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.blue { background: var(--primary-50); color: var(--primary); }

/* ---------- מסך התחברות ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 24px;
  background: linear-gradient(160deg, #1e3a8a, #0f172a);
}
.auth-card { background: #fff; border-radius: 20px; padding: 32px 24px;
             width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); }
.logo { display: flex; flex-direction: column; align-items: center;
        gap: 12px; margin-bottom: 24px; }
.logo img { width: 72px; height: 72px; }
.logo h1 { font-size: 24px; color: var(--primary); }
.logo p { color: var(--muted); font-size: 14px; }
.error-msg { background: var(--red-bg); color: var(--red); padding: 10px 14px;
             border-radius: 10px; font-size: 14px; margin-bottom: 14px; }
.info-msg { background: var(--primary-50); color: var(--primary); padding: 10px 14px;
            border-radius: 10px; font-size: 14px; margin-bottom: 14px; }
.dev-hint { background: var(--amber-bg); color: var(--amber); padding: 8px 12px;
            border-radius: 8px; font-size: 13px; margin-top: 10px; text-align: center; }

/* ---------- מבנה אפליקציה ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--primary); color: #fff;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  display: flex; align-items: center; justify-content: space-between;
}
.topbar h2 { font-size: 18px; font-weight: 700; }
.topbar .user-chip { font-size: 13px; opacity: .9; display: flex;
                     align-items: center; gap: 8px; }
.topbar button { background: rgba(255,255,255,.15); border: none; color: #fff;
                 padding: 6px 10px; border-radius: 8px; font-size: 13px; }

.content { padding: 16px; padding-bottom: 90px; max-width: 1100px; margin: 0 auto; }

/* ניווט תחתון – מובייל */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; padding-bottom: env(safe-area-inset-bottom);
  overflow-x: auto; overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
}
.tabbar::-webkit-scrollbar { display: none; }
.tabbar button {
  flex: 1 0 auto; min-width: 64px; background: none; border: none; padding: 8px 6px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted); font-size: 11px; font-weight: 600; position: relative;
  scroll-snap-align: start;
}
.tabbar button.active { color: var(--primary-600); }
.tabbar .ico { font-size: 22px; line-height: 1; }
/* מוצג רק בסיידבר הדסקטופ (למטה) — במובייל הוא בתוך שורת הטאבים הנגללת וגורם לגלישה */
#brand-home { display: none; }

/* ---------- רשימות ופריטים ---------- */
.list-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--surface); border-radius: 12px;
  box-shadow: var(--shadow); margin-bottom: 10px; gap: 10px;
}
.list-item .title { font-weight: 600; }
.list-item .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.list-item.selectable:active { background: var(--primary-50); }

.qty-row { display: flex; align-items: center; gap: 8px; }
.qty-row input { width: 70px; text-align: center; }
.stepper { display: flex; align-items: center; gap: 0; }
.stepper button { width: 38px; height: 38px; border: 1px solid var(--border);
                  background: var(--surface); font-size: 20px; color: var(--primary-600); }
.stepper button:first-child { border-radius: 0 10px 10px 0; }
.stepper button:last-child { border-radius: 10px 0 0 10px; }
.stepper input { width: 56px; border-radius: 0; border-right: none;
                 border-left: none; height: 38px; }

/* שדה "סה"כ יחידות" בסוף שורת ניפוק – קשור דו-כיוונית לכמות האריזות */
.units-box { display: flex; align-items: center; gap: 6px; margin-inline-start: 10px; }
.units-box input { width: 78px; height: 38px; text-align: center; font-weight: 700;
                   border-radius: 10px; border: 1px solid var(--border);
                   background: var(--surface-2); color: var(--primary); }
.units-box .units-lbl { font-size: 12px; color: var(--muted); }
@media (max-width: 560px) {
  .units-box input { width: 64px; }
}

/* ---------- טבלאות (דסקטופ/דוחות) ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--border); }
th { background: var(--surface-2); font-weight: 700; color: var(--muted);
     font-size: 12px; white-space: nowrap; position: sticky; top: 0; }
tbody tr:hover { background: var(--primary-50); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- כרטיסי סטטיסטיקה ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat { background: var(--surface); border-radius: var(--radius);
        box-shadow: var(--shadow); padding: 16px; }
.stat .val { font-size: 26px; font-weight: 800; color: var(--primary); }
.stat .lbl { font-size: 13px; color: var(--muted); margin-top: 4px; }
.stat.green .val { color: var(--green); }
.stat.red .val { color: var(--red); }
.stat.amber .val { color: var(--amber); }

/* ---------- מודאל / חתימה ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.6); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
}
.modal {
  background: var(--surface); width: 100%; max-width: 560px;
  border-radius: 20px 20px 0 0; padding: 20px; max-height: 92vh; overflow-y: auto;
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: .5; } }
.modal h3 { font-size: 19px; margin-bottom: 4px; }
.modal.center { text-align: center; }
.modal.center code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px;
                     direction: ltr; display: inline-block; }
.modal .close { position: absolute; }
.sign-pad {
  width: 100%; height: 220px; background: #fff; border: 2px dashed var(--border);
  border-radius: 12px; touch-action: none; display: block;
}
.sign-hint { text-align: center; color: var(--muted); font-size: 13px; margin: 8px 0; }

.section-title { font-size: 15px; font-weight: 700; margin: 18px 0 10px;
                 color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty .ico { font-size: 40px; opacity: .4; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 6px 12px; border-radius: 20px; border: 1px solid var(--border);
        background: var(--surface); font-size: 13px; }
.chip.on { background: var(--primary-600); color: #fff; border-color: var(--primary-600); }

.perm-grid { display: grid; gap: 8px; }
.perm-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px;
             border: 1px solid var(--border); border-radius: 10px; }
.perm-item input { width: auto; }

.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 12px 20px; border-radius: 30px;
  font-size: 14px; z-index: 100; box-shadow: var(--shadow-lg); max-width: 90%;
  animation: fadeIn .2s;
}
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }
@keyframes fadeIn { from { opacity: 0; transform: translate(-50%, 10px); } }

.spinner { width: 24px; height: 24px; border: 3px solid var(--border);
           border-top-color: var(--primary-600); border-radius: 50%;
           animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- התראות ---------- */
.nav-badge { background: var(--red); color: #fff; border-radius: 20px;
             font-size: 11px; font-weight: 700; padding: 1px 7px; margin-inline-start: 4px; }
.alert-card { border: 1px solid var(--amber); background: #fffdf5; }
.alert-row { display: flex; align-items: center; gap: 10px; padding: 8px 0;
             border-top: 1px solid var(--border); font-size: 14px; }
.alert-row:first-of-type { border-top: none; }
.alert-row .num { color: var(--muted); font-size: 13px; white-space: nowrap; }
.row-low { background: var(--amber-bg) !important; }

/* ---------- מיקום GPS ---------- */
.geo-status { font-size: 13px; padding: 8px 12px; border-radius: 8px;
              background: var(--surface-2); color: var(--muted); margin-bottom: 12px; }
.geo-status.ok { background: var(--green-bg); color: var(--green); }
.geo-status.err { background: var(--amber-bg); color: var(--amber); }

/* ---------- מפה ---------- */
.map { width: 100%; height: 60vh; min-height: 340px; border-radius: var(--radius);
       overflow: hidden; box-shadow: var(--shadow); z-index: 1; }
.map.hidden { display: none; }
a.btn { text-decoration: none; }

/* ---------- מסך בית – כפתורים גדולים מרובעים ---------- */
.home-greet { font-size: 20px; font-weight: 700; margin: 4px 4px 16px; }
.home-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.home-tile {
  position: relative; aspect-ratio: 1 / 1; border: none; border-radius: 20px;
  background: var(--surface); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; color: var(--text); transition: transform .08s, box-shadow .15s;
  border: 1px solid var(--border);
}
.home-tile:active { transform: scale(.96); }
.home-tile:hover { box-shadow: var(--shadow-lg); border-color: var(--primary-600); }
.home-ico { font-size: 44px; line-height: 1; }
.home-lbl { font-size: 16px; font-weight: 700; }
.home-badge { position: absolute; top: 12px; left: 12px; background: var(--red);
              color: #fff; border-radius: 20px; font-size: 12px; font-weight: 700;
              min-width: 22px; height: 22px; display: flex; align-items: center;
              justify-content: center; padding: 0 6px; }
@media (min-width: 700px) { .home-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1000px) { .home-grid { grid-template-columns: repeat(4, 1fr); }
  .home-tile { aspect-ratio: 4 / 3; } }

/* ---------- פעמון התראות ---------- */
.bell { position: relative; background: rgba(255,255,255,.15) !important;
        font-size: 16px; line-height: 1; padding: 7px 9px !important; }
.bell-badge { position: absolute; top: -4px; left: -4px; background: var(--red);
              color: #fff; border-radius: 20px; font-size: 10px; font-weight: 700;
              padding: 1px 5px; min-width: 16px; text-align: center; }
.notif-item { padding: 12px; border-radius: 10px; border: 1px solid var(--border);
              margin-bottom: 8px; }
.notif-item.unread { background: var(--primary-50); border-color: var(--primary-600); }
.notif-item .title { font-weight: 600; font-size: 14px; }

/* ---------- יעדים ---------- */
.target-track { background: var(--surface-2); border-radius: 20px; height: 14px; overflow: hidden; }
.target-fill { height: 100%; background: var(--primary-600); border-radius: 20px;
               transition: width .5s ease; }
.target-fill.over { background: var(--green); }

/* ---------- סורק ברקוד ---------- */
.scan-video { width: 100%; max-height: 60vh; background: #000; border-radius: 12px;
              object-fit: cover; }

/* ---------- גרפים ---------- */
.charts-2 { display: grid; grid-template-columns: 1fr; gap: 14px; margin-bottom: 14px; }
@media (min-width: 900px) { .charts-2 { grid-template-columns: 1fr 1fr; } }

.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar-row { display: grid; grid-template-columns: 90px 1fr auto; align-items: center; gap: 10px; }
.hbar-label { font-size: 13px; color: var(--text); white-space: nowrap;
              overflow: hidden; text-overflow: ellipsis; }
.hbar-track { background: var(--surface-2); border-radius: 8px; height: 22px; overflow: hidden; }
.hbar-fill { display: block; height: 100%; border-radius: 8px; min-width: 3px;
             transition: width .4s ease; }
.hbar-val { font-size: 12px; color: var(--muted); min-width: 54px; text-align: left; }

.vbars { display: flex; align-items: flex-end; gap: 4px; height: 170px;
         padding-top: 8px; overflow-x: auto; }
.vbar-col { flex: 1 0 auto; min-width: 26px; display: flex; flex-direction: column;
            align-items: center; height: 100%; }
.vbar-track { flex: 1; width: 100%; display: flex; align-items: flex-end;
              justify-content: center; }
.vbar-fill { width: 62%; min-height: 2px; border-radius: 5px 5px 0 0;
             transition: height .4s ease; }
.vbar-label { font-size: 10px; color: var(--muted); margin-top: 5px; white-space: nowrap; }

/* ---------- הדפסה / PDF ---------- */
@media print {
  .tabbar, .topbar { display: none !important; }
  .content { padding: 0 !important; }
}

/* ---------- דסקטופ ---------- */
@media (min-width: 900px) {
  .content { padding: 24px 32px; padding-bottom: 40px; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .tabbar {
    position: sticky; top: 0; bottom: auto; flex-direction: column;
    width: 240px; height: 100vh; max-height: 100vh; border-top: none;
    border-left: 1px solid var(--border);
    padding: 12px; align-items: stretch; gap: 6px;
    overflow-y: auto; scroll-snap-type: none;
  }
  .tabbar button {
    flex-direction: row; justify-content: flex-start; gap: 12px;
    padding: 12px 14px; border-radius: 12px; font-size: 15px;
    background: var(--surface-2); box-shadow: none; flex: 0 0 auto;
    transition: background .15s, box-shadow .15s, transform .05s;
  }
  .tabbar button:hover { background: var(--primary-50); }
  .tabbar button:active { transform: scale(.98); }
  .tabbar button.active {
    background: var(--primary-600); color: #fff; box-shadow: var(--shadow);
  }
  .tabbar .ico {
    font-size: 18px; width: 34px; height: 34px; flex: 0 0 auto;
    display: flex; align-items: center; justify-content: center;
    border-radius: 9px; background: var(--surface);
  }
  .tabbar button.active .ico { background: rgba(255,255,255,.18); }
  #brand-home { display: block; }
  .app-shell { display: flex; flex-direction: row-reverse; }
  .app-main { flex: 1; min-width: 0; }
}
@media (max-width: 899px) {
  .mobile-hide { display: none; }
  .app-shell { display: block; }
  /* דוחסים את שורת הכפתורים העליונה כדי שכפתור היציאה תמיד יישאר בתוך המסך */
  .topbar { padding-left: 8px; padding-right: 10px; gap: 6px; }
  .topbar h2 { font-size: 15px; overflow: hidden; text-overflow: ellipsis;
               white-space: nowrap; min-width: 0; }
  .topbar .row { gap: 4px; flex-shrink: 0; }
  .topbar button, .topbar .bell { padding: 6px 8px; font-size: 12px; }
  .company-pill { max-width: 74px; overflow: hidden; text-overflow: ellipsis;
                  white-space: nowrap; padding: 5px 8px; }
  #go-dash { display: none; }   /* מיותר במובייל — לחיצה על "בית" בכותרת עושה אותו דבר */
}

/* החלפת חברה (אמיתית / דמו) */
.company-seg { display: flex; gap: 6px; margin: 12px 0; background: var(--surface-2);
  padding: 4px; border-radius: 12px; }
.company-seg button { flex: 1; border: none; background: transparent; padding: 9px 10px;
  border-radius: 9px; font-weight: 700; font-size: 13px; color: var(--text-muted);
  cursor: pointer; transition: .15s; }
.company-seg button.on { background: #fff; color: var(--primary); box-shadow: var(--shadow); }
.company-seg button.on.demo { color: #b45309; }
.company-pill { border: 1px solid var(--border); background: rgba(255,255,255,.15);
  color: #fff; padding: 5px 10px; border-radius: 999px; font-weight: 700; font-size: 12px;
  cursor: pointer; white-space: nowrap; }
.company-pill.demo { background: #f59e0b; border-color: #f59e0b; color: #4a2c00; }
.demo-banner { background: #fef3c7; color: #92400e; text-align: center; font-weight: 600;
  font-size: 13px; padding: 8px 14px; border-bottom: 1px solid #fcd34d; }

/* רשימת לקוחות נגללת (מסך מכירות) */
.cust-scroll { max-height: 62vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
/* תצוגות לחיצות — כל ריכוז נתונים שפותח פירוט בלחיצה (KPI, שורת מסמך, נקודת מפה וכו') */
.clickable { cursor: pointer; }
.stat.clickable { transition: .12s; }
.stat.clickable:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
tr.clickable:hover, .card.clickable:hover { background: var(--primary-50); }
/* תג התראות שנצפה — אייקון ⚠️ במקום מספר */
.nav-badge.seen, .home-badge.seen { background: transparent !important; color: #f59e0b !important;
  box-shadow: none; font-size: 15px; }

/* --- הצג/הסתר סיסמה במסך התחברות --- */
.pw-wrap { position: relative; display: flex; align-items: center; }
.pw-wrap input { flex: 1; padding-left: 42px; }
.pw-eye { position: absolute; left: 6px; background: none; border: none; cursor: pointer;
  font-size: 18px; opacity: .55; padding: 4px; line-height: 1; }
.pw-eye:hover, .pw-eye.on { opacity: 1; }

/* --- דרופ-דאון בחירת חברה מתגית העליונה --- */
.company-dd { position: fixed; z-index: 1200; min-width: 240px; max-width: 90vw;
  background: var(--surface, #fff); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-lg); padding: 6px; animation: ddIn .12s ease; }
@keyframes ddIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.company-dd-head { font-size: 12px; color: var(--muted, #64748b); padding: 6px 10px 4px; }
.company-dd-item { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; text-align: right; background: none; border: none; cursor: pointer;
  padding: 10px 12px; border-radius: 10px; font-size: 15px; color: inherit; }
.company-dd-item:hover { background: var(--primary-50, #eff6ff); }
.company-dd-item.current { font-weight: 700; }
.company-dd-item.manage { border-top: 1px solid var(--border); margin-top: 4px; color: var(--muted, #64748b); }
.company-dd-item .chev { color: var(--primary-600, #2563eb); font-size: 18px; }

/* --- כינוי לקוח --- */
.cust-nick { color: var(--muted, #64748b); font-weight: 400; font-size: .9em; }

/* --- שורת התראה חדשה / כפתור סימון --- */
.alert-row { display: flex; align-items: center; gap: 8px; }
.alert-row.is-new { position: relative; }
.alert-row.is-new::before { content: '●'; color: #f59e0b; font-size: 12px; margin-inline-end: 2px; }
.alert-toggle { white-space: nowrap; font-size: 12px; }

/* --- מפה: פאנל בקרים בצד ימין, מפה גדולה בצד שמאל --- */
.map-layout { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
.map-side { display: flex; flex-direction: column; }
.map-main { position: relative; }
.map-tall { height: calc(100vh - 220px); min-height: 480px; border-radius: 14px; }
@media (max-width: 900px) { .map-layout { grid-template-columns: 1fr; } .map-tall { height: 60vh; } }

/* מסך מלאי – שתי עמודות: מחסנים בעמודה הראשונה (ימין ב-RTL), סוכנים בשנייה (שמאל) */
.stock-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .stock-layout { grid-template-columns: 1fr; } }

/* נקודת סוכן בצבע */
.agent-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  margin-inline-end: 8px; border: 1px solid rgba(0,0,0,.15); vertical-align: middle; }
.agent-marker { background: none !important; border: none !important; }

/* כל ערך מספרי שלילי בתוכנה — אדום */
.neg { color: var(--danger, #dc2626); font-weight: 700; }
