:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #1f2630;
  --line: #2a313c;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #d97757;
  --accent2: #f0a07f;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --radius: 14px;
  --nav-h: 64px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; color: inherit; }
code, pre { font-family: ui-monospace, "Cascadia Code", Menlo, Consolas, monospace; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error-text { color: var(--bad); min-height: 1.2em; margin: 0; }

/* Botones */
.btn { background: var(--bg3); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; cursor: pointer; transition: background .15s, transform .05s; }
.btn:hover { background: #283040; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a0f0a; font-weight: 600; }
.btn.primary:hover { background: var(--accent2); }
.btn.danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn.ok { background: transparent; border-color: var(--ok); color: var(--ok); }
.btn.small { padding: 6px 10px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { background: none; border: none; font-size: 1.2rem; cursor: pointer; padding: 6px 8px; color: var(--muted); }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 12px; text-align: center; background: var(--bg2); border: 1px solid var(--line); padding: 32px 24px; border-radius: 20px; }
.login-card h1 { margin: 4px 0 0; font-size: 1.5rem; }
.login-card p { margin: 0 0 8px; }
.login-logo { width: 64px; height: 64px; margin: 0 auto; }
input[type=password], input[type=text], textarea { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); }

/* Layout */
.app { display: flex; height: 100%; }
.nav { width: 220px; background: var(--bg2); border-right: 1px solid var(--line); padding: 16px 10px; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; font-weight: 700; }
.brand img { width: 28px; height: 28px; }
.nav-btn { position: relative; display: flex; align-items: center; gap: 12px; background: none; border: none; padding: 11px 12px; border-radius: 10px; cursor: pointer; color: var(--muted); text-align: left; }
.nav-btn:hover { background: var(--bg3); color: var(--text); }
.nav-btn.active { background: var(--bg3); color: var(--text); }
.nav-btn .ico { width: 20px; text-align: center; color: var(--accent); }
.badge { background: var(--bad); color: #fff; font-size: .7rem; border-radius: 999px; padding: 2px 7px; margin-left: auto; }
.main { flex: 1; overflow: auto; }
.view { padding: 24px; max-width: 1200px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.view-head h2 { margin: 0; }
.view-head p { margin: 2px 0 0; }
.live { color: var(--ok); font-size: .85rem; white-space: nowrap; }
.live.off { color: var(--bad); }

/* Tarjetas */
.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.card { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h3 { margin: 0 0 12px; font-size: 1rem; }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.7rem; font-weight: 700; margin: 6px 0; }
.stat .sub { color: var(--muted); font-size: .8rem; }
.bar { height: 6px; background: var(--bg3); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 99px; transition: width .4s; }
.bar > i.warn { background: var(--warn); }
.bar > i.bad { background: var(--bad); }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); font-size: .85rem; }
.pill.ok { border-color: rgba(63,185,80,.5); color: var(--ok); }
.pill.bad { border-color: rgba(248,81,73,.5); color: var(--bad); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: .9rem; }
.kv span:nth-child(odd) { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* Terminal */
#view-terminal { padding: 0; max-width: none; height: 100%; display: flex; flex-direction: column; gap: 0; }
.term-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.term-title { flex: 1; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9rem; color: var(--ok); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-status { font-size: .8rem; color: var(--bad); }
.term-status.on { color: var(--ok); }
.term { flex: 1; min-height: 0; background: #0b0e13; padding: 8px 0 0 10px; }
.term .xterm { height: 100%; }
.keybar { display: none; gap: 6px; padding: 8px; border-top: 1px solid var(--line); overflow-x: auto; background: var(--bg2); }
.keybar button { flex-shrink: 0; min-width: 44px; padding: 9px 10px; background: var(--bg3); border: 1px solid var(--line); border-radius: 8px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }
.keybar button.on { background: var(--accent); color: #1a0f0a; border-color: var(--accent); }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row input { flex: 1; min-width: 200px; }

/* Modelos */
.model-select { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; max-width: 210px; font-size: .85rem; }
.spend { display: grid; gap: 6px; margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 6px; }
.form-grid label { display: grid; gap: 6px; font-size: .85rem; color: var(--muted); }
.form-grid input { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.small { font-size: .8rem; }
.ollama { border: 1px dashed var(--line); border-radius: 12px; padding: 12px; margin: 12px 0; display: grid; gap: 8px; justify-items: start; }
.ollama code { background: var(--bg3); padding: 1px 6px; border-radius: 6px; }

.term-blocked { flex: 1; display: grid; place-content: center; text-align: center; padding: 24px; color: var(--text); }
.term-blocked .empty-ico { font-size: 2.2rem; }
.where { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .8rem; }
.where.home { background: rgba(63,185,80,.15); color: var(--ok); }
.where.out { background: rgba(210,153,34,.15); color: var(--warn); }

/* Gastos */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: 8px; }
.bars .b { flex: 1; min-width: 4px; background: var(--accent); border-radius: 4px 4px 0 0; position: relative; opacity: .85; }
.bars .b.zero { background: var(--bg3); height: 2px !important; }
.bars .b:hover { opacity: 1; }
.bars-legend { display: flex; justify-content: space-between; color: var(--muted); font-size: .75rem; margin-top: 6px; }
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.t th, table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.t th:first-child, table.t td:first-child { text-align: left; white-space: normal; }
table.t th { color: var(--muted); font-weight: 500; }
table.t td.money { font-weight: 600; }
table.t tr.sub td { color: var(--muted); font-size: .8rem; padding-top: 2px; }
.tag { font-size: .7rem; padding: 2px 7px; border-radius: 999px; margin-left: 6px; }
.tag.free { background: rgba(63,185,80,.15); color: var(--ok); }
.tag.paid { background: rgba(217,119,87,.15); color: var(--accent); }
.steps { margin: 8px 0 0; padding-left: 20px; line-height: 1.6; }

/* 2FA */
.twofa { display: grid; gap: 10px; justify-items: start; margin-bottom: 12px; }
.twofa img { background: #fff; border-radius: 12px; padding: 8px; }
.secret { background: var(--bg3); padding: 6px 10px; border-radius: 8px; word-break: break-all; cursor: pointer; font-size: .85rem; }

/* Docker */
.containers { display: grid; gap: 12px; }
.container { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.container .info { min-width: 0; }
.container .name { font-weight: 600; }
.container .meta { color: var(--muted); font-size: .8rem; word-break: break-all; }
.state { font-size: .75rem; padding: 3px 9px; border-radius: 999px; margin-left: 8px; }
.state.running { background: rgba(63,185,80,.15); color: var(--ok); }
.state.exited, .state.dead { background: rgba(248,81,73,.15); color: var(--bad); }
.state.other { background: rgba(210,153,34,.15); color: var(--warn); }
.container .btns { display: flex; gap: 6px; flex-wrap: wrap; }

/* Chat */
#view-claude { padding: 0; max-width: none; height: 100%; display: flex; }
.chat-layout { display: flex; height: 100%; flex: 1; min-width: 0; }
.chat-list { width: 270px; border-right: 1px solid var(--line); padding: 14px; overflow: auto; background: var(--bg); }
#chatItems { margin-top: 12px; display: grid; gap: 4px; }
.chat-item { display: flex; align-items: center; gap: 6px; padding: 10px; border-radius: 10px; cursor: pointer; color: var(--muted); font-size: .9rem; }
.chat-item:hover, .chat-item.active { background: var(--bg3); color: var(--text); }
.chat-item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .del { opacity: 0; background: none; border: none; color: var(--muted); cursor: pointer; }
.chat-item:hover .del { opacity: 1; }
.chat-item .run { color: var(--accent); }
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
#toggleChats { display: none; }
.chat-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.auto-banner { background: rgba(210,153,34,.12); color: var(--warn); font-size: .85rem; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.messages > * { flex-shrink: 0; }
.messages { flex: 1; min-width: 0; overflow-x: hidden; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 820px; width: 100%; min-width: 0; margin: 0 auto; }
.msg.user .bubble { background: var(--bg3); border: 1px solid var(--line); margin-left: auto; max-width: 85%; width: fit-content; white-space: pre-wrap; }
.bubble { padding: 12px 14px; border-radius: 14px; line-height: 1.55; overflow-wrap: anywhere; }
.msg.assistant .bubble { padding: 4px 2px; }
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow: auto; font-size: .85rem; }
.bubble code { background: var(--bg3); padding: 1px 6px; border-radius: 6px; font-size: .88em; }
.bubble pre code { background: none; padding: 0; }
.bubble ul, .bubble ol { margin: 0 0 10px; padding-left: 22px; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { margin: 12px 0 8px; font-size: 1.05rem; }
.msg.error .bubble { border: 1px solid rgba(248,81,73,.5); color: var(--bad); background: rgba(248,81,73,.06); }
.msg.info .bubble { color: var(--muted); font-size: .9rem; }
.tool { border: 1px solid var(--line); border-radius: 12px; background: var(--bg2); font-size: .88rem; overflow: hidden; }
.tool summary { list-style: none; cursor: pointer; padding: 10px 12px; display: flex; gap: 10px; align-items: baseline; }
.tool summary::-webkit-details-marker { display: none; }
.tool .tname { color: var(--accent); font-weight: 600; flex-shrink: 0; }
.tool .tsum { font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.tool .tstat { flex-shrink: 0; }
.tool pre { margin: 0; padding: 10px 12px; border-top: 1px solid var(--line); max-height: 320px; overflow: auto; white-space: pre-wrap; font-size: .8rem; color: var(--muted); }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.perm { border: 1px solid var(--accent); background: rgba(217,119,87,.08); border-radius: 14px; padding: 14px; display: grid; gap: 10px; }
.perm.danger { border-color: var(--bad); background: rgba(248,81,73,.08); }
.perm .ptitle { font-weight: 600; }
.perm pre { margin: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; white-space: pre-wrap; word-break: break-all; font-size: .85rem; max-height: 240px; overflow: auto; }
.perm .pbtns { display: flex; gap: 8px; flex-wrap: wrap; }
.perm .warn { color: var(--bad); font-size: .85rem; }
.auto-note { font-size: .8rem; color: var(--warn); max-width: 820px; width: 100%; margin: 0 auto; }
.thinking { color: var(--muted); font-size: .9rem; display: flex; gap: 8px; align-items: center; max-width: 820px; width: 100%; margin: 0 auto; }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 520px; }
.empty-ico { font-size: 2.4rem; color: var(--accent); }
.suggestions { display: grid; gap: 8px; margin-top: 16px; }
.chip { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; cursor: pointer; text-align: left; color: var(--text); }
.chip:hover { border-color: var(--accent); }
.composer { display: flex; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); align-items: flex-end; max-width: 860px; width: 100%; margin: 0 auto; }
.composer textarea { resize: none; max-height: 180px; }
.cost { text-align: center; font-size: .75rem; color: var(--muted); }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.slider { width: 38px; height: 22px; background: var(--bg3); border: 1px solid var(--line); border-radius: 99px; position: relative; transition: background .2s; }
.slider::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--muted); transition: transform .2s, background .2s; }
.switch input:checked + .slider { background: rgba(210,153,34,.3); border-color: var(--warn); }
.switch input:checked + .slider::after { transform: translateX(16px); background: var(--warn); }
.switch-label { font-size: .85rem; color: var(--muted); }

/* Modal y toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-card { background: var(--bg2); border: 1px solid var(--line); border-radius: 16px; width: 100%; max-width: 900px; max-height: 85vh; display: flex; flex-direction: column; }
.modal-card header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-card h3 { margin: 0; font-size: 1rem; }
.modal-card pre { margin: 0; padding: 16px; overflow: auto; white-space: pre-wrap; word-break: break-all; font-size: .8rem; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 20px); background: var(--bg3); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; z-index: 60; max-width: 90vw; }

/* Celular */
@media (max-width: 760px) {
  .app { flex-direction: column-reverse; }
  .nav { width: 100%; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); flex-direction: row; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); border-right: none; border-top: 1px solid var(--line); justify-content: space-around; }
  .brand { display: none; }
  .nav-btn { flex-direction: column; gap: 2px; font-size: .64rem; padding: 6px 2px; flex: 1; align-items: center; min-width: 0; }
  .nav-btn .ico { font-size: 1.1rem; }
  .badge { position: absolute; top: 2px; right: 18%; margin: 0; }
  .view { padding: 16px; }
  .grid.stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat .value { font-size: 1.35rem; }
  .chat-list { position: fixed; z-index: 40; top: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); left: 0; width: 82%; transform: translateX(-100%); transition: transform .2s; border-right: 1px solid var(--line); }
  .chat-list.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.6); }
  #toggleChats { display: block; }
  .switch .switch-label { display: none; }
  .model-select { max-width: 130px; }
  .switch.big .switch-label { display: inline; }
  .msg.user .bubble { max-width: 92%; }
  .keybar { display: flex; }
  .term-head .btn { padding: 6px 8px; }
}
@media (pointer: coarse) { .keybar { display: flex; } }
