:root {
  --bg: #f3f6f6;
  --card: #ffffff;
  --ink: #1d2a2e;
  --muted: #6a7b80;
  --line: #e1e8ea;
  --soft: #f7fafa;
  --teal: #0f8a8a;
  --teal-dark: #0b6b6b;
  --teal-soft: #e2f3f2;
  --bot: #eef0fb;
  --bot-ink: #4b4f9a;
  --warn: #9a5b00;
  --warn-soft: #fff4dc;
  --red: #b42318;
  --red-soft: #fdecea;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 40, 44, 0.06), 0 4px 16px rgba(16, 40, 44, 0.05);
  font-family: 'Heebo', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { font-size: 15px; line-height: 1.55; }
button, input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; }
.err { color: var(--red); font-size: 13px; min-height: 1em; }

/* כפתורים */
.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 8px 14px; cursor: pointer; font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-dark); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--soft); color: var(--ink); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px; width: 40px; height: 40px;
  cursor: pointer; font-size: 17px; display: inline-grid; place-items: center;
}
.icon-btn:hover { background: var(--soft); }

input, textarea, select {
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: #fff; width: 100%;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-soft); }
textarea { resize: vertical; }

/* כניסה */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  background: var(--card); padding: 32px 28px; border-radius: 20px; box-shadow: var(--shadow);
  width: min(360px, 100%); display: grid; gap: 14px; text-align: center;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.brand-mark { font-size: 34px; }

/* מבנה */
#app { height: 100%; display: flex; flex-direction: column; }
.top {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--card);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 17px; }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 99px; font-weight: 600; }
.pill.dormant { background: var(--warn-soft); color: var(--warn); }
.pill.live { background: var(--teal-soft); color: var(--teal-dark); }
.tabs { display: flex; gap: 4px; margin-inline-start: 8px; }
.tab { border: 0; background: transparent; padding: 7px 12px; border-radius: 9px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tab:hover { background: var(--soft); color: var(--ink); }
.tab.active { background: var(--teal-soft); color: var(--teal-dark); }
.tab b { font-size: 12px; background: var(--teal); color: #fff; border-radius: 99px; padding: 0 7px; margin-inline-start: 4px; }
.tab b:empty { display: none; }
.me-chip { margin-inline-start: auto; border: 1px solid var(--line); background: var(--soft); border-radius: 99px; padding: 4px 12px; cursor: pointer; font-size: 13px; }

.view { flex: 1; min-height: 0; }
.page { overflow: auto; padding: 20px 16px 40px; max-width: 1100px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h2 { margin: 0; font-size: 20px; }
.page-head input[type=search] { width: 220px; }

/* תיבת שיחות */
.inbox { display: grid; grid-template-columns: 360px 1fr; }
.list { background: var(--card); border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.filters { display: flex; gap: 6px; padding: 12px 12px 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 4px 11px;
  cursor: pointer; font-size: 13px; color: var(--muted);
}
.chip.active { background: var(--teal); border-color: var(--teal); color: #fff; }
.chip b { font-weight: 600; margin-inline-start: 3px; }
.chip b:empty { display: none; }
.list-tools { display: flex; gap: 8px; padding: 0 12px 10px; align-items: center; }
.list-tools input { padding: 6px 10px; }
.seg { display: inline-flex; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 2px; flex-shrink: 0; }
.seg button { border: 0; background: transparent; padding: 4px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--muted); }
.seg button.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.conv-list { overflow: auto; flex: 1; }
.conv {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; padding: 11px 12px; cursor: pointer;
  border-bottom: 1px solid var(--line); align-items: center;
}
.conv:hover { background: var(--soft); }
.conv.active { background: var(--teal-soft); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 600;
  background: #dfe9ea; color: var(--teal-dark); position: relative;
}
.avatar .ch { position: absolute; bottom: -2px; inset-inline-end: -2px; font-size: 13px; background: #fff; border-radius: 50%; width: 18px; height: 18px; display: grid; place-items: center; box-shadow: 0 0 0 1px var(--line); }
.conv-main { min-width: 0; }
.conv-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-prev { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-side { display: grid; justify-items: end; gap: 4px; font-size: 12px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--teal); }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--bot); color: var(--bot-ink); }
.list-empty { padding: 40px 16px; text-align: center; color: var(--muted); }

.thread { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.empty-thread { margin: auto; text-align: center; color: var(--muted); }
.empty-icon { font-size: 40px; opacity: .5; }
.thread-inner { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.thread-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.who { min-width: 0; flex: 1; }
.who-name { font-weight: 700; }
.who-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-actions { display: flex; gap: 6px; }
.back { display: none; }

.messages { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.day-sep { align-self: center; font-size: 12px; color: var(--muted); background: var(--card); border: 1px solid var(--line); padding: 2px 10px; border-radius: 99px; margin: 6px 0; }
.bubble {
  max-width: min(640px, 82%); padding: 9px 12px 6px; border-radius: 14px; background: var(--card);
  box-shadow: 0 1px 1px rgba(0,0,0,.05); white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
}
.bubble.in { align-self: flex-start; border-start-start-radius: 4px; }
.bubble.out { align-self: flex-end; background: var(--teal-soft); border-start-end-radius: 4px; }
.bubble.bot { background: var(--bot); }
.bubble.held { border: 1.5px dashed #d8a24a; }
.bubble.failed { border: 1.5px solid var(--red); }
.bubble a { color: var(--teal-dark); }
.b-author { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
.b-meta { display: flex; gap: 6px; justify-content: flex-end; font-size: 11px; color: var(--muted); margin-top: 3px; align-items: center; }
.b-meta .st-read { color: #2a7de1; }
.b-err { font-size: 12px; color: var(--red); margin-top: 3px; white-space: normal; }
.b-held { font-size: 12px; color: var(--warn); margin-top: 3px; }
.att { margin-top: 6px; }
.att img { max-width: 260px; max-height: 260px; border-radius: 10px; display: block; cursor: zoom-in; }
.att audio, .att video { max-width: 280px; display: block; }
.att a.file { display: inline-flex; gap: 6px; align-items: center; padding: 5px 10px; background: rgba(255,255,255,.7); border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--ink); font-size: 13px; }
.quote-toggle { font-size: 12px; color: var(--muted); background: none; border: 0; cursor: pointer; padding: 2px 0; text-decoration: underline; }
.quoted { font-size: 13px; color: var(--muted); border-inline-start: 3px solid var(--line); padding-inline-start: 8px; margin-top: 4px; max-height: 260px; overflow: auto; }

.draft {
  margin: 0 16px 8px; background: var(--card); border: 1px solid #d9dcf5; border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow);
}
.draft-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.draft-title { font-weight: 600; color: var(--bot-ink); }
.conf { font-size: 12px; background: var(--bot); color: var(--bot-ink); padding: 1px 8px; border-radius: 99px; }
.flag { font-size: 12px; background: var(--warn-soft); color: var(--warn); padding: 1px 8px; border-radius: 99px; }
.flag.halacha { background: var(--red-soft); color: var(--red); }
.draft-text { white-space: pre-wrap; max-height: 220px; overflow: auto; }
.draft-reason { font-size: 12px; color: var(--muted); margin-top: 4px; }
.draft-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.composer { padding: 10px 16px 14px; background: var(--card); border-top: 1px solid var(--line); }
.dormant-note { font-size: 12px; color: var(--warn); margin-bottom: 6px; }
.compose-row { display: flex; gap: 8px; align-items: flex-end; }
.compose-row textarea { min-height: 46px; max-height: 260px; }
.compose-btns { display: flex; gap: 6px; }

/* ידע */
.kinds { margin-bottom: 14px; }
.k-list { display: grid; gap: 10px; }
.k-item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.k-item.off { opacity: .55; }
.k-q { font-weight: 600; margin-bottom: 4px; }
.k-a { white-space: pre-wrap; color: #33464b; }
.k-foot { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.tag { font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--soft); border: 1px solid var(--line); color: var(--muted); }
.tag.knowledge { background: var(--teal-soft); border-color: transparent; color: var(--teal-dark); }
.tag.halacha { background: var(--red-soft); border-color: transparent; color: var(--red); }
.tag.flagged { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.tag.ok { background: var(--teal-soft); border-color: transparent; color: var(--teal-dark); }
.tag.bad { background: var(--red-soft); border-color: transparent; color: var(--red); }

/* ניסוי */
.sim { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; height: min(640px, calc(100vh - 170px)); }
.sim-msgs { background: var(--bg); }
.sim-hint { margin: auto; color: var(--muted); }
.sim-result { align-self: flex-end; max-width: min(640px, 88%); background: var(--bot); border-radius: 14px; padding: 10px 12px; }
.sim-result .r-text { white-space: pre-wrap; }
.sim-result .r-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

/* הגדרות */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 10px; align-content: start; }
.card.wide { grid-column: 1 / -1; }
.card-head { display: flex; align-items: center; gap: 8px; cursor: default; }
.card-head h3 { margin: 0; font-size: 16px; }
details > summary.card-head { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details[open] > summary.card-head { margin-bottom: 10px; }
.state-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.state-btn { border: 1.5px solid var(--line); background: var(--soft); border-radius: 12px; padding: 14px; cursor: pointer; font-weight: 600; font-size: 15px; }
.state-btn.on[data-state=dormant] { border-color: #e2b45f; background: var(--warn-soft); color: var(--warn); }
.state-btn.on[data-state=live] { border-color: var(--teal); background: var(--teal-soft); color: var(--teal-dark); }
.acc { display: flex; align-items: baseline; gap: 10px; }
.acc-num { font-size: 30px; font-weight: 700; color: var(--teal-dark); }
.row-toggle, .row-range, .row-num { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.row-toggle.inline { justify-content: flex-start; }
.row-range input { flex: 1; padding: 0; }
.row-num input { width: 110px; }
.switch { appearance: none; width: 42px; height: 24px; border-radius: 99px; background: #cfd9db; position: relative; cursor: pointer; border: 0; padding: 0; flex-shrink: 0; transition: background .2s; }
.switch::after { content: ''; position: absolute; top: 3px; inset-inline-start: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: inset-inline-start .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch:checked { background: var(--teal); }
.switch:checked::after { inset-inline-start: 21px; }
.switch:focus { box-shadow: 0 0 0 3px var(--teal-soft); }
.usage { font-size: 13px; color: var(--muted); }
.mb-list { display: grid; gap: 8px; }
.mb { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; flex-wrap: wrap; }
.mb-addr { font-weight: 600; direction: ltr; }
.mb .st { width: 10px; height: 10px; border-radius: 50%; background: #9fb3b7; }
.mb .st.ok { background: #16a34a; }
.mb .st.bad { background: var(--red); }
.mb-info { font-size: 12px; color: var(--muted); flex: 1; min-width: 160px; }
.add-mb > summary { list-style: none; display: inline-block; }
.form-grid { display: grid; gap: 8px; margin-top: 10px; }
.btn-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn-row select { width: auto; }
.adv > summary { cursor: pointer; }
.team { display: flex; gap: 6px; flex-wrap: wrap; }
.team .tag { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; padding: 3px 10px; }
.team .tag button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0; }
.inline-form { display: flex; gap: 8px; }

/* חלונות */
.modal { position: fixed; inset: 0; background: rgba(20, 35, 38, .35); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal-card { background: var(--card); border-radius: 18px; padding: 20px; width: min(380px, 100%); display: grid; gap: 12px; box-shadow: var(--shadow); }
.modal-card.wide { width: min(620px, 100%); }
.modal-card h3 { margin: 0; }
.who-list { display: flex; gap: 8px; flex-wrap: wrap; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1d2a2e; color: #fff; padding: 10px 18px; border-radius: 12px; z-index: 30; font-size: 14px; max-width: calc(100% - 32px); }
.toast.bad { background: var(--red); }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.8); display: grid; place-items: center; z-index: 40; cursor: zoom-out; }
.lightbox img { max-width: 94vw; max-height: 94vh; border-radius: 8px; }

/* טלפון */
@media (max-width: 820px) {
  .top { padding: 8px 12px; gap: 8px; }
  .tabs { order: 3; width: 100%; margin: 0; overflow-x: auto; }
  .me-chip { margin-inline-start: auto; }
  .inbox { grid-template-columns: 1fr; }
  .inbox .thread { display: none; }
  .inbox.show-thread .list { display: none; }
  .inbox.show-thread .thread { display: flex; }
  .back { display: inline-grid; }
  .bubble { max-width: 88%; }
  .page-head input[type=search] { width: 100%; }
  .cards { grid-template-columns: 1fr; }
  .att img { max-width: 200px; }
}
