:root {
  --bg: #f5f4ed;
  --panel: #fbfaf6;
  --side: #ecebe2;
  --ink: #141413;
  --muted: #6b6a62;
  --line: #dddbcf;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --accent-soft: #dfe8e2;
  --sand: #c8b48f;
  --danger: #a33a24;
  --user-bubble: #e8e5d8;
  --code-bg: #eeece3;
  --serif: "Lora", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1c1a; --panel: #252522; --side: #181816; --ink: #ecebe4; --muted: #a3a197;
    --line: #37362f; --accent: #7fb5a3; --accent-ink: #0f1e19; --accent-soft: #263a33;
    --danger: #f08a78; --user-bubble: #31302b; --code-bg: #2b2a26; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1c1a; --panel: #252522; --side: #181816; --ink: #ecebe4; --muted: #a3a197;
  --line: #37362f; --accent: #7fb5a3; --accent-ink: #0f1e19; --accent-soft: #263a33;
  --danger: #f08a78; --user-bubble: #31302b; --code-bg: #2b2a26; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.6 var(--sans);
}
h1, h2, h3, .welcome h2, .brand-name, .title-input, .msg.assistant .content { font-family: var(--serif); }
.msg.assistant .content { font-size: 16.5px; line-height: 1.65; }
.msg.assistant .content table { font-family: var(--sans); font-size: 14px; }
code, pre, .artifact-body pre, code.cred { font-family: var(--mono); }
.byline { margin: -8px 0 0 !important; font-size: 13px; color: var(--muted); letter-spacing: .02em; }
.fine.legal { font-size: 11px; line-height: 1.45; text-align: left; }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.fine { font-size: 12px; color: var(--muted); text-align: center; margin: 4px 0 0; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }
.spacer { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.row.end { justify-content: flex-end; }

.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; border-radius: 10px; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 6px 8px; border-radius: 6px; font-size: 16px; }
.icon-btn:hover { background: var(--side); }
.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; }
.chip { font-size: 12px; background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 99px; }

.logo-mark { width: 44px; height: 44px; background: var(--logo, url("/logo.svg")) center / contain no-repeat; }
.logo-mark.small { width: 26px; height: 26px; }

/* Accés */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 12px;
}
.login-card h1 { margin: 0; font-size: 24px; }
.login-card p { margin: 0; }
label { display: grid; gap: 4px; font-size: 14px; }
input, textarea, select {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 9px 11px; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

/* Estructura */
.app { display: flex; height: 100%; }
.sidebar {
  width: 270px; flex-shrink: 0; background: var(--side); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 12px; gap: 10px;
}
.side-head { display: flex; align-items: center; gap: 8px; font-weight: 700; padding: 4px 4px 6px; }
.side-nav { display: grid; }
.nav-item { text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.nav-item:hover, .nav-item.on { background: var(--panel); }
.side-label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 6px 10px 0; }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv-list li { display: flex; align-items: center; border-radius: 8px; }
.conv-list li:hover, .conv-list li.on { background: var(--panel); }
.conv-list li > button:first-child {
  flex: 1; text-align: left; border: 0; background: none; padding: 7px 10px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.conv-list li .del { visibility: hidden; font-size: 13px; color: var(--muted); }
.conv-list li:hover .del { visibility: visible; }
.conv-list .tag { font-size: 11px; color: var(--muted); margin-left: 6px; }
.conv-list.light li { border: 1px solid var(--line); margin-bottom: 6px; }
.side-foot { border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 8px; font-size: 13px; }
.me { display: flex; justify-content: space-between; }
.usage .bar { height: 5px; background: var(--line); border-radius: 9px; overflow: hidden; margin-top: 4px; }
.usage .bar > i { display: block; height: 100%; background: var(--accent); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 20px; border-bottom: 1px solid var(--line); min-height: 52px; }
.top-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-info { margin-left: auto; font-size: 13px; white-space: nowrap; }
.view { flex: 1; min-height: 0; }

/* Xat */
.chat-view { display: flex; flex-direction: column; }
.messages { flex: 1; overflow-y: auto; padding: 24px 16px 8px; }
.msg { max-width: 760px; margin: 0 auto 18px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble { background: var(--user-bubble); border-radius: 18px 18px 4px 18px; padding: 10px 14px; max-width: 85%; white-space: pre-wrap; }
.msg .files { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; justify-content: flex-end; }
.file-pill { font-size: 12px; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 3px 8px; }
.msg.assistant .content > :first-child { margin-top: 0; }
.msg .content table { border-collapse: collapse; margin: 10px 0; display: block; overflow-x: auto; }
.msg .content th, .msg .content td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.msg .content th { background: var(--side); }
.msg .content pre { background: var(--code-bg); padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.msg .content code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.msg .content pre code { background: none; padding: 0; }
.msg .status { color: var(--muted); font-size: 14px; font-style: italic; }
.msg .notice { color: var(--danger); font-size: 14px; }
.msg .actions { display: flex; gap: 4px; margin-top: 4px; }
.msg .actions button { font-size: 12px; color: var(--muted); }
.sources { margin-top: 8px; font-size: 13px; }
.sources a { display: inline-block; margin-right: 10px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.art-card {
  display: flex; align-items: center; gap: 12px; border: 1px solid var(--line); background: var(--panel);
  border-radius: 10px; padding: 10px 14px; margin: 10px 0; cursor: pointer; width: 100%; text-align: left; box-shadow: var(--shadow);
}
.art-card:hover { border-color: var(--accent); }
.art-card .ico { width: 34px; height: 34px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; }
.art-card small { display: block; color: var(--muted); }
.cursor::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

.welcome { max-width: 760px; margin: auto; padding: 16px; text-align: center; }
.welcome h2 { font-size: 26px; margin: 0 0 6px; }
.suggestions { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; margin-top: 20px; }
.suggestion { text-align: left; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 12px; cursor: pointer; }
.suggestion:hover { border-color: var(--accent); }

.composer {
  max-width: 760px; width: calc(100% - 32px); margin: 0 auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 10px 12px; box-shadow: var(--shadow);
}
.composer.drag { border-color: var(--accent); outline: 2px dashed var(--accent); }
.composer textarea { border: 0; padding: 4px; resize: none; max-height: 240px; outline: none; }
.composer-bar { display: flex; align-items: center; gap: 8px; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; }
.attachments .file-pill button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 0 0 4px; }
.disclaimer { text-align: center; font-size: 12px; color: var(--muted); margin: 6px 16px 10px; }

/* Pàgines */
.page { overflow-y: auto; padding: 24px; max-width: 1000px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 12px; margin: 8px 0; }
.page-head h2 { margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-top: 16px; }
.card { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 16px; cursor: pointer; text-align: left; }
.card:hover { border-color: var(--accent); }
.card h4 { margin: 0 0 4px; }
.card p { margin: 0; font-size: 13px; }
.title-input { font-size: 22px; font-weight: 700; border: 0; background: none; padding: 4px 0; flex: 1; min-width: 0; }
.plain-input { border: 0; background: none; padding: 0; color: var(--muted); }
.two-col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 24px; margin-top: 16px; }
.two-col h3 { margin: 12px 0 2px; font-size: 16px; }
.two-col p { margin: 0 0 8px; font-size: 13px; }
.file-list { list-style: none; padding: 0; margin: 0 0 8px; }
.file-list li { display: flex; justify-content: space-between; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin-bottom: 6px; background: var(--panel); font-size: 14px; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.check input { width: auto; }

/* Artifact */
.artifact { width: min(46vw, 720px); flex-shrink: 0; border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; }
.artifact-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.artifact-head strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.artifact-body { flex: 1; overflow: auto; }
.artifact-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.artifact-body .doc { padding: 20px 24px; }
.artifact-body pre { margin: 0; padding: 16px; font-size: 13px; white-space: pre-wrap; background: var(--code-bg); min-height: 100%; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: none; padding: 4px 10px; cursor: pointer; font-size: 13px; }
.seg button.on { background: var(--accent-soft); color: var(--accent); }

.dialog { border: 1px solid var(--line); border-radius: 14px; padding: 20px; background: var(--panel); color: var(--ink); width: min(420px, calc(100% - 32px)); }
.dialog::backdrop { background: rgba(0,0,0,.35); }
.dialog form { display: grid; gap: 12px; }
.dialog h3 { margin: 0; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 16px; border-radius: 8px; font-size: 14px; z-index: 10; }

.only-mobile { display: none; }
@media (max-width: 860px) {
  .only-mobile { display: inline-block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 5; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .artifact { position: fixed; inset: 0; width: auto; z-index: 6; }
  .two-col { grid-template-columns: 1fr; }
  .page { padding: 16px; }
  .top-info { display: none; }
}
.disclaimer .brand-name, .legal .brand-name { font-family: inherit; }

/* Carpeta local */
.chip.folder { display: inline-flex; align-items: center; gap: 4px; }
.chip.folder button { border: 0; background: none; cursor: pointer; color: inherit; padding: 0 0 0 2px; font-size: 11px; }
.tool-calls { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 4px; }
.tool-calls li { font-size: 13px; color: var(--muted); background: var(--side); border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; width: fit-content; }
.confirm-detail { max-height: 260px; overflow: auto; background: var(--code-bg); border-radius: 8px; padding: 10px; font-size: 12px; white-space: pre-wrap; margin: 0; }
.reserve-chip { display: inline-block; font-size: 12px; margin: 0 0 6px; padding: 2px 10px; border-radius: 99px; background: var(--side); color: var(--muted); border: 1px solid var(--line); }
.reserve-chip[hidden] { display: none; }
.reserve-opt[hidden] { display: none; }
