:root {
  --bg: #f4f6f5; --panel: #ffffff; --panel2: #f8faf9; --line: #e3e8e6; --text: #15201d; --muted: #66746f;
  --brand: #0f6b5c; --brand2: #13836f; --brand-soft: #e5f2ef; --ok: #16794a; --ok-soft: #e4f4ea;
  --warn: #9a5b00; --warn-soft: #fdf1dc; --bad: #b42318; --bad-soft: #fde8e6; --info-soft: #eaf0fb; --info: #2953a6;
  --bubble-in: #ffffff; --bubble-bot: #dcf3ea; --bubble-owner: #e5ecfb; --shadow: 0 1px 2px rgba(16,24,22,.06), 0 4px 16px rgba(16,24,22,.04);
  --r: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1514; --panel: #161e1c; --panel2: #1b2522; --line: #26322f; --text: #e6efec; --muted: #93a39e;
    --brand: #2fb39a; --brand2: #3cc7ad; --brand-soft: #173a33; --ok: #4fc58a; --ok-soft: #173327; --warn: #e3a43c; --warn-soft: #3a2c13;
    --bad: #ff7b6e; --bad-soft: #3d1c19; --info-soft: #1a2640; --info: #8fb0f5; --bubble-in: #1d2826; --bubble-bot: #183a31; --bubble-owner: #1d2a45;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1514; --panel: #161e1c; --panel2: #1b2522; --line: #26322f; --text: #e6efec; --muted: #93a39e;
  --brand: #2fb39a; --brand2: #3cc7ad; --brand-soft: #173a33; --ok: #4fc58a; --ok-soft: #173327; --warn: #e3a43c; --warn-soft: #3a2c13;
  --bad: #ff7b6e; --bad-soft: #3d1c19; --info-soft: #1a2640; --info: #8fb0f5; --bubble-in: #1d2826; --bubble-bot: #183a31; --bubble-owner: #1d2a45;
  --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.55 "Segoe UI", "Rubik", "Assistant", system-ui, -apple-system, Arial, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
.boot { display: grid; place-items: center; height: 100vh; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* מבנה */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-left: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-weight: 700; font-size: 18px; }
.logo img { width: 30px; height: 30px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; color: var(--text); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--panel2); }
.nav a.on { background: var(--brand-soft); color: var(--brand); }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav .badge { margin-inline-start: auto; }
.side .foot { margin-top: auto; font-size: 13px; color: var(--muted); padding: 8px; }
.main { padding: 26px 30px 60px; max-width: 1180px; width: 100%; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 22px; }
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* כרטיסים */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { padding: 14px 16px; }
.stat .n { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: Consolas, "Cascadia Mono", monospace; direction: ltr; text-align: left; }
pre.out { background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 12px; overflow: auto; max-height: 420px; font-size: 12.5px; white-space: pre-wrap; word-break: break-word; margin: 10px 0 0; direction: ltr; text-align: left; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* תגיות */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--panel2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }
.dot.live { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* טפסים */
label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-weight: 600; font-size: 13.5px; margin-bottom: 5px; }
label.f > small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 4px; }
input[type=text], input[type=password], input[type=number], input[type=tel], input[type=url], select, textarea {
  width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line); background: var(--panel); border-radius: 9px; padding: 8px 14px; cursor: pointer; font-weight: 600; transition: background .15s, transform .05s; white-space: nowrap; }
.btn:hover { background: var(--panel2); }
.btn:active { transform: translateY(1px); }
.btn.pri { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.pri:hover { background: var(--brand2); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.seg { display: inline-flex; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 7px 13px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--panel); color: var(--brand); box-shadow: var(--shadow); }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; }
.check input { width: 17px; height: 17px; accent-color: var(--brand); }

/* טבלאות */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12.5px; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
.tbl-wrap { overflow-x: auto; }
td input[type=text], td select { padding: 6px 8px; }

/* וואטסאפ */
.qr { background: #fff; padding: 12px; border-radius: 12px; border: 1px solid var(--line); width: 244px; height: 244px; }
.qr img { width: 100%; height: 100%; display: block; }
.steps { margin: 0; padding-inline-start: 20px; }
.steps li { margin-bottom: 6px; }
.pair-code { font: 700 28px/1 Consolas, monospace; letter-spacing: 4px; direction: ltr; }

/* שיחות */
.chats { display: grid; grid-template-columns: 330px 1fr; gap: 0; height: calc(100vh - 150px); min-height: 480px; padding: 0; overflow: hidden; }
.chat-list { border-left: 1px solid var(--line); overflow-y: auto; }
.chat-item { padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.chat-item:hover { background: var(--panel2); }
.chat-item.on { background: var(--brand-soft); }
.chat-item .t { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.chat-item .p { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread { display: flex; flex-direction: column; min-width: 0; }
.thread-head { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.msgs { flex: 1; overflow-y: auto; padding: 16px; background: var(--panel2); display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; box-shadow: var(--shadow); border: 1px solid var(--line); }
.msg .meta { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.msg.customer { align-self: flex-start; background: var(--bubble-in); }
.msg.bot { align-self: flex-end; background: var(--bubble-bot); border-color: transparent; }
.msg.owner { align-self: flex-end; background: var(--bubble-owner); border-color: transparent; }
.msg.tool, .msg.note { align-self: center; background: none; box-shadow: none; border: 1px dashed var(--line); font-size: 12.5px; color: var(--muted); padding: 3px 10px; max-width: 92%; }
.composer { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.composer textarea { min-height: 42px; height: 42px; }
.empty { color: var(--muted); text-align: center; padding: 40px 16px; }

/* אישורים */
.appr { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; background: var(--warn-soft); }
.log-row { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.log-row:last-child { border: 0; }
.log-row .when { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; min-width: 92px; }

/* כניסה */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth .logo { justify-content: center; padding: 0 0 6px; font-size: 22px; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; opacity: 0; transition: .25s; pointer-events: none; z-index: 50; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--bad); color: #fff; }

.svc-row td:first-child { width: 28%; }
.hide-m { }
@media (max-width: 900px) {
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: sticky; height: auto; flex-direction: row; padding: 8px 10px; overflow-x: auto; border-left: 0; border-bottom: 1px solid var(--line); z-index: 5; top: 0; }
  .side .logo, .side .foot { display: none; }
  .nav { display: flex; gap: 4px; }
  .nav a { padding: 7px 10px; white-space: nowrap; font-size: 14px; }
  .nav svg { display: none; }
  .main { padding: 18px 16px 50px; }
  .chats { grid-template-columns: 1fr; height: auto; }
  .chat-list { border-left: 0; max-height: 260px; border-bottom: 1px solid var(--line); }
  .msgs { min-height: 360px; }
  .msg { max-width: 92%; }
  .hide-m { display: none; }
  .qr { width: 220px; height: 220px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
