/* APIChat - tema oscuro responsive (chat + admin) */

:root {
  --bg: #0b0f14;
  --bg-soft: #0f151c;
  --panel: #121a23;
  --panel-2: #16202b;
  --border: #232f3c;
  --border-soft: #1a2430;
  --text: #e7eef5;
  --muted: #8a99a8;
  --accent: #FFC107;
  --accent-2: #FFB300;
  --accent-soft: rgba(255, 193, 7, .14);
  --on-accent: #101418;
  --danger: #f85149;
  --warn: #d29922;
  --user-bubble: #1b2a38;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
:root { --safe-bottom: env(safe-area-inset-bottom, 0px); }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre { font-family: var(--mono); }

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Botones ---------- */
.btn-primary,
.btn-ghost,
.btn-new,
.icon-btn,
.send-btn,
.stop-btn {
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  transition: background .15s, border-color .15s, color .15s, transform .05s;
}

.btn-primary {
  background: var(--accent-2);
  color: var(--on-accent);
  border-color: var(--accent-2);
  padding: 10px 16px;
  font-weight: 600;
  width: 100%;
}
.btn-primary:hover { background: var(--accent); }
.btn-primary:active { transform: translateY(1px); }
.btn-link { display: inline-block; text-align: center; text-decoration: none; }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
  padding: 10px 14px;
}
.btn-ghost:hover { background: var(--panel-2); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-danger { color: var(--danger); border-color: rgba(248, 81, 73, .4); }
.btn-danger:hover { background: rgba(248, 81, 73, .12); }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
  padding: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
}
.icon-btn svg {
  width: 18px;
  height: 18px;
  display: block;
}
.icon-btn[hidden] {
  display: none;
}
.icon-btn:hover { color: var(--text); background: var(--panel-2); }

/* ---------- Alertas ---------- */
.alert {
  background: rgba(248, 81, 73, .12);
  border: 1px solid rgba(248, 81, 73, .35);
  color: #ffb3b0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin: 12px 0;
  font-size: 14px;
}
.alert-info { background: rgba(88, 166, 255, .1); border-color: rgba(88, 166, 255, .3); color: #a9d1ff; }
.alert-ok { background: var(--accent-soft); border-color: rgba(255, 193, 7, .38); color: #FFE9A8; }

/* ---------- Login / instalador ---------- */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: calc(24px + env(safe-area-inset-top, 0px)) 24px calc(24px + env(safe-area-inset-bottom, 0px));
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(255, 193, 7, .10), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(88, 166, 255, .08), transparent 60%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.auth-card-wide { max-width: 760px; }

/* ---------- Instalador ---------- */
.installer-card { max-width: 560px; }
.installer-head { text-align: center; margin-bottom: 8px; }
.installer-head .brand-mark { margin: 0 auto 12px; width: 54px; height: 54px; font-size: 26px; }
.installer-head h1 { margin: 0; font-size: 30px; }
.step-indicator { text-align: center; color: var(--muted); font-size: 14px; margin: 0 0 22px; }
.input-wrap { position: relative; display: block; font-size: 15px; color: var(--text); }
.input-wrap input { padding-right: 46px; }
.eye-btn {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
  background: transparent; border: none; color: var(--muted);
  font-size: 16px; line-height: 1; padding: 7px 9px; border-radius: 8px; cursor: pointer;
}
.eye-btn:hover { color: var(--text); background: var(--panel-2); }
.success-box { text-align: center; padding: 8px 0 2px; }
.success-mark {
  width: 66px; height: 66px; margin: 0 auto 16px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); border: 1px solid rgba(255, 193, 7, .42);
  color: var(--accent); font-size: 30px; font-weight: 700;
}
.success-box h2 { margin: 0 0 8px; font-size: 23px; }
.success-box p { margin: 0 0 18px; }
.success-box .small { margin-top: 12px; }
.installer-card .alert { margin: 0 0 18px; }
.installer-card code { background: var(--panel-2); padding: 1px 5px; border-radius: 5px; }

/* ---------- Agente (Ajustes) ---------- */
.agent-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
}
.agent-state { display: grid; gap: 8px; }
.agent-state .status { font-size: 14px; }
.agent-state .status .dot { vertical-align: middle; margin-right: 6px; }
.grant-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.grant-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-soft);
}
.grant-list li:last-child { border-bottom: none; padding-bottom: 0; }
.grant-list .inline { margin: 0; }
.grant-list code { font-size: 13px; }
.token-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; align-items: center; }
.token-box {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 10px;
}
.token-box pre { margin: 0; overflow-x: auto; flex: 1 1 320px; }
.token-box code { font-size: 13px; word-break: break-all; }
.token-box .btn-ghost { flex: 0 0 auto; }

.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.auth-brand h1 { margin: 0; font-size: 20px; }
.auth-brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.brand-mark {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  color: #04120a;
  font-weight: 800;
  font-size: 20px;
  flex: 0 0 auto;
}

.auth-card label { display: block; margin-bottom: 14px; }
.auth-card label span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

input:not([type]), input[type="text"], input[type="password"], input[type="email"], input[type="url"], input[type="number"], input[type="search"], select, textarea {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font: inherit;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[disabled] { opacity: .5; }

.auth-foot { margin-top: 18px; text-align: center; color: var(--muted); font-size: 12px; }

.install-form h2 { font-size: 15px; margin: 22px 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.summary dl { display: grid; grid-template-columns: 180px 1fr; gap: 8px 12px; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; }
form.inline { display: inline; }

/* ---------- App: layout ---------- */
.app-body { overflow: hidden; overscroll-behavior: none; }
.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  height: 100dvh;
  height: var(--app-height, 100dvh);
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  border-right: 1px solid var(--border-soft);
  min-height: 0;
}

.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 14px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text span { font-size: 11px; color: var(--muted); }
.sidebar-close { display: none; }

.btn-new {
  margin: 0 12px 10px;
  padding: 10px 12px;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text);
  text-align: left;
  font-size: 14px;
}
.btn-new:hover { background: var(--panel); border-color: var(--accent); }

.conv-search { padding: 0 12px 8px; }
.conv-search input {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 12.5px;
  font-family: inherit;
}
.conv-search input:focus { outline: none; border-color: var(--accent); }

.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }
.conv-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--text);
  font-size: 13.5px;
  cursor: pointer;
  border: 1px solid transparent;
}
.conv-item:hover { background: var(--panel); }
.conv-item.active { background: var(--panel-2); border-color: var(--border); }
.conv-item .conv-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .conv-pin,
.conv-item .conv-del { opacity: 0; color: var(--muted); font-size: 13px; }
.conv-item:hover .conv-pin,
.conv-item:hover .conv-del { opacity: 1; }
.conv-item .conv-pin.active { opacity: 1; color: var(--warn); }
.conv-item .conv-pin:hover { color: var(--warn); }
.conv-item .conv-del:hover { color: var(--danger); }
.conv-badge {
  min-width: 18px; height: 18px; padding: 0 5px;
  display: inline-grid; place-items: center;
  background: var(--accent-2); color: var(--on-accent);
  border-radius: 99px; font-size: 10px; font-weight: 700;
}
.conv-needs {
  font-size: 13px;
  line-height: 1;
  animation: blink 1.2s infinite;
}
.conv-empty { color: var(--muted); font-size: 13px; padding: 10px; }

.sidebar-foot { border-top: 1px solid var(--border-soft); padding: 10px 12px 12px; display: grid; gap: 10px; }

.quota { font-size: 12px; color: var(--muted); }
.quota strong { color: var(--text); font-size: 14px; margin-left: 4px; }
.quota-est { display: block; margin-top: 2px; }
.quota-bar { height: 5px; background: var(--panel-2); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.quota-bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .3s; }
.quota-bar span.warn { background: var(--warn); }
.quota-bar span.danger { background: var(--danger); }

.status { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status .dot.ok { background: var(--accent); box-shadow: 0 0 8px rgba(255, 193, 7, .55); }
.status .dot.warn { background: var(--warn); box-shadow: 0 0 8px rgba(210, 153, 34, .55); }
.status .dot.bad { background: var(--danger); }

.user-row { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--panel-2); color: var(--text);
  font-size: 13px; font-weight: 700; flex: 0 0 auto;
}
.user-name { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 40; }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.chat-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(11, 15, 20, .8);
  backdrop-filter: blur(8px);
}
.chat-head h1 { font-size: 15px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.menu-btn { display: none; }

.config-banner {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  flex-wrap: wrap;
  padding: 9px 16px;
  background: rgba(210, 153, 34, .12);
  border-bottom: 1px solid rgba(210, 153, 34, .32);
  color: #f2d28a;
  font-size: 13px;
}
.config-banner[hidden] { display: none; }
.config-banner a { color: var(--warn); font-weight: 600; }
.config-banner a:hover { color: #f5c451; }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 16px 12px;
  scroll-behavior: smooth;
}

.msg { max-width: 820px; margin: 0 auto 18px; display: flex; gap: 12px; position: relative; }
.msg .bubble {
  padding: 12px 15px;
  border-radius: var(--radius);
  line-height: 1.55;
  font-size: 15px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg .quote {
  border-left: 2px solid var(--accent);
  background: rgba(255, 193, 7, .08);
  border-radius: 5px;
  padding: 5px 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
.msg .quote strong { display: block; color: var(--accent); font-size: 10px; margin-bottom: 1px; }
.msg .quote span { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.msg-actions {
  position: absolute;
  top: -10px;
  right: 8px;
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s;
}
.msg:hover .msg-actions,
.msg:focus-within .msg-actions { opacity: 1; pointer-events: auto; }
.msg.user .msg-actions { right: 8px; }
.msg-action {
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 5px;
  padding: 4px 6px;
  font-size: 12px;
  cursor: pointer;
  line-height: 1;
}
.msg-action:hover { background: var(--panel-2); color: var(--text); }
.msg-action.danger:hover { color: var(--danger); }

.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--user-bubble); border: 1px solid #24384a; border-bottom-right-radius: 6px; max-width: 85%; }
.msg.user .user-text { white-space: pre-wrap; }
.msg.assistant .bubble { background: transparent; max-width: 100%; padding-left: 0; }
.msg.assistant .who { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.msg.assistant .bubble { border-bottom-left-radius: 6px; }

.msg .bubble p { margin: 0 0 10px; }
.msg .bubble p:last-child { margin-bottom: 0; }
.msg .bubble ul, .msg .bubble ol { margin: 8px 0 10px; padding-left: 22px; }
.msg .bubble li { margin: 3px 0; }
.msg .bubble h3 { font-size: 15px; margin: 14px 0 6px; }
.msg .bubble a { color: #6cb6ff; }
.msg .bubble code {
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: .9em;
}
.msg .bubble pre {
  position: relative;
  background: #0a1017;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 30px 12px 12px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 13px;
  line-height: 1.45;
}
.msg .bubble pre code { background: none; border: none; padding: 0; }
.code-lang {
  position: absolute;
  top: 7px;
  left: 10px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  pointer-events: none;
}
.copy-code {
  position: absolute; top: 6px; right: 6px;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--muted); border-radius: 6px;
  font-size: 11px; padding: 3px 7px; cursor: pointer;
}
.copy-code:hover { color: var(--text); }

/* ---------- Tablas y fórmulas ---------- */
.table-wrap {
  margin: 10px 0;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.table-wrap table {
  border-collapse: collapse;
  width: 100%;
  min-width: 340px;
  font-size: 13px;
}
.table-wrap th,
.table-wrap td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
  text-align: left;
  vertical-align: top;
}
.table-wrap th {
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
}
.table-wrap tbody tr:nth-child(even) { background: rgba(255, 255, 255, .025); }
.table-wrap tbody tr:last-child td { border-bottom: none; }
.math-block {
  margin: 10px 0;
  overflow-x: auto;
}
.math-block .katex-display {
  margin: .5em 0;
  text-align: left;
}
.katex { font-size: 1.05em; }

.typing { display: inline-flex; gap: 4px; align-items: center; height: 18px; margin-left: 4px; vertical-align: middle; }
.msg .bubble > .typing { display: inline-flex; margin: 6px 0 0; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }
.agent-status {
  display: flex; align-items: center; gap: 7px;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}
.agent-status-dot {
  color: var(--accent);
  font-size: 9px;
  animation: blink 1.2s infinite;
}
.agent-status span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* Actividad cronologica de herramientas (feed tipo Telegram). */
.agent-feed {
  margin: 8px 0 6px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, .02);
  font-size: 12.5px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 260px;
  overflow-y: auto;
}
.agent-feed-head {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  opacity: .8;
  margin-bottom: 2px;
}
.agent-feed-row {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
}
.agent-feed-icon { width: 18px; text-align: center; flex: none; }
.agent-feed-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.agent-feed-mark { margin-left: auto; flex: none; opacity: .7; }
.agent-feed-row.running .agent-feed-mark { animation: blink 1.2s infinite; }
.agent-feed-row.done .agent-feed-mark { color: #7ee787; }
.agent-feed-row.error { color: #ffb3b0; }

.msg.assistant .bubble.local {
  color: var(--muted);
  font-size: 14px;
  border-left: 2px solid var(--border);
  padding-left: 10px;
}
.msg.assistant .bubble.error {
  border-left: 2px solid rgba(248, 81, 73, .55);
  padding-left: 10px;
}

/* ---------- Adjuntos ---------- */
.attachments { display: grid; gap: 8px; margin-top: 10px; }
.chat-image { margin: 0; }
.chat-image img {
  display: block;
  max-width: 100%;
  max-height: 420px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-soft);
}
.chat-image figcaption {
  display: flex; gap: 10px; align-items: center;
  margin-top: 5px; color: var(--muted); font-size: 12px;
}
.chat-image figcaption span:first-child {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-image figcaption a { color: var(--accent); }
.attachment-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.attachment-icon {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  flex: 0 0 auto;
  border-radius: 9px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px; font-weight: 700;
}
.attachment-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.attachment-info strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-info small { color: var(--muted); font-size: 11px; }
.attachment-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.md-image {
  max-width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin: 6px 0;
}
.audio-attachment {
  margin-top: 8px;
  padding: 8px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.audio-attachment audio { width: 100%; display: block; }
.audio-meta {
  display: flex; align-items: center; gap: 8px;
  margin-top: 5px; color: var(--muted); font-size: 11px;
}
.audio-meta span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audio-meta a { color: var(--accent); }

@media (max-width: 520px) {
  .attachment-card { flex-wrap: wrap; }
  .attachment-actions { width: 100%; justify-content: flex-start; }
}

/* ---------- Aprobaciones del agente ---------- */
.approval-card {
  margin: 0 0 10px;
  padding: 12px;
  border: 1px solid rgba(210, 153, 34, .45);
  border-radius: 10px;
  background: rgba(210, 153, 34, .08);
}
.approval-card.approved {
  border-color: rgba(255, 193, 7, .45);
  background: rgba(255, 193, 7, .08);
}
.approval-card.denied,
.approval-card.expired {
  border-color: rgba(248, 81, 73, .4);
  background: rgba(248, 81, 73, .07);
}
.approval-card.resolved { padding: 0; }
.approval-details { padding: 8px 10px; }
.approval-summary {
  cursor: pointer;
  list-style: none;
  color: #e3b341;
  font-size: 12px;
  font-weight: 600;
}
.approval-summary::-webkit-details-marker { display: none; }
.approval-summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 6px;
  color: var(--muted);
}
.approval-details[open] .approval-summary::before { content: '▾'; }
.approval-hint {
  color: var(--muted);
  font-weight: 400;
}
.approval-card.approved .approval-summary { color: #7ee787; }
.approval-card.denied .approval-summary,
.approval-card.expired .approval-summary { color: #ffb3b0; }
.approval-details .approval-desc { margin-top: 8px; }
.approval-details .approval-command { margin-top: 8px; }
.approval-head {
  color: #e3b341;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}
.approval-card.approved .approval-head { color: #7ee787; }
.approval-card.denied .approval-head,
.approval-card.expired .approval-head { color: #ffb3b0; }
.approval-desc {
  color: var(--text);
  font-size: 13px;
  margin-bottom: 8px;
}
.approval-command {
  margin: 0 0 10px;
  padding: 10px;
  max-height: 240px;
  overflow: auto;
  background: #0a1017;
  border: 1px solid var(--border);
  border-radius: 8px;
  white-space: pre-wrap;
  font-size: 12px;
  line-height: 1.45;
}
.approval-command code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}
.approval-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.approval-btn { font-size: 12px; }
.approval-btn.deny {
  color: var(--danger);
  border-color: rgba(248, 81, 73, .4);
}
.approval-btn:disabled { opacity: .5; cursor: default; }
.approval-status {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}
.approval-card.approved .approval-status { color: #7ee787; }
.approval-card.denied .approval-status,
.approval-card.expired .approval-status { color: #ffb3b0; }

/* Banner fijo de aprobacion: visible aunque el mensaje quede fuera de vista. */
.approval-banner {
  position: sticky;
  bottom: 0;
  z-index: 6;
  margin: 0 0 8px;
  padding: 10px 12px;
  border: 1px solid rgba(240, 180, 60, .45);
  border-radius: 12px;
  background: rgba(58, 42, 12, .94);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.approval-banner[hidden] { display: none; }
.approval-banner-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #ffd479;
}
.approval-banner-count { color: var(--muted); font-size: 12px; }
.approval-banner-desc {
  font-size: 12.5px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.approval-banner-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.approval-banner-actions .deny {
  color: var(--danger);
  border-color: rgba(248, 81, 73, .4);
}


/* ---------- Menú de comandos "/" ---------- */
.slash-menu {
  position: absolute;
  left: -1px; right: -1px;
  bottom: calc(100% + 8px);
  z-index: 30;
  max-height: min(45vh, 360px);
  overflow-y: auto;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.slash-menu[hidden] { display: none; }
.slash-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none; border-radius: 9px;
  background: transparent;
  color: var(--text);
  font: inherit; text-align: left;
  cursor: pointer;
}
.slash-item:hover, .slash-item.active { background: var(--panel-2); }
.slash-icon {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 14px;
}
.slash-text { display: flex; flex-direction: column; min-width: 0; }
.slash-text strong { font-size: 14px; font-weight: 600; }
.slash-text small { color: var(--muted); font-size: 12px; }
.btn-new:disabled { opacity: .5; cursor: not-allowed; }

.welcome { max-width: 640px; margin: 8vh auto 0; text-align: center; padding: 0 16px; }
.welcome h2 { font-size: 22px; margin: 0 0 8px; }
.welcome p { color: var(--muted); margin: 0 0 22px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  background: var(--panel); border: 1px solid var(--border);
  color: var(--text); padding: 9px 13px; border-radius: 999px;
  font-size: 13px; cursor: pointer;
}
.chip:hover { border-color: var(--accent); background: var(--panel-2); }

.scroll-btn {
  position: absolute; right: 26px; bottom: 108px; z-index: 5;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); display: grid; place-items: center; cursor: pointer;
}

/* ---------- Composer ---------- */
.composer { padding: 10px 16px calc(16px + var(--safe-bottom)); }
.reply-bar {
  max-width: 820px;
  margin: 0 auto 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 12px;
  background: var(--panel-2);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
}
.reply-bar[hidden] { display: none; }
.reply-bar-body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.reply-bar strong { color: var(--accent); font-size: 11px; }
.reply-bar span { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar .icon-btn { padding: 4px 6px; font-size: 14px; }
.pending-uploads {
  max-width: 820px;
  margin: 0 auto 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pending-uploads[hidden] { display: none; }
.pending-upload {
  display: flex; align-items: center; gap: 6px;
  max-width: 240px;
  padding: 5px 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 11px;
}
.pending-upload img {
  width: 34px; height: 34px; object-fit: cover;
  border-radius: 5px; flex: 0 0 auto;
}
.pending-upload span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-upload .remove {
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 13px; padding: 2px;
}
.pending-upload .remove:hover { color: var(--danger); }
.attach-btn { flex: 0 0 auto; padding: 8px; font-size: 17px; }
.mic-btn { flex: 0 0 auto; padding: 8px; font-size: 16px; }
.mic-btn.recording {
  color: #fff;
  background: var(--danger);
  animation: pulse-record 1s infinite;
}
@keyframes pulse-record { 0%,100% { opacity: 1; } 50% { opacity: .65; } }
.composer-box {
  max-width: 820px; margin: 0 auto;
  position: relative;
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 8px 8px 14px;
}
.composer-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer.drag-over .composer-box { border-color: var(--accent); background: var(--accent-soft); }
.composer textarea {
  flex: 1; resize: none; border: none; background: transparent; padding: 6px 0;
  max-height: 180px; min-height: 24px; line-height: 1.45;
}
.composer textarea:focus { box-shadow: none; }

.send-btn, .stop-btn {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  background: var(--accent-2); color: var(--on-accent); border: none; flex: 0 0 auto;
}
.send-btn[hidden], .stop-btn[hidden], .scroll-btn[hidden] { display: none; }
.send-btn:hover { background: var(--accent); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }
.stop-btn { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }

.composer-hint {
  max-width: 820px; margin: 6px auto 0;
  display: flex; justify-content: space-between;
  color: var(--muted); font-size: 11px; padding: 0 4px;
}
.counter.warn { color: var(--warn); }

/* ---------- Admin ---------- */
.admin-body { background: var(--bg); }
.admin-shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100dvh; }
.admin-side {
  background: var(--bg-soft); border-right: 1px solid var(--border-soft);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 18px;
}
.admin-nav { display: grid; gap: 4px; }
.admin-nav a {
  color: var(--muted); padding: 9px 10px; border-radius: 8px; font-size: 14px;
}
.admin-nav a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.admin-nav a.active { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.admin-user { margin-top: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; }

.admin-main { padding: 22px 26px 40px; min-width: 0; }
.admin-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.admin-head h1 { font-size: 22px; margin: 0; }
.admin-main h2 { font-size: 15px; margin: 26px 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpis-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.kpi span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.kpi strong { font-size: 22px; }
.kpi strong small { font-size: 12px; color: var(--muted); font-weight: 400; }
.kpi small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }

.admin-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.admin-toolbar .btn-link { width: auto; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th, .data-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border-soft); white-space: nowrap; }
.data-table thead th { background: var(--bg-soft); color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.data-table tbody tr:hover { background: rgba(255, 255, 255, .02); }
.data-table td.actions { display: flex; gap: 6px; align-items: center; }

.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  border: 1px solid var(--border); color: var(--muted);
}
.pill-admin { color: #a9d1ff; border-color: rgba(88, 166, 255, .4); background: rgba(88, 166, 255, .1); }
.pill-user { color: var(--muted); }
.pill-ok { color: #FFE9A8; border-color: rgba(255, 193, 7, .42); background: var(--accent-soft); }
.pill-off { color: #ffb3b0; border-color: rgba(248, 81, 73, .35); background: rgba(248, 81, 73, .08); }

.meter { width: 90px; height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 6px; }
.meter span { display: block; height: 100%; background: var(--accent); }
.meter-warn span { background: var(--warn); }
.meter-danger span { background: var(--danger); }
.meter-unlimited span { width: 100%; background: var(--border); }

.admin-form { max-width: 760px; }
.admin-form h2 { margin-top: 26px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.settings-intro { margin: 0 0 14px; font-size: 13px; }
.admin-form label { display: block; }
.admin-form label > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.admin-form label.check { display: flex; align-items: center; gap: 8px; margin-top: 26px; }
.admin-form label.check input { width: auto; }
.admin-form label.check span { margin: 0; color: var(--text); font-size: 14px; }
.quota-edit { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; }
.quota-quick { display: flex; gap: 8px; flex-wrap: wrap; }
.estimate { margin: 0; font-size: 15px; color: var(--accent); font-weight: 600; }
.form-actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.form-actions .btn-primary { width: auto; }

.filters { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 18px; }
.filters label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.filters select { min-width: 160px; }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 290px; z-index: 50;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: inline-flex; }
  .menu-btn { display: inline-flex; }
  .messages { padding: 16px 12px 8px; }
  .msg.user .bubble { max-width: 92%; }
  .scroll-btn { right: 14px; bottom: 96px; }

  .admin-shell { grid-template-columns: 1fr; }
  .admin-side { flex-direction: row; align-items: center; gap: 10px; overflow-x: auto; }
  .admin-side .brand-text { display: none; }
  .admin-nav { display: flex; gap: 4px; }
  .admin-user { margin: 0 0 0 auto; }
  .admin-main { padding: 16px 14px 32px; }
  .kpis, .kpis-2 { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .composer-hint span:first-child { display: none; }
  .auth-card { padding: 20px; }
  .kpi strong { font-size: 19px; }
}

/* Scrollbars */
.conv-list::-webkit-scrollbar, .messages::-webkit-scrollbar, .table-wrap::-webkit-scrollbar { width: 8px; height: 8px; }
.conv-list::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb, .table-wrap::-webkit-scrollbar-thumb {
  background: #24313f; border-radius: 99px;
}

/* ---------- Instalar PWA ---------- */
.install-help {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, .62);
  backdrop-filter: blur(3px);
}
.install-help-card {
  width: min(360px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  text-align: center;
  display: grid;
  justify-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
}
.install-help-card img { width: 56px; height: 56px; border-radius: 14px; }
.install-help-card h2 { margin: 0; font-size: 18px; }
.install-help-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.install-help-card button { margin-top: 4px; }

