:root {
  --bg: #f7f5f0; --panel: #ffffff; --side: #f0eee8; --line: #dfe2e8; --ink: #14213d; --muted: #5f6880; --sketch: #8a94a8;
  --accent: #14213d; --accent-ink: #ffffff; --accent-soft: #e7eaf1; --flash: #ffb703; --flash-soft: #fff3d1; --flash-light: #ffd166; --warn-bg: #fff4e0; --warn-ink: #7a4b00;
  --err-bg: #fdecec; --err-ink: #8a1c1c; --mark: #ff1e50; --radius: 12px;
  font-family: "Segoe UI", "Rubik", Arial, sans-serif; color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.hidden { display: none !important; }

/* כפתורים */
.btn { white-space: nowrap; text-decoration: none; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 14px; min-height: 38px; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: #f3f1ec; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.danger { color: var(--err-ink); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: none; background: transparent; width: 36px; height: 36px; border-radius: 8px; display: inline-grid; place-items: center; font-size: 18px; }
.icon-btn:hover { background: rgba(0,0,0,.06); }

/* סימן שאלה להסבר */
.help { position: relative; display: inline-block; vertical-align: middle; }
.help > summary { list-style: none; width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--line); color: var(--muted); font-size: 12px; display: grid; place-items: center; cursor: pointer; background: var(--panel); font-weight: 600; }
.help > summary::-webkit-details-marker { display: none; }
.help[open] > div { position: absolute; top: 26px; inset-inline-start: 0; z-index: 30; width: min(24rem, 80vw); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.12); font-size: 14px; font-weight: 400; line-height: 1.6; color: var(--ink); }
.help[open] > div p { margin: 0 0 6px; }

/* פריסה */
.app { display: grid; grid-template-columns: 270px 1fr; height: 100vh; }
.side { background: var(--side); border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-top { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 15px; }
.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.conv-group { font-size: 12px; color: var(--muted); padding: 10px 8px 4px; }
.conv { display: flex; align-items: center; gap: 4px; border-radius: 8px; padding: 0 4px 0 0; }
.conv a { flex: 1; min-width: 0; padding: 8px 6px; text-decoration: none; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.conv:hover { background: rgba(20,33,61,.05); }
.conv.active { background: var(--flash-soft); box-shadow: inset -3px 0 0 var(--flash); }
.conv .icon-btn { width: 28px; height: 28px; font-size: 14px; opacity: 0; }
.conv:hover .icon-btn, .conv.active .icon-btn { opacity: .7; }
.side-bottom { border-top: 1px solid var(--line); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.nav-link { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--ink); font-size: 14px; }
.nav-link:hover { background: rgba(20,33,61,.05); }
.nav-link.active { background: var(--flash-soft); box-shadow: inset -3px 0 0 var(--flash); }
.usage { color: var(--muted); line-height: 1.5; }
.usage b { color: var(--ink); font-weight: 600; }
.meter { height: 6px; background: #dcd8cf; border-radius: 3px; overflow: hidden; margin-top: 4px; }
.meter > i { display: block; height: 100%; background: var(--flash); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.topbar { height: 56px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.topbar h1 { font-size: 16px; margin: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar .spacer { flex: 1; }
.provider { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: none; background: var(--panel); padding: 6px 12px; font-size: 14px; }
.seg button.on { background: var(--accent); color: #fff; }
.seg button:disabled { color: #aaa; cursor: not-allowed; }

/* שיחה */
.scroll { flex: 1; overflow-y: auto; }
.thread { max-width: 860px; margin: 0 auto; padding: 24px 20px 12px; display: flex; flex-direction: column; gap: 22px; }
.msg-user { align-self: flex-end; max-width: 78%; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.bubble { background: var(--accent-soft); border-radius: 18px; padding: 10px 16px; white-space: pre-wrap; line-height: 1.6; word-break: break-word; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.thumbs img { width: 120px; height: 90px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in; background: #fff; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 3px 10px 3px 4px; font-size: 13px; max-width: 100%; }
.chip .sw { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; background: #cfd9d4; flex: none; }
.chip button { border: none; background: transparent; color: inherit; padding: 0 2px; font-size: 14px; }
.msg-bot { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.msg-bot .text { line-height: 1.7; white-space: pre-wrap; }
.msg-bot.blocked .text, .msg-bot.error .text { background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; padding: 10px 14px; }
.msg-bot.error .text { background: var(--err-bg); color: var(--err-ink); }
.render { position: relative; max-width: 100%; }
.render img { display: block; max-width: 100%; max-height: 70vh; border-radius: var(--radius); border: 1px solid var(--line); cursor: zoom-in; background: #fff; }
.render-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.render-actions .btn { min-height: 34px; padding: 5px 12px; font-size: 14px; }
.pending { display: flex; align-items: center; gap: 12px; color: var(--muted); }
.pending .ph { width: min(520px, 100%); aspect-ratio: 3/2; border-radius: var(--radius); background: linear-gradient(90deg, #eceef3 25%, var(--flash-soft) 50%, #eceef3 75%); background-size: 200% 100%; animation: sh 1.4s infinite linear; display: grid; place-items: center; color: var(--muted); font-size: 14px; text-align: center; padding: 12px; }
@keyframes sh { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.empty { max-width: 760px; margin: 0 auto; padding: 9vh 20px 20px; text-align: center; }
.empty h2 { font-size: 26px; margin: 0 0 8px; font-weight: 600; }
.empty p { color: var(--muted); margin: 0 0 22px; }
.starters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; align-items: stretch; }
.starter { text-align: start; border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 12px 14px; height: 100%; display: flex; flex-direction: column; gap: 4px; }
.starter:hover { border-color: var(--flash); }
.starter b { font-weight: 600; }
.starter span { color: var(--muted); font-size: 13px; line-height: 1.5; }

/* תיבת כתיבה */
.composer-wrap { flex: none; padding: 8px 20px 16px; }
.composer { max-width: 860px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 10px 12px 8px; box-shadow: 0 2px 10px rgba(0,0,0,.04); }
.composer.drag { border-color: var(--accent); background: var(--accent-soft); }
.composer textarea { width: 100%; border: none; outline: none; resize: none; min-height: 28px; max-height: 220px; line-height: 1.6; padding: 4px 6px; background: transparent; }
.attach-row { display: flex; gap: 8px; flex-wrap: wrap; padding: 2px 4px 8px; }
.att { position: relative; }
.att img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); display: block; }
.att .x { position: absolute; top: -6px; inset-inline-end: -6px; width: 20px; height: 20px; border-radius: 50%; border: none; background: #333; color: #fff; font-size: 12px; line-height: 20px; padding: 0; }
.att .tag { position: absolute; bottom: 3px; inset-inline-start: 3px; background: rgba(0,0,0,.6); color: #fff; font-size: 10px; border-radius: 4px; padding: 0 4px; }
.comp-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.comp-bar select { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 5px 8px; font-size: 13px; color: var(--muted); }
.comp-bar .spacer { flex: 1; }
.send { width: 38px; height: 38px; border-radius: 50%; border: none; background: var(--accent); color: #fff; font-size: 18px; display: grid; place-items: center; }
.send:disabled { background: #c9c5bc; }
.hint { max-width: 860px; margin: 6px auto 0; font-size: 12px; color: var(--muted); text-align: center; }
.err-line { max-width: 860px; margin: 6px auto 0; font-size: 13px; color: var(--err-ink); text-align: center; }

/* בורר חומרים */
.popover { position: absolute; z-index: 40; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.15); width: 320px; max-height: 360px; display: flex; flex-direction: column; }
.popover input { margin: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.popover .list { overflow-y: auto; padding: 0 6px 8px; }
.pick { display: flex; align-items: center; gap: 10px; width: 100%; border: none; background: transparent; padding: 7px 8px; border-radius: 8px; text-align: start; }
.pick:hover { background: #f3f1ec; }
.pick .sw { width: 30px; height: 30px; border-radius: 6px; object-fit: cover; background: #e4e0d8; flex: none; }
.pick small { color: var(--muted); display: block; }
.popover .none { padding: 14px; color: var(--muted); font-size: 14px; }

/* ספריית חומרים */
.page { max-width: 1100px; margin: 0 auto; padding: 24px 20px 40px; }
.page-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.page-head h2 { margin: 0; font-size: 20px; }
.page-head .spacer { flex: 1; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filters input { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; min-width: 240px; background: var(--panel); }
.mat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; align-items: stretch; }
.mat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; height: 100%; }
.mat .sw { aspect-ratio: 4/3; background: #e9e6df center/cover no-repeat; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.mat .body { padding: 10px 12px; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.mat .type { font-size: 12px; color: var(--accent); }
.mat .code { font-weight: 600; word-break: break-word; }
.mat .name { font-size: 14px; color: var(--muted); word-break: break-word; }
.mat .notes { font-size: 13px; color: var(--muted); margin-top: 4px; word-break: break-word; }
.mat .acts { display: flex; gap: 4px; padding: 0 8px 8px; }
.mat-grid:has(.tam) { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.mat.tam .sw { aspect-ratio: 3/2; }
.mat.tam .body { padding: 8px 10px; }
.mat.tam .code { font-size: 14px; }
.mat.tam .name { font-size: 13px; }
.empty-box { background: var(--panel); border: 1px dashed var(--line); border-radius: 12px; padding: 30px; text-align: center; color: var(--muted); }

/* חלונות */
.modal-bg { position: fixed; inset: 0; background: rgba(20,18,15,.55); z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal { background: var(--panel); border-radius: 16px; width: min(520px, 100%); max-height: calc(100vh - 40px); overflow: auto; padding: 20px; }
.modal h3 { margin: 0 0 14px; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 14px; }
.field input, .field select, .field textarea { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fff; }
.field .sw-prev { width: 100%; max-height: 180px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.modal .acts { display: flex; gap: 8px; justify-content: flex-start; margin-top: 6px; }
.form-err { color: var(--err-ink); font-size: 14px; min-height: 20px; }

/* תצוגה מוגדלת */
.lightbox { position: fixed; inset: 0; background: rgba(15,14,12,.92); z-index: 60; display: flex; flex-direction: column; }
.lightbox .lb-bar { display: flex; gap: 8px; padding: 12px 16px; justify-content: flex-start; }
.lightbox .lb-bar .btn { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.2); }
.lightbox .lb-img { flex: 1; min-height: 0; display: grid; place-items: center; padding: 0 16px 16px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* עורך סימון */
.editor { position: fixed; inset: 0; background: #1c1b19; z-index: 70; display: grid; grid-template-columns: 1fr 340px; color: #eee; }
.ed-stage { min-width: 0; min-height: 0; display: grid; place-items: center; padding: 20px; position: relative; }
.ed-canvas-wrap { position: relative; line-height: 0; }
.ed-canvas-wrap img { display: block; max-width: 100%; max-height: calc(100vh - 40px); border-radius: 6px; user-select: none; -webkit-user-drag: none; }
.ed-canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .45; cursor: none; touch-action: none; }
.ed-cursor { position: fixed; pointer-events: none; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.6); z-index: 80; transform: translate(-50%, -50%); }
.ed-side { background: #262522; border-inline-start: 1px solid #3a3834; padding: 18px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.ed-side h3 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.ed-side .help > summary { background: #333; border-color: #555; color: #ccc; }
.ed-tools { display: flex; gap: 6px; flex-wrap: wrap; }
.ed-tools .btn { background: #34322e; border-color: #4a4742; color: #eee; }
.ed-tools .btn.on { background: var(--mark); border-color: var(--mark); color: #fff; }
.ed-side label { font-size: 14px; color: #bbb; display: flex; flex-direction: column; gap: 6px; }
.ed-side input[type=range] { width: 100%; accent-color: var(--mark); }
.ed-side textarea { background: #1c1b19; border: 1px solid #4a4742; color: #eee; border-radius: 10px; padding: 10px; min-height: 110px; resize: vertical; line-height: 1.6; }
.ed-side .warn { color: #ffcf7a; font-size: 13px; min-height: 18px; }
.ed-side .acts { display: flex; gap: 8px; margin-top: auto; }
.ed-side .btn.ghost { color: #ddd; }

/* כניסה */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login form { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0 0 6px; font-size: 22px; display: flex; align-items: center; gap: 10px; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.login input { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.login .btn { justify-content: center; min-height: 44px; }

.brand { justify-content: center; padding: 2px 0 4px; }
.brand img { height: 40px; width: auto; display: block; }
.login .logo { display: block; width: 170px; height: auto; margin: 0 auto 10px; }
.tam-link { border: 1px dashed var(--accent); color: var(--accent); background: var(--panel); border-radius: 10px; padding: 7px 12px; font-size: 14px; }
.tam-link:hover { background: var(--accent-soft); }

/* חיבור AI */
.conn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: stretch; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; }
.conn-card { display: flex; flex-direction: column; gap: 12px; height: 100%; }
.conn-card h3 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.conn-card .sub { color: var(--muted); font-size: 14px; line-height: 1.6; margin: 0; }
.conn-card .grow { flex: 1; }
.status-chip { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 12px; font-size: 13px; width: fit-content; }
.status-chip.on { background: var(--flash-soft); color: var(--accent); font-weight: 600; }
.status-chip.off { background: #f0eee9; color: var(--muted); }
.conn-card input { border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; direction: ltr; text-align: left; font-family: Consolas, monospace; }
.conn-card .row { display: flex; gap: 8px; flex-wrap: wrap; }
.conn-card .msg { font-size: 14px; min-height: 20px; }
.conn-card .msg.err { color: var(--err-ink); } .conn-card .msg.ok { color: var(--accent); font-weight: 600; }
.notice { border-radius: 12px; padding: 12px 16px; margin-bottom: 16px; line-height: 1.6; font-size: 14px; background: var(--accent-soft); color: var(--accent); }
.notice.warn { background: var(--warn-bg); color: var(--warn-ink); }
.privacy h3 { margin: 0 0 8px; font-size: 16px; }
.privacy ul { margin: 0; padding-inline-start: 20px; line-height: 1.8; font-size: 14px; color: var(--ink); }
.modal.wide { width: min(760px, 100%); }
.guide ol { padding-inline-start: 22px; line-height: 1.8; margin: 8px 0; }
.guide li { margin-bottom: 8px; }
.guide .pre { background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; padding: 10px 14px; font-size: 14px; line-height: 1.7; }
.guide code, .guide .ui { direction: ltr; unicode-bidi: isolate; background: #f0eee9; border-radius: 5px; padding: 1px 6px; font-family: Consolas, monospace; font-size: 13px; }
.guide h4 { margin: 14px 0 4px; font-size: 15px; }
.guide .tip { font-size: 13px; color: var(--muted); }
.seg button.off { color: #aaa; }
.conn-card input:placeholder-shown { direction: rtl; text-align: right; font-family: inherit; }

/* פלטת הלוגו */
::selection { background: var(--flash-light); color: var(--ink); }
:focus-visible { outline: 2px solid var(--flash); outline-offset: 2px; }
.send { box-shadow: 0 0 0 0 var(--flash); transition: box-shadow .15s; }
.send:not(:disabled):hover { box-shadow: 0 0 0 3px var(--flash-light); }
.help > summary { border-color: var(--sketch); color: var(--sketch); }
/* הלוגו של MB בתחתית */
.made-by { display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--muted); font-size: 12px; text-decoration: none; padding-top: 2px; }
.made-by img { height: 32px; width: auto; display: block; }
.made-by:hover { color: var(--muted); }
.login-foot { margin-top: 14px; }
