:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6a64;
  --border: #dcdad2;
  --accent: #b4531f;
  --accent-text: #ffffff;
  --user-bg: #b4531f;
  --user-text: #ffffff;
  --bot-bg: #ffffff;
  --expert-bg: #e9f1e4;
  --notice-bg: #fbf1d9;
  --error: #a32020;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161614;
    --surface: #1f1f1c;
    --text: #ecebe6;
    --muted: #a09f97;
    --border: #3a3a35;
    --accent: #e08a55;
    --accent-text: #1a1209;
    --user-bg: #8a4220;
    --user-text: #fff;
    --bot-bg: #1f1f1c;
    --expert-bg: #25311f;
    --notice-bg: #3a3320;
    --error: #ff8a8a;
  }
}
:root[data-theme="dark"] {
  --bg: #161614;
  --surface: #1f1f1c;
  --text: #ecebe6;
  --muted: #a09f97;
  --border: #3a3a35;
  --accent: #e08a55;
  --accent-text: #1a1209;
  --user-bg: #8a4220;
  --user-text: #fff;
  --bot-bg: #1f1f1c;
  --expert-bg: #25311f;
  --notice-bg: #3a3320;
  --error: #ff8a8a;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 1.4rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.error { color: var(--error); margin: .5rem 0; }

.card {
  max-width: 680px;
  margin: 2rem auto;
  padding: 1.25rem 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.card.narrow { max-width: 420px; }
@media (max-width: 720px) { .card { margin: 0; border-radius: 0; border-left: 0; border-right: 0; min-height: 100vh; } }

.stack { display: grid; gap: .9rem; margin-top: 1rem; }
label { display: grid; gap: .25rem; font-weight: 600; font-size: .95rem; }
label.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 400; }
input[type=email], input[type=password], select, textarea {
  font: inherit;
  padding: .6rem .7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button {
  font: inherit;
  font-weight: 600;
  padding: .6rem 1.1rem;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
button:disabled { opacity: .5; cursor: not-allowed; }
button.link { background: none; color: var(--muted); padding: .25rem .4rem; text-decoration: underline; font-weight: 400; }

.notice {
  background: var(--notice-bg);
  border-radius: 8px;
  padding: .5rem .75rem;
  font-size: .9rem;
  margin: .75rem 0;
}
.notice.test { margin-top: 0; }

/* Chat */
.chat { max-width: 760px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; padding: 0 16px; }
.bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .75rem 0; border-bottom: 1px solid var(--border); }
.bar-right { display: flex; align-items: center; gap: .5rem; }
.bar-right form { margin: 0; }
.who { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; white-space: nowrap; }
.banners { margin-top: .25rem; }
.log { flex: 1; display: flex; flex-direction: column; gap: .75rem; padding: .5rem 0 1rem; }
.msg { max-width: 88%; padding: .6rem .85rem; border-radius: 14px; border: 1px solid var(--border); overflow-wrap: anywhere; }
.msg p { margin: 0 0 .6rem; }
.msg p:last-child, .msg ul:last-child { margin-bottom: 0; }
.msg ul { margin: 0 0 .6rem; padding-left: 1.25rem; }
.msg.user { align-self: flex-end; background: var(--user-bg); color: var(--user-text); border-color: transparent; }
.msg.assistant { align-self: flex-start; background: var(--bot-bg); }
.msg.expert { align-self: flex-start; background: var(--expert-bg); }
.msg .tag { display: block; font-size: .75rem; font-weight: 700; margin-bottom: .25rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.status { color: var(--muted); font-style: italic; padding: .25rem 0; }
.composer { position: sticky; bottom: 0; background: var(--bg); padding: .75rem 0 1rem; border-top: 1px solid var(--border); }
.composer textarea { resize: vertical; min-height: 4.5rem; }
.composer-row { display: flex; justify-content: space-between; align-items: center; margin-top: .5rem; }
.msg.live::after { content: "▍"; margin-left: 2px; opacity: .6; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .msg.live::after { animation: none; } }

/* Panel del experto */
.panel { max-width: 980px; margin: 0 auto; padding: 0 16px 3rem; }
.panel h1 { margin-top: 1rem; }
.panel h2 { font-size: 1.05rem; margin: 1.5rem 0 .5rem; }
.panel nav { flex-wrap: wrap; }
.panel a { color: var(--accent); }
.tabs { display: flex; gap: 1rem; margin: .5rem 0 1rem; }
.tabs a[aria-current="page"] { font-weight: 700; text-decoration: none; color: var(--text); border-bottom: 2px solid var(--accent); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; background: var(--notice-bg); font-size: .78rem; white-space: nowrap; }
.badge.overdue { background: var(--error); color: var(--bg); }
.log.plain { padding: 0; }
.plain-text { white-space: pre-wrap; }
details { margin: 1rem 0; }
.tech dt { font-weight: 600; margin-top: .5rem; }
.tech dd { margin: 0; overflow-wrap: anywhere; }
.tech pre { white-space: pre-wrap; margin: .25rem 0 0; font-size: .85rem; }
button.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.composer-actions { display: flex; gap: .5rem; align-items: center; }
.bar-right a { font-size: .9rem; }

.row-actions { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; margin: .75rem 0; }
form.inline { display: inline; margin: 0; }
a.button { display: inline-block; padding: .6rem 1.1rem; border-radius: 8px; background: var(--accent); color: var(--accent-text); font-weight: 600; text-decoration: none; }
.panel a.button { color: var(--accent-text); }
.detail-row td { border-bottom: 1px solid var(--border); padding-top: 0; }
.detail-row summary { cursor: pointer; color: var(--muted); font-size: .88rem; }
.panel .filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; margin: 1rem 0; }
.msg-actions { margin: .5rem 0 0; font-size: .85rem; }
.msg-actions a { color: var(--muted); }
.snapshot { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; font-size: .85rem; overflow-x: auto; }
