/* Logiassist — identidad de Maroru's Assistance (docs/brand-kit.md).
   Papel y carbón, una sola tinta granate, Instrument Serif para nombres y títulos,
   Hanken Grotesk para todo lo que se lee u opera. Plano, cuadrado, sobrio. */

:root {
  --paper: #f6f3ee;
  --bone: #ebe5dc;
  --charcoal: #2f2b28;
  --ink: #1f1c1a;
  --ink-muted: #5f5852;
  --on-dark: #efe9e1;
  --on-dark-muted: #b8ada1;
  --maroon: #b80000;
  --maroon-deep: #8a0000;
  --maroon-on-dark: #e8a9a0;
  --rule: #d6cec3;
  --rule-dark: #4a443f;

  --font-display: "Instrument Serif", "Times New Roman", serif;
  --font-body: "Hanken Grotesk", ui-sans-serif, system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;

  --gutter: 20px;
  --topbar: 56px;
}

@media (min-width: 768px) {
  :root { --gutter: 48px; }
}

*, *::before, *::after { box-sizing: border-box; border-radius: 0; }

html { -webkit-text-size-adjust: 100%; scrollbar-color: var(--ink-muted) var(--paper); scrollbar-width: thin; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-weight: 350;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--maroon); color: var(--paper); }
:focus-visible { outline: 2px solid var(--maroon); outline-offset: 3px; }
.on-dark :focus-visible { outline-color: var(--maroon-on-dark); }

a { color: inherit; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.22em; transition: color .15s; }
a:hover { color: var(--maroon); }
.on-dark a:hover { color: var(--maroon-on-dark); }

h1, h2, h3, h4, p { margin: 0; }

.display {
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 0.92;
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.muted { color: var(--ink-muted); }
.tabular { font-variant-numeric: tabular-nums; }
code, pre, kbd, .mono { font-family: var(--font-mono); font-size: 0.9em; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Superficies */
.on-dark { background: var(--charcoal); color: var(--on-dark); }
.on-dark .muted { color: var(--on-dark-muted); }
.panel { background: var(--bone); }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 10;
  height: var(--topbar); display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 var(--gutter);
  border-bottom: 1px solid var(--rule-dark);
}
.topbar .brand { font-family: var(--font-display); font-size: 1.75rem; line-height: 1; letter-spacing: -0.02em; text-decoration: none; }
.topbar .byline { font-size: 0.875rem; text-decoration: none; }
.topbar .byline:hover { text-decoration: underline; }

.demo-note {
  padding: 8px var(--gutter);
  font-size: 0.875rem;
  border-bottom: 1px solid var(--rule);
}

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 48px; padding: 0 24px; border: 0; cursor: pointer; flex: none;
  font: 400 1rem/1 var(--font-body); color: var(--paper); background: var(--maroon);
  transition: background-color .15s;
}
.btn:hover { background: var(--maroon-deep); }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.link-button {
  padding: 0; border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 0.875rem; color: var(--ink);
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.22em;
  transition: color .15s;
}
.link-button:hover { color: var(--maroon); }
.link-button:disabled { color: var(--ink-muted); text-decoration: none; cursor: default; }

/* Inputs */
.textarea {
  width: 100%; padding: 12px 0; background: transparent; color: var(--ink);
  font: 350 1.0625rem/1.5 var(--font-body);
  border: 0; border-bottom: 1px solid var(--ink-muted);
  resize: none; min-height: 48px; max-height: 40vh;
  transition: border-color .15s;
}
.textarea::placeholder { color: var(--ink-muted); opacity: 1; }
.textarea:focus { outline: none; border-bottom-color: var(--maroon); }

/* Filas entre líneas finas */
.rows { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.rows > li { border-bottom: 1px solid var(--rule); }

/* Filas accionables: fondo al pasar, flecha que avanza y borde de foco; se leen como botones sin ser tarjetas. */
.row-button {
  display: flex; align-items: center; gap: 16px;
  width: 100%; padding: 14px 12px; margin: 0 -12px; width: calc(100% + 24px);
  border: 0; background: transparent; cursor: pointer;
  text-align: left; font: inherit; color: var(--ink);
  transition: background-color .15s, color .15s;
}
.row-button__text { flex: 1; min-width: 0; }
.row-button__title { display: block; }
.row-button__detail { display: block; font-size: 0.875rem; color: var(--ink-muted); }
.row-button__arrow { flex: none; color: var(--ink-muted); transition: transform .15s, color .15s; }
.row-button:hover { background: var(--bone); }
.row-button:hover .row-button__title { color: var(--maroon); }
.row-button:hover .row-button__arrow { color: var(--maroon); transform: translateX(3px); }
.side .row-button:hover { background: var(--paper); }

/* Botón secundario: contorno de 1 px, cuadrado. */
.chip-button {
  display: inline-flex; align-items: center; height: 32px; padding: 0 12px;
  border: 1px solid var(--rule); background: transparent; cursor: pointer;
  font: 400 .875rem/1 var(--font-body); color: var(--ink);
  transition: border-color .15s, color .15s, background-color .15s;
}
.chip-button:hover { border-color: var(--maroon); color: var(--maroon); }
.chip-button:disabled { color: var(--ink-muted); border-color: var(--rule); cursor: default; }
.side .chip-button { border-color: var(--ink-muted); }

/* Disposición */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 1080px) {
  .layout { grid-template-columns: minmax(0, 1fr) 380px; }
  .side {
    position: sticky; top: var(--topbar);
    height: calc(100vh - var(--topbar)); overflow-y: auto;
    border-left: 1px solid var(--rule);
  }
}

/* Chat */
.chat {
  width: 100%; max-width: calc(760px + 2 * var(--gutter)); margin: 0 auto;
  padding: 32px var(--gutter) 0;
  min-height: calc(100vh - var(--topbar) - 41px);
  display: flex; flex-direction: column;
}

.empty { padding: 24px 0 32px; }
.empty__title { font-size: clamp(2.5rem, 5vw, 4rem); margin-bottom: 16px; }
.empty__lead { max-width: 60ch; margin-bottom: 32px; }
.empty[hidden] { display: none; }

.chat-log { flex: 1; }

.msg { padding: 20px 0; border-bottom: 1px solid var(--rule); }
.msg__who { font-size: .875rem; color: var(--ink-muted); margin-bottom: 6px; }
.msg__body { font-size: 1.0625rem; line-height: 1.6; overflow-wrap: anywhere; }
.msg__body > * + * { margin-top: 0.75em; }
.msg__body ul, .msg__body ol { margin: 0; padding-left: 1.4em; }
.msg__body li + li { margin-top: 0.25em; }
.msg__body strong { font-weight: 600; }
.msg__body .msg__heading { font-weight: 600; margin-top: 1.1em; }
.msg__body li > p { margin: 0; }
.msg--user { display: flex; flex-direction: column; align-items: flex-end; }
.msg--user .msg__body { background: var(--bone); padding: 12px 16px; max-width: 85%; white-space: pre-wrap; }
.msg--assistant .msg__body { max-width: 68ch; }
.msg--blocked .msg__body { color: var(--maroon); border-left: 1px solid var(--maroon); padding-left: 16px; }
.msg--error .msg__body { color: var(--maroon); }

.evidence { margin-top: 12px; font-size: .875rem; }
.evidence--ok { color: var(--ink); }
.evidence--weak { color: var(--ink-muted); font-style: italic; }
.evidence--none { color: var(--maroon); }

/* Fuentes: bloque aparte, en hueso y a menor tamaño, para no confundirlo con la respuesta. */
.sources-panel {
  margin-top: 16px; max-width: 68ch;
  background: var(--bone); padding: 12px 16px;
  font-size: .875rem;
}
.sources-panel__label { color: var(--ink-muted); margin-bottom: 4px; }
.basis { list-style: none; margin: 0; padding: 0; }
.basis li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; padding: 4px 0; }
.basis__title { color: var(--ink); }
.basis__meta { color: var(--ink-muted); }
.sources-all { margin-top: 8px; border-top: 1px solid var(--rule); }
.sources-all > summary {
  list-style: none; cursor: pointer; padding: 10px 0 2px;
  display: flex; align-items: center; gap: 8px; color: var(--ink);
  transition: color .15s;
}
.sources-all > summary::-webkit-details-marker { display: none; }
.sources-all > summary::before { content: "+"; width: 1em; color: var(--ink-muted); }
.sources-all[open] > summary::before { content: "−"; }
.sources-all > summary:hover { color: var(--maroon); }
.sources-all .rows { margin-top: 8px; }
.source-row { display: grid; grid-template-columns: 2rem minmax(0, 1fr); padding: 10px 0; }
.source-row__n { font-variant-numeric: tabular-nums; color: var(--ink-muted); }
.source-row__title { display: block; color: var(--ink); }
.source-row__used { margin-left: 8px; font-size: .75rem; color: var(--maroon); }
.source-row__meta { display: block; color: var(--ink-muted); }
.source-row__excerpt { display: block; color: var(--ink-muted); margin-top: 2px; }
.source-row:target { outline: 1px solid var(--maroon); outline-offset: 2px; }
.side .source-row { font-size: .875rem; }

.msg__thinking { color: var(--ink-muted); font-style: italic; }

.cite { font-size: .8em; vertical-align: super; line-height: 0; }

.msg__foot {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 8px;
  margin-top: 16px; font-size: .875rem; color: var(--ink-muted);
}

.stream-caret {
  display: inline-block; width: .5em; height: 1.1em; margin-left: 2px;
  background: var(--maroon); vertical-align: text-bottom;
  animation: caret 1s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

/* Composer */
.dock { position: sticky; bottom: 0; background: var(--paper); }
.composer { display: flex; align-items: flex-end; gap: 16px; padding: 16px 0 8px; }
.status { font-size: .875rem; padding-bottom: 20px; }

/* Conversaciones guardadas */
.conversation { position: relative; }
.conversation .row-button { padding-right: 12px; }
.conversation__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation .row-button__detail { padding-right: 150px; }
.conversation.is-current .row-button { box-shadow: inset 1px 0 0 var(--maroon); background: var(--paper); }
.conversation.is-current .conversation__title { color: var(--maroon); }
.conversation__actions {
  position: absolute; right: 0; bottom: 14px;
  display: flex; gap: 12px; font-size: .875rem;
  opacity: 0; transition: opacity .15s;
}
.conversation:hover .conversation__actions,
.conversation:focus-within .conversation__actions,
.conversation.is-current .conversation__actions { opacity: 1; }
@media (hover: none) { .conversation__actions { opacity: 1; } }
.conversation__input { margin: 10px 0 40px; }
.input {
  width: 100%; background: transparent; color: var(--ink);
  font: 350 1rem/1.5 var(--font-body);
  border: 0; border-bottom: 1px solid var(--ink-muted);
}
.input:focus { outline: none; border-bottom-color: var(--maroon); }

/* Panel lateral */
.side { padding: 32px var(--gutter) 48px; }
@media (min-width: 1080px) { .side { padding: 32px 32px 48px; } }
.side__block + .side__block { margin-top: 40px; }
.side__head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.side__title { font-size: 1.75rem; margin-bottom: 12px; }
.side__note { font-size: .875rem; }

.topic { border-bottom: 1px solid var(--rule); }
.topic:first-child { border-top: 1px solid var(--rule); }
.topic > summary {
  list-style: none; cursor: pointer; padding: 14px 0;
  display: flex; justify-content: space-between; gap: 12px;
  transition: color .15s;
}
.topic > summary::-webkit-details-marker { display: none; }
.topic > summary::after { content: "+"; color: var(--ink-muted); }
.topic[open] > summary::after { content: "−"; }
.topic > summary:hover { color: var(--maroon); }
.topic__desc { font-size: .875rem; color: var(--ink-muted); margin-bottom: 4px; }
.topic .rows { border-top: 0; }
.topic .rows > li:last-child { border-bottom: 0; }
.topic .row-button { padding: 10px 12px; font-size: .9375rem; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
