/* IA Oficina - estilo terminal financiera. Solo fuentes del sistema (nada se descarga de internet). */
:root {
  --bg: #07090c;
  --panel: #0d1117;
  --panel-2: #121821;
  --line: #1f2a36;
  --line-2: #2b3846;
  --text: #d3dae3;
  --dim: #6f7d8c;
  --accent: #ffb000;
  --accent-dim: #8a6200;
  --ok: #2bd47d;
  --bad: #ff5b5b;
  --warn: #f5c542;
  --cyan: #3fc6f2;
  --mono: "Cascadia Mono", "Cascadia Code", Consolas, "Lucida Console", monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); font: 13px/1.5 var(--mono);
  display: grid; grid-template-columns: 250px 1fr; grid-template-rows: 44px 1fr;
  grid-template-areas: "top top" "side main"; overflow: hidden;
}
button { font: inherit; cursor: pointer; }
.accent { color: var(--accent); }
.dim { color: var(--dim); }
.small { font-size: 11px; }

/* ---------- Barra superior ---------- */
.topbar {
  grid-area: top; display: flex; align-items: center; gap: 16px; padding: 0 14px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: 2px; white-space: nowrap; }
.brand-mark { color: var(--accent); }
.status { display: flex; gap: 8px; flex: 1; justify-content: center; flex-wrap: wrap; }
.pill {
  border: 1px solid var(--line-2); padding: 1px 8px; font-size: 11px; letter-spacing: 1px;
  color: var(--dim); white-space: nowrap;
}
.pill-ok { color: var(--ok); border-color: #1d5a3c; }
.pill-bad { color: var(--bad); border-color: #6b2525; }
.pill-warn { color: var(--warn); border-color: #6b5a1d; }
.top-right { display: flex; align-items: center; gap: 14px; }
.clock { color: var(--accent); font-variant-numeric: tabular-nums; }
.user { color: var(--cyan); }
.btn-ghost {
  background: transparent; color: var(--dim); border: 1px solid var(--line-2); padding: 3px 10px; letter-spacing: 1px;
}
.btn-ghost:hover { color: var(--accent); border-color: var(--accent-dim); }
.btn-xs { padding: 0 6px; font-size: 10px; }
.wide { width: 100%; }

/* ---------- Barra lateral ---------- */
.sidebar {
  grid-area: side; background: var(--panel); border-right: 1px solid var(--line);
  padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto;
}
.side-title { color: var(--accent); font-size: 11px; letter-spacing: 2px; margin: 10px 4px 4px; }
.side-title:first-child { margin-top: 0; }
.fn {
  display: flex; align-items: center; gap: 10px; text-align: left; width: 100%;
  background: transparent; color: var(--text); border: 1px solid transparent; padding: 6px 6px;
}
.fn:hover:not([disabled]) { background: var(--panel-2); border-color: var(--line-2); color: var(--accent); }
.fn[disabled] { color: #3c4754; cursor: not-allowed; }
.fkey {
  min-width: 26px; text-align: center; font-size: 10px; color: var(--bg); background: var(--accent);
  padding: 0 3px; font-weight: 700;
}
.fn[disabled] .fkey { background: #2b3846; color: #56626f; }
.side-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }

/* ---------- Area principal ---------- */
.main { grid-area: main; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.feed { flex: 1; overflow-y: auto; padding: 16px 22px 8px; }
.welcome { border: 1px solid var(--line); background: var(--panel); padding: 14px 16px; margin-bottom: 16px; }
.welcome-title { color: var(--accent); letter-spacing: 2px; font-weight: 700; margin-bottom: 6px; }
.welcome p { margin: 6px 0; max-width: 900px; }
.example {
  display: inline-block; margin: 4px 6px 0 0; padding: 1px 8px; border: 1px dashed var(--line-2);
  color: var(--cyan); cursor: pointer;
}
.example:hover { border-color: var(--cyan); }

.entry { margin: 0 0 14px; }
.entry-user { display: flex; gap: 10px; color: var(--accent); padding: 4px 0; }
.entry-user .user-text { color: #ffe2a3; white-space: pre-wrap; }
.entry-ai { border-left: 2px solid var(--line-2); padding: 2px 0 2px 14px; }
.entry-head { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; font-size: 11px; }
.tag { background: var(--cyan); color: var(--bg); font-weight: 700; padding: 0 6px; font-size: 10px; letter-spacing: 1px; }
.tag-q { background: var(--line-2); color: var(--text); }

.query { margin: 6px 0; }
.query summary { cursor: pointer; display: flex; gap: 10px; align-items: center; font-size: 11px; list-style: none; }
.query summary::-webkit-details-marker { display: none; }
.sql {
  margin: 6px 0 0; padding: 10px 12px; background: #05070a; border: 1px solid var(--line);
  color: #9fd7ff; white-space: pre-wrap; word-break: break-word; font-size: 12px;
}

.result { margin: 8px 0; border: 1px solid var(--line); background: var(--panel); }
.result-meta {
  display: flex; gap: 14px; align-items: center; padding: 4px 10px; border-bottom: 1px solid var(--line);
  font-size: 11px; color: var(--ok);
}
.result-meta .btn-ghost { margin-left: auto; }
.table-scroll { max-height: 380px; overflow: auto; }
table.grid { border-collapse: collapse; width: 100%; font-size: 12px; font-variant-numeric: tabular-nums; }
.grid th {
  position: sticky; top: 0; background: var(--panel-2); color: var(--accent); text-align: left;
  font-weight: 600; text-transform: uppercase; font-size: 10.5px; letter-spacing: 1px;
  padding: 5px 10px; border-bottom: 1px solid var(--line-2); white-space: nowrap;
}
.grid td { padding: 3px 10px; border-bottom: 1px solid #141b24; white-space: nowrap; }
.grid tbody tr:nth-child(even) td { background: #0a0e13; }
.grid tbody tr:hover td { background: #16202b; }
.grid td.num { text-align: right; color: #e8edf2; }
.grid td.neg { color: var(--bad); }
.md-table { margin: 8px 0; border: 1px solid var(--line); }

.answer { margin: 8px 0 4px; max-width: 980px; }
.answer p { margin: 4px 0; }
.answer ul, .answer ol { margin: 4px 0; padding-left: 22px; }
.answer li { margin: 2px 0; }
.answer li::marker { color: var(--accent); }
.answer strong { color: #fff; }
.answer code { background: #05070a; border: 1px solid var(--line); padding: 0 4px; color: #9fd7ff; }
.md-h { color: var(--accent); font-weight: 700; margin: 10px 0 4px; letter-spacing: 1px; }

.working { color: var(--dim); font-size: 12px; margin: 6px 0; }
.working::after { content: "▍"; color: var(--accent); margin-left: 4px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.warn { color: var(--warn); font-size: 12px; margin: 6px 0; }
.verify { font-size: 11px; margin: 6px 0; padding: 3px 8px; display: inline-block; letter-spacing: .5px; }
.verify-ok { color: var(--ok); border: 1px solid #1d5a3c; }
.verify-fix { color: var(--warn); border: 1px dashed #6b5a1d; }
.grid tfoot td {
  position: sticky; bottom: 0; background: var(--panel-2); border-top: 1px solid var(--accent-dim);
  color: var(--accent); font-weight: 700; padding: 4px 10px;
}
.total-label { letter-spacing: 1px; }
.verify-bad { color: var(--bad); border: 1px solid #6b2525; background: #1a0b0b; }
.err { color: var(--bad); margin: 6px 0; }

/* ---------- Reportes ---------- */
.fkey-rep { background: var(--cyan); }
.fkey-mkt { background: var(--ok); }
.btn-exp { margin-left: 0 !important; }
.result-meta .btn-ghost:first-of-type { margin-left: auto; }
.report-card { border: 1px solid var(--line-2); background: var(--panel); padding: 12px 14px; margin: 8px 0; max-width: 980px; }
.report-title { color: var(--accent); font-weight: 700; letter-spacing: 1px; margin-bottom: 8px; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; margin-bottom: 8px; }
.kpi { background: var(--panel-2); border: 1px solid var(--line); padding: 6px 8px; }
.kpi-label { color: var(--dim); font-size: 10.5px; }
.kpi-value { color: #fff; font-weight: 700; font-variant-numeric: tabular-nums; }
.report-narrative { margin: 4px 0 8px; padding-left: 20px; }
.downloads { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.dl {
  text-decoration: none; padding: 4px 10px; border: 1px solid; font-size: 12px; letter-spacing: .5px;
}
.dl-xlsx { color: var(--ok); border-color: #1d5a3c; }
.dl-pdf { color: var(--bad); border-color: #6b2525; }
.dl:hover { background: var(--panel-2); }

.dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--accent-dim); padding: 0; width: 440px;
  font: 13px/1.5 var(--mono);
}
.dialog::backdrop { background: rgba(0, 0, 0, .65); }
.dialog form { padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; }
.dialog-title { color: var(--accent); font-weight: 700; letter-spacing: 2px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 11px; letter-spacing: 1px; color: var(--accent); }
.field[hidden] { display: none; }
.field input, .field select {
  background: #05070a; color: var(--text); border: 1px solid var(--line-2); padding: 6px 8px; font: inherit;
  letter-spacing: 0; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent-dim); }
.checks { display: flex; gap: 16px; color: var(--text); letter-spacing: 0; font-size: 12px; }
.check-ia { font-size: 12px; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.dialog-error { color: var(--bad); min-height: 16px; font-size: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
#rep-go { background: var(--accent); color: var(--bg); border: none; padding: 0 16px; height: 32px; font-weight: 700; letter-spacing: 1px; }

/* ---------- Barra de comandos ---------- */
.cmdbar {
  display: flex; align-items: flex-end; gap: 10px; padding: 10px 16px; margin: 0;
  border-top: 1px solid var(--line); background: var(--panel);
}
.cmdbar .prompt { color: var(--accent); font-size: 18px; line-height: 30px; }
.cmdbar textarea {
  flex: 1; resize: none; background: #05070a; color: var(--text); border: 1px solid var(--line-2);
  padding: 6px 10px; font: inherit; outline: none; min-height: 32px;
}
.cmdbar textarea:focus { border-color: var(--accent-dim); }
#send, #login-btn {
  background: var(--accent); color: var(--bg); border: none; padding: 0 16px; height: 32px;
  font-weight: 700; letter-spacing: 1px;
}
#send:disabled, #login-btn:disabled { background: var(--accent-dim); cursor: wait; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--line-2); }

/* ---------- Login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; grid-template-areas: none; }
.login-box { width: 380px; border: 1px solid var(--line-2); background: var(--panel); padding: 28px; }
.brand-lg { font-size: 18px; }
.login-sub { color: var(--dim); margin: 6px 0 22px; font-size: 12px; }
.login-box form { display: flex; flex-direction: column; gap: 6px; }
.login-box label { color: var(--accent); font-size: 11px; letter-spacing: 2px; margin-top: 8px; }
.login-box input {
  background: #05070a; border: 1px solid var(--line-2); color: var(--text); padding: 8px 10px; font: inherit; outline: none;
}
.login-box input:focus { border-color: var(--accent-dim); }
#login-btn { margin-top: 16px; height: 36px; }
.login-error { color: var(--bad); min-height: 20px; font-size: 12px; }
.login-foot { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 18px; }
.login-box form[hidden], #totp-setup[hidden] { display: none; }
#totp-form { display: flex; flex-direction: column; gap: 6px; }
#totp-btn { background: var(--accent); color: var(--bg); border: none; height: 36px; margin-top: 12px; font-weight: 700; letter-spacing: 1px; }
.totp-help { font-size: 12px; line-height: 1.6; margin: 4px 0 8px; }
.totp-help b { color: var(--accent); }
.totp-qr { display: block; margin: 6px auto 10px; background: #fff; padding: 6px; width: 200px; height: 200px; image-rendering: pixelated; }
#code { font-size: 22px; letter-spacing: 8px; text-align: center; }

.menu-btn { display: none; background: transparent; border: 1px solid var(--line-2); color: var(--accent); font-size: 18px; padding: 0 10px; }

/* ---------- Telefono / pantallas chicas ---------- */
@media (max-width: 800px) {
  body { grid-template-columns: 1fr; grid-template-areas: "top" "main"; font-size: 14px; }
  .menu-btn { display: block; }
  .topbar { gap: 8px; padding: 0 8px; }
  .brand .dim, .status, .clock { display: none; }
  .top-right { margin-left: auto; gap: 8px; }
  .sidebar {
    display: flex; position: fixed; top: 44px; left: 0; bottom: 0; width: 86vw; max-width: 320px; z-index: 20;
    transform: translateX(-105%); transition: transform .2s ease; box-shadow: 4px 0 18px rgba(0, 0, 0, .6);
  }
  body.menu-open .sidebar { transform: none; }
  .fn { padding: 10px 6px; }
  .feed { padding: 10px 10px 6px; }
  .entry-ai { padding-left: 8px; }
  .cmdbar { padding: 8px; gap: 6px; }
  .cmdbar .prompt { display: none; }
  #send { padding: 0 10px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .welcome .example { display: block; }
  .dialog { width: 94vw; }
  .login-box { width: 92vw; padding: 20px; }
}
