:root {
  --bg: #0d0f14;
  --bg2: #12151c;
  --panel: #171b24;
  --panel2: #1d2230;
  --line: #262c3a;
  --text: #e6e8ee;
  --muted: #8b93a7;
  --accent: #7c5cff;
  --accent2: #9b83ff;
  --ok: #2fbf71;
  --warn: #e0a526;
  --bad: #ef4f5a;
  --code: #0a0c10;
  --radius: 12px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 15px; }
a { color: var(--accent2); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; background: #ffffff12; padding: 1px 5px; border-radius: 5px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.grow { flex: 1; }
.error-text { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; }

/* Botones */
.btn { display: inline-flex; align-items: center; gap: 6px; justify-content: center; border: 1px solid var(--line); background: var(--panel2); color: var(--text); padding: 9px 14px; border-radius: 9px; cursor: pointer; font: inherit; font-size: 14px; white-space: nowrap; transition: .15s; }
.btn:hover { border-color: #3a4256; background: #232938; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn.primary:hover { background: var(--accent2); }
.btn.danger { background: transparent; border-color: #ef4f5a66; color: #ff8a92; }
.btn.danger:hover { background: #ef4f5a22; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: #ffffff0d; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.pill { font-size: 11px; background: #7c5cff33; color: var(--accent2); padding: 2px 8px; border-radius: 99px; font-weight: 600; }
.badge { background: var(--bad); color: white; border-radius: 99px; font-size: 11px; padding: 1px 7px; margin-left: auto; }
.logo-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), #3fb8ff); color: white; font-weight: 800; }

input, select, textarea { font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; outline: none; width: 100%; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

/* Login */
#login { min-height: 100%; display: grid; place-items: center; padding: 20px; background: radial-gradient(1000px 500px at 50% -10%, #7c5cff22, transparent); }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.logo-big { font-size: 24px; font-weight: 800; display: flex; align-items: center; gap: 10px; }
.login-card p { margin: 0; }

/* Layout */
#app { display: flex; height: 100vh; height: 100dvh; }
#sidebar { width: 280px; flex-shrink: 0; background: var(--bg2); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px; gap: 12px; }
.brand { font-weight: 800; font-size: 18px; display: flex; align-items: center; gap: 9px; padding: 4px 4px 8px; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav button { display: flex; align-items: center; gap: 8px; text-align: left; background: transparent; border: 0; color: var(--muted); padding: 9px 10px; border-radius: 8px; cursor: pointer; font: inherit; }
#nav button:hover { background: #ffffff0a; color: var(--text); }
#nav button.active { background: #7c5cff22; color: var(--text); }
.side-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 6px 6px 0; }
#convList { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -4px; padding: 0 4px; }
.conv { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 8px; cursor: pointer; color: #c9cede; font-size: 14px; }
.conv:hover { background: #ffffff0a; }
.conv.active { background: #ffffff12; color: white; }
.conv .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .x { opacity: 0; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 4px; font-size: 13px; }
.conv:hover .x { opacity: 1; }
.conv .live { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.side-foot { display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 10px; font-size: 13px; }

main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); min-height: 56px; }
.topbar h1 { font-size: 16px; margin: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--accent2); background: #7c5cff1a; padding: 4px 10px; border-radius: 99px; }
.ws-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--bad); }
.ws-dot.on { background: var(--ok); }
.view { flex: 1; overflow-y: auto; padding: 20px; }
.only-mobile { display: none; }

/* Chat */
#view-chat { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
#messages { flex: 1; overflow-y: auto; padding: 24px max(20px, calc((100% - 860px) / 2)); display: flex; flex-direction: column; gap: 18px; }
.msg-user { align-self: flex-end; max-width: 80%; background: var(--panel2); border: 1px solid var(--line); padding: 10px 14px; border-radius: 14px 14px 4px 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg-ai { display: flex; gap: 12px; align-items: flex-start; }
.msg-ai .avatar { flex-shrink: 0; }
.msg-ai .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.msg-ai .meta { font-size: 12px; color: var(--muted); }
.msg-ai .err { background: #ef4f5a18; border: 1px solid #ef4f5a55; color: #ffb3b8; padding: 10px 12px; border-radius: 10px; white-space: pre-wrap; font-size: 13px; }
.md { line-height: 1.6; word-wrap: break-word; }
.md p { margin: 0 0 10px; }
.md p:last-child { margin-bottom: 0; }
.md h2, .md h3, .md h4, .md h5, .md h6 { margin: 14px 0 8px; line-height: 1.3; }
.md h2 { font-size: 1.25em; } .md h3 { font-size: 1.12em; } .md h4, .md h5, .md h6 { font-size: 1em; }
.md ul, .md ol { margin: 4px 0 10px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md blockquote { margin: 6px 0; padding: 4px 12px; border-left: 3px solid var(--accent); color: #c9cede; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.md table { border-collapse: collapse; margin: 8px 0; font-size: 14px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.md th { background: var(--panel2); }
pre.code { background: var(--code); border: 1px solid var(--line); border-radius: 10px; margin: 8px 0; overflow: hidden; }
pre.code .code-h { display: flex; justify-content: space-between; align-items: center; padding: 5px 10px; background: #ffffff08; font-size: 12px; color: var(--muted); font-family: inherit; }
pre.code code { display: block; padding: 12px; overflow-x: auto; background: none; font-size: 13px; line-height: 1.5; white-space: pre; }
.copy { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; font-size: 12px; }
.copy:hover { color: var(--text); }
.wslink { text-decoration: underline dotted; }

.tool { border: 1px solid var(--line); background: var(--bg2); border-radius: 10px; font-size: 13px; overflow: hidden; }
.tool > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 7px 10px; color: #c9cede; }
.tool > summary::-webkit-details-marker { display: none; }
.tool > summary:hover { background: #ffffff06; }
.tool .ti { width: 18px; text-align: center; }
.tool .tn { font-weight: 600; white-space: nowrap; }
.tool .ts { color: var(--muted); font-family: ui-monospace, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.tool .td { color: var(--muted); font-size: 12px; white-space: nowrap; }
.tool .tb { border-top: 1px solid var(--line); padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; }
.tool .tb pre { margin: 0; background: var(--code); padding: 8px 10px; border-radius: 8px; overflow: auto; max-height: 320px; font-size: 12px; line-height: 1.45; white-space: pre-wrap; word-break: break-all; }
.tool .lbl { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .06em; }
.tool.err { border-color: #ef4f5a66; }
.ok-ic { color: var(--ok); } .bad-ic { color: var(--bad); }

#composer { display: flex; gap: 10px; align-items: flex-end; padding: 12px max(20px, calc((100% - 860px) / 2)) 6px; }
#prompt { resize: none; max-height: 220px; min-height: 44px; line-height: 1.45; padding: 11px 13px; border-radius: 12px; }
.composer-foot { font-size: 12px; padding: 0 max(20px, calc((100% - 860px) / 2)) 12px; min-height: 16px; }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 520px; }
.empty h2 { color: var(--text); margin: 12px 0 6px; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }
.suggestions button { text-align: left; background: var(--panel); border: 1px solid var(--line); color: #c9cede; padding: 12px; border-radius: 10px; cursor: pointer; font: inherit; font-size: 13px; }
.suggestions button:hover { border-color: var(--accent); }

.req-banner { margin: 12px max(20px, calc((100% - 860px) / 2)) 0; }
.req-card { background: #7c5cff14; border: 1px solid #7c5cff66; border-radius: 12px; padding: 12px 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.req-card + .req-card { margin-top: 8px; }
.req-card .txt { flex: 1; min-width: 220px; }
.req-card .actions { display: flex; gap: 8px; }

/* Tarjetas / tablas */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.card h2 { font-size: 15px; margin: 0 0 12px; }
.card-h { display: flex; align-items: center; margin-bottom: 8px; }
.card-h h2 { margin: 0; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 9px 10px; border-bottom: 1px solid #ffffff08; vertical-align: middle; }
.table tr:hover td { background: #ffffff04; }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.table .name { cursor: pointer; display: flex; align-items: center; gap: 8px; }
.table .name:hover { color: var(--accent2); }
.table .empty-row { text-align: center; color: var(--muted); padding: 22px; }
.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 14px; }
.crumbs a { color: var(--text); text-decoration: none; padding: 4px 6px; border-radius: 6px; cursor: pointer; }
.crumbs a:hover { background: #ffffff0d; }
.crumbs span { color: var(--muted); }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #ffffff10; white-space: nowrap; }
.tag.ok { background: #2fbf7122; color: #6ee3a4; }
.tag.bad { background: #ef4f5a22; color: #ff9aa1; }
.tag.warn { background: #e0a52622; color: #f3c55e; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }
.form-actions { display: flex; gap: 8px; grid-column: 1 / -1; }
.deploy-log { background: var(--code); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-size: 13px; white-space: pre-wrap; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 20px; font-weight: 700; margin-top: 6px; }
.stat .s { font-size: 12px; color: var(--muted); margin-top: 4px; }
.bar { height: 6px; background: #ffffff10; border-radius: 99px; margin-top: 10px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

/* Modal / toasts */
.modal { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: min(920px, 100%); max-height: 90vh; display: flex; flex-direction: column; }
.modal-h { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); gap: 10px; }
.modal-h h3 { margin: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-b { padding: 14px 16px; overflow: auto; }
.modal-b pre { margin: 0; background: var(--code); padding: 12px; border-radius: 8px; font-size: 13px; line-height: 1.5; overflow: auto; white-space: pre; }
.modal-f { padding: 10px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.modal-f:empty { display: none; }
#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--panel2); border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 10px; max-width: 380px; font-size: 14px; box-shadow: 0 8px 24px #0006; white-space: pre-wrap; }
.toast.ok { border-left-color: var(--ok); }
.toast.bad { border-left-color: var(--bad); }

.spinner { width: 13px; height: 13px; border: 2px solid #7c5cff55; border-top-color: var(--accent2); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); 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; } 40% { opacity: 1; } }

/* Móvil */
@media (max-width: 820px) {
  .only-mobile { display: inline-flex; }
  #sidebar { position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: transform .2s; }
  #sidebar.open { transform: none; }
  #backdrop { position: fixed; inset: 0; background: #0008; z-index: 30; }
  .msg-user { max-width: 92%; }
  .form-grid, .suggestions { grid-template-columns: 1fr; }
  .view { padding: 14px; }
}
