/* giro-theme-20260915z: classic nav hierarchy */
@font-face {
  font-family: "Giro Display";
  src: url("/fonts/Montserrat-ExtraBold.woff2") format("woff2");
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Paleta derivada del logo Nuvem (azul marino #011028) */
  --bg: #011028;
  --card: #0a1f3d;
  --border: #1e3a5f;
  --text: #e8eef7;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-dim: #2563eb33;
  --ok: #22c55e;
  --danger: #ef4444;
  font-family: "Segoe UI", system-ui, sans-serif;
}

.giro-wordmark {
  font-family: "Giro Display", "Segoe UI", sans-serif;
  font-weight: 800;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: #fff;
  margin: 0;
  line-height: 1.05;
  padding-right: 0.05em;
}
.giro-wordmark-lg { font-size: clamp(1.85rem, 4vw, 2.25rem); }
.giro-wordmark-sm {
  font-size: 1.15rem;
  letter-spacing: 0.22em;
}

* { box-sizing: border-box; }

/* Mismo fondo que el body: en móvil el body va fijado al viewport visual
   y el html queda visible detrás (sin esto se ve una franja blanca). */
html {
  height: 100%;
  background: #011028;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(160deg, #011028 0%, #0a2244 100%);
  color: var(--text);
}

.logo {
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #fff;
  font-size: 0.85rem;
}

.logo-img {
  display: block;
  height: 26px;
  width: auto;
  max-width: 180px;
  object-fit: contain;
  object-position: left;
}
.logo-img.giro-mark {
  height: 40px;
  width: 40px;
  max-width: 40px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.brand-copy h1 { margin: 0; font-size: 1.05rem; font-weight: 600; }
.brand-copy h1:empty,
.brand-copy .sub:empty { display: none; }
.brand-copy .sub {
  margin: 0.2rem 0 0;
  font-size: 0.75rem;
}
.brand-copy .giro-wordmark { margin: 0; }
.login-card .logo-img, .auth-card .logo-img { height: 34px; margin-bottom: 0.75rem; }
.login-card .logo-img.giro-mark,
.auth-card .logo-img.giro-mark {
  height: 72px;
  width: 72px;
  max-width: 72px;
  border-radius: 18px;
  margin: 0 auto 1rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

.auth-page, .login-page {
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  min-height: 100vh;
  padding: 0;
  position: relative;
  overflow: hidden;
  background-color: #011028;
  background-image: linear-gradient(180deg, rgba(1, 16, 40, 0.72), rgba(1, 16, 40, 0.88)), url("/login-bg.webp");
  background-size: cover;
  background-position: center right;
}
.login-shell {
  display: grid;
  grid-template-columns: 1fr;
  width: 100%;
  min-height: 100vh;
}
.login-visual { display: none; }
.login-shell .login-card,
.login-shell .auth-card {
  margin: auto;
  width: calc(100% - 2rem);
}
@media (min-width: 900px) {
  .auth-page, .login-page {
    background-image: none;
  }
  .login-shell {
    grid-template-columns: minmax(26rem, 32rem) 1fr;
  }
  .login-visual {
    display: block;
    order: 2;
    background: url("/login-bg.webp") center / cover no-repeat;
    min-height: 100vh;
  }
  .login-shell .login-card,
  .login-shell .auth-card {
    order: 1;
    margin: auto 2.5rem;
    width: 100%;
    max-width: 420px;
  }
}
.login-brand {
  text-align: center;
  margin-bottom: 1.35rem;
}
.login-lead {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
  text-align: center;
  margin: 0 0 1.5rem;
}
.login-form { display: grid; gap: 0.85rem; }
.login-form label {
  margin-bottom: 0;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}
.login-form input,
.login-form select {
  height: 48px;
  border-radius: 12px;
  border-color: #2a4a73;
  background: rgba(1, 16, 40, 0.72);
  padding: 0.7rem 0.9rem;
}
.login-form input:focus,
.login-form select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.login-submit {
  width: 100%;
  height: 48px;
  margin-top: 0.35rem;
  border-radius: 12px;
  font-weight: 650;
  letter-spacing: 0.02em;
}
.login-footer {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1.35rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.82rem;
}
.login-footer a { color: #93c5fd; text-decoration: none; font-weight: 600; }
.login-footer a:hover { color: #fff; }

.auth-card, .login-card {
  width: 100%;
  max-width: 420px;
  position: relative;
  background: rgba(10, 31, 61, 0.78);
  border: 1px solid rgba(59, 130, 246, 0.22);
  border-radius: 24px;
  padding: 2.25rem 2rem 1.75rem;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(16px);
}

.auth-card h1, .login-card h1 { margin: 0.5rem 0; font-size: 1.4rem; }
.sub { color: var(--muted); font-size: 0.9rem; margin: 0.25rem 0 1rem; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

input, select, textarea {
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #011028;
  color: var(--text);
  /* ≥16px: evita que iOS Safari haga zoom automático al enfocar el campo */
  font-size: 1rem;
}

textarea { min-height: 80px; resize: vertical; }

.btn, .btn-primary, .btn-secondary, .btn-qbo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1.2rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: none;
  color: #fff;
}

.btn-primary, .btn-qbo { background: var(--accent); }
.btn-secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.error { color: var(--danger); font-size: 0.85rem; margin: 0.5rem 0; }
.ok { color: var(--ok); font-size: 0.85rem; margin: 0.5rem 0; }
.hint { color: var(--muted); font-size: 0.8rem; margin-top: 1rem; }
.hint a { color: var(--accent); }

.header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 31, 61, 0.9);
}

.header h1 { margin: 0.25rem 0 0; font-size: 1.2rem; }
.header-actions { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }

.wizard { max-width: 720px; margin: 2rem auto; padding: 0 1rem; }
.steps { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.step {
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
}
.step.active { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.step.done { border-color: var(--ok); color: var(--ok); }

.location-pick { display: flex; flex-direction: column; gap: 0.5rem; margin: 1rem 0; max-height: 22rem; overflow: auto; }
.location-pick label {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.location-pick label:hover, .location-pick label.selected { border-color: var(--accent); }
.location-pick .hint { color: var(--muted); font-size: 0.8rem; }

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
}

.provider-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 600px) { .provider-cards { grid-template-columns: 1fr; } }

.provider-card {
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  cursor: pointer;
  transition: border-color 0.15s;
}
.provider-card:hover, .provider-card.selected { border-color: var(--accent); }
.provider-logo { width: 40px; height: 40px; display: block; margin-bottom: 0.75rem; border-radius: 9px; }
.provider-card h3 { margin: 0 0 0.5rem; }
.provider-card p { margin: 0; color: var(--muted); font-size: 0.85rem; }

/* Chat: header + área de mensajes + input fijos al viewport */
body.chat-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  /* Anula el min-height:100vh global: en iPhone 100vh es la pantalla SIN
     barras del navegador, y empujaba la barra de chat fuera del área visible. */
  min-height: 0;
  overflow: hidden;
  /* Evita que el rebote de scroll arrastre toda la página en móvil */
  overscroll-behavior: none;
}

body.chat-page .header {
  flex-shrink: 0;
  height: 52px;
  min-height: 52px;
  padding: 0 14px;
  gap: 12px;
  overflow: visible;
}
body.chat-page .logo-img.giro-mark {
  height: 28px;
  width: 28px;
  max-width: 28px;
  border-radius: 8px;
}
body.chat-page .brand {
  position: relative;
  flex: 0 1 auto;
  min-width: 0;
}
body.chat-page .brand-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  gap: 1px;
}
body.chat-page .brand-product {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
  line-height: 1.15;
}
body.chat-page .brand-company {
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 18rem;
  text-align: left;
  cursor: pointer;
  line-height: 1.2;
}
body.chat-page .brand-company:hover,
body.chat-page .brand.open .brand-company {
  color: var(--text);
}
body.chat-page .company-panel {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 50;
  min-width: 220px;
  max-width: min(28rem, 90vw);
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
body.chat-page .company-panel[hidden] { display: none; }
body.chat-page .visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
body.chat-page .header-link {
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
}
body.chat-page .header-link:hover { color: var(--text); }
body.chat-page .header-end {
  margin-left: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
body.chat-page .account-menu { position: relative; }
body.chat-page .account-btn {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  padding: 0;
  cursor: pointer;
  color: var(--text);
}
body.chat-page .account-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 13px;
  font-weight: 650;
}
body.chat-page .account-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 50;
  min-width: 220px;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
body.chat-page .account-menu-panel[hidden] { display: none; }
body.chat-page .account-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
}
body.chat-page .account-item:hover { background: var(--card); }
body.chat-page .account-item[hidden] { display: none; }
body.chat-page .account-item.account-model {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 0;
  cursor: default;
}
/* The model is the plan's (the server ignores the page's choice): the picker stays hidden. */
body.chat-page .account-item.account-model[hidden] { display: none; }
body.chat-page .account-item.account-model select {
  flex: 1;
  min-width: 0;
  max-width: 11rem;
  height: 28px;
  margin: 0;
  padding: 0 6px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}
body.chat-page a.account-item#usageLabel {
  color: var(--muted);
  border: 0;
  box-shadow: none;
  background: transparent;
}
body.chat-page .company-panel .account-item[aria-selected="true"] {
  font-weight: 650;
}

/* Desktop: Giro + empresa · Mesa · Reglas · tema · avatar. */
@media (min-width: 801px) {
  body.chat-page .header {
    flex-wrap: nowrap;
    gap: 0.75rem;
  }
  body.chat-page .header-actions {
    flex-wrap: nowrap;
    flex: 0 0 auto;
    min-width: 0;
    justify-content: flex-start;
    align-items: center;
    gap: 1rem;
    margin-left: auto;
    overflow: visible;
  }
}

.chat-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Botones que solo existen en móvil (menú ☰ y panel de chats) */
.mobile-only { display: none; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 39;
  border: none;
  padding: 0;
}

@media (max-width: 800px) {
  /* Flex en vez de grid: en Safari iOS la fila implícita del grid puede
     crecer con el contenido y empujar la barra de escritura fuera de vista. */
  .chat-layout {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  .chat-main { flex: 1; min-height: 0; }

  /* iOS Safari desplaza el documento al abrir el teclado y deja la app
     «cortada». Fijar el body al viewport (Safari posiciona bien fixed
     respecto a sus barras) y reservar con --kb la altura del teclado. */
  body.chat-page {
    position: fixed;
    inset: 0;
    width: 100%;
    height: auto;
    max-height: none;
    padding-bottom: var(--kb, 0px);
  }

  .mobile-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: 1.15rem;
    cursor: pointer;
    flex-shrink: 0;
  }

  body.chat-page .header {
    padding: 0.6rem 0.75rem;
    gap: 0.5rem;
    flex-wrap: nowrap;
  }
  body.chat-page .header h1 { font-size: 1rem; }
  body.chat-page .brand { flex: 1; min-width: 0; }
  body.chat-page .header .brand-company {
    max-width: 42vw;
  }

  /* El bloque de acciones se convierte en menú desplegable */
  body.chat-page .header-actions {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    width: min(85vw, 320px);
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    padding: 1rem;
    padding-top: max(1rem, env(safe-area-inset-top));
    background: var(--bg);
    border-left: 1px solid var(--border);
    overflow-y: auto;
  }
  body.chat-page .header-actions.open { display: flex; }
  body.chat-page .header-actions label { margin-bottom: 0; }
  body.chat-page .header-actions select { width: 100%; }
  body.chat-page .header-actions .usage-bar { justify-content: space-between; }

  /* Sidebar de conversaciones: panel deslizante */
  body.chat-page .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    width: min(85vw, 320px);
    background: var(--bg);
    border-right: 1px solid var(--border);
    padding-top: max(1rem, env(safe-area-inset-top));
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  body.chat-page .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }

  /* Botón eliminar conversación siempre visible (no hay hover en táctil) */
  .conv-delete { opacity: 1; }

  .messages { padding: 0.75rem; gap: 0.75rem; }
  .btn-jump-bottom { right: 0.7rem; bottom: 0.7rem; }
  .msg { max-width: 94%; }
  .msg.assistant.msg-formatted { max-width: 100%; }
  .action-card { width: 100%; padding: 0.85rem; flex-shrink: 0; }
  .action-card-fields { grid-template-columns: 1fr; row-gap: 0.1rem; }
  .action-field-label { padding-top: 0.35rem; }
  .action-card-buttons { flex-direction: column; }
  .action-card-buttons button { width: 100%; padding: 0.7rem; }

  .chat-input { padding: 0.5rem 0.6rem; padding-bottom: max(0.5rem, env(safe-area-inset-bottom)); gap: 0.4rem; }
  .composer-choices { padding: 0.45rem 0.6rem 0.25rem; max-height: 7.5rem; }
  .composer-choice { font-size: 0.84rem; padding: 0.4rem 0.65rem; }
  .attachment-preview { padding: 0.5rem 0.6rem 0; }
  .msg-actions { opacity: 1; }
}

.sidebar {
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
  background: rgba(10, 31, 61, 0.5);
  min-height: 0;
}
.sidebar-head {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.sidebar-head h3 { margin: 0; font-size: 0.85rem; color: var(--muted); }
.sidebar-head-actions { display: flex; gap: 0.35rem; }
.sidebar-head-actions [hidden] { display: none !important; }
.sidebar-head-actions #btnNewConv { order: -1; flex: 1; }
.sidebar-head-actions .btn-danger {
  background: rgba(229, 62, 62, 0.15);
  border-color: rgba(229, 62, 62, 0.4);
  color: #fc8181;
}
.sidebar-head-actions .btn-danger:hover { background: rgba(229, 62, 62, 0.25); }
.sidebar-head-actions .active { border-color: var(--accent); color: var(--accent); }
.conv-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.25rem; }
.conv-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  position: relative;
}
.conv-check { flex-shrink: 0; accent-color: var(--accent); cursor: pointer; }
.conv-item {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
}
.conv-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-when {
  flex-shrink: 0;
  color: var(--ink-3, var(--muted));
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.conv-delete {
  flex-shrink: 0;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  opacity: 1;
  transition: background 0.15s, color 0.15s;
}
.conv-delete:hover { background: rgba(229, 62, 62, 0.15); color: #fc8181; }
.conv-item:hover { background: rgba(255, 255, 255, 0.05); border-color: var(--border); }
.conv-item.active { background: rgba(99, 179, 237, 0.12); border-color: rgba(99, 179, 237, 0.35); color: #e2e8f0; }
.conv-empty { font-size: 0.8rem; color: var(--muted); padding: 0.5rem 0; }

.chat-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.messages-pane {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.btn-jump-bottom {
  position: static;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: rgba(10, 31, 61, 0.94);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 650;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.btn-jump-bottom-icon {
  font-size: 1.1rem;
  line-height: 1;
}
.btn-jump-bottom:hover,
.btn-jump-bottom:focus-visible {
  background: var(--accent);
  color: #fff;
  outline: none;
}
.btn-jump-bottom[hidden] {
  display: none !important;
}

.msg {
  max-width: 85%;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 0.92rem;
  line-height: 1.5;
  white-space: pre-wrap;
}
.msg.msg-formatted {
  white-space: normal;
}
.msg.msg-formatted .msg-body {
  white-space: normal;
}
.msg-body strong {
  font-weight: 700;
  color: inherit;
}
.msg-body em {
  font-style: italic;
}
.msg-body p {
  margin: 0.45rem 0;
}
.msg-body p:first-child {
  margin-top: 0;
}
.msg-body p:last-child {
  margin-bottom: 0;
}
.msg-body ul,
.msg-body ol {
  margin: 0.45rem 0;
  padding-left: 1.35rem;
}
.msg-body li {
  margin: 0.2rem 0;
}
.msg-body table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  margin: 0.65rem 0;
  font-size: 0.84rem;
  line-height: 1.35;
}
.msg-body th,
.msg-body td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.55rem;
  text-align: left;
  vertical-align: top;
}
.msg-body th {
  background: var(--bg);
  font-weight: 600;
}
.msg-body td:nth-child(3),
.msg-body th:nth-child(3),
.msg-body td:nth-child(n+4),
.msg-body th:nth-child(n+4) {
  text-align: right;
}
.msg-body td:first-child,
.msg-body th:first-child,
.msg-body td:last-child,
.msg-body th:last-child {
  text-align: left;
  white-space: normal;
  min-width: 6rem;
}
.msg-body td:nth-child(2),
.msg-body th:nth-child(2) {
  white-space: nowrap;
}
.msg-body tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.03);
}
.msg-body tr:last-child td {
  font-weight: 600;
  border-top-width: 2px;
}
.msg-body code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.84em;
  background: rgba(0, 0, 0, 0.06);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
.msg-body pre {
  margin: 0.5rem 0;
  padding: 0.65rem 0.75rem;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.84rem;
}
.msg-body pre code {
  background: none;
  padding: 0;
}
.msg-body h1,
.msg-body h2,
.msg-body h3 {
  margin: 0.65rem 0 0.35rem;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
}
.msg-body h1 { font-size: 1.08rem; }
.msg-status {
  margin-top: 0.55rem;
  color: var(--muted);
  font-style: italic;
  font-size: 0.85rem;
  white-space: pre-wrap;
}
.msg.assistant.msg-formatted {
  max-width: min(96%, 56rem);
}
.msg.msg-formatted .msg-body {
  overflow-x: auto;
  max-width: 100%;
}
.msg.user {
  align-self: flex-end;
  max-width: 72%;
  font-size: 13.5px;
  padding: 9px 13px;
  border-radius: 12px 12px 3px 12px;
  background: var(--accent);
  color: #fff;
  position: relative;
}
.msg.assistant {
  align-self: flex-start;
  max-width: 82%;
  font-size: 13.5px;
  padding: 10px 13px;
  border-radius: 12px 12px 12px 3px;
  background: var(--surface-2, var(--card));
  border: 0;
}
.msg.thinking { color: var(--muted); font-style: italic; }
.msg.assistant.is-working {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-dim);
}
/* One loader, same as Mesa: the pill in Giro's bubble. The composer only turns Enviar into Detener. */
.msg.assistant.is-working .msg-body.is-placeholder { display: none; }
.msg.assistant.placeholder-hidden { display: none; }
.msg.assistant.is-working .msg-body.is-placeholder + .giro-working,
.msg.assistant.is-working > .giro-working:first-child { margin-top: 0; }
.giro-working {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 5px 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--wait, var(--accent));
  font-size: 12px;
  font-style: normal;
  font-weight: 600;
  animation: giro-working-glow 1.7s ease-in-out infinite;
}
.giro-working-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.giro-working-dots span {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.35;
  animation: giro-working-dot 1.1s ease-in-out infinite;
}
.giro-working-dots span:nth-child(2) { animation-delay: 0.16s; }
.giro-working-dots span:nth-child(3) { animation-delay: 0.32s; }
@keyframes giro-working-dot {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0) scale(0.85); }
  40% { opacity: 1; transform: translateY(-3px) scale(1); }
}
@keyframes giro-working-glow {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 28%, transparent); }
  50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 0%, transparent); }
}
.giro-working-hint {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 1.5rem 0.2rem;
  /* The theme's muted ink: #cfe3ff was unreadable in light mode (29/09). */
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}
.giro-working-hint.is-error { color: var(--danger); }
.giro-working-hint[hidden] { display: none !important; }
/* Confirmation is ready: never keep the "Giro está trabajando" bar over Aprobar.
   After the click, .approval-in-flight cards must not hide the working bar. */
body.chat-page:has(.action-card[data-action-id]:not(.resolved):not(.superseded):not(.approval-in-flight)) #giroWorkingHint,
body.chat-page:has(.composer-choice-approve):not(:has(.action-card.approval-in-flight)) #giroWorkingHint {
  display: none !important;
}
/* The turn is still open while cards are on screen: a slim line says Giro keeps
   preparing, and the cards of this turn wait (buttons off) until it ends. */
.giro-turn-hint {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 1.5rem 0.15rem;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
}
.giro-turn-hint[hidden] { display: none !important; }
.action-card.turn-wait .action-card-buttons button {
  opacity: 0.55;
  cursor: not-allowed;
}
.action-card-turn-wait {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}
body.chat-page:has(.action-card.approval-in-flight) .composer-choice-approve,
body.chat-page:has(.action-card.approval-in-flight) .composer-choice-reject {
  display: none !important;
}
.chat-input.is-working {
  box-shadow: inset 0 2px 0 var(--accent);
}
.msg.stopped { opacity: 0.85; }
.msg-actions {
  position: absolute;
  top: -0.5rem;
  right: 0.25rem;
  opacity: 0;
  transition: opacity 0.15s;
}
.msg.user:hover .msg-actions { opacity: 1; }
.msg-edit-btn {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.2);
  color: #fff;
  cursor: pointer;
}
.msg-edit-btn:hover { background: rgba(0, 0, 0, 0.35); }
.btn-stop {
  background: #c0392b !important;
  border-color: #a93226 !important;
  animation: giro-stop-pulse 1.6s ease-in-out infinite;
}
.btn-stop:hover { background: #a93226 !important; }
@keyframes giro-stop-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(192, 57, 43, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .giro-working,
  .giro-working-dots span,
  .btn-stop {
    animation: none;
  }
  .giro-working-dots span { opacity: 0.85; }
}

/* Tarjeta de confirmación de acción (Aprobar/Rechazar) — classic-card-20260915c */
.action-card {
  align-self: stretch;
  width: min(96%, 46rem);
  background: var(--surface, var(--card));
  border: 1px solid var(--rule-2, var(--border));
  border-radius: 10px;
  padding: 0;
  font-size: 13.5px;
  line-height: 1.5;
  box-shadow: var(--shadow, 0 2px 12px rgba(0, 0, 0, 0.08));
  overflow: hidden;
  flex-shrink: 0;
  min-height: min-content;
}
.action-card.chat-card header,
.chat-card-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule, var(--border));
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}
.chat-card-head svg,
.action-card.chat-card header svg {
  width: 15px;
  height: 15px;
  color: var(--wait);
  flex-shrink: 0;
}
.chat-card-body { padding: 13px 14px 18px; }
.approval-group {
  width: min(96%, 46rem);
  min-width: 0;
  flex-shrink: 0;
  border-block: 2px solid var(--rule-2, var(--border));
}
.approval-group h3 { margin: 0; padding: 14px; font-size: 15px; }
.approval-group .action-card {
  width: 100%;
  border: 0;
  border-top: 1px solid var(--rule, var(--border));
  border-radius: 0;
  box-shadow: none;
}
.approval-group-footer { padding: 14px; display: flex; justify-content: flex-end; }
.approval-group-footer button { white-space: normal; }
.chat-card-head { flex-wrap: wrap; }
.proposal-reference { margin-left: auto; overflow-wrap: anywhere; font-weight: 500; }
.chat-card .ledger,
.action-card .ledger {
  border-top: 1.5px solid var(--ink, var(--text));
  margin: 0 0 4px;
}
.chat-card .ledger table,
.action-card .ledger table {
  width: 100%;
  border-collapse: collapse;
}
.chat-card .ledger th,
.action-card .ledger th {
  text-align: right;
  font-size: 11.5px;
  font-weight: 550;
  color: var(--ink-2, var(--muted));
  padding: 8px 0 6px;
  border-bottom: 1px solid var(--rule, var(--border));
}
.chat-card .ledger th:first-child,
.action-card .ledger th:first-child { text-align: left; }
.chat-card .ledger td,
.action-card .ledger td {
  padding: 8px 0;
  border-bottom: 1px solid var(--rule, var(--border));
  font-size: 13.5px;
}
.chat-card .ledger td:not(:first-child),
.action-card .ledger td:not(:first-child) {
  text-align: right;
  width: 120px;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.chat-card .ledger .acct,
.action-card .ledger .acct { font-weight: 550; }
.chat-card .ledger .acct em,
.action-card .ledger .acct em {
  display: block;
  font-style: normal;
  font-weight: 400;
  color: var(--ink-2, var(--muted));
  font-size: 12px;
}
.chat-card .ledger tfoot td,
.action-card .ledger tfoot td {
  border-bottom: 0;
  border-top: 1.5px solid var(--ink, var(--text));
  font-weight: 650;
  padding-top: 9px;
}
.chat-card .ledger .zero,
.action-card .ledger .zero { color: var(--ink-3, var(--muted)); }
.chat-card .meta,
.action-card dl.meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  font-size: 13px;
  margin: 16px 0 0;
}
.chat-card .meta dt,
.action-card dl.meta dt { color: var(--ink-2, var(--muted)); }
.chat-card .meta dd,
.action-card dl.meta dd { margin: 0; }
.chat-card .actions,
.action-card .actions {
  display: flex;
  gap: 9px;
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid var(--rule, var(--border));
}
.btn.btn-ok {
  background: var(--ok);
  color: #fff;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 8px 17px;
  font-size: 13.5px;
  font-weight: 550;
}
.btn.btn-ghost {
  background: transparent;
  border: 1px solid var(--rule-2, var(--border));
  color: var(--ink-2, var(--muted));
  border-radius: 7px;
  padding: 8px 17px;
  font-size: 13.5px;
  font-weight: 550;
}
.btn.btn-ghost:hover { border-color: var(--ink-3, var(--muted)); color: var(--ink, var(--text)); }
.action-card-head {
  margin-bottom: 0.75rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}
.action-card-overline {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.2rem;
}
.action-card-title {
  font-weight: 700;
  font-size: 1.02rem;
}
.action-card-fields {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  column-gap: 1.1rem;
  row-gap: 0.3rem;
  margin-bottom: 0.85rem;
}
.action-field-label {
  color: var(--muted);
  font-size: 0.84rem;
  padding-top: 0.05rem;
  white-space: nowrap;
}
.action-field-value {
  font-weight: 500;
  word-break: break-word;
  overflow-wrap: break-word;
}
.action-field-value.action-field-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: keep-all;
}
.action-card-items-head {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}
.action-card-items {
  list-style: none;
  margin: 0 0 0.85rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.action-card-items li {
  padding: 0.45rem 0.7rem;
  font-size: 0.87rem;
  word-break: break-word;
}
.action-card-items li:nth-child(odd) {
  background: rgba(255, 255, 255, 0.04);
}
.action-card-items li + li {
  border-top: 1px solid var(--border);
}
.action-card-summary {
  white-space: pre-wrap;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.85rem;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.75rem;
  overflow-x: auto;
}
.action-card-buttons {
  display: flex;
  gap: 0.6rem;
}
.action-card-buttons .btn-approve {
  background: #1e8e4e;
  border: 1px solid #17703d;
  color: #fff;
  padding: 0.45rem 1.1rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}
.action-card-buttons .btn-approve:hover { background: #17703d; }
html[data-theme] body.chat-page .action-card-buttons .btn-approve.btn-danger { background: #c0392b; border-color: #c0392b; color: #fff; }
html[data-theme] body.chat-page .action-card-buttons .btn-approve.btn-danger:hover { background: #a93226; border-color: #a93226; }
.mutation-card .action-card-items { white-space: pre-wrap; }
.action-card-buttons .btn-reject {
  background: transparent;
  border: 1px solid #c0392b;
  color: #c0392b;
  padding: 0.45rem 1.1rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}
.action-card-buttons .btn-reject:hover { background: rgba(192, 57, 43, 0.12); }
.action-card-buttons button:disabled { opacity: 0.5; cursor: not-allowed; }
.action-card.approval-in-flight .action-card-buttons {
  display: none !important;
}
.action-card.resolved { border-color: var(--border); opacity: 0.75; }
.action-card.superseded { opacity: 0.45; pointer-events: none; }
.action-card-result {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.chat-card .action-card-result,
.action-card.chat-card .action-card-result {
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid var(--rule, var(--border));
  font-size: 13.5px;
  font-weight: 550;
  color: var(--ink, var(--text));
}

/* Execution on the classic card — same states as Mesa's cards (mesa.html, exec-*):
   En cola (still ring, dashed edge) → Registrando (turning ring, pulsing edge,
   progress shimmer, clock) → Registrado (tick + green flash) / Falló (red) /
   Sin confirmar (amber). Theme tokens from giro-theme.css, light and dark. */
@keyframes giro-exec-spin { to { transform: rotate(360deg); } }
@keyframes giro-exec-ring {
  0%, 100% { box-shadow: 0 0 0 0 var(--exec-ring); }
  50% { box-shadow: 0 0 0 4px var(--exec-ring); }
}
@keyframes giro-exec-edge {
  0%, 100% { border-left-color: var(--accent); }
  50% { border-left-color: color-mix(in srgb, var(--accent) 25%, transparent); }
}
@keyframes giro-exec-shimmer { from { background-position: -70% 0; } to { background-position: 170% 0; } }
@keyframes giro-exec-flash-ok {
  0% { background-color: var(--ok-bg, rgba(34, 197, 94, 0.16)); }
  100% { background-color: var(--surface, var(--card)); }
}
@keyframes giro-exec-pop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); }
}
body.chat-page .action-card[data-exec-phase] {
  position: relative;
  --exec-ring: color-mix(in srgb, var(--accent) 28%, transparent);
}
body.chat-page .action-card.resolved:is(.exec-queued, .exec-running, .exec-done, .exec-failed, .exec-unknown) { opacity: 1; }
:root body.chat-page .action-card.exec-queued { border-style: dashed; border-color: var(--rule-2, var(--border)); }
:root body.chat-page .action-card.exec-running {
  border-color: var(--accent);
  border-left: 3px solid var(--accent);
  animation: giro-exec-ring 1.6s ease-in-out infinite, giro-exec-edge 1.6s ease-in-out infinite;
}
body.chat-page .action-card.exec-running::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--accent), transparent) no-repeat;
  background-size: 40% 100%;
  animation: giro-exec-shimmer 1.6s linear infinite;
}
:root body.chat-page .action-card.exec-done { border-color: color-mix(in srgb, var(--ok) 55%, var(--rule-2, var(--border))); }
:root body.chat-page .action-card.exec-failed { border-color: color-mix(in srgb, var(--bad, var(--danger)) 55%, var(--rule-2, var(--border))); border-left: 3px solid var(--bad, var(--danger)); }
:root body.chat-page .action-card.exec-unknown { border-color: color-mix(in srgb, var(--wait, #d6a44c) 55%, var(--rule-2, var(--border))); border-left: 3px solid var(--wait, #d6a44c); }
body.chat-page .action-card.just-done { animation: giro-exec-flash-ok 1400ms ease-out; }
body.chat-page .action-card.just-done .exec-tick { animation: giro-exec-pop 380ms ease-out; }
body.chat-page .action-card-result.exec-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  line-height: 1.4;
}
body.chat-page .exec-line .exec-text { min-width: 0; overflow-wrap: anywhere; }
body.chat-page .exec-line.queue, body.chat-page .exec-line.muted { color: var(--ink-2, var(--muted)); }
body.chat-page .exec-line.run { color: var(--accent); }
body.chat-page .exec-line.ok { color: var(--ok); }
body.chat-page .exec-line.bad { color: var(--bad, var(--danger)); font-weight: 500; }
body.chat-page .exec-line.wait { color: var(--wait, #d6a44c); font-weight: 500; }
body.chat-page .exec-line .exec-clock { margin-left: auto; flex: none; font-variant-numeric: tabular-nums; }
body.chat-page .exec-spin {
  display: inline-block;
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  border-right-color: transparent;
  animation: giro-exec-spin 0.8s linear infinite;
}
body.chat-page .exec-ring {
  display: inline-block;
  flex: none;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid currentColor;
}
body.chat-page .exec-tick,
body.chat-page .exec-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  color: var(--surface, #fff);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}
body.chat-page .exec-tick { background: var(--ok); }
body.chat-page .exec-tick svg { width: 10px; height: 10px; display: block; }
body.chat-page .exec-x { background: var(--bad, var(--danger)); }
body.chat-page .pv-chip.queue { background: var(--surface-2, transparent); color: var(--ink-2, var(--muted)); box-shadow: inset 0 0 0 1px var(--rule-2, var(--border)); }
body.chat-page .pv-chip.muted { background: var(--surface-2, transparent); color: var(--ink-2, var(--muted)); }
body.chat-page .chat-card-head .chat-card-state { font-weight: 600; }
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
@media (prefers-reduced-motion: reduce) {
  /* No loop, same words and colors: a full ring, a steady edge, no shimmer, no flash. */
  :root body.chat-page .action-card.exec-running,
  body.chat-page .action-card.just-done,
  body.chat-page .action-card.just-done .exec-tick,
  body.chat-page .exec-spin { animation: none !important; }
  body.chat-page .exec-spin { border-right-color: var(--accent); }
  body.chat-page .action-card.exec-running::after { display: none; }
  :root body.chat-page .action-card.exec-running { box-shadow: 0 0 0 2px var(--exec-ring); }
}
.msg.assistant.msg-result-box {
  width: min(96%, 46rem);
  max-width: 46rem;
  padding: 0;
  background: transparent;
  border: none;
}
.msg-result-box .msg-body {
  overflow: visible;
}
.approved-result-stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.action-card.result-card {
  border-color: #1e8e4e;
  border-left: 4px solid #1e8e4e;
  width: 100%;
}
.action-card.result-card .action-card-overline {
  color: #1e8e4e;
}
.action-card.result-card .action-card-summary {
  display: none;
}

.composer-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.55rem 1.5rem 0.35rem;
  border-top: 1px solid var(--border);
  background: rgba(10, 31, 61, 0.92);
  max-height: 9rem;
  overflow-y: auto;
}
.composer-choices[hidden] {
  display: none !important;
}
.composer-choice {
  appearance: none;
  border: 1px solid rgba(59, 130, 246, 0.45);
  background: rgba(15, 42, 78, 0.95);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.25;
  padding: 0.45rem 0.75rem;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  max-width: 100%;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.composer-choice:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.composer-choice:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.composer-choice-approve {
  background: #1e8e4e;
  border-color: #17703d;
  color: #fff;
  font-weight: 600;
}
.composer-choice-approve:hover {
  background: #17703d;
  border-color: #145f34;
}
.composer-choice-approve:focus-visible {
  outline-color: var(--ok);
}
.composer-choice-reject {
  background: transparent;
  border-color: #c0392b;
  color: #f87171;
  font-weight: 600;
}
.composer-choice-reject:hover {
  background: rgba(192, 57, 43, 0.2);
  border-color: #e74c3c;
  color: #fca5a5;
}
.composer-choice-reject:focus-visible {
  outline-color: var(--danger);
}
.composer-choice:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-input {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
  padding: 0.75rem 1.5rem;
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: rgba(10, 31, 61, 0.95);
  align-items: flex-end;
}
.chat-input textarea {
  flex: 1;
  min-height: 44px;
  max-height: min(50vh, 280px);
  resize: none;
  overflow-y: hidden;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.chat-input .btn-primary {
  flex-shrink: 0;
  align-self: flex-end;
}

.btn-attach {
  flex-shrink: 0;
  align-self: flex-end;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}
.btn-attach:hover { border-color: var(--accent); }
.btn-attach:disabled { opacity: 0.5; cursor: not-allowed; }

.chat-input.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
}

.attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 1.5rem 0;
  border-top: 1px solid var(--border);
  background: rgba(1, 16, 40, 0.5);
}
.attachment-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 0.75rem;
  max-width: 220px;
}
.attachment-chip img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
}
.attachment-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.attachment-remove {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 0.15rem;
}
.attachment-remove:hover { color: #f87171; }

.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.msg-att {
  position: relative;
  display: inline-flex;
  align-items: flex-start;
}
.msg-att-remove {
  position: absolute;
  top: -0.4rem;
  right: -0.4rem;
  width: 1.25rem;
  height: 1.25rem;
  border: 0;
  border-radius: 999px;
  background: var(--card, #1b2128);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0;
  box-shadow: 0 0 0 1px var(--border, rgba(255,255,255,0.15));
}
.msg-att-remove:hover { color: #f87171; }
.msg-attachment-img {
  max-width: 240px;
  max-height: 180px;
  border-radius: 8px;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.2);
}
.msg-attachment-doc {
  display: inline-block;
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  color: inherit;
  text-decoration: none;
  font-size: 0.85rem;
}
.msg.user .msg-attachment-doc { background: rgba(0, 0, 0, 0.15); }

.tenant-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.tenant-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
}
.tenant-row-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(52, 152, 219, 0.25);
}
.tenant-row-main strong {
  font-size: 1rem;
}
.tenant-badge {
  display: inline-block;
  margin-left: 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  vertical-align: middle;
}
.tenant-row-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}
.btn-danger {
  background: #c0392b;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
}
.btn-danger:hover {
  background: #a93226;
}
.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
}

.usage-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(1, 16, 40, 0.6);
  font-size: 0.75rem;
}
.usage-bar-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}
.usage-label { color: var(--muted); white-space: nowrap; }
.usage-link { text-decoration: none; color: var(--muted); }
.usage-link:hover { color: var(--accent); text-decoration: underline; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.75rem; }

.billing-page { max-width: 900px; margin: 1.5rem auto; padding: 0 1rem 2rem; }
.usage-panel { margin-bottom: 1.5rem; }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
.plan-card h3 { margin: 0 0 0.5rem; }
.plan-price { font-size: 2rem; font-weight: 700; margin: 0.5rem 0 1rem; }
.plan-price span { font-size: 0.9rem; font-weight: 400; color: var(--muted); }
.plan-features { margin: 0 0 1rem; padding-left: 1.2rem; color: var(--muted); font-size: 0.85rem; }
.plan-features li { margin-bottom: 0.35rem; }
.plan-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-dim); }

.usage-page h2 { margin: 0 0 0.75rem; font-size: 1.1rem; }
.usage-hint { margin: 0 0 1rem; }
.usage-table-wrap { overflow-x: auto; }
.usage-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.usage-table th,
.usage-table td { padding: 0.6rem 0.5rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.usage-table th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
.usage-table tbody tr:hover { background: rgba(255, 255, 255, 0.03); }
.usage-limit { color: var(--muted); font-size: 0.8rem; max-width: 14rem; }
.usage-empty { text-align: center; color: var(--muted); padding: 2rem !important; }
.usage-badge { display: inline-block; margin-left: 0.35rem; padding: 0.1rem 0.4rem; border-radius: 4px; font-size: 0.65rem; font-weight: 600; vertical-align: middle; }
.usage-badge.premium { background: rgba(99, 179, 237, 0.15); color: #63b3ed; }
.usage-badge.included { background: rgba(72, 187, 120, 0.12); color: #68d391; }
.credit-meter { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); margin: 0.75rem 0; overflow: hidden; }
.credit-meter-fill { height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--accent), #63b3ed); transition: width 0.3s; }
.credit-meter-fill.credit-meter-free { background: linear-gradient(90deg, #68d391, #48bb78); }

.giro-timeline-box {
  margin: 0 0 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  background: rgba(1, 16, 40, 0.45);
}
.giro-timeline-box > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.5rem 0.8rem;
  font-size: 0.8rem;
  color: var(--muted);
  user-select: none;
}
.giro-timeline-box > summary::-webkit-details-marker { display: none; }
.giro-timeline-box > summary::before {
  content: "";
  display: inline-block;
  width: 0.45rem;
  height: 0.45rem;
  margin-right: 0.45rem;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  vertical-align: 0.15rem;
  transition: transform 0.15s ease;
}
.giro-timeline-box[open] > summary::before {
  transform: rotate(45deg);
  vertical-align: 0.05rem;
}
.giro-timeline {
  list-style: none;
  margin: 0;
  padding: 0 0.8rem 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
}
.giro-step {
  font-size: 0.84rem;
  line-height: 1.4;
  color: #c5d0de;
  padding-left: 1.1rem;
  position: relative;
}
.giro-step::before {
  position: absolute;
  left: 0;
  top: 0.15rem;
  font-size: 0.75rem;
}
.giro-step.thought {
  font-style: italic;
  color: var(--muted);
}
.giro-step.thought::before { content: "·"; color: #7aa2c8; }
.giro-step.action {
  color: #d5e4f5;
}
.giro-step.action::before { content: "▸"; color: #7aa2c8; }
.giro-step.action.running {
  color: #9ec4e8;
}
.giro-step.action.running::before { content: "●"; font-size: 0.55rem; top: 0.35rem; }
.giro-step.result.ok { color: #8fd0a8; }
.giro-step.result.ok::before { content: "✓"; color: #8fd0a8; }
.giro-step.result.fail { color: #e8a0a0; }
.giro-step.result.fail::before { content: "!"; color: #e8a0a0; }

.hidden { display: none !important; }

/* Página Reglas: conducta numerada, no claves técnicas */
.rules-lede {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}
.rules-lede strong { color: var(--text); font-weight: 600; }
.rule-card {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 1rem 1.05rem;
  margin: 0 0 0.75rem;
  background: #102a4d;
  border: 1px solid #2a4d78;
  border-radius: 12px;
}
.rule-card:last-child { margin-bottom: 0; }
.rule-num {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.95rem;
  background: #1d4ed8;
  color: #fff;
  border: none;
}
.rule-body { flex: 1; min-width: 0; }
.rule-text {
  margin: 0;
  color: #ffffff;
  font-size: 1.08rem;
  font-weight: 600;
  line-height: 1.55;
  letter-spacing: 0.01em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.rule-readable .rule-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}
.rule-readable h4 {
  margin: 0;
  color: #ffffff;
  font-size: 1.05rem;
  font-weight: 600;
  flex: 1;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.rule-chip {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(255,255,255,.08);
  color: rgba(255,255,255,.78);
  border: 1px solid #2a4d78;
  white-space: nowrap;
}
.rule-readable p {
  margin: 0;
  color: rgba(255,255,255,.72);
  font-size: 0.95rem;
  font-weight: 400;
  line-height: 1.5;
  max-width: 60ch;
}
.rule-readable details { margin-top: 10px; }
.rule-readable summary {
  font-size: 12.5px;
  color: rgba(255,255,255,.55);
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.rule-readable summary::-webkit-details-marker { display: none; }
.rule-readable summary svg { width: 12px; height: 12px; transition: transform .15s; }
.rule-readable details[open] summary svg { transform: rotate(90deg); }
.rule-readable details table {
  width: 100%;
  margin-top: 9px;
  border-collapse: collapse;
  font-size: 12.5px;
}
.rule-readable details td {
  padding: 5px 10px 5px 0;
  border-bottom: 1px solid #2a4d78;
  color: rgba(255,255,255,.7);
}
.rule-readable details td:first-child { color: #fff; font-weight: 500; }
.rule-readable .guid { font-size: 11px; color: rgba(255,255,255,.5); cursor: pointer; }
.rule-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.85rem;
  margin-top: 0.45rem;
  font-size: 0.75rem;
  color: var(--muted);
}
.rule-area {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.7rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.rule-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}
.rule-card.is-editing .rule-actions { display: none; }
.rule-edit textarea {
  display: block;
  width: 100%;
  min-height: 110px;
  margin: 0 0 0.6rem;
  padding: 0.75rem;
  background: #011028;
  color: #fff;
  border: 1px solid #3b82f6;
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1.5;
}
.rule-edit label { margin-bottom: 0.35rem; }
.rule-edit-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0.4rem 0 0;
}
@media (max-width: 640px) {
  .rule-card { flex-wrap: wrap; }
  .rule-actions {
    width: 100%;
    flex-direction: row;
    justify-content: flex-end;
  }
}
.rule-empty {
  text-align: left;
  padding: 0.25rem 0 0.5rem;
}
.rule-empty h3 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}
.rule-examples {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.85rem 0 0;
  padding: 0;
  list-style: none;
}
.rule-examples button {
  text-align: left;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  color: inherit;
  cursor: pointer;
  font-size: 0.88rem;
  line-height: 1.4;
}
.rule-examples button:hover { border-color: var(--accent); }
.rule-form-stack { display: grid; gap: 10px; margin-top: 4px; }
.rule-form-stack textarea {
  width: 100%;
  min-height: 96px;
  resize: vertical;
}
.rule-form-stack select { width: 100%; max-width: 280px; }
.rule-form-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.facts-panel summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}
.facts-panel summary::-webkit-details-marker { display: none; }
.facts-panel summary::after {
  content: " ▾";
  color: var(--muted);
  font-weight: 400;
}
.facts-panel[open] summary::after { content: " ▴"; }
.facts-panel .sub { margin-top: 0.65rem; }
.fact-key {
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Extracto en el chat clásico: UNA tarjeta resumen por extracto (Rotulpak 30/09).
   Una fila compacta por movimiento; la fila se abre en su detalle (vista de propuesta). */
.statement-card {
  align-self: stretch;
  width: min(96%, 46rem);
  min-width: 0;
  flex-shrink: 0;
  background: var(--surface, var(--card));
  border: 1px solid var(--rule-2, var(--border));
  border-radius: 10px;
  box-shadow: var(--shadow, 0 2px 12px rgba(0, 0, 0, 0.08));
  font-size: 13.5px;
  line-height: 1.45;
  overflow: hidden;
}
.statement-card .stmt-head { padding: 12px 14px 10px; border-bottom: 1px solid var(--rule, var(--border)); }
.statement-card .stmt-kicker { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2, var(--muted)); }
.statement-card .stmt-title { margin: 6px 0 8px; font-size: 16px; font-weight: 600; }
.statement-card .stmt-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.statement-card .stmt-pill { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2, var(--muted)); }
.statement-card .stmt-pill.ok { background: var(--ok-bg); color: var(--ok); }
.statement-card .stmt-pill.warn, .statement-card .stmt-pill.wait { background: var(--wait-bg); color: var(--wait); }
.statement-card .stmt-pill.bad { background: var(--bad-bg); color: var(--bad); }
.statement-card .stmt-pill.run { background: var(--accent-soft); color: var(--accent); }
.statement-card .stmt-rows { display: flex; flex-direction: column; }
.statement-card .stmt-row { display: grid; grid-template-columns: 34px minmax(0, 1fr); border-top: 1px solid var(--rule, var(--border)); }
.statement-card .stmt-rows > .stmt-row:first-child { border-top: 0; }
.statement-card .stmt-row.is-question { background: var(--wait-bg); }
.statement-card .stmt-row.phase-registered,
.statement-card .stmt-row.phase-rejected,
.statement-card .stmt-row.phase-expired { color: var(--ink-3, var(--muted)); }
.statement-card .stmt-check { display: flex; align-items: flex-start; justify-content: center; padding-top: 11px; }
.statement-card .stmt-check input { width: 16px; height: 16px; margin: 0; accent-color: var(--ok); }
.statement-card .stmt-main {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto auto;
  align-items: start;
  gap: 4px 10px;
  width: 100%;
  min-width: 0;
  padding: 9px 14px 9px 0;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.statement-card .stmt-main:focus-visible { outline: 2px solid var(--focus, var(--accent)); outline-offset: -2px; }
.statement-card .stmt-date { color: var(--ink-2, var(--muted)); font-variant-numeric: tabular-nums; padding-top: 1px; }
.statement-card .stmt-text { display: flex; flex-direction: column; min-width: 0; }
.statement-card .stmt-concept { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.statement-card .stmt-how { font-size: 12.5px; color: var(--ink-2, var(--muted)); overflow-wrap: anywhere; }
.statement-card .stmt-state { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; white-space: nowrap; color: var(--ink-2, var(--muted)); padding-top: 2px; }
.statement-card .stmt-state.ok { color: var(--ok); }
.statement-card .stmt-state.bad { color: var(--bad); }
.statement-card .stmt-state.warn, .statement-card .stmt-state.wait { color: var(--wait); }
.statement-card .stmt-state.run { color: var(--accent); }
.statement-card .stmt-amount { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.statement-card .num.in { color: var(--ok); }
.statement-card .stmt-detail { grid-column: 1 / -1; padding: 4px 14px 14px 34px; display: grid; gap: 10px; }
.statement-card .stmt-detail .pv { font-size: 13px; }
.statement-card .stmt-detail-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.statement-card .stmt-detail-actions .btn { padding: 5px 12px; font-size: 12.5px; }
.statement-card .stmt-more { display: block; width: 100%; padding: 9px 14px; border: 0; border-top: 1px solid var(--rule, var(--border)); background: var(--surface-2); color: var(--accent); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; text-align: center; }
.statement-card .stmt-invalid { border-top: 1px solid var(--rule-2, var(--border)); }
.statement-card .stmt-invalid h4 { margin: 0; padding: 9px 14px 3px; font-size: 11.5px; font-weight: 600; color: var(--bad); }
.statement-card .stmt-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--rule-2, var(--border)); background: var(--surface-2); }
.statement-card .stmt-totals { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--ink-2, var(--muted)); }
.statement-card .stmt-totals strong { font-variant-numeric: tabular-nums; color: var(--ink, var(--text)); }
.statement-card .stmt-totals strong.in { color: var(--ok); }
.statement-card .stmt-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-left: auto; }
.statement-card .stmt-wait { font-size: 12px; color: var(--ink-2, var(--muted)); }
.statement-card .btn.btn-ok:disabled { opacity: 0.55; cursor: default; }
@media (max-width: 560px) {
  .statement-card .stmt-main { grid-template-columns: 40px minmax(0, 1fr) auto; }
  .statement-card .stmt-state { grid-column: 2; }
  .statement-card .stmt-detail { padding-left: 14px; }
  .statement-card .stmt-actions { margin-left: 0; width: 100%; }
  .statement-card .stmt-actions .btn-ok { flex: 1; }
}
