:root {
  --bg: #0f0f11; --panel: #18181c; --panel2: #202026; --line: #2c2c35;
  --text: #ececf1; --muted: #9a9aa8; --red: #e5484d; --red2: #f2555a; --ok: #46a758; --warn: #f5a524;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, textarea, select { font: inherit; color: inherit; }
h1 { font-size: 24px; margin: 0 0 6px; }
h2 { font-size: 17px; margin: 32px 0 6px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .error { color: var(--red2); }

.shell { display: flex; flex-direction: column; height: 100dvh; }
.top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); flex: none; }
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.dot { width: 11px; height: 11px; border-radius: 50%; background: var(--red); display: inline-block; }
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tab { background: none; border: 0; padding: 8px 12px; border-radius: 8px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--text); background: var(--panel2); }
.tab.active { color: var(--text); background: var(--panel2); }
.pill { font-size: 12.5px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; white-space: nowrap; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; }
.pill.up::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 6px; }
.pill.down::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--red); margin-right: 6px; }

.pill.watching { color: var(--warn); border-color: var(--warn); }
.view { display: none; flex: 1; min-height: 0; }
.view.active { display: flex; }
.scroll { overflow-y: auto; }
.page { width: 100%; max-width: 860px; margin: 0 auto; padding: 28px 20px 80px; }

button.primary { background: var(--red); border: 0; color: #fff; padding: 9px 16px; border-radius: 9px; cursor: pointer; font-weight: 600; }
button.primary:hover { background: var(--red2); }
button.primary:disabled { opacity: .5; cursor: default; }
button.ghost { background: none; border: 1px solid var(--line); padding: 6px 12px; border-radius: 8px; cursor: pointer; }
button.ghost:hover { background: var(--panel2); }
button.wide { width: 100%; }
:focus-visible { outline: 2px solid var(--red2); outline-offset: 2px; }
input, textarea, select { background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; width: 100%; }
textarea { resize: vertical; }
label { display: block; font-weight: 600; margin: 0 0 6px; }
.field { margin: 22px 0; }
.row { display: flex; gap: 10px; align-items: center; margin: 14px 0; flex-wrap: wrap; }
.row input { flex: 1; min-width: 200px; }

/* chat */
.side { width: 270px; flex: none; border-right: 1px solid var(--line); background: var(--panel); padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.chatlist { overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chatitem { display: flex; align-items: center; gap: 4px; border-radius: 8px; }
.chatitem button.open { flex: 1; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 8px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.chatitem:hover, .chatitem.active { background: var(--panel2); }
.chatitem.active button.open { color: var(--text); }
.chatitem button.del { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px 8px; visibility: hidden; }
.chatitem:hover button.del, .chatitem button.del:focus-visible { visibility: visible; }
.talk { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.sidebtn { display: none; position: absolute; top: 8px; left: 8px; z-index: 2; background: var(--panel); }
.msgs { flex: 1; overflow-y: auto; padding: 24px 16px 8px; }
.msg { max-width: 780px; margin: 0 auto 18px; }
.msg .who { font-size: 12.5px; color: var(--muted); margin-bottom: 3px; }
.msg.user .body { background: var(--panel2); border-radius: 14px; padding: 10px 14px; display: inline-block; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.rojo .body { overflow-wrap: anywhere; }
.msg .body p { margin: 0 0 10px; } .msg .body p:last-child { margin-bottom: 0; }
.msg .body pre { background: #0a0a0c; border: 1px solid var(--line); border-radius: 9px; padding: 12px; overflow-x: auto; }
.msg .body code { font-family: ui-monospace, Consolas, monospace; font-size: 13.5px; background: #0a0a0c; padding: 1px 5px; border-radius: 5px; }
.msg .body pre code { background: none; padding: 0; }
.msg .meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.toolcard { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 8px 0; background: var(--panel); font-size: 14px; }
.toolcard .name { font-weight: 600; }
.toolcard code { display: block; margin: 6px 0; white-space: pre-wrap; overflow-wrap: anywhere; font-family: ui-monospace, Consolas, monospace; font-size: 13px; color: var(--muted); }
.toolcard .out { max-height: 160px; overflow: auto; }
.toolcard.ask { border-color: var(--warn); }
.empty { text-align: center; color: var(--muted); margin-top: 18vh; padding: 0 20px; }
.empty .big { font-size: 22px; color: var(--text); margin-bottom: 6px; }
.composer { display: flex; gap: 10px; padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); max-width: 812px; width: 100%; margin: 0 auto; align-items: flex-end; }
.composer textarea { resize: none; max-height: 200px; }
.typing::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--red2); }
@keyframes blink { 50% { opacity: 0; } }

.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; max-width: 812px; width: 100%; margin: 0 auto; padding: 6px 16px 0; font-size: 13.5px; color: var(--muted); }
.controls select { width: auto; padding: 5px 8px; font-size: 13.5px; }
label.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; font-weight: 400; }
label.check input { width: auto; }
.mic.on { background: var(--red); border-color: var(--red); color: #fff; }
.mic.busy { opacity: .6; }
.msg img.pic, .gallery img { display: block; max-width: 100%; height: auto; border-radius: 12px; border: 1px solid var(--line); margin: 8px 0; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-top: 18px; }
.gallery a { display: block; }
.gallery img { margin: 0; width: 100%; }

/* memory + nodes */
.mem { display: flex; gap: 10px; align-items: flex-start; border-bottom: 1px solid var(--line); padding: 10px 0; }
.mem .t { flex: 1; overflow-wrap: anywhere; }
.cards { display: grid; gap: 12px; margin-top: 16px; }
.card { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; background: var(--panel); }
.card .head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card .name { font-weight: 700; font-size: 16px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.badge.on { color: var(--ok); border-color: var(--ok); } .badge.off { color: var(--red2); border-color: var(--red2); }
.card dl { display: grid; grid-template-columns: 130px 1fr; gap: 4px 12px; margin: 12px 0 0; font-size: 14px; }
.card dt { color: var(--muted); } .card dd { margin: 0; overflow-wrap: anywhere; }
.bar { height: 6px; border-radius: 3px; background: var(--panel2); overflow: hidden; margin-top: 4px; max-width: 320px; }
.bar > i { display: block; height: 100%; background: var(--red); }
.card details { margin-top: 12px; } .card summary { cursor: pointer; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.cmd { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 12px 0; background: var(--panel); }
.cmdhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.cmd code { display: block; font-family: ui-monospace, Consolas, monospace; font-size: 13px; overflow-wrap: anywhere; background: #0a0a0c; padding: 10px; border-radius: 8px; user-select: all; }
.checks { display: flex; gap: 14px; flex-wrap: wrap; }
.checks label { font-weight: 400; display: flex; gap: 6px; align-items: center; margin: 0; }
.checks input { width: auto; }

/* login */
.login-body { display: grid; place-items: center; min-height: 100dvh; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; }
.login-card .brand { font-size: 24px; margin-bottom: 4px; }
.login-card label { margin-top: 16px; }
.login-card button { width: 100%; margin-top: 22px; padding: 11px; }

@media (max-width: 760px) {
  .top { gap: 6px 8px; padding: 8px 10px 4px; flex-wrap: wrap; justify-content: space-between; }
  .pill { max-width: 62vw; }
  .tabs { order: 3; flex: 0 0 100%; flex-wrap: wrap; overflow: visible; }
  .tab { padding: 7px 9px; font-size: 14px; }
  .side { position: absolute; z-index: 5; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: transform .15s; }
  .side.open { transform: none; box-shadow: 2px 0 12px rgba(0,0,0,.4); }
  .scrim { position: absolute; inset: 0; z-index: 4; background: rgba(0,0,0,.5); border: 0; }
  .chatitem button.del { visibility: visible; }
  #chat { position: relative; }
  .sidebtn { display: block; }
  .msgs { padding-top: 52px; }
  .card dl { grid-template-columns: 1fr; } .card dt { margin-top: 6px; }
  .grid2 { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { .typing::after { animation: none; } .side { transition: none; } }
