:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --panel-2: #fbfaf7;
  --border: #e4e1d8;
  --text: #22211e;
  --muted: #706c62;
  --accent: #2f5d50;
  --accent-soft: #e3eeea;
  --danger: #a23b2a;
  --user-bubble: #2f5d50;
  --user-text: #ffffff;
  --code-bg: #f1efe9;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161715;
    --panel: #1e1f1c;
    --panel-2: #232420;
    --border: #34352f;
    --text: #e8e6df;
    --muted: #9b978c;
    --accent: #7fb8a5;
    --accent-soft: #24332d;
    --danger: #e0806e;
    --user-bubble: #2f5d50;
    --user-text: #f2f1ec;
    --code-bg: #2a2b27;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- butoane ---------- */
.btn {
  border: 1px solid var(--border); background: var(--panel); border-radius: 6px;
  padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--panel); }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- autentificare ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: min(360px, 100%); background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 28px; display: grid; gap: 12px;
}
.auth-card h1 { margin: 0; font-size: 22px; }
.auth-card p { margin: 0; color: var(--muted); }
.auth-card input { padding: 9px 11px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2); }
.err { color: var(--danger) !important; min-height: 1em; }

/* ---------- layout ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 8px 14px;
  background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.brand { font-weight: 650; letter-spacing: .2px; color: var(--accent); }
.search { flex: 1 1 200px; }
.search input, .model-picker select, .model-picker input {
  width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2);
}
.model-picker { display: flex; gap: 6px; }
.model-picker select { width: auto; }
.model-picker input { width: 210px; font-family: var(--mono); font-size: 13px; }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }

.tabs { display: none; }
.panes { flex: 1; min-height: 0; display: grid; grid-template-columns: 260px minmax(0, 1fr) minmax(340px, 38%); }
.pane { min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.side { background: var(--panel-2); border-right: 1px solid var(--border); overflow-y: auto; }
.note { background: var(--panel); }
.chat { background: var(--panel-2); border-left: 1px solid var(--border); }

/* ---------- sidebar ---------- */
.side-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 12px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted);
}
.side-head .actions { display: flex; gap: 4px; text-transform: none; letter-spacing: 0; }
.tree, .chat-list { padding: 0 6px 8px; margin: 0; list-style: none; }
.tree ul { list-style: none; margin: 0; padding-left: 12px; }
.tree-item, .chat-list li {
  display: flex; align-items: center; gap: 6px; width: 100%; text-align: left; border: 0; background: none;
  padding: 3px 8px; border-radius: 5px; cursor: pointer; font-size: 14px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tree-item:hover, .chat-list li:hover { background: var(--accent-soft); }
.tree-item.active, .chat-list li.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree-item.dir { color: var(--muted); font-weight: 600; }
.tree-item .chev { width: 10px; display: inline-block; font-size: 10px; }
.chat-list li { justify-content: space-between; }
.chat-list li span { overflow: hidden; text-overflow: ellipsis; }
.chat-list .del { opacity: 0; border: 0; background: none; color: var(--muted); cursor: pointer; }
.chat-list li:hover .del { opacity: 1; }
.search-results { padding: 0 8px 8px; }
.search-results .res { padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.search-results .res:hover { background: var(--accent-soft); }
.search-results .res b { display: block; font-size: 13px; }
.search-results .res small { color: var(--muted); display: block; font-size: 12px; }

/* ---------- notiță ---------- */
.note-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 10px 20px; border-bottom: 1px solid var(--border);
}
.note-path { font-family: var(--mono); font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.note-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.note-view { flex: 1; overflow-y: auto; padding: 18px 28px 40px; }
.note-editor {
  flex: 1; resize: none; border: 0; outline: none; padding: 18px 28px; background: var(--panel);
  font: 14px/1.6 var(--mono);
}

/* ---------- markdown ---------- */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md h1 { font-size: 1.6em; margin: .2em 0 .6em; }
.md h2 { font-size: 1.25em; margin: 1.4em 0 .5em; }
.md h3 { font-size: 1.05em; margin: 1.2em 0 .4em; }
.md a { color: var(--accent); }
.md a.wiki { text-decoration: none; border-bottom: 1px dashed var(--accent); }
.md code { font-family: var(--mono); font-size: .9em; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
.md pre { background: var(--code-bg); padding: 12px; border-radius: var(--radius); overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 1em 0; padding: 2px 14px; border-left: 3px solid var(--accent); color: var(--muted); }
.md table { border-collapse: collapse; margin: 1em 0; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 10px; }
.md ul, .md ol { padding-left: 1.4em; }
.md li > input[type=checkbox] { margin-right: 6px; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }
.empty { color: var(--muted); max-width: 520px; }
.empty.small { padding: 4px; font-size: 14px; }
.examples { list-style: none; padding: 0; display: grid; gap: 6px; }
.examples button {
  border: 1px solid var(--border); background: var(--panel); border-radius: 6px; padding: 6px 10px;
  cursor: pointer; text-align: left; width: 100%;
}
.examples button:hover { border-color: var(--accent); }

/* ---------- chat ---------- */
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 14px; }
.messages { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.msg-user {
  align-self: flex-end; max-width: 88%; background: var(--user-bubble); color: var(--user-text);
  padding: 8px 12px; border-radius: 12px 12px 3px 12px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg-assistant { max-width: 100%; }
.msg-meta { font-size: 11px; color: var(--muted); margin-top: 4px; font-family: var(--mono); }
.tool {
  font-size: 12.5px; color: var(--muted); border: 1px solid var(--border); border-radius: 6px;
  background: var(--panel); margin: 4px 0;
}
.tool summary { padding: 4px 9px; cursor: pointer; font-family: var(--mono); overflow-wrap: anywhere; list-style: none; }
.tool summary::-webkit-details-marker { display: none; }
.tool summary::before { content: "▸ "; }
.tool[open] summary::before { content: "▾ "; }
.tool.write summary { color: var(--accent); }
.tool.error summary { color: var(--danger); }
.tool pre { margin: 0; padding: 8px 10px; border-top: 1px solid var(--border); max-height: 260px; overflow: auto; white-space: pre-wrap; font: 12px/1.45 var(--mono); }
.working { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.working::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .25; transform: scale(.7); } }
.chat-error {
  margin: 0 16px; padding: 8px 10px; border-radius: 6px; background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger); font-size: 13px; display: flex; gap: 10px; align-items: center; justify-content: space-between;
}
.composer { padding: 10px 16px 14px; display: grid; gap: 6px; }
.composer textarea {
  width: 100%; resize: vertical; min-height: 54px; max-height: 240px; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel);
}
.composer textarea:focus, .search input:focus, .note-editor:focus { outline: 2px solid var(--accent-soft); }
.composer-actions { display: flex; justify-content: flex-end; gap: 6px; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 8px 16px; border-radius: 6px; font-size: 14px; z-index: 10; max-width: calc(100% - 32px);
}

/* ---------- ecrane mici ---------- */
@media (max-width: 1100px) {
  .panes { grid-template-columns: 220px minmax(0, 1fr) minmax(300px, 42%); }
  .model-picker input { width: 160px; }
}
@media (max-width: 820px) {
  .topbar { gap: 8px; padding: 8px 10px; }
  .search { order: 5; flex-basis: 100%; }
  .model-picker { flex: 1; }
  .model-picker input { flex: 1; width: auto; min-width: 0; }
  .toggle { font-size: 12px; }
  .tabs { display: flex; border-bottom: 1px solid var(--border); background: var(--panel); }
  .tabs button { flex: 1; border: 0; background: none; padding: 9px; cursor: pointer; color: var(--muted); }
  .tabs button.active { color: var(--accent); box-shadow: inset 0 -2px var(--accent); }
  .panes { display: block; }
  .pane { height: 100%; display: none; }
  .pane.show { display: flex; }
  .side, .chat { border: 0; }
  .note-view, .note-editor { padding: 14px 16px 30px; }
}

/* ---------- multi-user ---------- */
.user-menu { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 190px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 6px 24px rgb(0 0 0 / .12); padding: 4px; display: grid;
}
.menu button { border: 0; background: none; text-align: left; padding: 7px 10px; border-radius: 5px; cursor: pointer; }
.menu button:hover { background: var(--accent-soft); }

.badge {
  display: inline-block; font-size: 10.5px; line-height: 1; padding: 3px 6px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; letter-spacing: .2px; vertical-align: middle;
  font-family: var(--font);
}
.tree-item.dir.shared { color: var(--accent); }
.tree-item .badge { margin-left: auto; }
.note-path .badge { margin-left: 8px; }
mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: inherit; border-radius: 2px; padding: 0 1px; }

.dlg {
  border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--panel); color: var(--text);
  width: min(420px, calc(100% - 32px));
}
.dlg.wide { width: min(1020px, calc(100% - 32px)); }
.dlg::backdrop { background: rgb(0 0 0 / .35); }
.dlg-body { padding: 20px 22px; display: grid; gap: 10px; }
.dlg h2 { margin: 0 0 4px; font-size: 18px; }
.dlg h3 { margin: 10px 0 2px; font-size: 15px; }
.dlg input:not([type=checkbox]) {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2);
}
.dlg-actions { display: flex; justify-content: flex-end; gap: 6px; }
.muted { color: var(--muted); margin: 0; font-size: 14px; }
.table-wrap { overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; font-size: 14px; }
table.users th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
table.users th, table.users td { padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.users td.actions { white-space: normal; }
table.users td.actions .acts { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.add-user .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: center; }
@media (max-width: 560px) { .add-user .grid { grid-template-columns: 1fr; } }

/* ---------- v3: atașamente, administrare ---------- */
.badge.ro { background: color-mix(in srgb, var(--muted) 18%, transparent); color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 13px; }
.spacer { flex: 1; }
.composer-actions { align-items: center; }

.att-row { display: flex; flex-wrap: wrap; gap: 6px; }
.att-row.sent { justify-content: flex-end; margin-bottom: 4px; }
.msg-user-wrap { align-self: flex-end; max-width: 88%; display: flex; flex-direction: column; align-items: flex-end; }
.msg-user-wrap .msg-user { max-width: 100%; }
.att {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 4px 6px 4px 4px; font-size: 13px;
}
.att.bad { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.att-kind {
  font-size: 10.5px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase;
  background: var(--accent-soft); color: var(--accent); border-radius: 5px; padding: 3px 5px; white-space: nowrap;
}
.att.bad .att-kind { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.att-err { color: var(--danger); font-size: 12px; max-width: 260px; }
.att-act {
  border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px 4px; border-radius: 4px;
  text-decoration: none; font-size: 12.5px; white-space: nowrap;
}
.att-act:hover { color: var(--accent); background: var(--accent-soft); }
.att-spin {
  width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.chat { position: relative; }
.drop-zone {
  position: absolute; inset: 8px; border: 2px dashed var(--accent); border-radius: 12px; z-index: 5;
  background: color-mix(in srgb, var(--panel) 88%, transparent); display: grid; place-items: center;
  color: var(--accent); font-weight: 600; pointer-events: none;
}

.dlg-title { display: flex; align-items: center; justify-content: space-between; }
.admin-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.admin-tabs button {
  border: 0; background: none; padding: 8px 12px; cursor: pointer; color: var(--muted); border-radius: 6px 6px 0 0;
}
.admin-tabs button.active { color: var(--accent); box-shadow: inset 0 -2px var(--accent); font-weight: 600; }
.admin-tab { display: grid; gap: 10px; }
.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.dlg select, .dlg textarea {
  width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2);
}
.dlg textarea { resize: vertical; font: inherit; }
.cards { display: grid; gap: 8px; }
.card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel-2); }
.card summary { padding: 9px 12px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.card-body { padding: 4px 12px 12px; display: grid; gap: 10px; }
.card-body .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
table.models td .acts { flex-wrap: nowrap; }
table.models input[data-f=model] { min-width: 180px; }
table.models input:not([type=checkbox]):not([type=radio]), table.models select {
  width: 100%; min-width: 120px; padding: 5px 7px; border: 1px solid var(--border); border-radius: 5px; background: var(--panel);
}
table.models td.c { text-align: center; }
table.users select { padding: 4px 6px; }
@media (max-width: 560px) { .card-body .grid { grid-template-columns: 1fr; } }

/* ---------- v4: acces extern ---------- */
.ext-cell { white-space: nowrap; }
.ext-cell label { display: inline-flex; align-items: center; gap: 3px; margin-right: 8px; font-size: 13px; cursor: pointer; }
.ext-cell select { margin-top: 4px; display: block; }
.ext-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.token-box { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: var(--radius); padding: 10px 12px; }
.token-box p { margin: 0 0 6px; }
.copy-row { display: flex; gap: 6px; }
.copy-row input { flex: 1; min-width: 0; }
.steps { margin: 10px 0 0; padding-left: 20px; display: grid; gap: 4px; font-size: 14px; }
details.help summary { cursor: pointer; color: var(--accent); font-size: 13px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters select { width: auto; }
table.log td.wrap { white-space: normal; max-width: 280px; overflow-wrap: anywhere; }
table.log tr.bad td { background: color-mix(in srgb, var(--danger) 6%, transparent); }

/* ---------- identitate HelpNote ---------- */
.brand { display: flex; align-items: center; gap: 8px; }
.logo { width: 28px; height: 28px; flex: none; }
.logo.big { width: 56px; height: 56px; }
.wordmark { font-family: Sora, var(--font); font-weight: 700; letter-spacing: -0.3px; color: var(--text); font-size: 19px; }
.wordmark span { font-weight: 400; color: var(--accent); }
.auth-logo { display: flex; align-items: center; gap: 14px; margin-bottom: 4px; }
.auth-card h1.wordmark { font-size: 30px; margin: 0; }
@media (max-width: 820px) { .brand .wordmark { font-size: 17px; } .logo { width: 26px; height: 26px; } }
