:root {
  --navy: #012d66;
  --navy-2: #073a7d;
  --gold: #c9a961;
  --gold-2: #b8963f;
  --bg: #f4f6fa;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #7a8699;
  --line: #e5e9f0;
  --ok: #1f9d55;
  --warn: #d97706;
  --danger: #dc2626;
  --shadow: 0 2px 12px rgba(1,45,102,.08);
  font-family: "Segoe UI", "Assistant", "Heebo", Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
button { cursor: pointer; font-family: inherit; }

/* ---------- Login ---------- */
.login-screen { min-height: 100vh; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--navy), #001a3d); }
.login-card { background: var(--card); width: 360px; max-width: 92vw; padding: 34px 30px;
  border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.brand { text-align: center; margin-bottom: 22px; }
.brand .logo-img { width: 92px; height: 92px; object-fit: contain; margin-bottom: 4px; }
.brand h1 { margin: 6px 0 2px; color: var(--navy); letter-spacing: 1px; font-size: 30px; }
.brand .sub { margin: 0; color: var(--muted); font-size: 13px; }
.role-tabs { display: flex; gap: 6px; background: var(--bg); padding: 5px; border-radius: 10px; margin-bottom: 16px; }
.role-tabs button { flex: 1; border: 0; background: transparent; padding: 9px 4px; border-radius: 7px;
  color: var(--muted); font-size: 14px; font-weight: 600; }
.role-tabs button.active { background: var(--navy); color: #fff; }
#loginForm { display: flex; flex-direction: column; gap: 10px; }
#loginForm input { padding: 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 16px; text-align: center; }
#loginForm button { padding: 12px; border: 0; border-radius: 9px; background: var(--gold); color: var(--navy);
  font-weight: 700; font-size: 16px; }
#loginForm button:hover { background: var(--gold-2); }
.err { color: var(--danger); font-size: 13px; text-align: center; min-height: 18px; margin: 8px 0 0; }

/* ---------- Topbar ---------- */
.topbar { display: flex; align-items: center; gap: 18px; background: var(--navy); color: #fff;
  padding: 0 18px; height: 56px; position: sticky; top: 0; z-index: 20; }
.topbar .logo { font-weight: 700; font-size: 18px; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.topbar .logo .logo-mark-sm { width: 30px; height: 30px; object-fit: contain; background: #fff; border-radius: 7px; padding: 2px; }
.topbar .logo .muted { color: #9fb3d1; font-weight: 400; font-size: 14px; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button { border: 0; background: transparent; color: #cdd9ec; padding: 8px 14px; border-radius: 8px;
  font-size: 15px; font-weight: 600; white-space: nowrap; }
.tabs button.active { background: rgba(255,255,255,.14); color: #fff; }
.tabs button:hover { color: #fff; }
.tabs .badge { background: var(--gold); color: var(--navy); border-radius: 20px; font-size: 11px;
  padding: 0 6px; margin-inline-start: 5px; font-weight: 800; }
.user { display: flex; align-items: center; gap: 8px; }
.user #userLabel { font-size: 13px; color: #cdd9ec; }
.user button { border: 1px solid rgba(255,255,255,.25); background: transparent; color: #fff;
  border-radius: 7px; padding: 6px 10px; font-size: 13px; }
.user button:hover { background: rgba(255,255,255,.12); }

main { padding: 20px; max-width: 1200px; margin: 0 auto; }

/* ---------- KPI cards ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 22px; }
.kpi { background: var(--card); border-radius: 12px; padding: 16px; box-shadow: var(--shadow);
  border-top: 3px solid var(--gold); }
.kpi .num { font-size: 30px; font-weight: 800; color: var(--navy); line-height: 1; }
.kpi .lbl { color: var(--muted); font-size: 13px; margin-top: 6px; }
.kpi.accent { border-top-color: var(--ok); }
.kpi.accent .num { color: var(--ok); }

/* ---------- Section / cards ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 14px; }
.section-head h2 { margin: 0; color: var(--navy); font-size: 21px; }
.btn { background: var(--navy); color: #fff; border: 0; border-radius: 8px; padding: 9px 16px; font-weight: 600; font-size: 14px; }
.btn:hover { background: var(--navy-2); }
.btn.gold { background: var(--gold); color: var(--navy); }
.btn.gold:hover { background: var(--gold-2); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.ghost { background: transparent; color: var(--navy); border: 1px solid var(--line); }

.card { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { background: #fafbfe; color: var(--muted); font-weight: 700; font-size: 12.5px; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: #fafcff; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* status pills */
.pill { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.pill.gray { background: #eef1f6; color: #64748b; }
.pill.blue { background: #e0edff; color: #1d4ed8; }
.pill.green { background: #dcfce7; color: #15803d; }
.pill.gold { background: #f7edd3; color: #92702a; }
.pill.orange { background: #ffedd5; color: #c2410c; }
.pill.red { background: #fee2e2; color: #b91c1c; }

.agent-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.agent-card { background: var(--card); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); }
.agent-card h3 { margin: 0 0 2px; color: var(--navy); }
.agent-card .city { color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.agent-card .comm { font-size: 28px; font-weight: 800; color: var(--ok); }
.agent-card .comm small { font-size: 14px; color: var(--muted); font-weight: 500; }
.agent-card .stats { display: flex; gap: 14px; margin: 12px 0; font-size: 13px; }
.agent-card .stats b { color: var(--navy); font-size: 17px; display: block; }
.agent-card .row { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }

.linkish { color: var(--navy); text-decoration: none; font-weight: 600; }
.linkish:hover { text-decoration: underline; }
.wa { color: var(--ok); text-decoration: none; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(1,20,45,.55); display: grid; place-items: center; z-index: 50; }
.modal-card { background: var(--card); width: 460px; max-width: 94vw; max-height: 90vh; overflow: auto; border-radius: 14px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); }
.modal-head h3 { margin: 0; color: var(--navy); }
.modal-head button { border: 0; background: transparent; font-size: 18px; color: var(--muted); }
#modalBody { padding: 20px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.field input, .field select, .field textarea { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 15px; font-family: inherit; }
.field textarea { min-height: 64px; resize: vertical; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-start; margin-top: 8px; }

/* file box (חוזה) */
.file-box { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: #fafbfe; border: 1px solid var(--line); border-radius: 8px; padding: 10px; }

/* photo grid (לפני/אחרי) */
.photo-grid { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.photo-cell { position: relative; width: 78px; height: 78px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.photo-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-x { position: absolute; top: 2px; inset-inline-end: 2px; width: 20px; height: 20px; border: 0; border-radius: 50%;
  background: rgba(220,38,38,.9); color: #fff; font-size: 12px; line-height: 1; cursor: pointer; display: grid; place-items: center; }

/* thread (שרשור טיפול) */
.thread { display: flex; flex-direction: column; gap: 6px; margin: 6px 0; max-height: 180px; overflow-y: auto; }
.thread-item { background: #fafbfe; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 13.5px; line-height: 1.5; }
.thread-add { display: flex; gap: 6px; margin-top: 8px; }
.thread-add input { flex: 1; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; font-family: inherit; font-size: 14px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--navy);
  color: #fff; padding: 12px 22px; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.3); z-index: 60; font-weight: 600; }
.toast.ok { background: var(--ok); }
.toast.bad { background: var(--danger); }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px; }
  .tabs { order: 3; width: 100%; }
  main { padding: 12px; }
  th:nth-child(n+4), td:nth-child(n+4) { display: none; }
}
