:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --text: #16202a;
  --muted: #5b6875;
  --border: #d9e0e6;
  --primary: #0f766e;
  --primary-text: #ffffff;
  --danger: #b42318;
  --bubble-me: #d9f2ee;
  --bubble-agent: #ffffff;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419;
    --surface: #182028;
    --surface-2: #202a33;
    --text: #e6edf3;
    --muted: #93a1ad;
    --border: #2d3a45;
    --primary: #2dd4bf;
    --primary-text: #062a26;
    --danger: #f97066;
    --bubble-me: #134e48;
    --bubble-agent: #202a33;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419; --surface: #182028; --surface-2: #202a33; --text: #e6edf3; --muted: #93a1ad;
  --border: #2d3a45; --primary: #2dd4bf; --primary-text: #062a26; --danger: #f97066;
  --bubble-me: #134e48; --bubble-agent: #202a33; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body { overscroll-behavior-y: none; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "Rubik", "Assistant", Arial, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
a { color: var(--primary); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 10px; padding: 8px 14px; font: inherit; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: .9em; }
.btn:disabled { opacity: .5; cursor: default; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
label { display: block; font-weight: 600; margin: 12px 0 4px; }
label small { font-weight: 400; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.row > .grow { min-width: 150px; }
.stack > * + * { margin-top: 12px; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); text-align: center; }
.login-card .logo { font-size: 48px; }
.login-card > input, .login-card > button { margin-top: 12px; width: 100%; }
.password-wrap { position: relative; margin-top: 12px; }
.password-wrap input { padding-inline-end: 44px; }
.icon-btn { position: absolute; inset-inline-end: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none; cursor: pointer; font-size: 18px; padding: 4px; }

/* layout */
.app { display: flex; min-height: 100dvh; }
.nav {
  width: 190px; background: var(--surface); border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 12px 8px; gap: 2px; position: sticky; top: 0; height: 100dvh; flex: none;
}
.nav .brand { font-weight: 700; padding: 8px 12px 16px; font-size: 1.1rem; }
.nav button {
  display: flex; gap: 10px; align-items: center; border: 0; background: none; color: var(--text);
  padding: 9px 12px; border-radius: 10px; font: inherit; cursor: pointer; text-align: start;
}
.nav button em { font-style: normal; }
.nav button.active { background: var(--surface-2); font-weight: 600; color: var(--primary); }
main { flex: 1; min-width: 0; padding: 20px; max-width: 1100px; }
.small { font-size: .82em; }

.topbar { display: none; }
html, body { overflow-x: hidden; }

/* נייד: כמו אפליקציה – בר עליון ובר תחתון קבועים, רק התוכן באמצע גולל */
@media (max-width: 760px) {
  html, body { overflow: hidden; overscroll-behavior: none; }
  .app {
    position: fixed; inset: 0 0 auto 0; height: var(--app-h, 100dvh); min-height: 0;
    flex-direction: column; overflow: hidden;
  }
  .topbar {
    display: flex; flex: none; order: 0; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem;
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--surface); border-bottom: 1px solid var(--border);
  }
  .nav {
    order: 2; position: static; flex: none; width: 100%; height: auto;
    display: grid; grid-template-columns: repeat(7, 1fr); gap: 0;
    padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
    border-inline-end: 0; border-top: 1px solid var(--border);
  }
  .nav .brand { display: none; }
  .nav button { flex-direction: column; gap: 1px; padding: 5px 0; font-size: 10.5px; min-width: 0; align-items: center; justify-content: center; }
  .nav button span { font-size: 20px; line-height: 1.1; }
  .nav button em { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  main {
    order: 1; flex: 1; min-height: 0; max-width: none; padding: 12px 12px 20px;
    overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  }
  main.is-chat { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 8px; }
  main.is-chat .chat { flex: 1; min-height: 0; height: auto; }
  /* 16px ומעלה: iOS לא מגדיל את הדף בלחיצה על שדה (מה שגרם לתזוזה לצדדים) */
  input, textarea, select { font-size: 16px; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
}

/* agents grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.agent-card { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.agent-card:hover { border-color: var(--primary); }
.avatar {
  font-size: 26px; width: 44px; height: 44px; border-radius: 50%; background: var(--surface-2);
  display: inline-grid; place-items: center; flex: none; overflow: hidden; line-height: 1;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.xs { width: 20px; height: 20px; font-size: 13px; }
.avatar.sm { width: 38px; height: 38px; font-size: 21px; }
.avatar.lg { width: 56px; height: 56px; font-size: 30px; box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--border); }
.avatar.xl { width: 80px; height: 80px; font-size: 42px; margin: 0 auto; }
.avatar.xxl { width: 120px; height: 120px; font-size: 60px; box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--primary); }
.avatar-card { display: flex; gap: 20px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.avatar-card details summary { cursor: pointer; color: var(--primary); font-size: .92em; }
.prompt-box { background: var(--surface-2); padding: 10px; border-radius: 8px; white-space: pre-wrap; text-align: left; }
.agent-card { align-items: center; }
.agent-card .name { font-weight: 700; }
.badge { display: inline-block; font-size: .75rem; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); margin-inline-start: 4px; }
.badge.warn { color: var(--danger); }

/* chat */
.chat { display: flex; flex-direction: column; height: calc(100dvh - 40px); }
.agent-strip { display: flex; gap: 6px; overflow-x: auto; overscroll-behavior-x: contain; max-width: 100%; padding: 2px 2px 10px; scrollbar-width: none; flex: none; }
.agent-strip::-webkit-scrollbar { display: none; }
.chip {
  display: flex; flex-direction: column; align-items: center; gap: 2px; flex: none; min-width: 56px;
  border: 1px solid transparent; background: none; color: var(--text); border-radius: 12px; padding: 4px 6px;
  cursor: pointer; font: inherit;
}
.chip-av { width: 46px; height: 46px; font-size: 24px; box-shadow: 0 0 0 2px transparent; transition: box-shadow .15s; }
.chip-name { font-size: 11.5px; white-space: nowrap; }
.chip.active { background: none; }
.chip.active .chip-av { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--primary); }
/* דיוקן עם טבעת ותג משלו (רקע שקוף): בלי חיתוך עגול ובלי מסגרת נוספת */
.avatar.framed, .avatar.framed.lg, .avatar.framed.xxl, .chip-av.framed { background: none; border-radius: 0; overflow: visible; box-shadow: none; }
.avatar.framed img { object-fit: contain; }
.chip.active .chip-av.framed { box-shadow: none; filter: drop-shadow(0 0 3px var(--primary)); }
.chip.active .chip-name { color: var(--primary); font-weight: 700; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 8px 0 10px; border-bottom: 1px solid var(--border); flex: none; }
.chat-title { font-weight: 700; }
.chat-head .channel { width: auto; max-width: 42%; padding: 6px 8px; font-size: .88em; }
.btn.icon { padding: 6px 9px; }
.messages { flex: 1; overflow-y: auto; padding: 14px 2px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.msg {
  max-width: min(82%, 720px); padding: 8px 12px 6px; border-radius: 16px; overflow-wrap: anywhere;
  box-shadow: var(--shadow); line-height: 1.55;
}
.msg .body { text-align: start; }
.msg .ln { white-space: pre-wrap; min-height: 1em; }
.msg .ln.gap { height: .55em; min-height: 0; }
.msg .ln.li { padding-inline-start: .4em; }
.msg a { overflow-wrap: anywhere; }
.msg code { background: var(--surface-2); padding: 0 4px; border-radius: 4px; }
/* ב-RTL: flex-start = ימין. הסוכן מימין, ההודעות שלך משמאל */
.msg.assistant { align-self: flex-start; background: var(--bubble-agent); border: 1px solid var(--border); border-start-start-radius: 4px; }
.msg.user { align-self: flex-end; background: var(--bubble-me); border-start-end-radius: 4px; }
.msg .who { font-size: .78rem; font-weight: 700; color: var(--primary); margin-bottom: 3px; display: flex; align-items: center; gap: 6px; }
.msg .time { font-size: .7rem; color: var(--muted); margin-top: 3px; text-align: end; }
.msg .media { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin-top: 6px; }
.dots { display: inline-flex; gap: 4px; vertical-align: middle; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; opacity: .6; } }
.empty { margin: auto; text-align: center; color: var(--text); display: flex; flex-direction: column; gap: 6px; padding: 24px; }
.composer { display: flex; gap: 6px; align-items: flex-end; padding-top: 8px; border-top: 1px solid var(--border); flex: none; }
.composer textarea { min-height: 44px; max-height: 160px; resize: none; border-radius: 22px; padding: 10px 14px; line-height: 1.4; }
.composer .send, .composer .attach { width: 44px; height: 44px; border-radius: 50%; padding: 0; flex: none; font-size: 18px; }
.composer .send { transform: scaleX(-1); }
.readonly-note { padding: 10px; text-align: center; color: var(--muted); font-size: .9em; border-top: 1px solid var(--border); }
.pending-files { display: flex; gap: 6px; flex-wrap: wrap; padding-top: 8px; }
.pending-files:empty { display: none; }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 220px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 4px 6px; font-size: .82em;
}
.file-chip img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; }
.file-chip .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip button { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 16px; padding: 0 2px; }
.msg .files { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.msg .files img { max-width: 100%; max-height: 280px; border-radius: 10px; display: block; }
.msg .files a.file-link {
  display: inline-flex; gap: 6px; align-items: center; background: var(--surface-2); padding: 6px 10px;
  border-radius: 10px; color: var(--text); text-decoration: none; font-size: .88em; max-width: 100%;
}
.drop-hint { outline: 2px dashed var(--primary); outline-offset: -6px; border-radius: 12px; }

/* lists */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; gap: 10px; align-items: flex-start; }
.item .grow .sub { color: var(--muted); font-size: .88em; white-space: pre-wrap; }
.done .title { text-decoration: line-through; color: var(--muted); }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; }
.checks label { font-weight: 400; margin: 0; display: flex; gap: 8px; align-items: center; background: var(--surface-2); padding: 6px 10px; border-radius: 8px; }
.checks input { width: auto; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 12px; flex-wrap: wrap; }
.hint { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; color: var(--muted); font-size: .9em; }
code, .mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em; direction: ltr; unicode-bidi: embed; }
.kv { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: 8px 12px; align-items: center; }
@media (max-width: 600px) { .kv { grid-template-columns: 1fr; } }
.kv label { margin: 0; }
.status { font-size: .85em; }
.status.ok { color: var(--primary); }
.status.bad { color: var(--danger); }
.toast {
  position: fixed; bottom: calc(96px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 50;
  max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.toast.bad { background: var(--danger); color: #fff; }
@media (min-width: 761px) { .toast { bottom: 24px; } }
.activity .item { font-size: .92em; }
.activity .kind { font-size: .75rem; color: var(--muted); min-width: 70px; }
