/* ניהול דילים: ערכת עיצוב. כל הצבעים מגיעים ממשתני CSS שמוגדרים מ-core.js (applyTheme) */
:root {
  --accent: #4F46E5; --accent-d: #4338CA; --accent-soft: #EEF0FF; --on-accent: #fff;
  --bg: #F4F5FB; --surface-rgb: 255,255,255; --surface: #fff; --alt: #F8F9FA; --header: #F1F3F4;
  --border: #DADCE0; --text: #202124; --muted: #5F6368; --side: #1F2340; --side-text: #D5D8F0; --side-sel: #4F46E5;
  --side-hover: #2B3055; --danger: #DC2626; --ok: #16A34A; --warn: #B45309;
  --glass: 1; --sideglass: 1; --radius: 14px; --r-btn: 18px; --r-in: 10px; --fs: 15px; --font: 'Heebo', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  --veil: 0;
}
* { box-sizing: border-box; }
html, body, #root { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: var(--fs);
  line-height: 1.55; -webkit-font-smoothing: antialiased; overflow: hidden;
}
#bg { position: fixed; inset: 0; z-index: -2; background-size: cover; background-position: center; }
#veil { position: fixed; inset: 0; z-index: -1; background: rgba(0,0,0,var(--veil)); pointer-events: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.ltr { direction: ltr; text-align: left; unicode-bidi: plaintext; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 10px; }
.spacer { flex: 1; }

/* ---------- מסך כניסה ---------- */
.login-wrap { height: 100%; display: grid; place-items: center; padding: 20px; overflow: auto; }
.login-card { width: min(400px, 100%); }
.login-card h1 { margin: 0 0 4px; font-size: 1.6rem; }
.login-logo { font-size: 2.4rem; }

/* ---------- מבנה ראשי ---------- */
.shell { display: flex; height: 100%; }
.side {
  width: 220px; flex: none; display: flex; flex-direction: column; padding: 14px 10px; gap: 4px;
  background: rgba(var(--side-rgb, 31,35,64), var(--sideglass)); color: var(--side-text);
  border-inline-end: 1px solid rgba(255,255,255,.06); overflow-y: auto; z-index: 20;
}
.side.light-side { border-inline-end: 1px solid var(--border); }
.logo { font-size: 1.15rem; font-weight: 700; padding: 10px 8px 16px; color: var(--logo, #fff); }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: start; border: 0; background: transparent;
  color: inherit; padding: 11px 14px; border-radius: var(--r-btn); cursor: pointer; font-weight: 500; white-space: nowrap;
}
.nav-item:hover { background: var(--side-hover); }
.nav-item.on { background: var(--side-sel); color: var(--side-sel-text, #fff); font-weight: 700; }
.nav-item .badge { margin-inline-start: auto; background: var(--danger); color: #fff; border-radius: 99px; font-size: .75rem; padding: 0 7px; }
.side-foot { margin-top: auto; padding: 10px 6px 4px; font-size: .8rem; display: flex; flex-direction: column; gap: 8px; }
.chip { opacity: .85; word-break: break-word; }
.main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; height: 100%; }
.topbar { display: none; align-items: center; gap: 10px; padding: 10px 14px; background: rgba(var(--surface-rgb), var(--glass)); border-bottom: 1px solid var(--border); }
.content { flex: 1; overflow-y: auto; padding: 22px 26px 60px; }
.content.no-pad { padding: 0; overflow: hidden; }
.page { max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.page.wide { max-width: none; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; align-items: start; }
.cols > .col { min-width: 0; }

/* ---------- כרטיסים וטפסים ---------- */
.card, .tcard {
  background: rgba(var(--surface-rgb), var(--glass)); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px;
}
.glass-on .card, .glass-on .tcard, .glass-on .modal, .glass-on .topbar { backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2); }
.glass-on .side { backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.page-title h1 { margin: 0; font-size: 1.6rem; font-weight: 600; }
.page-title p { margin: 2px 0 0; color: var(--muted); }
.group { padding: 22px 20px 18px; position: relative; margin-top: 8px; }
.group > h2 { position: absolute; top: -13px; inset-inline-start: 16px; margin: 0; padding: 2px 12px; font-size: .95rem; font-weight: 600; color: var(--accent); background: rgba(var(--surface-rgb), max(var(--glass), .88)); border-radius: 99px; border: 1px solid var(--border); }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > label { font-weight: 500; font-size: .92rem; }
.field small { color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=search], input[type=url], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--r-in);
  background: rgba(var(--surface-rgb), max(var(--glass), .85)); outline: none;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=color] { width: 54px; height: 34px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: transparent; cursor: pointer; }
.check { display: flex; align-items: center; gap: 9px; margin: 6px 0; cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center; border: 1px solid var(--border);
  background: rgba(var(--surface-rgb), max(var(--glass), .9)); color: var(--accent-d); padding: 8px 16px; border-radius: var(--r-btn);
  font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--accent-soft); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; font-weight: 600; }
.btn.primary:hover { background: var(--accent-d); }
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.sm { padding: 4px 11px; font-size: .88rem; }
.btn.icon { padding: 7px 10px; border-radius: 50%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.pill { display: inline-block; padding: 1px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent-d); font-size: .82rem; }
.pill.off { background: var(--header); color: var(--muted); }
.pill.bad { background: #fee2e2; color: #991b1b; }
.pill.ok { background: #dcfce7; color: #166534; }
.notice { padding: 11px 14px; border-radius: var(--r-in); border: 1px solid var(--border); background: rgba(var(--surface-rgb), max(var(--glass), .9)); }
.notice.warn { border-color: #f59e0b; color: var(--warn); background: #fffbeb; }
.dark .notice.warn { background: #3a2a05; color: #fbbf24; }
.notice.err { border-color: #ef4444; color: #991b1b; background: #fef2f2; }
.dark .notice.err { background: #3b1111; color: #fca5a5; }

/* ---------- כרטיסי סטטיסטיקה וגרפים ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.stat { padding: 16px 18px; }
.stat b { display: block; font-size: 2rem; font-weight: 600; color: var(--accent); line-height: 1.2; }
.stat span { color: var(--muted); font-size: .92rem; }
.chart h3 { margin: 0 0 8px; font-size: 1rem; font-weight: 600; }
.chart svg { width: 100%; height: 190px; display: block; }
.chart .bar { fill: var(--accent); }
.chart .bar:hover { opacity: .8; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .val { fill: var(--text); font-weight: 600; }
.chart line { stroke: var(--border); }

/* ---------- טבלאות ---------- */
.table-wrap { overflow: auto; border-radius: var(--radius); background: rgba(var(--surface-rgb), var(--glass)); border: 1px solid var(--border); max-height: 62vh; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { position: sticky; top: 0; background: rgba(var(--surface-rgb), max(var(--glass), .96)); color: var(--muted); font-weight: 600; text-align: start; padding: 10px 12px; border-bottom: 2px solid var(--border); white-space: nowrap; z-index: 1; }
table.t td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.t tr.sel td { background: var(--accent-soft); }
table.t tbody tr { cursor: pointer; }
table.t tbody tr:hover td { background: rgba(127,127,127,.08); }
table.t tbody tr.sel:hover td { background: var(--accent-soft); }
table.t td.ellipsis { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- חלונות ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 100; animation: fade .12s; }
.modal { width: min(520px, 100%); max-height: 92vh; overflow: auto; background: rgba(var(--surface-rgb), max(var(--glass), .96)); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal.wide { width: min(760px, 100%); }
.modal h2 { margin: 0 0 12px; font-size: 1.2rem; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-start; margin-top: 16px; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
#toasts { position: fixed; bottom: 20px; inset-inline: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 200; pointer-events: none; }
.toast { background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 99px; box-shadow: 0 6px 22px rgba(0,0,0,.3); max-width: min(92vw, 560px); pointer-events: auto; animation: fade .15s; }
.toast.err { background: #b91c1c; }
.toast.ok { background: #15803d; }

/* ---------- צ'אט של העוזר ---------- */
.chatlog { min-height: 280px; max-height: 52vh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 14px; }
.msg-ai, .msg-me { padding: 9px 14px; border-radius: 16px; max-width: 86%; white-space: pre-wrap; word-break: break-word; }
.msg-me { align-self: flex-start; background: var(--accent-soft); }
.msg-ai { align-self: flex-end; background: rgba(var(--surface-rgb), max(var(--glass), .95)); border: 1px solid var(--border); }
.msg-who { font-size: .78rem; font-weight: 700; color: var(--accent); display: block; margin-bottom: 2px; }

/* ---------- הודעות (מסנג'ר) ---------- */
.mx { display: flex; height: 100%; min-height: 0; }
.mx-list { width: 340px; flex: none; display: flex; flex-direction: column; border-inline-end: 1px solid var(--border); background: rgba(var(--surface-rgb), var(--glass)); min-height: 0; }
.mx-head { padding: 10px 12px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.mx-tabs { display: flex; gap: 6px; }
.seg { border: 1px solid var(--border); background: transparent; border-radius: 99px; padding: 6px 16px; font-weight: 600; cursor: pointer; }
.seg.on { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.mx-status { font-size: .82rem; color: var(--muted); padding: 6px 12px; border-bottom: 1px solid var(--border); }
.mx-chats { flex: 1; overflow-y: auto; min-height: 0; }
.chat-item { display: flex; gap: 10px; padding: 9px 12px; cursor: pointer; align-items: center; border-bottom: 1px solid rgba(127,127,127,.12); }
.chat-item:hover { background: rgba(127,127,127,.08); }
.chat-item.on { background: var(--accent-soft); }
.avatar { width: 44px; height: 44px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 1.05rem; background-size: cover; background-position: center; position: relative; }
.avatar.sm { width: 34px; height: 34px; font-size: .9rem; }
.avatar .dot { position: absolute; inset-inline-start: 0; bottom: 0; width: 12px; height: 12px; border-radius: 50%; background: #22c55e; border: 2px solid var(--surface); }
.ci-body { flex: 1; min-width: 0; }
.ci-top { display: flex; gap: 6px; align-items: baseline; }
.ci-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.ci-time { font-size: .76rem; color: var(--muted); flex: none; }
.ci-last { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: .88rem; }
.ci-last span.txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.unread { background: var(--accent); color: var(--on-accent); border-radius: 99px; min-width: 20px; height: 20px; padding: 0 6px; font-size: .74rem; display: grid; place-items: center; font-weight: 700; }
.unread.muted-b { background: var(--muted); }
.mx-chat { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.mx-chat-head { padding: 10px 14px; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid var(--border); background: rgba(var(--surface-rgb), var(--glass)); }
.mx-msgs { flex: 1; overflow-y: auto; padding: 14px 18px; display: flex; flex-direction: column; gap: 4px; background-image: radial-gradient(rgba(127,127,127,.10) 1px, transparent 1px); background-size: 22px 22px; min-height: 0; }
.day-sep { align-self: center; background: rgba(127,127,127,.18); border-radius: 99px; padding: 1px 12px; font-size: .78rem; margin: 8px 0; color: var(--muted); }
.bubble { max-width: min(560px, 80%); padding: 7px 11px 5px; border-radius: 16px; position: relative; word-break: break-word; white-space: pre-wrap; border: 1px solid var(--border); background: rgba(var(--surface-rgb), max(var(--glass), .95)); }
.bubble.me { align-self: flex-start; background: var(--accent-soft); border-color: transparent; }
.bubble.them { align-self: flex-end; }
.bubble .who { display: block; font-size: .78rem; font-weight: 700; color: var(--accent); }
.bubble .meta { display: flex; gap: 5px; justify-content: flex-end; align-items: center; font-size: .72rem; color: var(--muted); margin-top: 2px; white-space: normal; }
.bubble .ticks { color: var(--muted); letter-spacing: -3px; }
.bubble .ticks.read { color: #0ea5e9; }
.bubble .reply { border-inline-start: 3px solid var(--accent); padding: 2px 8px; margin-bottom: 4px; background: rgba(127,127,127,.12); border-radius: 6px; font-size: .84rem; cursor: pointer; }
.bubble .reply b { display: block; color: var(--accent); }
.bubble img.media, .bubble video.media { max-width: 100%; max-height: 320px; border-radius: 10px; display: block; margin-bottom: 4px; cursor: pointer; }
.bubble audio { width: 240px; max-width: 100%; display: block; margin-bottom: 4px; }
.bubble .filebox { display: flex; gap: 8px; align-items: center; padding: 6px 4px; }
.bubble .ctx { position: absolute; inset-block-start: 2px; inset-inline-end: 4px; opacity: 0; border: 0; background: var(--surface); border-radius: 50%; width: 24px; height: 24px; cursor: pointer; line-height: 1; }
.bubble:hover .ctx { opacity: .85; }
.mx-compose { padding: 10px 12px; border-top: 1px solid var(--border); background: rgba(var(--surface-rgb), var(--glass)); display: flex; flex-direction: column; gap: 6px; }
.mx-compose .box { display: flex; gap: 8px; align-items: flex-end; }
.mx-compose textarea { min-height: 42px; max-height: 160px; resize: none; border-radius: 20px; }
.replybar { display: flex; gap: 8px; align-items: center; padding: 4px 10px; border-inline-start: 3px solid var(--accent); background: rgba(127,127,127,.12); border-radius: 6px; font-size: .86rem; }
.menu { position: fixed; background: rgba(var(--surface-rgb), 1); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.3); padding: 6px; z-index: 150; min-width: 170px; }
.menu button { display: block; width: 100%; text-align: start; border: 0; background: transparent; padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--accent-soft); }
.menu button.danger { color: var(--danger); }
.emoji-pop { position: absolute; bottom: 64px; inset-inline-end: 12px; background: rgba(var(--surface-rgb), 1); border: 1px solid var(--border); border-radius: 12px; padding: 8px; width: 320px; max-height: 240px; overflow: auto; display: flex; flex-wrap: wrap; gap: 2px; box-shadow: 0 10px 30px rgba(0,0,0,.3); z-index: 30; }
.emoji-pop button { border: 0; background: transparent; font-size: 1.3rem; cursor: pointer; border-radius: 6px; padding: 2px 4px; }
.emoji-pop button:hover { background: var(--accent-soft); }
.mx-empty { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; }
.mx-back { display: none; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: grid; place-items: center; z-index: 160; }
.lightbox img { max-width: 94vw; max-height: 92vh; border-radius: 8px; }

.swatch-row { display: flex; flex-wrap: wrap; gap: 8px; }
.theme-chip { border: 1px solid #80868B; border-radius: 99px; padding: 7px 14px; font-weight: 600; cursor: pointer; }

/* ---------- מובייל ---------- */
@media (max-width: 860px) {
  .side { position: fixed; inset-block: 0; inset-inline-start: 0; transform: translateX(100%); transition: transform .2s; width: 250px; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  [dir=rtl] .side { transform: translateX(100%); }
  .side.open { transform: none !important; }
  .topbar { display: flex; }
  .content { padding: 14px 12px 60px; }
  .cols { grid-template-columns: 1fr; }
  .mx-list { width: 100%; }
  .mx.chat-open .mx-list { display: none; }
  .mx:not(.chat-open) .mx-chat { display: none; }
  .mx-back { display: inline-flex; }
  .bubble { max-width: 90%; }
}
