/* ============================================================
   אופטיקה לכל כיס — מערכת ניהול מכירות | עיצוב RTL
   ============================================================ */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  --brand: #1e4e8c;
  --brand-dark: #163a68;
  --brand-light: #e8f0fb;

  --green: #16a34a;
  --green-bg: #d6f5e0;
  --green-border: #86efac;
  --blue: #2563eb;
  --blue-bg: #d6e6ff;
  --blue-border: #93c5fd;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --red-border: #fca5a5;
  --gray: #64748b;
  --gray-bg: #dfe5ee;
  --gray-border: #cbd5e1;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --purple: #7c3aed;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .07), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .12);
  --font: "Segoe UI", "Assistant", "Rubik", Arial, "Noto Sans Hebrew", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  direction: rtl;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ------------------------------ פריסה ------------------------------ */

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

.sidebar {
  width: 232px; flex-shrink: 0;
  background: var(--brand);
  color: #fff;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
}
.sidebar .brand { padding: 20px 18px 16px; border-bottom: 1px solid rgba(255,255,255,.15); }
.sidebar .brand h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.2px; }
.sidebar .brand p { margin: 4px 0 0; font-size: 12px; opacity: .75; }
.nav { padding: 10px 8px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 3px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.85); text-decoration: none;
  font-size: 14.5px; cursor: pointer;
  transition: background .12s;
}
.nav a:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav a.active { background: #fff; color: var(--brand); font-weight: 600; }
.nav a .ico { font-size: 17px; width: 22px; text-align: center; }
.sidebar-foot { padding: 12px 14px; font-size: 11.5px; opacity: .6; border-top: 1px solid rgba(255,255,255,.12); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 22px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 30;
}
.topbar h2 { margin: 0; font-size: 20px; font-weight: 700; }
.topbar .spacer { flex: 1; }

.content { padding: 20px 22px 60px; }

/* ------------------------------ רכיבים ------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}
.card > h3 {
  margin: 0; padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 15.5px; font-weight: 700;
  background: var(--surface-2);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.card > h3 .spacer { flex: 1; }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer; font-size: 14px; font-weight: 500;
  transition: all .12s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-faint); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.success:hover { filter: brightness(.93); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger:hover { filter: brightness(.93); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 9px; font-size: 12.5px; }
.btn.lg { padding: 11px 20px; font-size: 15.5px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; color: var(--text-muted); margin-bottom: 5px; font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%; padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff; color: var(--text);
  outline: none; transition: border-color .12s, box-shadow .12s;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-light); }
textarea.input { min-height: 72px; resize: vertical; }

.grid { display: grid; gap: 12px; }
.grid.c2 { grid-template-columns: repeat(2, 1fr); }
.grid.c3 { grid-template-columns: repeat(3, 1fr); }
.grid.c4 { grid-template-columns: repeat(4, 1fr); }
.grid.c5 { grid-template-columns: repeat(5, 1fr); }
.grid.c6 { grid-template-columns: repeat(6, 1fr); }
@media (max-width: 1100px) { .grid.c5, .grid.c6 { grid-template-columns: repeat(3, 1fr); } .grid.c4 { grid-template-columns: repeat(2,1fr);} }
@media (max-width: 760px) { .grid.c2, .grid.c3, .grid.c4, .grid.c5, .grid.c6 { grid-template-columns: 1fr; } }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--gray-bg); color: var(--gray);
  border: 1px solid var(--gray-border);
}
.badge.green { background: var(--green-bg); color: #15803d; border-color: var(--green-border); }
.badge.blue { background: var(--blue-bg); color: #1d4ed8; border-color: var(--blue-border); }
.badge.red { background: var(--red-bg); color: #b91c1c; border-color: var(--red-border); }
.badge.amber { background: var(--amber-bg); color: #b45309; border-color: #fcd34d; }
.badge.purple { background: #ede9fe; color: #6d28d9; border-color: #c4b5fd; }

/* ------------------------------ KPI ------------------------------ */

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px; box-shadow: var(--shadow);
  border-top: 3px solid var(--brand);
}
.kpi .label { font-size: 12px; color: var(--text-muted); font-weight: 600; margin-bottom: 5px; }
.kpi .value { font-size: 22px; font-weight: 700; letter-spacing: -.5px; }
.kpi .sub { font-size: 11.5px; color: var(--text-faint); margin-top: 3px; }
.kpi.green { border-top-color: var(--green); } .kpi.green .value { color: #15803d; }
.kpi.red { border-top-color: var(--red); } .kpi.red .value { color: #b91c1c; }
.kpi.amber { border-top-color: var(--amber); } .kpi.amber .value { color: #b45309; }
.kpi.blue { border-top-color: var(--blue); } .kpi.blue .value { color: #1d4ed8; }
.kpi.purple { border-top-color: var(--purple); } .kpi.purple .value { color: #6d28d9; }

/* ------------------------------ לוח שנה ------------------------------ */

.cal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.cal-title { font-size: 22px; font-weight: 700; }
.cal-title small { display: block; font-size: 13px; color: var(--text-muted); font-weight: 500; }

.calendar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.cal-dow { display: grid; grid-template-columns: repeat(7, 1fr); background: var(--brand); color: #fff; }
.cal-dow div { padding: 9px 4px; text-align: center; font-size: 13px; font-weight: 600; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }

.cal-day {
  min-height: 116px; border-left: 1px solid var(--border); border-bottom: 1px solid var(--border);
  padding: 6px 7px; position: relative; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px;
  transition: box-shadow .12s, filter .12s;
  background: var(--surface);
}
.cal-day:nth-child(7n) { border-left: none; }
.cal-day:hover { box-shadow: inset 0 0 0 2px var(--brand); z-index: 2; }
.cal-day.other { opacity: .38; }
.cal-day.today { box-shadow: inset 0 0 0 2px var(--amber); }
.cal-day .dnum { display: flex; align-items: baseline; gap: 6px; }
.cal-day .g { font-size: 17px; font-weight: 700; line-height: 1; }
.cal-day .h { font-size: 11.5px; color: var(--text-muted); font-weight: 600; }
.cal-day .hol { font-size: 10.5px; color: var(--gray); font-weight: 600; line-height: 1.25; }

.cal-day.st-available { background: var(--green-bg); }
.cal-day.st-available .g { color: #15803d; }
.cal-day.st-sale { background: var(--blue-bg); }
.cal-day.st-sale .g { color: #1d4ed8; }
.cal-day.st-blocked { background: var(--red-bg); }
.cal-day.st-blocked .g { color: #b91c1c; }
.cal-day.st-off { background: var(--gray-bg); color: var(--gray); }
.cal-day.st-off .g { color: var(--gray); }

.sale-chip {
  background: #fff; border: 1px solid var(--blue-border); border-right: 3px solid var(--blue);
  border-radius: 6px; padding: 3px 6px; font-size: 11.5px; line-height: 1.3;
  overflow: hidden;
}
.sale-chip b { display: block; font-size: 12px; color: #1d4ed8; }
.sale-chip span { color: var(--text-muted); }
.sale-chip.s2 { border-right-color: var(--purple); border-color: #c4b5fd; }
.sale-chip.s2 b { color: #6d28d9; }

.cal-add {
  position: absolute; bottom: 4px; left: 4px;
  width: 22px; height: 22px; border-radius: 6px;
  border: 1px dashed var(--border-strong); background: rgba(255,255,255,.85);
  color: var(--text-muted); font-size: 15px; line-height: 1;
  display: none; align-items: center; justify-content: center; cursor: pointer; padding: 0;
}
.cal-day:hover .cal-add { display: flex; }
.cal-add:hover { background: var(--brand); color: #fff; border-color: var(--brand); border-style: solid; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; font-size: 12.5px; color: var(--text-muted); }
.legend i { display: inline-block; width: 13px; height: 13px; border-radius: 4px; margin-left: 5px; vertical-align: -2px; border: 1px solid rgba(0,0,0,.08); }

@media (max-width: 900px) { .cal-day { min-height: 92px; } }

/* ------------------------------ טבלאות ------------------------------ */

.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th, table.tbl td { border: 1px solid var(--border); padding: 6px 8px; text-align: right; vertical-align: middle; }
table.tbl thead th {
  background: var(--brand); color: #fff; font-weight: 600; font-size: 13px;
  position: sticky; top: 0; z-index: 5; white-space: nowrap;
}
table.tbl tbody tr:nth-child(even) { background: var(--surface-2); }
table.tbl tbody tr:hover { background: var(--brand-light); }
table.tbl td.side-head { background: var(--brand-light); font-weight: 700; text-align: center; color: var(--brand); white-space: nowrap; }
table.tbl tfoot td { background: #eef2f7; font-weight: 700; }
table.tbl input, table.tbl select {
  width: 100%; border: 1px solid transparent; background: transparent;
  padding: 4px 5px; border-radius: 5px; outline: none; min-width: 60px;
}
table.tbl input:focus, table.tbl select:focus { border-color: var(--brand); background: #fff; box-shadow: 0 0 0 2px var(--brand-light); }
table.tbl input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--green); cursor: pointer; }
table.tbl td.center { text-align: center; }
table.tbl .rownum { background: var(--surface-2); color: var(--text-faint); font-size: 12px; text-align: center; width: 42px; }
.tbl-title { padding: 9px 14px; background: var(--brand-light); border-bottom: 1px solid var(--border); font-weight: 700; color: var(--brand); }

/* ------------------------------ מודאל ------------------------------ */

.modal-back {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); width: min(760px, 100%);
  max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal.wide { width: min(1100px, 100%); }
.modal.narrow { width: min(440px, 100%); }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; background: var(--surface-2); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px; overflow: auto; flex: 1; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-start; background: var(--surface-2); }

/* ------------------------------ טוסט ------------------------------ */

.toasts { position: fixed; bottom: 20px; left: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #0f172a; color: #fff; padding: 11px 16px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); font-size: 14px; max-width: 380px;
  animation: slideIn .18s ease-out;
}
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }
@keyframes slideIn { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ------------------------------ שונות ------------------------------ */

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button {
  background: none; border: none; padding: 9px 15px; cursor: pointer;
  font-size: 14.5px; color: var(--text-muted); font-weight: 600;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.tabs button:hover { color: var(--text); }

.empty { text-align: center; padding: 40px 20px; color: var(--text-faint); }
.empty .ico { font-size: 40px; opacity: .5; margin-bottom: 8px; }

.chart { display: flex; align-items: flex-end; justify-content: center; gap: 10px; height: 180px; padding: 10px 0; }
.chart .bar { flex: 1; max-width: 110px; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; min-width: 0; }
.chart .bar .fill { width: 100%; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; transition: height .3s; }
.chart .bar .fill.green { background: var(--green); }
.chart .bar .fill.red { background: var(--red); }
.chart .bar .lbl { font-size: 10.5px; color: var(--text-muted); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.chart .bar .val { font-size: 11px; font-weight: 700; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin: 0; min-width: 140px; }

.checkline { display: flex; align-items: center; gap: 8px; padding: 5px 0; }
.checkline input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--brand); }

.file-drop {
  border: 2px dashed var(--border-strong); border-radius: var(--radius);
  padding: 26px; text-align: center; color: var(--text-muted); cursor: pointer;
  background: var(--surface-2); transition: all .12s;
}
.file-drop:hover, .file-drop.over { border-color: var(--brand); background: var(--brand-light); color: var(--brand); }

.ad-thumb { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); }
.ad-thumb img { width: 100%; display: block; max-height: 260px; object-fit: contain; }
.ad-thumb .meta { padding: 8px 10px; font-size: 12.5px; display: flex; gap: 6px; align-items: center; }

.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { padding: 8px 10px; border-bottom: 1px solid var(--border); display: flex; gap: 8px; align-items: center; font-size: 13.5px; }
.mini-list li:last-child { border-bottom: none; }
.mini-list li.done { opacity: .55; }
.mini-list li.done .txt { text-decoration: line-through; }

/* --------------------- מגירת ניווט למסכים צרים --------------------- */

.sidebar-toggle { display: none; }
.nav-scrim { display: none; }

@media (max-width: 900px) {
  .sidebar {
    position: fixed; top: 0; right: 0; bottom: 0; height: 100%;
    width: 258px; z-index: 60;
    transform: translateX(100%);
    transition: transform .22s ease;
    box-shadow: -6px 0 24px rgba(15, 23, 42, .28);
  }
  .app.nav-open .sidebar { transform: none; }

  .nav-scrim {
    display: block; position: fixed; inset: 0;
    background: rgba(15, 23, 42, .45);
    z-index: 55; opacity: 0; pointer-events: none;
    transition: opacity .22s ease;
  }
  .app.nav-open .nav-scrim { opacity: 1; pointer-events: auto; }

  .sidebar-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; padding: 0; flex-shrink: 0;
    font-size: 19px; line-height: 1;
  }

  .topbar { padding: 10px 12px; gap: 10px; flex-wrap: nowrap; }
  .topbar h2 { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* קיצורי הדרך כפולים למגירת הניווט — מוסתרים כדי לפנות מקום */
  .topbar > .btn.sm { display: none; }
  .content { padding: 14px 12px 60px; }
  .card > h3 { padding: 11px 12px; font-size: 14.5px; }
  .card-body { padding: 12px; }
  .kpis { gap: 8px; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); }
  .kpi { padding: 10px 12px; }
  .kpi .value { font-size: 19px; }
  .cal-head { gap: 6px; }
  .cal-title { font-size: 18px; width: 100%; order: -1; }
  .modal-back { padding: 0; align-items: flex-end; }
  .modal { max-height: 94vh; border-radius: var(--radius) var(--radius) 0 0; }
}

/* ------------------------ לוח שנה במסך צר ------------------------ */

.dow-full { display: inline; }
.dow-short { display: none; }

@media (max-width: 640px) {
  .dow-full { display: none; }
  .dow-short { display: inline; }
  .cal-dow div { padding: 7px 1px; font-size: 12px; }
  .cal-day { min-height: 76px; padding: 4px 3px 20px; gap: 2px; }
  .cal-day .dnum { flex-direction: column; align-items: flex-start; gap: 0; }
  .cal-day .g { font-size: 14px; }
  .cal-day .h { font-size: 9.5px; line-height: 1.15; }
  .cal-day .hol { font-size: 8.5px; }
  .cal-day .badge { font-size: 9.5px; padding: 1px 5px; }
  .sale-chip { font-size: 9.5px; padding: 2px 3px; border-right-width: 2px; }
  .sale-chip b { font-size: 10px; }
  .sale-chip span { display: none; }
  /* אין hover במסך מגע — הכפתור תמיד גלוי, בשקיפות עדינה */
  .cal-add { display: flex; width: 17px; height: 17px; font-size: 12px; opacity: .6; bottom: 2px; left: 2px; }
  .legend { font-size: 11.5px; gap: 10px; }
  .btn { padding: 7px 11px; font-size: 13.5px; }
  .btn.sm { padding: 5px 8px; font-size: 12px; }
  table.tbl { font-size: 12.5px; }
  .chart { height: 150px; }
}

.print-only { display: none; }
@media print {
  .sidebar, .topbar, .btn, .no-print, .nav-scrim { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none; page-break-inside: avoid; }
  .print-only { display: block; }
  body { background: #fff; }
}
