:root {
  --bg: #faf9f5; --side: #f3f1ea; --card: #ffffff; --line: #e7e3d8; --line-2: #dcd7ca;
  --text: #2a2925; --muted: #86837a; --soft: #5e5b53;
  --accent: #c4643f; --accent-2: #ad5533; --accent-soft: #f6e7df;
  --bubble: #efebe1; --ok: #4d7c55; --warn: #b7791f; --err: #b3412e;
  --serif: "Iowan Old Style", "Charter", "Source Serif Pro", Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
.hidden, [hidden] { display: none !important; }
input[type=file] { display: none !important; }
.muted { color: var(--muted); }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }

/* ---------- marca ---------- */
.mark { width: 26px; height: 26px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center;
  font: 700 15px/1 var(--serif); }
.mark.big { width: 46px; height: 46px; border-radius: 13px; font-size: 26px; margin: 0 auto 14px; }

/* ---------- botones ---------- */
.btn { border: 1px solid var(--line-2); background: var(--card); border-radius: 10px; padding: 8px 14px; transition: background .15s, border-color .15s; }
.btn:hover { background: #f7f5ef; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.wide { width: 100%; padding: 11px; margin-top: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.icon-btn { border: 0; background: transparent; width: 36px; height: 36px; border-radius: 10px; display: inline-grid; place-items: center; color: var(--soft); }
.icon-btn:hover { background: #ece8de; color: var(--text); }

/* ---------- login ---------- */
#login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(380px, 100%); text-align: center; }
.login-card h1 { font: 500 30px/1.2 var(--serif); margin: 0 0 6px; }
.login-card p { margin: 0 0 26px; }
.login-card form { text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 22px;
  box-shadow: 0 1px 2px rgba(0,0,0,.03), 0 8px 24px rgba(60,50,30,.05); }
label { display: block; font-size: 13px; color: var(--soft); margin-bottom: 12px; }
label input, .field input { display: block; width: 100%; margin-top: 5px; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: 10px; background: #fff; outline: none; }
label input:focus, .field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-err { color: var(--err); font-size: 13px; min-height: 18px; margin-top: 10px; }

/* ---------- layout ---------- */
#main { display: grid; grid-template-columns: 290px 1fr; height: 100vh; height: 100dvh; }
#sidebar { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px; }
.brand { display: flex; align-items: center; gap: 9px; font: 600 16px var(--serif); }
.new-chat { margin: 6px 12px 10px; text-align: left; display: flex; align-items: center; gap: 8px; border-radius: 12px; }
.new-chat .plus { color: var(--accent); font-weight: 700; }
.side-title { font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 10px 20px 6px; }
#agentList { padding: 0 8px 6px; display: flex; flex-direction: column; gap: 4px; }
.agent-card { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 1px solid transparent; background: transparent;
  border-radius: 12px; padding: 8px 10px; }
.agent-card:hover { background: #ebe8df; }
.agent-card.sel { background: var(--card); border-color: var(--line-2); box-shadow: 0 1px 3px rgba(60,50,30,.06); }
.agent-card .avatar { width: 34px; height: 34px; font-size: 16px; }
.agent-card { overflow: hidden; }
.agent-card .a-txt { min-width: 0; flex: 1 1 auto; display: flex; flex-direction: column; overflow: hidden; }
.agent-card .a-name { display: block; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-card .a-desc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-size: 12px; line-height: 1.35; color: var(--muted); white-space: normal; overflow-wrap: anywhere; }
.agent-card .a-count:empty { display: none; }
.agent-card .a-count { font-size: 11.5px; color: var(--muted); background: #ebe8df; border-radius: 10px; padding: 1px 7px; }
.agent-card.sel .a-count { background: var(--accent-soft); color: var(--accent-2); }
.side-sep { height: 1px; background: var(--line); margin: 6px 14px 4px; }
.head-agent { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--soft); background: #f0ede4; border-radius: 20px; padding: 2px 10px 2px 3px; }
.head-agent .avatar { width: 20px; height: 20px; font-size: 11px; }
.welcome .avatar.agent { width: 56px; height: 56px; font-size: 28px; margin: 0 auto 14px; }
.welcome .who-line { font-size: 14px; color: var(--soft); margin-top: 4px; }
.search { padding: 4px 12px 8px; }
.search input { width: 100%; border: 1px solid transparent; background: #ebe8df; border-radius: 10px; padding: 8px 11px; outline: none; font-size: 14px; }
.search input:focus { background: #fff; border-color: var(--line-2); }
#convs { flex: 1; overflow: auto; padding: 0 8px 12px; }
.group { font-size: 12px; color: var(--muted); padding: 14px 8px 4px; font-weight: 600; }
.conv { display: block; width: 100%; text-align: left; border: 0; background: transparent; border-radius: 10px; padding: 8px 10px; }
.conv:hover { background: #ebe8df; }
.conv.sel { background: #e6e1d5; }
.conv .t { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 7px; }
.conv .m { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; background: #c9c4b6; }
.dot.run { background: var(--warn); animation: pulse 1.2s infinite; } .dot.ok { background: var(--ok); } .dot.err { background: var(--err); }
@keyframes pulse { 50% { opacity: .35; } }
.side-foot { position: relative; border-top: 1px solid var(--line); padding: 10px; }
.user-chip { width: 100%; display: flex; align-items: center; gap: 10px; border: 0; background: transparent; border-radius: 10px; padding: 7px 8px; }
.user-chip:hover { background: #ebe8df; }
.user-name { flex: 1; text-align: left; font-weight: 500; }
.caret { color: var(--muted); font-size: 12px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #d9cfbd; color: #4c4436; display: grid; place-items: center; font-weight: 600; font-size: 13px; flex: 0 0 auto; }
.avatar.agent { background: var(--accent); color: #fff; font-family: var(--serif); }
.menu { position: absolute; bottom: 60px; left: 10px; right: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(40,30,10,.12); padding: 6px; z-index: 20; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 10px; border-radius: 8px; }
.menu button:hover { background: #f3f1ea; }

/* ---------- chat ---------- */
#chat { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-bottom: 1px solid transparent; min-height: 58px; }
.chat-head.scrolled { border-bottom-color: var(--line); }
.head-text { min-width: 0; }
.head-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.pill { font-size: 11.5px; padding: 1px 8px; border-radius: 20px; background: #ece8de; color: var(--soft); }
.pill.run { background: #fbf0dc; color: var(--warn); } .pill.ok { background: #e6efe5; color: var(--ok); } .pill.err { background: #f8e3df; color: var(--err); }
#scroller { flex: 1; overflow: auto; padding: 8px 20px 24px; }
.col { width: 100%; max-width: 780px; margin: 0 auto; }
.welcome { text-align: center; margin: 14vh auto 0; max-width: 560px; }
.welcome h2 { font: 400 34px/1.2 var(--serif); margin: 0 0 8px; }

.msg { margin: 22px 0; }
.msg .who { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.msg .who b { color: var(--text); font-weight: 600; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .who { justify-content: flex-end; }
.msg.user .bubble { background: var(--bubble); border-radius: 18px 18px 4px 18px; padding: 10px 15px; max-width: 85%; white-space: pre-wrap; word-wrap: break-word; }
.msg.user.other .bubble { background: #e9eef3; }
.msg.agent .body { font-family: var(--serif); font-size: 16.5px; line-height: 1.65; padding-left: 39px; word-wrap: break-word; }
.msg.system .body { background: #f8e3df; color: var(--err); border-radius: 10px; padding: 10px 14px; font-size: 14px; }
.msg.error .body { color: var(--err); }
.typing { display: inline-flex; gap: 5px; align-items: center; color: var(--muted); font-family: var(--sans); font-size: 14px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: none; } }

/* markdown */
.md p { margin: 0 0 .75em; } .md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--serif); margin: 1.1em 0 .4em; line-height: 1.3; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.2em; } .md h3, .md h4 { font-size: 1.05em; }
.md ul, .md ol { margin: .3em 0 .8em; padding-left: 1.4em; } .md li { margin: .2em 0; }
.md code { font-family: var(--mono); font-size: .82em; background: #efece3; padding: 1px 5px; border-radius: 5px; }
.md pre { font-family: var(--mono); font-size: 13px; line-height: 1.5; background: #f1eee6; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; overflow: auto; white-space: pre; }
.md pre code { background: none; padding: 0; font-size: inherit; }
.md a { color: var(--accent-2); }
.md blockquote { margin: .5em 0; padding-left: 12px; border-left: 3px solid var(--line-2); color: var(--soft); }
.tbl-wrap { overflow: auto; margin: .6em 0 .9em; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.md table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: 13.5px; }
.md th, .md td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.md th { background: #f6f4ee; font-weight: 600; } .md tr:last-child td { border-bottom: 0; }

/* tarea del escaner */
.task { width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.task-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.task-ico { width: 32px; height: 32px; border-radius: 9px; background: var(--accent-soft); color: var(--accent-2); display: grid; place-items: center; font-size: 17px; }
.task-title { font-weight: 600; } .task-sub { font-size: 12.5px; color: var(--muted); }
.task-toggle { margin-left: auto; font-size: 13px; color: var(--accent-2); background: none; border: 0; }
.task-body { border-top: 1px solid var(--line); padding: 12px 14px; font-size: 14px; }
.task-body .md { font-family: var(--sans); font-size: 14px; }

/* adjuntos */
.atts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; justify-content: flex-end; }
.att { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 6px 10px; font-size: 13px; color: var(--text); text-decoration: none; max-width: 260px; }
.att .ext { font: 700 10px var(--sans); color: #fff; background: var(--soft); border-radius: 5px; padding: 3px 5px; text-transform: uppercase; }
.att .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-img { display: block; max-width: 260px; max-height: 200px; border-radius: 12px; border: 1px solid var(--line); }

/* composer */
.composer-wrap { padding: 0 20px 14px; }
.composer { background: var(--card); border: 1px solid var(--line-2); border-radius: 20px; padding: 10px 10px 8px 14px;
  box-shadow: 0 2px 6px rgba(60,50,30,.04), 0 10px 30px rgba(60,50,30,.05); transition: border-color .15s; }
.composer:focus-within { border-color: #cfc8b8; }
#txt { width: 100%; border: 0; outline: none; resize: none; background: transparent; padding: 6px 2px; max-height: 260px; line-height: 1.5; }
.composer-bar { display: flex; align-items: center; gap: 2px; }
.spacer { flex: 1; }
.hint { font-size: 12px; color: var(--muted); margin-right: 8px; }
.send { width: 36px; height: 36px; border-radius: 11px; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; transition: background .15s, opacity .15s; }
.send:hover { background: var(--accent-2); } .send:disabled { opacity: .35; cursor: default; }
#micBtn.on { color: #fff; background: var(--err); animation: pulse 1.4s infinite; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips:not(:empty) { margin-bottom: 6px; }
.chip { display: inline-flex; align-items: center; gap: 7px; background: #f3f1ea; border: 1px solid var(--line); border-radius: 10px; padding: 5px 6px 5px 9px; font-size: 13px; max-width: 240px; }
.chip img { width: 28px; height: 28px; object-fit: cover; border-radius: 6px; }
.chip .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip button { border: 0; background: transparent; color: var(--muted); padding: 0 4px; }
.chip.up { opacity: .6; }
.foot-note { text-align: center; font-size: 11.5px; color: var(--muted); margin-top: 7px; }
#dropzone { position: absolute; inset: 10px; border: 2px dashed var(--accent); border-radius: 18px; background: rgba(250,249,245,.92);
  display: grid; place-items: center; font: 500 18px var(--serif); color: var(--accent-2); z-index: 30; }

/* modal */
#modal { position: fixed; inset: 0; background: rgba(42,41,37,.35); display: grid; place-items: start center; padding: 7vh 16px; z-index: 50; overflow: auto; }
.dialog { width: min(760px, 100%); background: var(--card); border-radius: 18px; padding: 22px 24px; box-shadow: 0 20px 60px rgba(30,20,0,.25); }
.dialog h3 { font: 500 22px var(--serif); margin: 0; }
.dlg-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; } .dlg-head h3 { flex: 1; }
.ulist { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.urow { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.urow:last-child { border-bottom: 0; }
.urow .info { flex: 1; min-width: 0; } .urow .info .s { font-size: 12.5px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; margin-top: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.check { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line-2); border-radius: 10px; padding: 7px 11px; font-size: 14px; color: var(--text); margin: 0; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 16px; }
.badge-n { background: var(--accent); color: #fff; border-radius: 10px; font-size: 11px; font-weight: 700; padding: 1px 7px; margin-left: 6px; }
.learn-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.learn-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.learn-top .r { font-weight: 600; flex: 1; min-width: 200px; }
.learn-meta { font-size: 12px; color: var(--muted); margin: 2px 0 8px; }
.learn-det { background: #f6f4ee; border-radius: 8px; padding: 8px 10px; font-size: 13.5px; white-space: pre-wrap; word-wrap: break-word; margin-top: 6px; max-height: 260px; overflow: auto; }
.learn-det .old { color: var(--muted); text-decoration: line-through; display: block; margin-bottom: 4px; }
.learn-acts { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.btn.danger { color: var(--err); border-color: #e9c3bb; }
.btn.danger-fill { background: var(--err); border-color: var(--err); color: #fff; }
.btn.danger-fill:hover { background: #9b3626; }
.del-btn { color: var(--muted); } .del-btn:hover { color: var(--err); background: #f8e3df; }
.users-bar { display: flex; gap: 10px; margin-bottom: 12px; }
.users-bar input { flex: 1; border: 1px solid var(--line-2); border-radius: 10px; padding: 8px 12px; outline: none; }
.users-bar input:focus { border-color: var(--accent); }
.warn-box { background: #fbf0dc; color: #7a5310; border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 10px 0; }
.pw-row { display: flex; gap: 6px; } .pw-row input { flex: 1; margin-top: 0; }
.pw-row input { display: block; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: 10px; outline: none; }
.mem-box { background: #f6f4ee; border-radius: 10px; padding: 10px 12px; font-size: 13.5px; white-space: pre-wrap; margin: 6px 0 14px; }
.section-t { font: 500 16px var(--serif); margin: 18px 0 6px; }
/* validacion automatica */
.avatar.bot { background: #e4e9ee; color: #3d5466; font-size: 15px; }
.vcard { margin-left: 39px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); padding: 12px 14px; font-size: 14px; }
.vcard.ok { border-color: #cfe0cc; background: #f6faf5; } .vcard.ko { border-color: #ecd9b6; background: #fffaf1; }
.v-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-weight: 600; }
.v-meta { font-weight: 400; font-size: 12px; color: var(--muted); }
.v-item { margin-top: 10px; } .v-item ul { margin: 4px 0 0; padding-left: 22px; color: var(--soft); }
.v-err { color: #8a5a12; background: #fbf0dc; border-radius: 8px; padding: 7px 10px; margin-top: 6px; font-size: 13.5px; }
/* aprendizajes por seccion */
.learn-sec { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin: 12px 0; }
.learn-sec-h { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.sec-ico { width: 34px; height: 34px; border-radius: 10px; background: #f3f1ea; display: grid; place-items: center; font-size: 18px; flex: 0 0 auto; }
.learn-sec-h > div { flex: 1; } .sec-t { font-weight: 600; } .sec-s { font-size: 12.5px; color: var(--muted); }
.sec-empty { margin: 4px 0 0 46px; font-size: 13px; }
.learn-sec .learn-item { margin: 8px 0 0; }
pre.diff { font-family: var(--mono); font-size: 12px; line-height: 1.45; background: #f8f7f3; border: 1px solid var(--line); border-radius: 8px; padding: 10px; max-height: 360px; overflow: auto; }
pre.diff .add { background: #e6f2e4; display: inline-block; width: 100%; } pre.diff .del { background: #f9e1dc; display: inline-block; width: 100%; }
pre.diff .hunk { color: var(--muted); }
details summary { cursor: pointer; color: var(--accent-2); font-size: 13.5px; margin: 6px 0; }
.mem-now { margin-top: 8px; }
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #2a2925; color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 14px; z-index: 60; }

.only-mobile { display: none; }
@media (max-width: 820px) {
  #main { grid-template-columns: 1fr; }
  #sidebar { position: fixed; inset: 0 auto 0 0; width: 86vw; max-width: 320px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  #sidebar.open { transform: none; }
  #scrim { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 35; }
  .only-mobile { display: inline-grid; }
  #scroller { padding: 4px 14px 18px; } .composer-wrap { padding: 0 10px 10px; }
  .msg.agent .body { padding-left: 0; font-size: 16px; } .msg.user .bubble { max-width: 92%; }
  .welcome { margin-top: 8vh; } .form-grid { grid-template-columns: 1fr; }
}

