:root {
  --bg: #0d0f12;
  --panel: #14171c;
  --panel-2: #1a1e24;
  --line: #262b33;
  --text: #e6e8eb;
  --muted: #8a919c;
  --accent: #d97757;
  --accent-soft: rgba(217, 119, 87, 0.14);
  --ok: #4fb286;
  --warn: #d6a33c;
  --bad: #e0605b;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }

/* login */
.login-body { display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 340px; display: grid; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.login .muted { margin: -6px 0 6px; }
.login input { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.login button { background: var(--accent); border: 0; border-radius: 8px; padding: 10px; font-weight: 600; color: #fff; }
.err { color: var(--bad); min-height: 1.2em; margin: 0; }
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.logo { color: var(--accent); }

/* layout */
.app { display: grid; grid-template-columns: 220px 1fr; height: 100vh; }
.side { border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; background: var(--panel); }
.side .brand { padding: 0 8px 16px; }
.nav { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--muted); border: 0; background: none; text-align: left; width: 100%; }
.nav:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.nav.active { background: var(--accent-soft); color: var(--text); }
.nav .ico { width: 18px; text-align: center; opacity: .9; }
.nav .count { margin-left: auto; font-size: 11px; color: var(--muted); }
.side .spacer { flex: 1; }
.main { overflow: auto; min-width: 0; }
.view { padding: 24px 28px 40px; max-width: 1280px; }
.view-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.view-head h1 { font-size: 20px; margin: 0; }
.view-head .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; }
.btn:hover { border-color: #3a414b; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger { color: var(--bad); }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 28px 0 10px; font-weight: 600; }

/* cards */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 24px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: 12px; }
.bar { height: 6px; background: var(--panel-2); border-radius: 3px; margin-top: 10px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.ok > i { background: var(--ok); } .bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--bad); }

.agent { display: flex; flex-direction: column; gap: 8px; }
.agent .top { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-weight: 700; background: var(--accent-soft); color: var(--accent); flex: none; }
.agent .name { font-weight: 650; }
.agent .role { color: var(--muted); font-size: 13px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 12.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.crons { border-top: 1px solid var(--line); padding-top: 8px; font-size: 12.5px; display: grid; gap: 6px; }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(79,178,134,.15); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.pill { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.accent { color: var(--accent); border-color: rgba(217,119,87,.35); background: var(--accent-soft); }

/* tables */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; background: var(--panel-2); }
tr:last-child td { border-bottom: 0; }
td.mono { white-space: nowrap; }
.group td { background: var(--bg); color: var(--muted); font-size: 12px; font-weight: 600; padding: 6px 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* chat */
.chat { display: grid; grid-template-columns: 250px 1fr; height: 100vh; }
.chat-list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.chat-list .head { padding: 18px 14px 10px; display: flex; gap: 8px; }
.chat-list .head .btn { flex: 1; }
.chat-items { overflow: auto; padding: 0 8px 12px; display: grid; gap: 2px; align-content: start; }
.chat-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; color: var(--muted); cursor: pointer; border: 0; background: none; text-align: left; width: 100%; }
.chat-item:hover { background: var(--panel-2); color: var(--text); }
.chat-item.active { background: var(--accent-soft); color: var(--text); }
.chat-item .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.chat-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.messages { flex: 1; overflow: auto; padding: 24px 28px; }
.messages-inner { max-width: 860px; margin: 0 auto; display: grid; gap: 18px; }
.msg.user { justify-self: end; background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px 14px 4px 14px; padding: 10px 14px; max-width: 80%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant { display: grid; gap: 10px; min-width: 0; }
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md h1, .md h2, .md h3 { font-size: 15px; text-transform: none; letter-spacing: 0; color: var(--text); margin: 16px 0 8px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md pre { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow-x: auto; }
.md code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.md table { margin: 8px 0; border: 1px solid var(--line); }
.md th, .md td { padding: 5px 10px; }
.tool { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-size: 12.5px; }
.tool summary { list-style: none; cursor: pointer; padding: 7px 10px; display: flex; gap: 8px; align-items: center; min-width: 0; }
.tool summary::-webkit-details-marker { display: none; }
.tool .tname { font-weight: 600; flex: none; }
.tool .tin { color: var(--muted); font-family: var(--mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool pre { margin: 0; padding: 8px 10px; border-top: 1px solid var(--line); max-height: 320px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); }
.spin { width: 10px; height: 10px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.meta { color: var(--muted); font-size: 11.5px; }
.msg-error { color: var(--bad); font-size: 13px; }
.composer { border-top: 1px solid var(--line); padding: 14px 28px 18px; }
.composer-inner { max-width: 860px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 8px 8px 14px; }
.composer-inner:focus-within { border-color: #3a414b; }
.composer textarea { flex: 1; background: none; border: 0; outline: none; resize: none; max-height: 220px; padding: 6px 0; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .big { font-size: 20px; color: var(--text); font-weight: 650; margin-bottom: 6px; }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; }
.suggest button { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; color: var(--text); }
.suggest button:hover { border-color: var(--accent); }

.mobile-top { display: none; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; height: auto; min-height: 100vh; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.5); }
  .mobile-top { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
  .view { padding: 18px 16px 32px; }
  .chat { grid-template-columns: 1fr; height: calc(100vh - 53px); height: calc(100dvh - 53px); }
  .chat-list { display: none; }
  .chat.show-list .chat-list { display: flex; }
  .chat.show-list .chat-main { display: none; }
  .messages { padding: 16px; }
  .composer { padding: 10px 16px 14px; }
  .msg.user { max-width: 92%; }
}

/* cuenta */
.account { max-width: 420px; display: grid; gap: 12px; }
.account label { display: grid; gap: 4px; color: var(--muted); font-size: 12.5px; }
.account input { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; color: var(--text); font-size: 14px; }
.ok-msg { color: var(--ok); }

/* actualizaciones */
.nav .count.alert { background: var(--accent); color: #fff; border-radius: 999px; padding: 0 7px; font-weight: 600; }
.banner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--accent-soft); border: 1px solid rgba(217,119,87,.35); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; }
.banner > span:first-child, .banner > span:nth-child(2) { flex: 1; min-width: 200px; }
.banner .spin { flex: none; min-width: 0 !important; }
.banner.warn { background: rgba(214,163,60,.12); border-color: rgba(214,163,60,.4); }
.upd-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.warn-text { color: var(--warn); font-size: 12px; margin-top: 2px; }
.btn:disabled { opacity: .5; cursor: default; }
