:root {
  --bg: #f7f5f1; --bg2: #ffffff; --bg3: #eeeae3; --fg: #1f1d1a; --muted: #6f6a62; --line: #e2ddd4;
  --accent: #d97757; --accent-fg: #fff; --danger: #c0392b; --user: #efe9e0; --code: #f3f1ec;
  --shadow: 0 8px 30px rgba(0,0,0,.08); --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1f1e1b; --bg2: #2a2825; --bg3: #33302c; --fg: #ecebe6; --muted: #a39d93; --line: #3c3934;
    --user: #3a3631; --code: #26241f; --shadow: 0 8px 30px rgba(0,0,0,.4); }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.55 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--fg); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--danger); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
button, input, select, textarea { font: inherit; color: inherit; }
.btn { border: 1px solid var(--line); background: var(--bg2); border-radius: 10px; padding: 8px 14px; cursor: pointer; }
.btn:hover { background: var(--bg3); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.link { background: none; border: none; color: var(--muted); text-decoration: underline; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: none; background: transparent; cursor: pointer; font-size: 18px; padding: 6px 8px; border-radius: 8px; color: var(--muted); }
.icon-btn:hover { background: var(--bg3); color: var(--fg); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 16px; }
.logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; }

/* ---- login ---- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); }
.login-card .brand { justify-content: center; margin-bottom: 20px; font-size: 20px; }
.login-step { display: grid; gap: 12px; }
.login-step label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.login-step input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 15px; }
.qr { width: 200px; height: 200px; margin: 0 auto; display: block; border-radius: 8px; background: #fff; }

/* ---- layout ---- */
.app { display: flex; height: 100%; }
.sidebar { width: 280px; flex: none; background: var(--bg2); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px; }
#btn-close-sidebar { display: none; }
.new-chat { margin: 6px 12px 10px; text-align: left; }
.conv-list { flex: 1; overflow-y: auto; padding: 0 8px; }
.conv-item { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 10px; cursor: pointer; color: var(--fg); }
.conv-item:hover { background: var(--bg3); }
.conv-item.active { background: var(--bg3); font-weight: 600; }
.conv-item .t { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.conv-item .c { font-size: 11px; color: var(--muted); }
.conv-item .p { font-size: 11px; color: var(--accent); }
.sidebar-foot { padding: 10px 12px 14px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.foot-actions { display: flex; gap: 6px; }
.foot-actions .btn { flex: 1; padding: 8px 6px; font-size: 13px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--bg); }
#btn-open-sidebar { display: none; }
.title-wrap { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.conv-title { flex: 1; min-width: 0; border: 1px solid transparent; background: transparent; font-weight: 600; font-size: 15px; padding: 4px 8px; border-radius: 8px; }
.conv-title:hover, .conv-title:focus { border-color: var(--line); background: var(--bg2); outline: none; }

.messages { flex: 1; overflow-y: auto; padding: 24px 16px 8px; }
.empty { max-width: 640px; margin: 12vh auto 0; text-align: center; }
.empty-logo { width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; margin: 0 auto 14px; }
.empty h1 { font-size: 26px; font-weight: 600; margin: 0 0 6px; }

.msg { max-width: 780px; margin: 0 auto 18px; display: flex; gap: 12px; }
.msg .avatar { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.msg.user .avatar { background: var(--bg3); }
.msg.assistant .avatar { background: var(--accent); color: #fff; }
.msg .body { flex: 1; min-width: 0; }
.msg.user .bubble { background: var(--user); border-radius: 14px; padding: 10px 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg .md { line-height: 1.6; word-wrap: break-word; }
.md p { margin: .4em 0 .8em; } .md p:first-child { margin-top: 0; }
.md pre { background: var(--code); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; overflow-x: auto; position: relative; }
.md pre code { background: none; padding: 0; font-size: 13px; }
.md :not(pre) > code { background: var(--code); border: 1px solid var(--line); padding: 1px 5px; border-radius: 6px; font-size: 13px; }
.md table { border-collapse: collapse; margin: .6em 0; } .md th, .md td { border: 1px solid var(--line); padding: 5px 9px; }
.md blockquote { border-left: 3px solid var(--line); margin: .6em 0; padding-left: 12px; color: var(--muted); }
.md h1, .md h2, .md h3 { margin: 1em 0 .4em; } .md h1 { font-size: 20px; } .md h2 { font-size: 17px; } .md h3 { font-size: 15.5px; }
.copy-btn { position: absolute; top: 6px; right: 6px; font-size: 11px; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg2); cursor: pointer; opacity: .7; }
.copy-btn:hover { opacity: 1; }
.thinking { font-size: 13px; color: var(--muted); border-left: 3px solid var(--line); padding: 4px 10px; margin-bottom: 8px; white-space: pre-wrap; }
.thinking summary { cursor: pointer; }
.meta { font-size: 11.5px; color: var(--muted); margin-top: 6px; display: flex; gap: 10px; flex-wrap: wrap; }
.meta .err { color: var(--danger); }
.pending { font-style: italic; color: var(--muted); }
.pending .dot::after { content: "…"; animation: dots 1.2s steps(4, end) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.att-view { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.att-view img { max-width: 220px; max-height: 180px; border-radius: 8px; border: 1px solid var(--line); }
.att-view .doc { padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 12.5px; background: var(--bg2); }
.cursor::after { content: "▍"; animation: blink 1s infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

/* ---- composer ---- */
.composer-wrap { padding: 8px 16px 10px; max-width: 812px; width: 100%; margin: 0 auto; }
.composer { background: var(--bg2); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 10px 12px 8px; }
.composer:focus-within { border-color: var(--accent); }
#input { width: 100%; border: none; background: transparent; resize: none; outline: none; font-size: 15px; max-height: 40vh; padding: 4px 4px; }
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.composer-left, .composer-right { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sel { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 5px 8px; font-size: 13px; max-width: 190px; }
.send { width: 38px; height: 38px; padding: 0; border-radius: 50%; display: grid; place-items: center; font-size: 15px; }
.estimate { white-space: nowrap; }
.estimate b { color: var(--fg); }
.disclaimer { text-align: center; margin: 6px 0 0; }
.attachments { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.att { display: flex; align-items: center; gap: 6px; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 4px 8px; font-size: 12.5px; }
.att img { width: 32px; height: 32px; object-fit: cover; border-radius: 6px; }
.att button { border: none; background: none; cursor: pointer; color: var(--muted); }

.toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; user-select: none; }
.toggle input { display: none; }
.toggle-track { width: 36px; height: 20px; border-radius: 10px; background: var(--line); position: relative; transition: .2s; }
.toggle-thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.toggle input:checked + .toggle-track { background: #2e8b57; }
.toggle input:checked + .toggle-track .toggle-thumb { left: 18px; }

/* ---- modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-card { background: var(--bg2); border-radius: var(--radius); width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 14px 18px 18px; }
.modal-body h3 { font-size: 14px; margin: 16px 0 6px; }
.modal-body input[type=password], .modal-body input[type=text], .modal-body textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.row > input { flex: 1; min-width: 160px; }
.row.end { justify-content: flex-end; }
.row label { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.chk { gap: 6px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 60; box-shadow: var(--shadow); max-width: 90vw; }

/* ---- mobile ---- */
@media (max-width: 820px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; width: min(300px, 85vw); }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  #btn-close-sidebar, #btn-open-sidebar { display: inline-block; }
  .messages { padding: 16px 12px 6px; }
  .composer-wrap { padding: 6px 10px 8px; }
  .sel { max-width: 140px; }
  .estimate { font-size: 11.5px; }
  .disclaimer { display: none; }
}

/* ---- composer v2: chip + popover, fără salturi de layout ---- */
.composer { position: relative; }
#input { min-height: 28px; }
.composer-bar { flex-wrap: nowrap; }
.composer-left { flex-wrap: nowrap; min-width: 0; flex: 1; }
.composer-right { flex-wrap: nowrap; flex: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--bg); border-radius: 999px;
  padding: 4px 10px 4px 8px; cursor: pointer; font-size: 12.5px; color: var(--muted); min-width: 0; max-width: 100%; }
.chip:hover, .chip[aria-expanded="true"] { color: var(--fg); border-color: var(--accent); }
.chip-ico { font-size: 13px; }
.chip-text { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.chip .sep { opacity: .45; }
.mode-badge { background: #2e8b57; color: #fff; border-radius: 6px; padding: 0 5px; font-size: 11px; font-weight: 600; }
.estimate { display: inline-block; min-width: 76px; text-align: right; font-size: 12.5px; color: var(--muted);
  font-variant-numeric: tabular-nums; white-space: nowrap; transition: opacity .15s; }
.estimate b { color: var(--fg); font-weight: 600; }
.estimate.loading { opacity: .45; }
.popover { position: absolute; left: 10px; bottom: calc(100% + 8px); width: min(360px, calc(100vw - 32px)); background: var(--bg2);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 14px; z-index: 30; display: grid; gap: 14px; }
.pop-row { display: grid; gap: 6px; }
.pop-row > label:first-child { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.pop-row .sel { max-width: none; width: 100%; padding: 7px 9px; }
.pop-hint { margin: 0; font-size: 12px; color: var(--muted); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { flex: 1; border: none; background: var(--bg); padding: 6px 0; font-size: 12.5px; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }
@media (max-width: 820px) {
  .chip { padding: 4px 8px; }
  .estimate { min-width: 64px; font-size: 12px; }
  .popover { left: 0; }
}

/* ---- logo ---- */
img.logo { width: 28px; height: 28px; border-radius: 8px; background: none; display: block; }
.login-card img.logo { width: 36px; height: 36px; border-radius: 10px; }
img.empty-logo { width: 64px; height: 64px; border-radius: 18px; background: none; display: block; margin: 0 auto 14px; box-shadow: 0 6px 20px rgba(198,90,52,.35); }
.msg img.avatar { width: 30px; height: 30px; border-radius: 9px; }
.msg.user .avatar { font-size: 11px; }

/* ---- buget ---- */
.budget { display: grid; gap: 5px; }
.budget-row { display: flex; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
.budget-bar { height: 6px; border-radius: 3px; background: var(--bg3); overflow: hidden; }
.budget-bar span { display: block; height: 100%; width: 0; background: #2e8b57; transition: width .3s; }
.budget-bar.warn span { background: #d4a017; }
.budget-bar.over span { background: var(--danger); }
#btn-admin { text-align: left; font-size: 13px; }
.estimate.over b, .estimate.over { color: var(--danger); }
.banner { background: rgba(212,160,23,.15); border: 1px solid rgba(212,160,23,.5); border-radius: 10px; padding: 10px 12px; margin: 0 0 10px; font-size: 13.5px; }

/* ---- admin ---- */
.modal-card.wide { max-width: 860px; }
.create-box { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin: 8px 0 14px; }
.create-box summary { cursor: pointer; font-weight: 600; }
.create-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.create-form label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.create-form input, .create-form select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); max-width: none; }
.create-form .models-pick, .create-form .row { grid-column: 1 / -1; }
.models-pick { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin: 0; }
.models-pick legend { font-size: 12.5px; padding: 0 4px; }
.model-checks { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.model-checks label { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--fg); }
.temp-pass { border: 1px solid #2e8b57; background: rgba(46,139,87,.1); border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; }
.temp-pass p { margin: 4px 0; }
.temp-pass code { font-size: 16px; padding: 6px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; user-select: all; }
.user-list { display: grid; gap: 10px; }
.user-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; gap: 8px; }
.user-card.inactive { opacity: .6; }
.uc-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.uc-head .who b { font-size: 14.5px; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); margin-left: 4px; }
.tag.admin { border-color: var(--accent); color: var(--accent); }
.tag.off { border-color: var(--danger); color: var(--danger); }
.tag.ok { border-color: #2e8b57; color: #2e8b57; }
.uc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px 14px; align-items: end; }
.uc-grid label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
.uc-grid input { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.uc-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.uc-actions .btn { padding: 6px 10px; font-size: 12.5px; }
@media (max-width: 640px) { .create-form { grid-template-columns: 1fr; } }

/* ---- web ---- */
.web-badge { font-size: 12px; line-height: 1; }
.web-badge.off { display: none; }
.tool-status { font-size: 12.5px; color: var(--muted); margin: 2px 0 8px; display: grid; gap: 3px; }
.tool-status div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-status div:last-child.live::after { content: "…"; animation: dots 1.2s steps(4, end) infinite; }
.sources { margin-top: 10px; font-size: 12.5px; border-top: 1px dashed var(--line); padding-top: 8px; }
.sources summary { cursor: pointer; color: var(--muted); }
.sources ol { margin: 6px 0 0; padding-left: 20px; display: grid; gap: 3px; }
.sources a { color: var(--accent); text-decoration: none; word-break: break-word; }
.sources a:hover { text-decoration: underline; }
.sources .host { color: var(--muted); margin-left: 4px; }

/* ---- bare de derulare în tema site-ului ---- */
:root { --scroll-thumb: #d6cfc4; --scroll-thumb-hover: #c9a594; }
@media (prefers-color-scheme: dark) { :root { --scroll-thumb: #45413b; --scroll-thumb-hover: #7a4f3d; } }
/* Firefox folosește proprietățile standard; Chrome/Edge/Safari stilul ::-webkit-scrollbar de mai jos (mai fin) */
@supports not selector(::-webkit-scrollbar) { * { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; } }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; min-height: 40px; }
::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:active { background: var(--accent); border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }
.md pre::-webkit-scrollbar { height: 8px; }

/* ---- fără zoom pe telefon ---- */
html, body { touch-action: pan-x pan-y; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
button, a, .chip, .toggle, .conv-item { touch-action: manipulation; }
@media (max-width: 820px), (pointer: coarse) {
  /* sub 16px, iOS mărește automat pagina când apeși pe un câmp */
  input, textarea, select, #input, .sel, .pop-row .sel { font-size: 16px !important; }
}

/* ---- iconițe SVG ---- */
.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.icon-btn { display: inline-grid; place-items: center; line-height: 0; }
.icon-btn .i { width: 20px; height: 20px; }
.send .i { width: 18px; height: 18px; stroke-width: 2.4; }
.foot-actions .btn, #btn-admin { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
#btn-admin { justify-content: flex-start; }
.foot-actions .btn .i, #btn-admin .i { width: 16px; height: 16px; }
.chip-ico { display: inline-flex; } .chip-ico .i { width: 15px; height: 15px; }
.web-badge { display: inline-flex; color: var(--accent); } .web-badge .i { width: 14px; height: 14px; }
.conv-item .p { display: inline-flex; color: var(--accent); } .conv-item .p .i { width: 14px; height: 14px; }
.att-view .doc, .tool-status div, .tool-status summary { display: flex; align-items: center; gap: 6px; }
.tool-status summary { display: list-item; } .tool-status summary .i { margin-right: 5px; }
.att-view .doc .i, .tool-status .i { width: 15px; height: 15px; }
.att .i { width: 16px; height: 16px; color: var(--muted); }
.att button { display: inline-grid; place-items: center; padding: 2px; } .att button .i { width: 14px; height: 14px; }
.copy-btn { display: inline-flex; align-items: center; gap: 4px; } .copy-btn .i { width: 12px; height: 12px; }
.create-box summary .i { width: 16px; height: 16px; margin-right: 6px; }

/* ---- telefon: chenarul de scris puțin mai sus, peste bara de jos a iPhone-ului ---- */
@media (max-width: 820px) {
  .composer-wrap { padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px)); }
}
/* înălțimea vizibilă reală pe mobil (bara browserului nu mai acoperă chenarul) */
@supports (height: 100dvh) { .app { height: 100dvh; } }
#input { overflow-y: hidden; }
