/* QLMG Collab - one stylesheet. Logical properties throughout so RTL (Hebrew) mirrors for free. */
:root {
  --bg: #fbfaf8;
  --bg-side: #f3f1ed;
  --surface: #ffffff;
  --surface-2: #f6f5f2;
  --border: #e4e1da;
  --text: #1f1e1c;
  --muted: #6d6a64;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --accent-soft: #e3efe9;
  --danger: #b4432f;
  --warn-bg: #fdf3dc;
  --warn-ink: #7a5a10;
  --ok-bg: #e3f1e7;
  --ok-ink: #24613a;
  --err-bg: #fbe6e1;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Hebrew", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1c1a; --bg-side: #171615; --surface: #252422; --surface-2: #2c2b28; --border: #3a3834;
    --text: #ecebe7; --muted: #a29f97; --accent: #6fb8a0; --accent-ink: #10201b; --accent-soft: #23342e;
    --danger: #e3866f; --warn-bg: #3a3020; --warn-ink: #f0d18a; --ok-bg: #1f3326; --ok-ink: #9fd6ae; --err-bg: #3d2420;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1d1c1a; --bg-side: #171615; --surface: #252422; --surface-2: #2c2b28; --border: #3a3834;
  --text: #ecebe7; --muted: #a29f97; --accent: #6fb8a0; --accent-ink: #10201b; --accent-soft: #23342e;
  --danger: #e3866f; --warn-bg: #3a3020; --warn-ink: #f0d18a; --ok-bg: #1f3326; --ok-ink: #9fd6ae; --err-bg: #3d2420;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; font-weight: 600; margin: 0 0 .75rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1.25rem 0 .5rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; direction: ltr; unicode-bidi: isolate; }
.ltr { direction: ltr; unicode-bidi: plaintext; text-align: start; }
.ltr-path { direction: ltr; text-align: start; unicode-bidi: isolate; }
.wrap { white-space: pre-wrap; word-break: break-word; }
[hidden] { display: none !important; }

/* ---------- controls ---------- */
input, select, textarea {
  font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .5rem .65rem; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[type=file] { padding: .35rem; }
textarea.code { font-family: var(--mono); font-size: .85rem; line-height: 1.5; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; font-weight: 500; }
label.inline { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
label small { font-weight: 400; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .5rem .75rem; display: flex; flex-wrap: wrap; gap: .25rem 1rem; }
legend { font-size: .85rem; color: var(--muted); padding: 0 .25rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; cursor: pointer;
  font: inherit; font-size: .9rem; font-weight: 500; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .45rem .9rem; white-space: nowrap;
  text-decoration: none !important;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.sm { padding: .25rem .6rem; font-size: .82rem; }
.btn.danger-outline { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 1.15rem; cursor: pointer; padding: .3rem .45rem; border-radius: var(--radius-sm); line-height: 1; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.stack { display: flex; flex-direction: column; gap: .9rem; }
.row { display: flex; align-items: center; }
.row.gap { gap: .5rem; }
.row.between { justify-content: space-between; gap: 1rem; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.push { margin-inline-start: auto; }

/* ---------- layout ---------- */
.app { display: flex; height: 100vh; height: 100dvh; }
.sidebar {
  width: 264px; flex: none; background: var(--bg-side); border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column; padding: .75rem; gap: .5rem; overflow-y: auto;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: .25rem .35rem; }
.brand { font-weight: 650; color: var(--text); letter-spacing: -.01em; }
.brand.big { font-size: 1.35rem; text-align: center; margin-bottom: 1rem; }
.new-chat { width: 100%; justify-content: flex-start; }
.nav-main { display: flex; flex-direction: column; }
.nav-section { display: flex; flex-direction: column; margin-top: .5rem; }
.nav-section.grow { flex: 1; min-height: 0; }
.nav-heading { display: flex; justify-content: space-between; align-items: center; font-size: .75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: .35rem .5rem; }
.nav-add { color: var(--muted); font-size: 1rem; }
.nav-item {
  display: flex; align-items: center; gap: .5rem; padding: .4rem .55rem; border-radius: var(--radius-sm);
  color: var(--text); font-size: .9rem; min-width: 0;
}
.nav-item:hover { background: color-mix(in srgb, var(--text) 6%, transparent); text-decoration: none; }
.nav-item.active { background: color-mix(in srgb, var(--text) 9%, transparent); font-weight: 500; }
.nav-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.nav-sub { font-size: .72rem; color: var(--muted); white-space: nowrap; max-width: 40%; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); opacity: .7; flex: none; }
.sidebar-bottom { border-top: 1px solid var(--border); padding-top: .5rem; display: flex; flex-direction: column; }
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.main { flex: 1; min-height: 0; overflow-y: auto; }
.page { max-width: 1040px; margin: 0 auto; padding: 1.75rem 1.5rem 4rem; }
.narrow-page { max-width: 640px; }
.topbar { display: none; align-items: center; gap: .5rem; padding: .5rem .75rem; border-bottom: 1px solid var(--border); background: var(--bg); }
.topbar-title { font-weight: 600; }
.only-mobile { display: none; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.card.flat { padding: 0; overflow: hidden; }
.card.narrow { max-width: 440px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-2 > .card { margin-bottom: 0; min-width: 0; }
.grid-2 + .card, .grid-2 { margin-bottom: 1rem; }

.flash { padding: .6rem .85rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: .92rem; }
.flash.ok { background: var(--ok-bg); color: var(--ok-ink); }
.flash.err { background: var(--err-bg); color: var(--danger); }
.flash.warn { background: var(--warn-bg); color: var(--warn-ink); }

.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .12rem .5rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); vertical-align: middle; white-space: nowrap; }
.ok-badge { background: var(--ok-bg); color: var(--ok-ink); }
.warn-badge { background: var(--warn-bg); color: var(--warn-ink); }
.muted-badge { background: var(--surface-2); color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: .25rem; font-size: .82rem; padding: .2rem .6rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); margin: .25rem .25rem 0 0; }
.chip button { background: none; border: 0; cursor: pointer; color: var(--muted); padding: 0 .1rem; }

.avatar {
  --h: 160; display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 26px; height: 26px; border-radius: 50%; font-size: .68rem; font-weight: 700;
  background: hsl(var(--h) 45% 88%); color: hsl(var(--h) 45% 28%);
}
.avatar.sm { width: 22px; height: 22px; font-size: .62rem; }
:root[data-theme="dark"] .avatar { background: hsl(var(--h) 30% 28%); color: hsl(var(--h) 60% 85%); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .avatar { background: hsl(var(--h) 30% 28%); color: hsl(var(--h) 60% 85%); } }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: start; font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
th, td { padding: .55rem .7rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
td input { padding: .3rem .45rem; }
input.short { width: 7rem; }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; overflow-x: auto; }
.tab { padding: .5rem .8rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--text); border-color: var(--accent); font-weight: 500; }
.tab:hover { text-decoration: none; color: var(--text); }

.list { list-style: none; margin: 0; padding: 0; }
.list-row { display: flex; align-items: center; gap: .6rem; padding: .45rem 0; border-bottom: 1px solid var(--border); min-width: 0; }
.list-row:last-child { border-bottom: 0; }
.list-row > a, .list-row > span:not(.avatar):not(.push):not(.badge) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 0 1 auto; }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { display: flex; gap: .6rem; padding: .3rem 0; }
.checklist .mark { width: 1.2rem; color: var(--muted); }
.checklist .done .mark { color: var(--ok-ink); }
.checklist .done a { color: var(--muted); text-decoration: line-through; }
.quick-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.btn.quick { border-radius: 999px; }
.crumb { display: inline-block; font-size: .85rem; color: var(--muted); margin-bottom: .25rem; }
.breadcrumbs { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: 1rem; font-size: .92rem; }
.breadcrumbs .sep { color: var(--muted); }
.breadcrumbs .sep:last-child { display: none; }
.file-link { color: var(--text); }
.upload-form input[type=file] { max-width: 18rem; }
.access-form { margin: .5rem 0 1rem; }
.upload-form + form, .row.gap.wrap + .muted { margin-top: .75rem; }
textarea.code { min-height: 14rem; height: 50vh; }
.access-form select { width: auto; }
.mode-help { background: var(--surface-2); border-radius: var(--radius-sm); padding: .75rem .9rem; font-size: .88rem; }
.mode-help p { margin-bottom: .4rem; }
.copy-row { display: flex; gap: .4rem; }
.copy-row input { font-size: .8rem; }
.code-view { background: var(--surface-2); border-radius: var(--radius-sm); padding: 1rem; overflow: auto; max-height: 70vh; font: .82rem/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; margin: 0; }
.preview-img { max-width: 100%; border-radius: var(--radius-sm); }
.preview-pdf { width: 100%; height: 75vh; border: 0; border-radius: var(--radius-sm); background: var(--surface-2); }
details.menu { position: relative; }
details.menu > summary { list-style: none; }
details.menu > summary::-webkit-details-marker { display: none; }
.menu-body { position: absolute; inset-inline-end: 0; top: calc(100% + .3rem); z-index: 20; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: .6rem; display: flex; flex-direction: column; gap: .5rem; min-width: 16rem; }
.search-bar input { flex: 1; }
.search-bar select { width: auto; max-width: 14rem; }
.hits { list-style: none; padding: 0; }
.hit { padding: .75rem 0; border-bottom: 1px solid var(--border); }
.snippet { font-size: .88rem; color: var(--muted); margin-top: .2rem; }
.snippet mark { background: var(--accent-soft); color: var(--text); border-radius: 3px; padding: 0 .1rem; }

/* ---------- bare pages (login, setup) ---------- */
.center-page { display: flex; min-height: 100%; align-items: center; justify-content: center; }
.bare { width: 100%; display: flex; justify-content: center; padding: 2rem 1rem; }
.bare-inner { width: 100%; max-width: 420px; }
.bare .card { box-shadow: var(--shadow); padding: 1.5rem; }
.lang-switch { text-align: center; margin-top: 1rem; font-size: .9rem; }

/* ---------- chat ---------- */
.chat-page { height: 100%; }
.chat { display: flex; flex-direction: column; height: 100%; }
.chat-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .7rem 1.25rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.chat-title-row { display: flex; align-items: center; gap: .6rem; min-width: 0; flex-wrap: wrap; }
.chat-title { font-size: 1rem; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40ch; }
.chat-title-row .crumb { margin: 0; }
.chat-title-row .crumb::after { content: " /"; }
.owner-badge { display: inline-flex; align-items: center; gap: .35rem; font-size: .85rem; color: var(--muted); }
.messages { flex: 1; overflow-y: auto; padding: 1.5rem 1rem 1rem; }
.messages > * { max-width: 760px; margin-inline: auto; }
.msg { margin-bottom: 1.4rem; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .msg-head { display: flex; align-items: center; gap: .4rem; font-size: .78rem; color: var(--muted); margin-bottom: .3rem; }
.user-text { background: var(--surface-2); border: 1px solid var(--border); border-radius: 18px; border-end-end-radius: 6px; padding: .6rem .9rem; max-width: 85%; white-space: pre-wrap; word-break: break-word; }
.msg.recipe details { max-width: 85%; }
.msg.recipe summary { cursor: pointer; color: var(--muted); font-size: .88rem; text-align: end; }
.msg.recipe .user-text { max-width: 100%; margin-top: .4rem; font-size: .85rem; }
.msg.assistant .md { line-height: 1.65; }
.md > :first-child { margin-top: 0; }
.md p { margin: 0 0 .8rem; }
.md pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .8rem; overflow-x: auto; direction: ltr; text-align: left; }
.md code { font-family: var(--mono); font-size: .86em; background: var(--surface-2); padding: .1rem .3rem; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.md table { margin: .5rem 0 1rem; }
.md blockquote { margin: 0 0 .8rem; padding-inline-start: .9rem; border-inline-start: 3px solid var(--border); color: var(--muted); }
.md ul, .md ol { padding-inline-start: 1.4rem; margin: 0 0 .8rem; }
.md h1, .md h2, .md h3 { margin: 1rem 0 .5rem; }
.math { direction: ltr; unicode-bidi: isolate; }
.katex-display { overflow-x: auto; overflow-y: hidden; direction: ltr; }
details.reasoning, details.tool { font-size: .86rem; margin: .2rem 0 .6rem; }
details.reasoning summary, details.tool summary { cursor: pointer; color: var(--muted); user-select: none; }
details.reasoning > div { color: var(--muted); border-inline-start: 2px solid var(--border); padding-inline-start: .75rem; margin-top: .4rem; white-space: pre-wrap; }
details.tool pre { background: var(--surface-2); border-radius: var(--radius-sm); padding: .6rem .75rem; margin: .4rem 0 0; max-height: 18rem; overflow: auto; font-size: .78rem; white-space: pre-wrap; word-break: break-word; text-align: left; }
details.tool.err summary { color: var(--danger); }
.tool-icon { opacity: .7; }
.msg-foot { margin-top: .2rem; }
.model-tag { font-size: .72rem; color: var(--muted); }
.msg.notice { font-size: .85rem; color: var(--muted); text-align: center; background: var(--surface-2); border-radius: var(--radius-sm); padding: .5rem .75rem; }
.streaming .md::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }
.live-status { font-size: .82rem; color: var(--muted); margin: .2rem 0 .5rem; }
.empty-chat { text-align: center; margin-top: 18vh; }
.empty-chat h2 { font-size: 1.6rem; font-weight: 600; }

.composer {
  max-width: 760px; width: calc(100% - 2rem); margin: 0 auto 1rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); padding: .55rem .6rem .45rem;
}
.composer textarea { border: 0; resize: none; padding: .4rem .5rem; max-height: 40vh; outline: none; background: transparent; }
.composer textarea:focus { outline: none; }
.composer-bar { display: flex; align-items: center; gap: .4rem; }
.composer-bar select { width: auto; max-width: 14rem; border-radius: 999px; padding: .25rem .6rem; font-size: .82rem; background: var(--surface-2); border-color: transparent; }
.composer .send { border-radius: 50%; width: 2.1rem; height: 2.1rem; padding: 0; font-size: 1.1rem; }
.composer-note { max-width: 760px; margin: 0 auto 1rem; text-align: center; color: var(--muted); font-size: .9rem; padding: .75rem; }
.chat > .flash { max-width: 760px; margin: 0 auto 1rem; }

/* ---------- pop-up panel (temporary chats) ---------- */
.panel {
  position: fixed; inset-block: 0; inset-inline-end: 0; width: min(520px, 100vw); z-index: 50;
  background: var(--bg); border-inline-start: 1px solid var(--border); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.panel-head { display: flex; align-items: center; gap: .5rem; padding: .6rem .9rem; border-bottom: 1px solid var(--border); }
.panel-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.panel-body .chat-header { display: none; }
.panel .human-only { margin: .75rem 1rem 0; font-size: .85rem; }
.panel .human-only ul { margin: .35rem 0 0; padding-inline-start: 1.2rem; }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
  .only-mobile { display: inline-flex; }
  .topbar.only-mobile { display: flex; }
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 40; transform: translateX(-105%); transition: transform .18s ease; box-shadow: var(--shadow); }
  [dir="rtl"] .sidebar { transform: translateX(105%); }
  .sidebar.open { transform: none !important; }
  .page { padding: 1.1rem 1rem 3rem; }
  .chat-title { max-width: 22ch; }
}
