:root {
  --bg: #f6f7f5; --surface: #ffffff; --surface-2: #eef2ef; --text: #17201c; --muted: #5b6863;
  --brand: #0f7a5a; --brand-soft: #dcefe7; --accent: #c2581b; --accent-soft: #f8e6da;
  --danger: #b42318; --danger-soft: #fbe4e1; --border: #dfe5e1;
  --term-bg: #101614; --term-text: #d6e2dc;
  --shadow: 0 1px 2px rgba(16,40,32,.04), 0 8px 24px rgba(16,40,32,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412; --surface: #151d1a; --surface-2: #1b2622; --text: #e7ece9; --muted: #97a59f;
    --brand: #34b98b; --brand-soft: #173a2e; --accent: #f08a4b; --accent-soft: #3a2416;
    --danger: #f97066; --danger-soft: #3b1714; --border: #26332e;
    --term-bg: #0a0f0d; --term-text: #d6e2dc;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font-family: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.55; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); }
code, pre, .mono { font-family: "JetBrains Mono", ui-monospace, monospace; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

nav { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
nav .wrap { display: flex; align-items: center; justify-content: space-between; height: 58px; gap: 10px; }
.logo { font-weight: 800; text-decoration: none; color: var(--text); letter-spacing: -.02em; white-space: nowrap; }
.logo span { color: var(--brand); }
nav ul { list-style: none; display: flex; gap: 6px; margin: 0; padding: 0; }
nav ul a { color: var(--muted); text-decoration: none; font-weight: 700; font-size: .86rem; padding: 6px 10px; border-radius: 999px; }
nav ul a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
nav ul a:hover { color: var(--text); }

.head { padding: 28px 0 18px; }
.kicker { font-size: .76rem; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; color: var(--accent); }
h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); letter-spacing: -.03em; margin: 4px 0 6px; line-height: 1.15; }
.head p { color: var(--muted); margin: 0; max-width: 760px; }
.pystate { display: inline-flex; align-items: center; gap: 8px; margin-top: 12px; font-size: .8rem; font-weight: 700;
  padding: 5px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.pystate::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pystate[data-tipo="cargando"]::before { animation: pulso 1s infinite alternate; }
.pystate[data-tipo="listo"] { background: var(--brand-soft); color: var(--brand); }
.pystate[data-tipo="error"] { background: var(--danger-soft); color: var(--danger); }
@keyframes pulso { from { opacity: .25; } to { opacity: 1; } }

.app { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 16px; padding-bottom: 48px; align-items: start; }
@media (max-width: 900px) { .app { grid-template-columns: minmax(0, 1fr); } }
.col { display: grid; gap: 16px; min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.panel h2 { font-size: 1rem; margin: 0 0 4px; letter-spacing: -.01em; }
.panel .hint { color: var(--muted); font-size: .86rem; margin: 0 0 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.btn { font: inherit; font-weight: 700; font-size: .9rem; cursor: pointer; border-radius: 999px; padding: 9px 16px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); transition: transform .12s ease; }
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: 6px 12px; font-size: .8rem; }
.chip { font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); text-align: left; }
.chip:hover { border-color: var(--brand); }
.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip.danger { border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); background: var(--danger-soft); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 700; font-size: .9rem; user-select: none; }
.switch input { appearance: none; width: 42px; height: 24px; border-radius: 999px; background: var(--border); position: relative; cursor: pointer; margin: 0; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--brand); }
.switch input:checked::after { transform: translateX(18px); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; }
.stat b { display: block; font-size: 1.3rem; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .78rem; }
.stat.bad b { color: var(--danger); }
.stat.good b { color: var(--brand); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: .76rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.bad { color: var(--danger); font-weight: 700; }
.good { color: var(--brand); font-weight: 700; }

.chart { width: 100%; height: auto; display: block; }
.chart text { font-family: "Manrope", system-ui, sans-serif; font-size: 11px; fill: var(--muted); }
.chart .val { fill: var(--text); font-weight: 700; font-size: 10px; }
.legend { display: flex; gap: 14px; font-size: .78rem; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* Chat */
.chat { display: flex; flex-direction: column; gap: 10px; height: 430px; overflow-y: auto; padding: 4px 2px 8px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 14px; font-size: .92rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg.sys { align-self: center; background: transparent; color: var(--muted); font-size: .8rem; text-align: center; }
.msg .meta { display: block; font-size: .72rem; opacity: .75; margin-top: 6px; }
.composer { display: flex; gap: 8px; margin-top: 10px; }
.composer textarea { flex: 1; min-width: 0; font: inherit; font-size: .92rem; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); resize: vertical; min-height: 44px; max-height: 160px; }
.composer textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 50%, transparent); outline-offset: 1px; }
.sugerencias { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

pre.term { margin: 0; background: var(--term-bg); color: var(--term-text); padding: 12px 14px; border-radius: 12px;
  overflow-x: auto; font-size: .74rem; line-height: 1.5; max-height: 340px; white-space: pre; }
.frag { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.frag header { display: flex; justify-content: space-between; gap: 8px; font-size: .82rem; font-weight: 700; }
.frag p { margin: 6px 0 0; color: var(--muted); font-size: .82rem; }
.bar { height: 6px; border-radius: 999px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.empty { color: var(--muted); font-size: .85rem; font-style: italic; }

.tree { font-size: .84rem; }
.tree .dir { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--border); gap: 8px; }
.tree .dir b { font-family: "JetBrains Mono", monospace; font-size: .8rem; }
.tree .files { color: var(--muted); font-size: .75rem; font-family: "JetBrains Mono", monospace; padding: 2px 0 6px 14px; overflow-wrap: anywhere; }
.tag { font-size: .72rem; font-weight: 700; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.tag.ok { background: var(--brand-soft); color: var(--brand); }
.tag.ko { background: var(--danger-soft); color: var(--danger); }
.tag.warn { background: var(--accent-soft); color: var(--accent); }

.logitem { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; font-size: .82rem; }
.logitem header { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-weight: 700; }
.logitem .hash { font-family: "JetBrains Mono", monospace; font-size: .7rem; color: var(--muted); overflow-wrap: anywhere; margin-top: 4px; }
.logs { max-height: 380px; overflow-y: auto; }

/* Modal HITL */
dialog { border: none; border-radius: 18px; padding: 0; max-width: 560px; width: calc(100% - 32px); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10, 15, 13, .6); backdrop-filter: blur(2px); }
.modal-head { background: var(--danger-soft); color: var(--danger); padding: 16px 20px; font-weight: 800; }
.modal-body { padding: 16px 20px; font-size: .9rem; }
.modal-body dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 12px; }
.modal-body dt { color: var(--muted); font-weight: 600; }
.modal-body dd { margin: 0; overflow-wrap: anywhere; }
.modal-body input { width: 100%; font: inherit; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 0 20px 18px; flex-wrap: wrap; }

.callout { font-size: .84rem; color: var(--muted); border-left: 3px solid var(--accent); padding: 4px 0 4px 12px; margin: 12px 0 0; }
input[type=range] { width: 100%; accent-color: var(--brand); }
label.field { display: grid; gap: 4px; font-size: .82rem; font-weight: 600; color: var(--muted); }
label.field output { color: var(--text); font-weight: 800; }
footer { padding: 24px 0 40px; color: var(--muted); font-size: .84rem; border-top: 1px solid var(--border); }
