:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1d2329;
  --muted: #687280;
  --line: #e4e7eb;
  --soft: #f7f8fa;
  --accent: #0f766e;
  --pos: #047857;
  --neg: #b42318;
  --c-principal: #2563eb;
  --c-binance: #c8960c;
  --c-fausto: #0f766e;
  --warn-bg: #fff6e5;
  --warn-text: #7a4b00;
  --warn-line: #f3d9a4;
  --err-bg: #fdeeee;
  --err-text: #9b1c1c;
  --err-line: #f5c2c2;
  --ok-bg: #e9f7f1;
  --ok-text: #065f46;
  --info-bg: #eef4ff;
  --info-text: #1e40af;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 8px rgba(16, 24, 40, .04);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --card: #1a1f25;
    --text: #e8eaed;
    --muted: #9aa3ad;
    --line: #2b323a;
    --soft: #20262d;
    --accent: #2dd4bf;
    --pos: #34d399;
    --neg: #f87171;
    --c-principal: #60a5fa;
    --c-binance: #facc15;
    --c-fausto: #2dd4bf;
    --warn-bg: #2d2412;
    --warn-text: #fcd58a;
    --warn-line: #5b4517;
    --err-bg: #2f1819;
    --err-text: #fca5a5;
    --err-line: #6b2526;
    --ok-bg: #12291f;
    --ok-text: #86efac;
    --info-bg: #162238;
    --info-text: #93c5fd;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { padding: 20px 16px 48px; }

a { color: var(--accent); }

button { font: inherit; color: inherit; }

.contenedor { max-width: 900px; margin: 0 auto; }

/* ---------- Encabezado ---------- */
.encabezado {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}
.encabezado h1 { margin: 0; font-size: 24px; letter-spacing: -.01em; }
.subtitulo { margin-top: 2px; color: var(--muted); font-size: 13px; }
.usuario { text-align: right; font-size: 12px; color: var(--muted); line-height: 1.6; }
.usuario a { color: var(--muted); }
.btn-link {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--accent); font-size: 12px; text-decoration: underline;
}

/* ---------- Pestañas ---------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 18px;
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.tab.activa { background: var(--text); color: var(--card); }
.tab .punto {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--neg); margin-left: 6px; vertical-align: 2px;
}
.panel { display: none; }
.panel.activo { display: block; }

/* ---------- Tarjetas ---------- */
.tarjeta {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}
.seccion-titulo {
  margin: 26px 0 10px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
.seccion-titulo:first-child { margin-top: 0; }
.etiqueta { font-size: 13px; color: var(--muted); }
.valor { font-size: 20px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.valor small { font-size: 13px; font-weight: 600; color: var(--muted); }
.detalle { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid .tarjeta { margin-bottom: 0; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; word-break: break-all; }

/* ---------- Caja total + distribución ---------- */
.caja { padding: 22px 20px; }
.caja .valor { font-size: 34px; letter-spacing: -.02em; }
.barra {
  display: flex; height: 12px; border-radius: 6px; overflow: hidden;
  background: var(--soft); margin: 18px 0 14px;
}
.barra span { display: block; height: 100%; }
.leyenda { display: grid; gap: 10px; }
.leyenda-fila { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.leyenda-fila .color { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.leyenda-fila .nombre { flex: 1; }
.leyenda-fila .monto { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.leyenda-fila .pct { width: 46px; text-align: right; color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.c-principal { background: var(--c-principal); }
.c-binance { background: var(--c-binance); }
.c-fausto { background: var(--c-fausto); }

details.reglas { font-size: 13.5px; color: var(--muted); }
details.reglas summary { cursor: pointer; font-weight: 600; color: var(--text); }
details.reglas ul { margin: 10px 0 0; padding-left: 18px; }
details.reglas li { margin-bottom: 4px; }

/* ---------- Avisos ---------- */
.aviso {
  border: 1px solid var(--warn-line);
  background: var(--warn-bg);
  color: var(--warn-text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13.5px;
  margin-bottom: 14px;
}
.aviso.error { border-color: var(--err-line); background: var(--err-bg); color: var(--err-text); }
.aviso.ok { border-color: transparent; background: var(--ok-bg); color: var(--ok-text); }
.aviso.info { border-color: transparent; background: var(--info-bg); color: var(--info-text); }
.aviso strong { display: block; margin-bottom: 2px; }
.aviso ul { margin: 6px 0 0; padding-left: 18px; }

/* ---------- Movimientos en tarjetas ---------- */
.filtros { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 5px 12px; font-size: 13px; cursor: pointer; color: var(--muted);
}
.chip.activo { border-color: var(--text); color: var(--text); font-weight: 600; }

.mov { padding: 16px 18px; }
.mov-cabecera { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.mov-monto { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.mov-id { font-size: 12px; color: var(--muted); margin-top: 2px; }
.mov-fecha { text-align: right; font-size: 13px; font-weight: 600; white-space: nowrap; }
.mov-fecha .etiqueta { font-size: 11px; font-weight: 400; }
.mov-datos { margin-top: 12px; display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 13.5px; }
.mov-datos dt { color: var(--muted); }
.mov-datos dd { margin: 0; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.notas {
  margin-top: 12px; padding: 10px 12px; border-radius: 10px;
  background: var(--soft); font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere;
}
.comprobantes { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 9px;
  padding: 7px 11px; font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none; color: var(--text);
}
.btn:hover { border-color: var(--muted); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-primario { background: var(--text); color: var(--card); border-color: var(--text); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; white-space: nowrap;
}
.b-ingreso { background: var(--ok-bg); color: var(--ok-text); }
.b-envio_fausto { background: var(--info-bg); color: var(--info-text); }
.b-interno { background: var(--soft); color: var(--muted); }
.b-salida, .b-pago_caja { background: #f3e8ff; color: #6b21a8; }
.b-pago_fausto { background: var(--warn-bg); color: var(--warn-text); }
.b-ok { background: var(--ok-bg); color: var(--ok-text); }
.b-mal { background: var(--err-bg); color: var(--err-text); }
@media (prefers-color-scheme: dark) {
  .b-salida, .b-pago_caja { background: #2a1838; color: #d8b4fe; }
}

/* ---------- Dirección de Fausto ---------- */
.direccion {
  display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 15px; margin: 10px 0;
}
.direccion span { padding: 2px 4px; border-radius: 4px; background: var(--soft); }
.direccion span.medio { background: var(--info-bg); color: var(--info-text); font-weight: 700; }

/* ---------- Tablas ---------- */
.tabla-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--soft); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.tabla-movs { min-width: 980px; }
td a.mono, td span.mono { white-space: nowrap; }
.tabla-card { padding: 0; overflow: hidden; }

/* ---------- Asistente ---------- */
.chat {
  height: 52vh; min-height: 300px; overflow-y: auto; padding: 4px 2px 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.msg { max-width: 86%; padding: 10px 13px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.msg-ia { align-self: flex-start; background: var(--soft); }
.msg-yo { align-self: flex-end; background: var(--text); color: var(--card); }
.chat-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 8px; }
.chat-form textarea {
  resize: vertical; min-height: 46px; max-height: 160px; padding: 11px 12px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit;
}
.adjunto { display: flex; gap: 10px; align-items: center; font-size: 13px; color: var(--muted); margin-top: 10px; }
.adjunto input { display: none; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50; display: none;
  background: rgba(10, 14, 20, .6); padding: 16px; align-items: center; justify-content: center;
}
.modal.visible { display: flex; }
.modal-caja {
  width: min(960px, 100%); height: min(88vh, 900px); background: var(--card);
  border-radius: 16px; overflow: hidden; display: flex; flex-direction: column;
}
.modal-cabecera { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); gap: 10px; }
.modal-cabecera strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-cerrar { border: 0; background: var(--soft); width: 34px; height: 34px; border-radius: 50%; font-size: 20px; cursor: pointer; flex: 0 0 auto; }
.modal iframe { flex: 1; width: 100%; border: 0; background: #fff; }

/* ---------- Login / estados ---------- */
.login { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.login .tarjeta { max-width: 400px; width: 100%; text-align: center; padding: 28px 24px; }
.login h1 { margin: 0 0 8px; font-size: 24px; }
.login p { color: var(--muted); margin: 0 0 20px; }
.login .g_id_signin { display: flex; justify-content: center; }
.error-texto { color: var(--neg); font-size: 13.5px; margin-top: 14px; }
.cargando { padding: 40px 0; text-align: center; color: var(--muted); }
.vacio { color: var(--muted); font-size: 14px; }
.pie { margin-top: 12px; font-size: 12px; color: var(--muted); text-align: center; }

@media (max-width: 640px) {
  body { padding-top: 14px; }
  .grid { grid-template-columns: 1fr; }
  .caja .valor { font-size: 30px; }
  .encabezado h1 { font-size: 21px; }
  .mov-datos { grid-template-columns: 1fr; gap: 0; }
  .mov-datos dt { margin-top: 6px; font-size: 12px; }
}
