/* ===== וואטסאפ יד עוטפת — מסך ייעודי בסגנון WhatsApp Business ===== */
:root {
  --wa-green: #128C7E;
  --wa-green-dark: #075E54;
  --wa-light: #25D366;
  --bg-app: #f0f2f5;
  --bg-side: #ffffff;
  --bg-head: #f0f2f5;
  --bg-thread: #efeae2;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --ink: #111b21;
  --muted: #667781;
  --line: #e9edef;
  --hover: #f5f6f6;
  --active: #f0f2f5;
  --tick: #53bdeb;
  --shadow: 0 1px 1px rgba(11,20,26,.13);
}
[data-theme="dark"] {
  --bg-app: #0b141a;
  --bg-side: #111b21;
  --bg-head: #202c33;
  --bg-thread: #0b141a;
  --bubble-in: #202c33;
  --bubble-out: #005c4b;
  --ink: #e9edef;
  --muted: #8696a0;
  --line: #222d34;
  --hover: #202c33;
  --active: #2a3942;
  --shadow: 0 1px 1px rgba(0,0,0,.3);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; direction: rtl; background: var(--bg-app); color: var(--ink);
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif; font-size: 15px;
  overflow: hidden;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; color: inherit; }

/* מסך טעינה */
.boot { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg-app); z-index: 500; }
.boot-inner { text-align: center; color: var(--muted); }
.boot-logo { font-size: 56px; margin-bottom: 10px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: .35 } 50% { opacity: 1 } }

/* פריסה */
.app { display: flex; height: 100vh; height: 100dvh; max-width: 1600px; margin: 0 auto; background: var(--bg-side); box-shadow: 0 0 20px rgba(0,0,0,.06); }
.side { width: 380px; flex: 0 0 380px; display: flex; flex-direction: column; border-inline-start: 1px solid var(--line); background: var(--bg-side); min-height: 0; }
.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg-thread); position: relative; }

/* ראש סרגל הצד */
.side-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--bg-head); border-bottom: 1px solid var(--line); }
.me { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.me-txt { display: flex; flex-direction: column; min-width: 0; }
.me-txt b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-txt span { font-size: 11px; color: var(--muted); }
.side-actions { display: flex; gap: 2px; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 17px; color: var(--muted); text-decoration: none; }
.icon-btn:hover { background: var(--hover); }

/* עיגול ראשי תיבות */
.avatar { width: 44px; height: 44px; border-radius: 50%; flex: 0 0 44px; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: #fff; background: var(--wa-green); letter-spacing: .5px; user-select: none; }
.me-avatar { width: 38px; height: 38px; flex-basis: 38px; font-size: 13px; }

/* חיפוש + צ'יפים */
.search-row { padding: 7px 11px; background: var(--bg-side); }
.search-row input { width: 100%; padding: 9px 13px; border-radius: 9px; border: none; background: var(--bg-head); font-size: 14px; outline: none; }
/* גלישה לשתי שורות במקום גלילה אופקית — כל המסננים נראים בבת אחת */
.chips { display: flex; flex-wrap: wrap; gap: 4px; padding: 2px 11px 8px; }
.chip { flex: 0 0 auto; padding: 3px 7px; border-radius: 999px; background: var(--bg-head); color: var(--muted); font-size: 11.5px; white-space: nowrap; line-height: 1.55; }
.chip.active { background: #d9fdd3; color: #015c4b; font-weight: 600; }
[data-theme="dark"] .chip.active { background: #103529; color: #a6e6c4; }

/* רשימת שיחות */
.convos { flex: 1; overflow-y: auto; min-height: 0; }
.convo { display: flex; gap: 12px; padding: 10px 13px; cursor: pointer; border-bottom: 1px solid var(--line); position: relative; }
.convo:hover { background: var(--hover); }
.convo.active { background: var(--active); }
.convo.care::before { content: ''; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 3px; background: #f59e0b; }
.cv-body { flex: 1; min-width: 0; }
.cv-top { display: flex; align-items: baseline; gap: 6px; }
.cv-name { font-size: 15px; font-weight: 500; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo.unread .cv-name { font-weight: 700; }
.cv-time { font-size: 11.5px; color: var(--muted); flex: 0 0 auto; }
.convo.unread .cv-time { color: var(--wa-light); font-weight: 600; }
.cv-last { display: flex; align-items: center; gap: 5px; margin-top: 2px; }
.cv-txt { flex: 1; min-width: 0; font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-dot { flex: 0 0 auto; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 999px; background: var(--wa-light); color: #fff; font-size: 11.5px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.cv-tags { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.tag { font-size: 10.5px; padding: 1.5px 7px; border-radius: 999px; background: var(--bg-head); color: var(--muted); }
.tag.lead { background: #dbeafe; color: #1e40af; }
.tag.care { background: #fef3c7; color: #92400e; }
.tag.done { background: #dcfce7; color: #166534; }
.tag.ext { background: #ede9fe; color: #5b21b6; }
[data-theme="dark"] .tag.lead { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .tag.care { background: #4a3410; color: #fcd34d; }
[data-theme="dark"] .tag.done { background: #14432a; color: #86efac; }
[data-theme="dark"] .tag.ext { background: #3b2a5c; color: #c4b5fd; }
.side-foot { padding: 7px 13px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--line); text-align: center; }

/* מסך ריק */
.placeholder { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--muted); padding: 30px; }
.ph-logo { font-size: 76px; opacity: .3; }
.placeholder h2 { font-size: 30px; font-weight: 300; margin: 12px 0 6px; color: var(--ink); opacity: .75; }
.placeholder p { font-size: 14px; line-height: 1.8; margin: 0; }

/* חלון שיחה */
.chat-inner { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 11px; padding: 8px 14px; background: var(--bg-head); border-bottom: 1px solid var(--line); }
.back-btn { display: none; }
.ch-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ch-txt b { font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-txt span { font-size: 12.5px; color: var(--muted); }
.ch-actions { display: flex; align-items: center; gap: 6px; }
.win-badge { font-size: 11.5px; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.win-badge.open { background: #d9fdd3; color: #015c4b; }
.win-badge.closed { background: #fde2e2; color: #b91c1c; }
[data-theme="dark"] .win-badge.open { background: #103529; color: #a6e6c4; }
[data-theme="dark"] .win-badge.closed { background: #4a1d1d; color: #fca5a5; }

/* שורת שיוך */
.assign-bar { display: flex; align-items: center; gap: 7px; padding: 6px 14px; background: var(--bg-side); border-bottom: 1px solid var(--line); }
.assign-lbl { font-size: 12.5px; color: var(--muted); }
.assign-sel { padding: 4px 8px; border-radius: 7px; border: 1px solid var(--line); background: var(--bg-head); font-size: 12.5px; outline: none; }
.assign-btn { font-size: 12px; font-weight: 700; padding: 4px 11px; border-radius: 999px; }
.assign-btn.todo { background: #fef3c7; color: #92400e; }
.assign-btn.done { background: #dcfce7; color: #166534; }

/* אזור ההודעות — רקע הדוodle של וואטסאפ */
.thread { flex: 1; overflow-y: auto; padding: 16px 6% 10px; min-height: 0;
  background-color: var(--bg-thread);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='90' viewBox='0 0 90 90'%3E%3Cg fill='%23000' fill-opacity='.03'%3E%3Ccircle cx='12' cy='12' r='2.5'/%3E%3Ccircle cx='58' cy='34' r='2'/%3E%3Ccircle cx='30' cy='66' r='2.2'/%3E%3Ccircle cx='76' cy='74' r='1.8'/%3E%3Cpath d='M46 8h10v2H46zM4 44h8v2H4zM64 54h9v2h-9z'/%3E%3C/g%3E%3C/svg%3E");
}
.day { text-align: center; margin: 14px 0 10px; }
.day span { background: var(--bubble-in); color: var(--muted); font-size: 12px; padding: 5px 12px; border-radius: 8px; box-shadow: var(--shadow); }

.bubble { max-width: 68%; padding: 6px 9px 8px; border-radius: 8px; margin-bottom: 5px; box-shadow: var(--shadow);
  position: relative; word-wrap: break-word; white-space: pre-wrap; line-height: 1.5; font-size: 14.4px; clear: both; }
.bubble.in { background: var(--bubble-in); margin-inline-end: auto; border-start-end-radius: 0; }
.bubble.out { background: var(--bubble-out); margin-inline-start: auto; border-start-start-radius: 0; }
.bubble.grp { border-start-end-radius: 8px; border-start-start-radius: 8px; }
.b-meta { display: flex; align-items: center; justify-content: flex-start; gap: 4px; float: left; margin: 4px 0 -4px 0; padding-inline-start: 8px; }
.b-time { font-size: 11px; color: var(--muted); white-space: nowrap; }
.b-tick { font-size: 12px; color: var(--muted); }
.b-tick.read { color: var(--tick); }
.b-tick.err { color: #ef4444; }
.b-quote { border-inline-start: 4px solid var(--wa-light); background: rgba(0,0,0,.05); border-radius: 5px; padding: 4px 8px; margin-bottom: 4px; font-size: 13px; opacity: .85; }
.b-tpl { font-size: 10.5px; color: var(--muted); margin-bottom: 3px; }
.b-media img { max-width: 100%; border-radius: 6px; display: block; margin-bottom: 4px; cursor: pointer; }
.b-file { display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,.06); border-radius: 7px; padding: 8px 10px; margin-bottom: 4px; text-decoration: none; color: inherit; }
.b-file b { font-size: 13px; }
.b-by { font-size: 10.5px; color: var(--muted); margin-top: 3px; }
/* פעולות על בועה (תשובה/מחיקה) — מופיעות בריחוף, מחוץ לבועה */
.b-acts { position: absolute; top: 0; inset-inline-start: -30px; display: flex; flex-direction: column; gap: 2px; opacity: 0; transition: opacity .15s; }
.bubble:hover .b-acts { opacity: 1; }
.b-acts button { font-size: 12px; line-height: 1; padding: 3px; border-radius: 50%; color: var(--muted); background: var(--bg-side); box-shadow: var(--shadow); }
.b-acts button:hover { color: var(--wa-green); }
.b-acts button:last-child:hover { color: #dc2626; }
.icon-btn.danger-btn:hover { background: #fee2e2; color: #b91c1c; }

/* פס ציטוט מעל תיבת הכתיבה */
.reply-strip { display: flex; align-items: center; gap: 8px; padding: 7px 14px; background: var(--bg-head); border-top: 1px solid var(--line); }
.reply-strip-in { flex: 1; min-width: 0; border-inline-start: 4px solid var(--wa-light); padding-inline-start: 9px; }
.reply-strip-in b { display: block; font-size: 12.5px; color: var(--wa-green); }
.reply-strip-in span { font-size: 12.5px; color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* תיבת כתיבה */
.compose { display: flex; align-items: flex-end; gap: 5px; padding: 8px 12px; background: var(--bg-head); }
.input-wrap { flex: 1; background: var(--bg-side); border-radius: 9px; padding: 8px 12px; min-width: 0; }
.input-wrap textarea { width: 100%; border: none; outline: none; resize: none; background: transparent; font-size: 14.5px; line-height: 1.5; max-height: 130px; }
.send-btn { width: 42px; height: 42px; border-radius: 50%; background: var(--wa-green); color: #fff; font-size: 18px; flex: 0 0 42px; display: flex; align-items: center; justify-content: center; }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }
.compose.locked .input-wrap { opacity: .55; }

/* אימוג'ים */
.emoji-pop { position: absolute; bottom: 62px; inset-inline-start: 12px; background: var(--bg-side); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px; display: grid; grid-template-columns: repeat(9, 1fr); gap: 2px; box-shadow: 0 6px 26px rgba(0,0,0,.22); z-index: 40; max-height: 210px; overflow-y: auto; }
.emoji-pop button { font-size: 21px; width: 32px; height: 32px; border-radius: 6px; }
.emoji-pop button:hover { background: var(--hover); }

/* מודאל */
.modal { position: fixed; inset: 0; background: rgba(11,20,26,.65); display: flex; align-items: center; justify-content: center; z-index: 300; padding: 20px; }
.modal-card { background: var(--bg-side); border-radius: 14px; width: 460px; max-width: 100%; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 12px 50px rgba(0,0,0,.35); }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; flex: 1; font-size: 17px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-body label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.modal-body input, .modal-body select { width: 100%; margin-top: 4px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-head); font-size: 14.5px; outline: none; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); }
.btn-primary { background: var(--wa-green); color: #fff; padding: 9px 20px; border-radius: 8px; font-size: 14.5px; font-weight: 600; }
.btn-ghost { background: transparent; border: 1px solid var(--line); padding: 9px 18px; border-radius: 8px; font-size: 14.5px; }
.tpl-prev-lbl { font-size: 12px; color: var(--muted); margin: 6px 0; }
.bubble.preview { max-width: 100%; margin: 0; float: none; }
.err { color: #ef4444; font-size: 13px; min-height: 18px; margin: 8px 0 0; }

/* טוסט */
.toast { position: fixed; bottom: 24px; inset-inline-start: 50%; transform: translateX(50%); background: #111b21; color: #fff;
  padding: 11px 20px; border-radius: 9px; font-size: 14px; z-index: 400; box-shadow: 0 6px 24px rgba(0,0,0,.35); max-width: 90vw; }

/* מובייל — מסך אחד בכל פעם */
@media (max-width: 820px) {
  .app { max-width: none; }
  .side { width: 100%; flex-basis: 100%; border: none; }
  .app.in-chat .side { display: none; }
  .app:not(.in-chat) .chat { display: none; }
  .back-btn { display: inline-flex; }
  .thread { padding: 12px 10px 8px; }
  .bubble { max-width: 84%; }
}

/* מונים על הצ'יפים */
.chip-n { display: none; margin-inline-start: 4px; background: var(--muted); color: #fff; border-radius: 999px;
  padding: 0 5px; font-size: 10.5px; font-weight: 700; min-width: 15px; text-align: center; }
.chip-n.on { display: inline-block; }
.chip-n.warn { background: #f59e0b; color: #422006; }
.chip-n.red { background: #ef4444; }
.chip-n.green { background: var(--wa-light); }
.chip-n.blue { background: #3b82f6; }
.chip.active .chip-n { background: #015c4b; color: #fff; }
.chip.active .chip-n.warn { background: #b45309; color: #fff; }
.chip.active .chip-n.red { background: #b91c1c; }
.chip.active .chip-n.blue { background: #1d4ed8; }
.tag.fam { background: #fce7f3; color: #9d174d; }
[data-theme="dark"] .tag.fam { background: #4a1d38; color: #f9a8d4; }
.tag.merged { background: #e0f2fe; color: #075985; }
[data-theme="dark"] .tag.merged { background: #0c3a54; color: #7dd3fc; }

/* סימון מהיר נקרא / לא-נקרא בשורת השיחה */
.cv-mark { flex: 0 0 auto; font-size: 13px; line-height: 1; color: #cbd5e1; padding: 2px; border-radius: 50%; opacity: 0; transition: opacity .15s; }
.convo:hover .cv-mark, .cv-mark.on { opacity: 1; }
.cv-mark.on { color: var(--wa-light); }
.cv-mark:hover { color: var(--wa-green); }
