:root {
  --bg: #0f1115; --panel: #161920; --panel-2: #1d2129; --hover: #232835; --line: #2a2f3a;
  --text: #e6e8ee; --muted: #8b93a7; --accent: #7c6cf2; --accent-2: #9a8dff;
  --ok: #3ccf8e; --warn: #f2b84b; --bad: #f2666b;
  --radius: 12px; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
a { color: inherit; }
code, kbd, pre { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 20px; margin: 0; } h2 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.error { color: var(--bad); min-height: 1.2em; margin: 0; }
.pad { padding: 4px 8px; }

/* botones */
.btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 14px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: #3a4150; background: var(--hover); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { background: #3a1d22; border-color: #5a2a31; color: #ffb3b6; }
.btn.ghost { background: transparent; }
.btn.danger.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.link { background: none; border: 0; color: var(--accent-2); cursor: pointer; padding: 0; text-decoration: none; }
.link:hover { text-decoration: underline; }
.link.danger { color: #ff9ea2; }
.me .link { color: var(--muted); }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; padding: 0 6px; }
.brand.big { font-size: 22px; justify-content: center; margin-bottom: 8px; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, var(--accent), #4fc3f7); display: inline-block; }

/* login */
.login { display: grid; place-items: center; height: 100%; padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 14px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
input, select, textarea { background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 9px 11px; font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.stack { display: grid; gap: 12px; }
.qr { width: 220px; height: 220px; justify-self: center; background: #fff; border-radius: 10px; padding: 6px; }
.secret { word-break: break-all; font-size: 13px; color: var(--text); letter-spacing: .04em; }
.login-card p { margin: 0; }

/* estructura */
.app { display: grid; grid-template-columns: 220px 1fr; height: 100%; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 10px; display: flex; flex-direction: column; gap: 16px; min-height: 0; }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); }
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active { background: #262a35; color: var(--text); }
.nav .ico { width: 18px; text-align: center; color: var(--accent-2); }
.side-bottom { margin-top: auto; display: grid; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.side-link { background: none; border: 0; text-align: left; padding: 6px 10px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; color: var(--muted); }
.side-link:hover { background: var(--panel-2); color: var(--text); }
.me { display: flex; justify-content: space-between; padding: 0 10px; color: var(--muted); }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: #4a5163; display: inline-block; flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
#ai-dots { display: inline-flex; gap: 4px; }
.pill { font-size: 12px; padding: 1px 9px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); white-space: nowrap; }
.pill.running { color: var(--ok); border-color: #1f5a41; } .pill.exited, .pill.created { color: var(--muted); } .pill.missing, .pill.dead { color: var(--bad); }
.tag { font-size: 11px; padding: 0 7px; border-radius: 99px; background: #2a2550; color: #c9c2ff; margin-left: 6px; }
.spinner { width: 10px; height: 10px; border: 2px solid var(--accent); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* páginas */
.page { padding: 24px 28px 40px; overflow: auto; display: grid; gap: 18px; align-content: start; height: 100%; }
.page.narrow { max-width: 980px; }
.page-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; justify-content: space-between; }
.page-head > .muted { flex: 1; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: grid; gap: 12px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.rows { display: grid; }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-radius: 8px; text-decoration: none; min-width: 0; }
a.row:hover { background: var(--panel-2); }

/* indicadores */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 6px; align-content: start; }
.tile-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.tile-value { font-size: 24px; font-weight: 650; }
.tile-detail { color: var(--muted); font-size: 12px; }
.bar { height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 99px; background: var(--ok); }
.bar span.warn { background: var(--warn); } .bar span.bad { background: var(--bad); }
.ai-row { display: flex; align-items: center; gap: 8px; }
.spark { width: 100%; height: 90px; display: block; }
.spark .line { fill: none; stroke: var(--accent-2); stroke-width: 2; vector-effect: non-scaling-stroke; }
.spark .area { fill: rgba(124, 108, 242, .15); stroke: none; }
.bars { display: grid; gap: 8px; }
.hbar { display: grid; grid-template-columns: 200px 1fr 170px; gap: 12px; align-items: center; }
.hbar-track { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.hbar-track span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

/* proyectos */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.pcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; display: grid; gap: 6px; }
.pcard:hover { border-color: #3a4150; background: #191c24; }
.pcard p { margin: 0; min-height: 1.5em; }
.pcard-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.pcard-foot { display: flex; gap: 10px; align-items: center; }
.empty-card { grid-column: 1 / -1; text-align: center; padding: 40px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
.tpl-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tpl { text-align: left; display: grid; gap: 2px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.tpl:hover { border-color: #3a4150; }
.tpl.active { border-color: var(--accent); background: #1c1a33; }

.project { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.project-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.project-head .title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.project-head h1 { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { font-size: 18px; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; padding: 0 16px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { background: none; border: 0; padding: 10px 12px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; text-decoration: none; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-color: var(--accent); }
.tab-body { flex: 1; min-height: 0; display: flex; }
.tab-body.scroll { display: block; overflow: auto; }
.editor-frame { flex: 1; border: 0; width: 100%; height: 100%; background: #1e1e1e; }
.form-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; align-items: start; }
.form-grid label { align-content: start; }
.form-grid .check { grid-column: 1 / -1; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.logbox { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; max-height: 360px; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 0; color: #c9cede; }
.logbox.tall { max-height: calc(100vh - 260px); }

/* chat */
.assistant-body { flex: 1; min-height: 0; display: flex; }
.chat-layout { display: grid; grid-template-columns: 250px 1fr; flex: 1; min-height: 0; }
.chat-list { border-right: 1px solid var(--line); padding: 12px; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.new-chat { display: flex; gap: 6px; margin-bottom: 8px; }
.chat-item { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; padding: 8px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; text-decoration: none; }
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: #262a35; border-color: var(--line); }
.chat-item .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .agent { font-size: 10px; font-weight: 700; letter-spacing: .06em; color: #c9c2ff; background: #2a2550; border-radius: 4px; padding: 1px 4px; }
.chat-item .agent.gemini { color: #b6e3ff; background: #16324a; }
.chat-item .del { opacity: 0; background: none; border: 0; color: var(--muted); cursor: pointer; }
.chat-item:hover .del { opacity: 1; }
.conversation { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.conv-empty { margin: auto; max-width: 460px; text-align: center; color: var(--muted); padding: 24px; }
.conv-status { padding: 6px 24px; color: var(--muted); font-size: 12.5px; }
.messages { flex: 1; overflow: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 880px; width: 100%; }
.msg.user { align-self: flex-end; max-width: 640px; width: auto; background: #2a2550; border: 1px solid #3b3473; padding: 9px 13px; border-radius: 12px 12px 2px 12px; white-space: pre-wrap; }
.msg.assistant { line-height: 1.6; }
.msg.assistant pre { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow: auto; }
.msg.assistant code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.msg.assistant pre code { background: none; padding: 0; }
.msg.assistant p { margin: .4em 0; }
.msg.assistant table { border-collapse: collapse; } .msg.assistant td, .msg.assistant th { border: 1px solid var(--line); padding: 4px 8px; }
.tool { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; font-size: 12.5px; }
.tool summary { cursor: pointer; padding: 6px 10px; display: flex; gap: 8px; align-items: center; list-style: none; }
.tool summary::-webkit-details-marker { display: none; }
.tool .name { font-family: var(--mono); color: var(--accent-2); }
.tool .arg { color: var(--muted); font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool pre { margin: 0; padding: 8px 10px; border-top: 1px solid var(--line); max-height: 260px; overflow: auto; white-space: pre-wrap; word-break: break-word; color: #c9cede; }
.msg.done { color: var(--muted); font-size: 12px; }
.msg.error { background: #2b1619; border: 1px solid #5a2a31; color: #ffc9cb; padding: 10px 12px; border-radius: 8px; white-space: pre-wrap; font-size: 13px; }
.composer { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { flex: 1; resize: none; max-height: 220px; }

/* archivos */
.files-wrap { flex: 1; min-height: 0; display: flex; }
.files-main { flex: 1; min-width: 0; overflow: auto; padding: 14px 20px 30px; position: relative; }
.crumbs { padding: 4px 0 12px; display: flex; flex-wrap: wrap; gap: 2px; }
.crumbs a { text-decoration: none; color: var(--accent-2); }
.files { width: 100%; border-collapse: collapse; }
.files th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.files td { padding: 7px 10px; border-bottom: 1px solid #1f232c; vertical-align: middle; }
.files tr:hover td { background: #171a21; }
.files td.name a { text-decoration: none; display: inline-flex; gap: 8px; align-items: center; }
.files td.acts { text-align: right; white-space: nowrap; }
.files td.acts > * { margin-left: 10px; }
.files tr.hiddenfile td.name { opacity: .6; }
.files tr.up a { color: var(--muted); text-decoration: none; }
.fico { width: 18px; text-align: center; }
.upload-progress { min-height: 1em; }
.dropzone { position: absolute; inset: 8px; border: 2px dashed var(--accent); border-radius: var(--radius); background: rgba(124, 108, 242, .12); display: grid; place-items: center; font-size: 16px; pointer-events: none; }
.preview { width: min(440px, 45%); border-left: 1px solid var(--line); padding: 14px 16px; overflow: auto; display: flex; flex-direction: column; gap: 8px; background: var(--panel); }
.preview-body img, .preview-body video { max-width: 100%; border-radius: 8px; }
.preview-body iframe { width: 100%; height: 70vh; border: 0; background: #fff; border-radius: 8px; }
.preview-body pre { white-space: pre-wrap; word-break: break-word; margin: 0; font-size: 12px; }

/* diálogos y avisos */
.dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(480px, calc(100% - 32px)); }
.dialog.wide { width: min(620px, calc(100% - 32px)); }
.dialog::backdrop { background: rgba(0, 0, 0, .55); }
.dialog form { padding: 22px; display: grid; gap: 12px; }
.dialog h2 { font-size: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.account { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
details summary { cursor: pointer; color: var(--accent-2); }
details ol { padding-left: 20px; color: var(--muted); }
details li { margin: 6px 0; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--ok); padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 24px rgba(0, 0, 0, .35); transition: opacity .4s; max-width: 360px; }
.toast.bad { border-left-color: var(--bad); }
.toast.out { opacity: 0; }

@media (max-width: 1000px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
  .hbar { grid-template-columns: 120px 1fr 120px; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); padding: 10px; gap: 8px; }
  .nav { grid-auto-flow: column; overflow-x: auto; }
  .nav a { white-space: nowrap; }
  .side-bottom { display: none; }
  .page { padding: 16px; }
  .chat-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .chat-list { border-right: 0; border-bottom: 1px solid var(--line); max-height: 150px; }
  .preview { display: none; }
  .tpl-grid, .form-grid { grid-template-columns: 1fr; }
}

/* ---------- tema claro ---------- */
:root[data-theme="light"] {
  --bg: #f5f6fa; --panel: #ffffff; --panel-2: #f0f1f6; --hover: #e8eaf1; --line: #dfe2ea;
  --text: #1c2030; --muted: #5f6880; --accent: #6656e6; --accent-2: #5b4bd9;
  --ok: #17a36b; --warn: #c98a12; --bad: #d64550;
  color-scheme: light;
}
:root[data-theme="light"] .nav a.active, :root[data-theme="light"] .chat-item.active, :root[data-theme="light"] .project-list a.active { background: #e9e7fb; }
:root[data-theme="light"] .msg.user { background: #ece9fd; border-color: #d6d0fb; }
:root[data-theme="light"] .msg.error, :root[data-theme="light"] .btn.danger { background: #fdecee; border-color: #f4c3c8; color: #a8303b; }
:root[data-theme="light"] .btn.danger.ghost { background: transparent; }
:root[data-theme="light"] .files tr:hover td { background: #f6f7fb; }
:root[data-theme="light"] .files td { border-bottom-color: #eceef3; }
:root[data-theme="light"] .tpl.active { background: #efedfd; }
:root[data-theme="light"] .pcard:hover { background: #fafbfd; }
:root[data-theme="light"] .tag, :root[data-theme="light"] .chat-item .agent { background: #e9e7fb; color: #4a3ec4; }
:root[data-theme="light"] .chat-item .agent.gemini { background: #e0f0fc; color: #1d5f8f; }
:root[data-theme="light"] .tool pre, :root[data-theme="light"] .logbox { color: #2b3145; }
:root[data-theme="light"] .editor-frame { background: #fff; }

/* ---------- perfil, ajustes ---------- */
.avatar { display: inline-grid; place-items: center; border-radius: 50%; color: #fff; font-weight: 650; flex: none; letter-spacing: .02em; }
.me { align-items: center; gap: 8px; padding: 0 4px 0 6px; }
.me-chip { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); min-width: 0; padding: 4px 6px; border-radius: 8px; flex: 1; }
.me-chip:hover { background: var(--panel-2); }
a.side-link { text-decoration: none; }
.profile-preview { display: flex; align-items: center; gap: 14px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--panel) inset; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.banner { padding: 12px 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); }
.banner.warn { border-color: #6b5418; background: #2a2414; color: #f6d68c; }
:root[data-theme="light"] .banner.warn { background: #fff6df; border-color: #f0d48a; color: #6d4d00; }
.codes { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; font-size: 15px; line-height: 1.9; letter-spacing: .06em; columns: 2; margin: 0; }
.secret.big { font-size: 18px; display: block; padding: 10px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; text-align: center; }
.files td.acts.wrap { white-space: normal; text-align: left; }
.files td.acts.wrap > * { margin: 2px 4px 2px 0; }
@media (max-width: 760px) {
  .form-grid.three, .kv { grid-template-columns: 1fr; }
  .codes { columns: 1; }
}

/* ---------- tareas en paralelo ---------- */
.chat-single { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-single .conversation { flex: 1; }
.chat-layout.tasks { grid-template-columns: 270px 1fr; }
.chat-list .side-label { margin: 10px 4px 2px; }
.btn.block { justify-content: center; }
.closed-tasks summary { list-style: none; cursor: pointer; }
.closed-tasks summary::-webkit-details-marker { display: none; }
.task-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.task-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.task-head .title { display: flex; align-items: center; gap: 10px; min-width: 0; flex-wrap: wrap; }
.task-head h2 { font-size: 16px; max-width: 420px; }
.tabs.sub { padding: 0 12px; }
.tabs.sub .tab { padding: 8px 10px; font-size: 13px; }
.task-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: auto; }
.task-form textarea { resize: vertical; min-height: 140px; }
label.inline { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.steps li { margin: 4px 0; }
.diff-wrap { padding: 14px 18px 30px; display: grid; gap: 10px; align-content: start; }
.diff-summary { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.add { color: var(--ok); } .del { color: var(--bad); }
.diff-file { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); overflow: hidden; }
.diff-file summary { cursor: pointer; padding: 8px 12px; background: var(--panel-2); }
.diff-file pre { margin: 0; padding: 6px 0; overflow: auto; font-size: 12px; line-height: 1.45; }
.diff-file pre span { display: block; padding: 0 12px; white-space: pre; }
.l-add { background: rgba(60, 207, 142, .13); }
.l-del { background: rgba(242, 102, 107, .13); }
.l-hunk { color: var(--accent-2); background: rgba(124, 108, 242, .08); }
@media (max-width: 760px) { .chat-layout.tasks { grid-template-columns: 1fr; } }
.keybox { columns: 1; font-size: 12px; white-space: pre-wrap; word-break: break-all; letter-spacing: 0; line-height: 1.5; }
