/* ===== מסנג'ר רבדים — מערכת העיצוב ===== */

@font-face {
  font-family: "Heebo";
  src: url("/static/fonts/heebo-hebrew.woff2") format("woff2");
  unicode-range: U+0590-05FF, U+20AA, U+25CC, U+FB1D-FB4F;
  font-weight: 100 900; font-display: swap;
}
@font-face {
  font-family: "Heebo";
  src: url("/static/fonts/heebo-latin.woff2") format("woff2");
  font-weight: 100 900; font-display: swap;
}

:root {
  --bg: #eef1f8;
  --bg-glow-1: rgba(99, 102, 241, .14);
  --bg-glow-2: rgba(217, 70, 239, .10);
  --surface: rgba(255, 255, 255, .78);
  --surface-solid: #ffffff;
  --border: rgba(15, 23, 42, .08);
  --text: #0f172a;
  --text-dim: #64748b;
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --accent-grad: linear-gradient(135deg, #6366f1, #a855f7);
  --danger: #e11d48;
  --ok: #16a34a;
  --warn: #d97706;
  --warn-bg: rgba(245, 158, 11, .12);
  --bubble-in: #ffffff;
  --bubble-out: linear-gradient(135deg, #6366f1, #7c3aed);
  --bubble-out-text: #ffffff;
  --note-bg: #fef9c3;
  --note-text: #713f12;
  --shadow: 0 8px 30px rgba(15, 23, 42, .08);
  --radius: 18px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --bg-glow-1: rgba(99, 102, 241, .16);
    --bg-glow-2: rgba(217, 70, 239, .10);
    --surface: rgba(23, 30, 51, .72);
    --surface-solid: #171e33;
    --border: rgba(148, 163, 184, .12);
    --text: #e2e8f0;
    --text-dim: #94a3b8;
    --bubble-in: #1e2740;
    --note-bg: #423c14;
    --note-text: #fde68a;
    --shadow: 0 8px 30px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  font-family: "Heebo", system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  background-image:
    radial-gradient(60rem 40rem at 110% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(50rem 36rem at -20% 110%, var(--bg-glow-2), transparent 60%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input, textarea { font-family: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }

/* ===== מעטפת ===== */
.app { display: flex; flex-direction: column; height: 100dvh; max-width: 1280px; margin: 0 auto; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 12px; background: var(--accent-grad);
  display: grid; place-items: center; color: #fff; font-size: 17px;
  box-shadow: 0 4px 14px rgba(124, 58, 237, .4);
}
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(22, 163, 74, .2); }
.live-dot.off { background: var(--danger); box-shadow: 0 0 0 3px rgba(225, 29, 72, .15); }
.topbar .spacer { flex: 1; }
.topbar .user { color: var(--text-dim); font-size: 13px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--border); font-size: 16px;
  transition: transform .15s;
}
.icon-btn:active { transform: scale(.92); }
.icon-btn.on { background: var(--accent-grad); color: #fff; border-color: transparent; }

/* ===== גוף: רשימה + שיחה ===== */
.body { flex: 1; display: flex; gap: 14px; padding: 0 14px 14px; min-height: 0; }
.pane {
  background: var(--surface); border: 1px solid var(--border);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.pane.list { width: 370px; flex-shrink: 0; }
.pane.chat { flex: 1; }

@media (max-width: 860px) {
  .body { padding: 0 8px 8px; }
  .pane.list { width: 100%; }
  .pane.chat { position: fixed; inset: 0; z-index: 40; border-radius: 0; display: none; }
  body.chat-open .pane.chat { display: flex; }
  body.chat-open .pane.list { display: none; }
}
@media (min-width: 861px) { .back-btn { display: none !important; } }

/* ===== טאבים ===== */
.tabs { display: flex; gap: 6px; padding: 12px 12px 8px; }
.tab {
  flex: 1; padding: 8px 4px; border-radius: 12px; font-size: 13px; font-weight: 600;
  color: var(--text-dim); background: transparent; position: relative;
  transition: background .2s, color .2s;
}
.tab.active { background: var(--accent-grad); color: #fff; box-shadow: 0 4px 12px rgba(124, 58, 237, .35); }
.tab .count {
  font-size: 11px; font-weight: 800; margin-inline-start: 4px;
  background: rgba(255, 255, 255, .25); border-radius: 99px; padding: 0 6px;
}
.tab:not(.active) .count { background: var(--border); }
.tab.attention::after {
  content: ""; position: absolute; top: 4px; inset-inline-end: 8px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--warn);
  animation: pulse 1.6s infinite;
}

/* ===== רשימת שיחות ===== */
.conv-list { flex: 1; overflow-y: auto; padding: 4px 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.conv-card {
  display: flex; gap: 10px; align-items: center; text-align: start; width: 100%;
  padding: 10px 12px; border-radius: 14px; border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.conv-card:hover { background: rgba(99, 102, 241, .06); }
.conv-card.selected { background: rgba(99, 102, 241, .1); border-color: rgba(99, 102, 241, .25); }
.conv-card.pending { border-color: rgba(217, 119, 6, .4); background: var(--warn-bg); animation: glowPulse 2.2s infinite; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 16px;
}
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; align-items: center; gap: 6px; }
.conv-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { margin-inline-start: auto; font-size: 11px; color: var(--text-dim); flex-shrink: 0; }
.conv-preview { font-size: 12.5px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.badges { display: flex; align-items: center; gap: 5px; margin-top: 4px; flex-wrap: wrap; }
.unread {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px;
  background: var(--accent-grad); color: #fff; font-size: 11px; font-weight: 800;
  display: grid; place-items: center; flex-shrink: 0;
}

/* תגי ערוץ */
.chip {
  font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 99px;
  color: #fff; display: inline-flex; align-items: center; gap: 4px;
}
.chip.whatsapp  { background: #22c55e; }
.chip.messenger { background: #3b82f6; }
.chip.instagram { background: linear-gradient(45deg, #f59e0b, #ec4899, #8b5cf6); }
.chip.email     { background: #d97706; }
.chip.telegram  { background: #0ea5e9; }
.chip.mirakl    { background: #ef4444; }
.chip.web       { background: #64748b; }

.chip.status { color: var(--text); background: var(--border); }
.chip.status.bot      { background: rgba(99, 102, 241, .15); color: var(--accent); }
.chip.status.pending  { background: var(--warn-bg); color: var(--warn); }
.chip.status.open     { background: rgba(22, 163, 74, .15); color: var(--ok); }
.chip.status.resolved { background: var(--border); color: var(--text-dim); }
.chip.wait { background: var(--warn); color: #fff; animation: pulse 1.6s infinite; }

/* ===== מסך שיחה ===== */
.chat-header {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.chat-header .titles { min-width: 0; }
.chat-header .name { font-weight: 800; font-size: 15px; }
.chat-header .sub { display: flex; gap: 6px; align-items: center; margin-top: 3px; }
.chat-actions { margin-inline-start: auto; display: flex; gap: 6px; flex-shrink: 0; }
.btn {
  padding: 8px 14px; border-radius: 12px; font-size: 13px; font-weight: 700;
  border: 1px solid var(--border); background: var(--surface-solid);
  transition: transform .15s, box-shadow .15s;
}
.btn:active { transform: scale(.95); }
.btn.primary { background: var(--accent-grad); color: #fff; border-color: transparent; box-shadow: 0 4px 12px rgba(124, 58, 237, .35); }
.btn.ghost-danger { color: var(--danger); }
.btn:disabled { opacity: .45; cursor: default; }

.messages { flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 8px; }
.day-sep { align-self: center; font-size: 11px; color: var(--text-dim); background: var(--border); padding: 3px 12px; border-radius: 99px; margin: 8px 0 4px; }
.msg { max-width: 76%; display: flex; flex-direction: column; }
.msg.in  { align-self: flex-start; }
.msg.out { align-self: flex-end; }
.msg .bubble {
  padding: 9px 13px; border-radius: 16px; font-size: 14px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; box-shadow: 0 2px 8px rgba(15, 23, 42, .06);
}
.msg.in .bubble  { background: var(--bubble-in); border-start-start-radius: 4px; }
.msg.out .bubble { background: var(--bubble-out); color: var(--bubble-out-text); border-start-end-radius: 4px; }
.msg.note .bubble { background: var(--note-bg); color: var(--note-text); border: 1px dashed rgba(120, 90, 20, .35); }
.msg .meta { display: flex; gap: 6px; align-items: center; font-size: 10.5px; color: var(--text-dim); margin-top: 3px; padding: 0 4px; }
.msg.out .meta { align-self: flex-end; }
.sender-tag { font-weight: 700; }
.sender-tag.bot { color: var(--accent); }
.tick { font-size: 11px; }
.tick.read { color: #38bdf8; }
.tick.failed { color: var(--danger); font-weight: 800; }
.msg img.attach { max-width: 240px; border-radius: 12px; margin-top: 6px; display: block; }

/* ===== קומפוזר ===== */
.composer { padding: 10px 12px 12px; border-top: 1px solid var(--border); }
.composer-banner {
  font-size: 12.5px; padding: 8px 12px; border-radius: 10px; margin-bottom: 8px;
  background: var(--warn-bg); color: var(--warn); font-weight: 600;
}
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--border); background: var(--surface-solid);
  border-radius: 14px; padding: 10px 14px; font-size: 14px; line-height: 1.4;
  max-height: 120px; outline: none;
}
.composer textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99, 102, 241, .15); }
.composer textarea.note-mode { background: var(--note-bg); color: var(--note-text); }
.send-btn {
  width: 42px; height: 42px; border-radius: 50%; background: var(--accent-grad); color: #fff;
  font-size: 17px; display: grid; place-items: center; flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(124, 58, 237, .4); transition: transform .15s;
}
.send-btn:active { transform: scale(.88); }
.send-btn:disabled { opacity: .4; }
.note-toggle { font-size: 12px; font-weight: 700; color: var(--text-dim); padding: 6px 10px; border-radius: 10px; }
.note-toggle.on { background: var(--note-bg); color: var(--note-text); }

/* ===== מצבים ריקים ===== */
.empty { flex: 1; display: grid; place-items: center; color: var(--text-dim); text-align: center; padding: 30px; }
.empty .big { font-size: 44px; margin-bottom: 10px; }

/* ===== באנר התקנה (אייפון) ===== */
.install-banner {
  margin: 12px 12px 0; padding: 9px 12px; border-radius: 12px; font-size: 12.5px;
  background: var(--soft, rgba(99, 102, 241, .08)); color: var(--text);
  border: 1px solid rgba(99, 102, 241, .25); display: flex; align-items: center; gap: 6px;
}
.install-banner b { font-weight: 700; }
.install-banner button { margin-inline-start: auto; color: var(--text-dim); font-size: 13px; }

/* ===== חיפוש ===== */
.search-row { padding: 12px 12px 0; }
.search-box {
  width: 100%; padding: 9px 14px; border-radius: 12px; font-size: 13.5px;
  border: 1px solid var(--border); background: var(--surface-solid); outline: none;
}
.search-box:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99, 102, 241, .12); }

/* ===== התיישנות בתור — כתום אחרי שעה, אדום אחרי 4 ===== */
.conv-card.age-warn { border-inline-start: 3px solid var(--warn); }
.conv-card.age-crit { border-inline-start: 3px solid var(--danger); background: rgba(225, 29, 72, .05); }

/* ===== תשובות שמורות ===== */
.canned-picker {
  margin-bottom: 8px; background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); max-height: 220px; overflow-y: auto;
}
.canned-item {
  display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: start;
  padding: 9px 14px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.canned-item:last-child { border-bottom: 0; }
.canned-item:hover { background: rgba(99, 102, 241, .07); }
.canned-item b { font-size: 12.5px; }
.canned-item span { color: var(--text-dim); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===== שלח-וסגור + תפריט ===== */
.send-btn.secondary { background: var(--surface-solid); color: var(--ok);
  border: 1px solid var(--border); box-shadow: none; font-size: 15px; }
.menu-wrap { position: relative; }
.menu {
  position: absolute; top: 42px; inset-inline-end: 0; z-index: 50; min-width: 190px;
  background: var(--surface-solid); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden;
}
.menu button { display: block; width: 100%; text-align: start; padding: 10px 14px; font-size: 13px; }
.menu button:hover { background: rgba(99, 102, 241, .07); }
.menu button.danger { color: var(--danger); }

.toast-action {
  margin-inline-start: 10px; font-weight: 800; color: var(--accent);
  background: rgba(255, 255, 255, .15); border-radius: 8px; padding: 2px 10px;
}

/* ===== טוסט ===== */
.toast {
  position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px;
  font-size: 13px; font-weight: 600; box-shadow: var(--shadow); z-index: 100;
  opacity: 0; transition: opacity .25s; pointer-events: none; max-width: 90vw;
}
.toast.show { opacity: 1; pointer-events: auto; }

/* ===== התחברות ===== */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  backdrop-filter: blur(14px); border-radius: 22px; box-shadow: var(--shadow);
  padding: 32px 28px; text-align: center;
}
.login-card .logo {
  width: 62px; height: 62px; border-radius: 20px; background: var(--accent-grad);
  display: grid; place-items: center; color: #fff; font-size: 30px; margin: 0 auto 14px;
  box-shadow: 0 8px 24px rgba(124, 58, 237, .45);
}
.login-card h1 { font-size: 20px; font-weight: 800; margin-bottom: 4px; }
.login-card .sub { color: var(--text-dim); font-size: 13px; margin-bottom: 22px; }
.login-card input {
  width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-solid); font-size: 14px; margin-bottom: 10px; outline: none;
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99, 102, 241, .15); }
.login-card .btn.primary { width: 100%; padding: 11px; font-size: 14px; margin-top: 6px; }
.login-error { color: var(--danger); font-size: 13px; font-weight: 600; min-height: 18px; margin-top: 10px; }

/* ===== אנימציות ===== */
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(217, 119, 6, .25); }
  50% { box-shadow: 0 0 0 6px rgba(217, 119, 6, 0); }
}
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg, .conv-card { animation: slideIn .18s ease-out; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
