/* TerzaghAI — estilos (extraído de TerzaghAI.html para cacheo) */
  :root {
    --navy: #1a2649;
    --navy-dark: #0f1830;
    --navy-soft: #2a3866;
    --green: #2dd845;
    --green-dark: #1fa832;
    --white: #ffffff;
    --ink: #1a2649;
    --muted: #6b7a99;
    --line: #e4e8f0;
    --line-soft: #f0f3f8;
    --bg-soft: #f7f9fc;
    --user-bg: #eef5ff;
    --code-bg: #f5f7fb;
  }

  * { box-sizing: border-box; margin: 0; padding: 0; }

  html, body {
    min-height: 100vh;
    min-height: 100dvh;   /* dvh = altura visible real en móvil (descuenta barra del navegador) */
    font-family: 'Inter', -apple-system, sans-serif;
    color: var(--ink);
    background: var(--white);
    font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  .page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
  }

  /* ─── LOGO ─── */
  .logo-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
    gap: 18px;
  }

  .logo-icon {
    flex-shrink: 0;
  }

  .logo-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
  }

  .logo-main {
    font-family: 'Inter', sans-serif;
    font-weight: 800;
    font-size: 54px;
    line-height: 0.95;
    letter-spacing: -2px;
    color: var(--navy);
  }

  .logo-main .green {
    color: var(--green);
  }

  .logo-sub {
    font-family: 'Inter', sans-serif;
    font-weight: 400;
    font-size: 16px;
    color: var(--navy);
    letter-spacing: 8px;
    margin-top: 2px;
    padding-top: 4px;
    border-top: 2px solid var(--green);
    width: 100%;
    text-align: center;
  }

  .tagline {
    text-align: center;
    font-size: 13px;
    color: var(--muted);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    margin-bottom: 28px;
    margin-top: 4px;
    font-weight: 500;
  }

  /* ─── CAJA PRINCIPAL DEL CHAT ─── */
  .chat-card {
    width: 100%;
    max-width: 860px;
    background: var(--white);
    border: 1.5px solid var(--line);
    border-radius: 20px;
    box-shadow: 0 4px 24px rgba(26, 38, 73, 0.06), 0 2px 6px rgba(26, 38, 73, 0.04);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 520px;
  }

  .chat-header {
    background: var(--navy);
    color: white;
    padding: 18px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
  }

  .chat-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 0.3px;
  }

  .chat-header-title::before {
    content: "";
    width: 8px;
    height: 8px;
    background: var(--green);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--green);
    animation: pulse 2s infinite;
  }

  @keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
  }

  .chat-header-actions {
    display: flex;
    gap: 8px;
  }

  .icon-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background 0.15s;
  }

  .icon-btn:hover {
    background: rgba(255, 255, 255, 0.18);
  }

  /* ─── STREAM DE MENSAJES ─── */
  #chat-stream {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    max-height: 55vh;
    min-height: 280px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    background: var(--bg-soft);
  }

  .msg {
    display: flex;
    gap: 12px;
    max-width: 92%;
    animation: fadeIn 0.3s ease-out;
  }

  @keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
  }

  .msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
  }

  .msg-avatar {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: -0.5px;
  }

  .msg.assistant .msg-avatar {
    background: var(--navy);
    color: var(--green);
  }

  .msg.user .msg-avatar {
    background: var(--green);
    color: var(--navy);
  }

  .msg-bubble {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14.5px;
    line-height: 1.55;
    color: var(--ink);
  }

  .msg.assistant .msg-bubble {
    background: white;
    border: 1px solid var(--line);
  }

  .msg.user .msg-bubble {
    background: var(--navy);
    color: white;
  }

  .msg-bubble p { margin-bottom: 8px; }
  .msg-bubble p:last-child { margin-bottom: 0; }
  .msg-bubble strong { font-weight: 700; color: var(--navy); }
  .msg.user .msg-bubble strong { color: white; }

  .msg-bubble ul, .msg-bubble ol {
    padding-left: 20px;
    margin: 8px 0;
  }

  .msg-bubble li { margin-bottom: 4px; }

  .msg-bubble code {
    font-family: 'JetBrains Mono', monospace;
    background: var(--code-bg);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 13px;
    color: var(--navy);
  }

  .msg.user .msg-bubble code {
    background: rgba(255, 255, 255, 0.15);
    color: white;
  }

  .msg-bubble pre {
    background: var(--code-bg);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 12.5px;
  }

  .msg-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 13px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    border-radius: 4px;
    overflow: hidden;
  }

  .msg-bubble th, .msg-bubble td {
    padding: 7px 10px;
    text-align: left;
    border: 1px solid var(--line);
  }

  .msg-bubble th {
    background: var(--navy);
    color: var(--white);
    font-weight: 600;
    letter-spacing: 0.2px;
    font-size: 12px;
    text-transform: uppercase;
  }

  .msg-bubble tbody tr:nth-child(even) td {
    background: var(--bg-soft);
  }

  /* Alineación derecha para columnas numéricas (última y penúltimas) */
  .msg-bubble td:nth-last-child(-n+3):not(:first-child) {
    font-variant-numeric: tabular-nums;
    text-align: right;
  }
  .msg-bubble th:nth-last-child(-n+3):not(:first-child) {
    text-align: right;
  }

  /* Primera columna (# o numeración) compacta y centrada */
  .msg-bubble td:first-child, .msg-bubble th:first-child {
    text-align: center;
    width: 36px;
    color: var(--muted);
  }

  /* Filas totales (detectadas por contenido en negrita en una celda) */
  .msg-bubble tr:has(td strong) td {
    background: #eaf6ec;
    font-weight: 600;
    color: var(--navy);
    border-top: 2px solid var(--green-dark);
  }

  /* ─── ENHANCED RESPONSE UI ─── */
  .cell-good   { background: #e8f9eb !important; color: #1a6b2a !important; font-weight: 600; }
  .cell-warn   { background: #fffbe6 !important; color: #7d5a00 !important; font-weight: 600; }
  .cell-danger { background: #fff0f0 !important; color: #b91c1c !important; font-weight: 600; }

  .cell-bar {
    height: 3px;
    border-radius: 2px;
    margin-top: 4px;
    transition: width 0.7s ease;
  }
  .cell-bar.bar-good    { background: #2dd845; }
  .cell-bar.bar-warn    { background: #f59e0b; }
  .cell-bar.bar-danger  { background: #ef4444; }
  .cell-bar.bar-neutral { background: #93a4c0; }

  .geo-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    margin: 12px 0;
  }
  .geo-card {
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px 8px 10px;
    text-align: center;
    transition: transform 0.15s;
  }
  .geo-card:hover { transform: translateY(-2px); }
  .geo-card.card-good   { border-color: #2dd845; background: #f0fff4; }
  .geo-card.card-warn   { border-color: #f59e0b; background: #fffbeb; }
  .geo-card.card-danger { border-color: #ef4444; background: #fff5f5; }
  .gc-icon  { font-size: 20px; margin-bottom: 5px; }
  .gc-val   { font-size: 19px; font-weight: 700; color: var(--navy); line-height: 1.1; }
  .gc-unit  { font-size: 10px; color: var(--muted); margin-top: 1px; }
  .gc-label { font-size: 10px; color: var(--muted); margin-top: 5px; font-weight: 500; }

  .chart-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 8px 0 4px;
    padding: 5px 13px;
    background: var(--navy);
    color: var(--white);
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    font-weight: 500;
    letter-spacing: 0.2px;
  }
  .chart-toggle-btn:hover { background: var(--navy-soft); }
  .chart-wrap {
    margin: 6px 0 12px;
    background: var(--bg-soft);
    border-radius: 8px;
    padding: 14px 12px;
    border: 1px solid var(--line);
    display: none;
  }
  .chart-wrap.visible { display: block; }
  .chart-wrap canvas  { max-height: 260px; }

  /* Badge que muestra qué modelo respondió */
  .msg-model-badge {
    display: inline-block;
    margin-top: 10px;
    padding-top: 6px;
    border-top: 1px dashed var(--line);
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--muted);
    letter-spacing: 0.3px;
    opacity: 0.7;
  }
  .msg-model-badge .dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 5px;
    vertical-align: middle;
  }
  .msg-model-badge .dot.simple { background: var(--navy-soft); }
  .msg-model-badge .dot.compleja { background: var(--green); }

  /* Citas normativas inline */
  .cite {
    background: #eef4ff;
    border-radius: 3px;
    padding: 1px 5px;
    font-weight: 600;
    font-size: 0.88em;
    color: var(--navy);
    white-space: nowrap;
  }

  /* Separador horizontal en respuestas */
  .msg-bubble hr {
    border: none;
    border-top: 1px solid var(--line);
    margin: 10px 0;
  }

  /* Cursor de streaming */
  .stream-cursor {
    display: inline-block;
    color: var(--green);
    font-weight: 700;
    animation: blink 0.7s step-end infinite;
    margin-left: 1px;
  }
  @keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

  .stream-text {
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 14px;
    line-height: 1.65;
  }

  .msg-continuar-aviso {
    margin-top: 10px;
    padding: 8px 12px;
    background: #fff8e1;
    border-left: 3px solid #f59e0b;
    border-radius: 6px;
    font-size: 13px;
    color: #92400e;
    line-height: 1.5;
  }

  /* ── Barra de acciones de respuesta ─────────────────────────── */
  .msg-actions {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed var(--line);
    opacity: 0;
    transition: opacity .2s;
  }
  .msg.assistant:hover .msg-actions { opacity: 1; }
  /* Táctil (sin hover): los botones de acción deben estar siempre visibles */
  @media (hover: none) {
    .msg-actions { opacity: 1; }
    .history-item-del { opacity: 1; }
  }
  .msg-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: transparent;
    color: var(--muted);
    font-size: 11px;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
    font-family: inherit;
  }
  .msg-action-btn:hover {
    background: var(--navy);
    color: #fff;
    border-color: var(--navy);
  }
  .msg-action-btn.copied {
    background: var(--green);
    color: var(--navy);
    border-color: var(--green);
  }

  .typing {
    display: flex;
    gap: 4px;
    padding: 4px 2px;
  }

  .typing span {
    width: 6px;
    height: 6px;
    background: var(--navy-soft);
    border-radius: 50%;
    animation: bounce 1.4s infinite;
  }

  .typing span:nth-child(2) { animation-delay: 0.16s; }
  .typing span:nth-child(3) { animation-delay: 0.32s; }

  @keyframes bounce {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
  }

  /* ─── ÁREA DE INPUT ─── */
  .input-area {
    padding: 16px 20px 20px;
    background: white;
    border-top: 1px solid var(--line);
  }

  .quick-prompts-wrap { margin-top: 10px; }

  /* Fila de chips de categoría */
  .qp-cats {
    display: flex;
    gap: 5px;
    overflow-x: auto;
    padding-bottom: 8px;
    scrollbar-width: none;
  }
  .qp-cats::-webkit-scrollbar { display: none; }
  .qp-cat {
    flex-shrink: 0;
    font-family: 'Inter', sans-serif;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 11px;
    border-radius: 20px;
    border: 1.5px solid var(--line);
    background: #fff;
    color: var(--muted);
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
  }
  .qp-cat:hover { border-color: var(--navy); color: var(--navy); }
  .qp-cat.active {
    background: var(--navy);
    color: #fff;
    border-color: var(--navy);
  }

  .quick-prompts {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
  }

  .quick-prompt {
    font-family: 'Inter', sans-serif;
    background: var(--bg-soft);
    color: var(--navy);
    border: 1px solid var(--line);
    font-size: 11.5px;
    padding: 5px 10px;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
  }

  .quick-prompt:hover {
    background: var(--navy);
    color: white;
    border-color: var(--navy);
  }
  .quick-prompt.hidden { display: none; }

  .input-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
  }

  textarea#user-input {
    flex: 1;
    min-width: 0;   /* permite que el textarea ceda ancho en vez de empujar/cortar los botones */
    font-family: 'Inter', sans-serif;
    font-size: 14.5px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg-soft);
    border: 1.5px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    resize: none;
    min-height: 48px;
    max-height: 180px;
    outline: none;
    transition: border-color 0.15s, background 0.15s;
  }

  textarea#user-input:focus {
    border-color: var(--green);
    background: white;
    box-shadow: 0 0 0 3px rgba(45, 216, 69, 0.12);
  }

  #send-btn {
    height: 48px;
    padding: 0 20px;
    background: var(--navy);
    color: white;
    border: none;
    border-radius: 12px;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-shrink: 0;       /* el botón nunca se comprime ni corta su texto */
    white-space: nowrap;
  }

  #send-btn:hover:not(:disabled) {
    background: var(--navy-dark);
    transform: translateY(-1px);
  }

  #send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }

  #stop-btn {
    height: 48px;
    padding: 0 18px;
    background: #fff;
    color: #e53e3e;
    border: 2px solid #e53e3e;
    border-radius: 12px;
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
    animation: stopPulse 1.8s ease-in-out infinite;
  }
  #stop-btn:hover {
    background: #e53e3e;
    color: #fff;
    animation: none;
  }
  @keyframes stopPulse {
    0%, 100% { border-color: #e53e3e; box-shadow: none; }
    50%       { border-color: #c53030; box-shadow: 0 0 0 3px rgba(229,62,62,.2); }
  }

  /* ─── FOOTER ─── */
  .footer-card {
    width: 100%;
    max-width: 860px;
    margin-top: 24px;
    padding: 22px 26px;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 16px;
    font-size: 12.5px;
    line-height: 1.55;
    color: var(--muted);
  }

  .footer-card h4 {
    font-size: 11px;
    font-weight: 700;
    color: var(--navy);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    margin-bottom: 8px;
  }

  .footer-card h4:not(:first-child) {
    margin-top: 16px;
  }

  .footer-card ul {
    list-style: none;
    padding: 0;
  }

  .footer-card li {
    padding: 3px 0;
    position: relative;
    padding-left: 14px;
  }

  .footer-card li::before {
    content: "▸";
    color: var(--green);
    position: absolute;
    left: 0;
    font-size: 10px;
    top: 6px;
  }

  .footer-card .disclaimer {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px dashed var(--line);
    font-size: 11.5px;
    font-style: italic;
    color: var(--muted);
  }

  .footer-card code {
    font-family: 'JetBrains Mono', monospace;
    color: var(--navy);
    font-size: 11px;
    background: white;
    padding: 1px 4px;
    border-radius: 3px;
    border: 1px solid var(--line);
  }

  .footer-brand {
    text-align: center;
    margin-top: 20px;
    font-size: 11px;
    color: var(--muted);
    letter-spacing: 0.5px;
  }

  .footer-brand b { color: var(--navy); font-weight: 700; }

  /* Scrollbar */
  #chat-stream::-webkit-scrollbar { width: 6px; }
  #chat-stream::-webkit-scrollbar-track { background: transparent; }
  #chat-stream::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
  #chat-stream::-webkit-scrollbar-thumb:hover { background: var(--muted); }

  @media (max-width: 640px) {
    .page { padding: 12px 10px; }                 /* header más compacto: menos padding */
    .logo-main { font-size: 32px; letter-spacing: -1.5px; }
    .logo-sub { font-size: 11px; letter-spacing: 4px; }
    .logo-wrap { gap: 8px; }
    .logo-icon svg { width: 36px; height: 56px; }
    .tagline { font-size: 11px; line-height: 1.4; margin-top: 6px; }
    .chat-card { border-radius: 14px; }
    #chat-stream { padding: 16px; max-height: 58vh; }
    /* safe-area-inset: input + quick prompts quedan por encima de la barra/indicador de iOS */
    .input-area { padding: 10px 12px calc(14px + env(safe-area-inset-bottom)); }
    #send-btn { padding: 0 14px; }
    #stop-btn { padding: 0 12px; }
    .msg { max-width: 100%; }
  }

  /* Botón adjuntar archivos */
  .attach-btn {
    background: var(--navy-soft);
    color: var(--gray-100);
    border: 1px solid var(--gray-700);
    width: 44px;
    height: 44px;
    border-radius: 10px;
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
  }
  .attach-btn:hover { background: var(--navy); transform: translateY(-1px); }
  .attach-btn:disabled { opacity: 0.5; cursor: not-allowed; }
  .input-row { display: flex; gap: 8px; align-items: flex-end; }

  /* Previews de adjuntos */
  #attachment-previews {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
  }
  #attachment-previews:empty { display: none; }
  .attachment-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--navy-soft);
    border: 1px solid var(--gray-700);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12px;
    color: var(--gray-100);
    max-width: 220px;
  }
  .attachment-chip .chip-icon { font-size: 16px; flex-shrink: 0; }
  .attachment-chip .chip-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: 'JetBrains Mono', monospace;
  }
  .attachment-chip .chip-remove {
    background: none;
    border: none;
    color: var(--gray-300);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 2px;
    flex-shrink: 0;
  }
  .attachment-chip .chip-remove:hover { color: #e53e3e; }
  .attachment-chip img.chip-thumb {
    width: 28px;
    height: 28px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
  }

  /* Chip de adjunto dentro del mensaje de usuario */
  .msg-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
  }
  .msg-attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.12);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 11px;
  }
  .msg-attachment-chip img {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
  }

  /* Menú de export dropdown */
  .export-wrap { position: relative; }
  .export-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 6px;
    background: var(--navy);
    border: 1px solid var(--gray-700);
    border-radius: 8px;
    padding: 6px;
    min-width: 180px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    z-index: 100;
  }
  .export-menu.active { display: block; }
  .export-menu button {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    color: var(--gray-100);
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.15s;
  }
  .export-menu button:hover { background: var(--navy-soft); }

  /* Badge contador memoria en botón 🧠 */
  #memory-btn { position: relative; }
  .memory-count-badge {
    position: absolute;
    top: -4px; right: -6px;
    background: var(--green);
    color: var(--navy);
    font-size: 9px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    padding: 0 3px;
    line-height: 1;
    pointer-events: none;
  }

  /* Modal memoria */
  .memory-modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 24, 48, 0.55);
    backdrop-filter: blur(4px);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
  }
  .memory-modal-backdrop.active { display: flex; }
  .memory-modal {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 24px 26px;
    max-width: 720px;
    width: 100%;
    max-height: 82vh;
    overflow-y: auto;
    color: var(--ink);
    box-shadow: 0 20px 60px rgba(15, 24, 48, 0.2);
  }
  .memory-modal h3 {
    margin: 0 0 8px 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--navy);
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .memory-modal h3::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 18px;
    background: var(--green);
    border-radius: 2px;
  }
  .memory-modal > p {
    font-size: 13px;
    color: var(--muted);
    margin: 0 0 18px 0;
    line-height: 1.5;
  }
  .memory-entry {
    border: 1px solid var(--line);
    border-left: 3px solid var(--green);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 10px;
    font-size: 13px;
    background: var(--bg-soft);
    line-height: 1.5;
  }
  .memory-entry .entry-meta {
    color: var(--muted);
    font-size: 11px;
    margin-bottom: 8px;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: 0.3px;
    text-transform: uppercase;
  }
  .memory-entry .entry-q {
    color: var(--navy);
    font-weight: 600;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px dashed var(--line);
    white-space: pre-wrap;
    word-break: break-word;
  }
  .memory-entry .entry-q::before {
    content: 'PREGUNTA';
    display: block;
    font-size: 10px;
    color: var(--green-dark);
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    font-weight: 600;
  }
  .memory-entry .entry-r {
    color: #3d4a6b;
    white-space: pre-wrap;
    word-break: break-word;
  }
  .memory-entry .entry-r::before {
    content: 'RESPUESTA';
    display: block;
    font-size: 10px;
    color: var(--navy-soft);
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    font-weight: 600;
  }
  .entry-r-toggle {
    display: block;
    margin-top: 8px;
    background: none;
    border: none;
    color: var(--green-dark);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: 0.3px;
  }
  .entry-r-toggle:hover { text-decoration: underline; }
  .memory-modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    justify-content: flex-end;
  }
  .memory-modal-actions button {
    padding: 9px 16px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: var(--white);
    color: var(--navy);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
  }
  .memory-modal-actions button:hover {
    background: var(--bg-soft);
    border-color: var(--navy-soft);
  }
  .memory-modal-actions button.danger {
    background: transparent;
    border-color: #e4b4b4;
    color: #c53030;
  }
  .memory-modal-actions button.danger:hover {
    background: #fdf2f2;
    border-color: #c53030;
  }
  .memory-empty {
    text-align: center;
    padding: 32px 20px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.6;
    background: var(--bg-soft);
    border-radius: 8px;
    border: 1px dashed var(--line);
  }

  /* ── Botón flotante WhatsApp ─────────────────────────────────────────── */
  #wa-btn {
    position: fixed;
    bottom: 84px;
    right: 28px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #25d366;
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(37,211,102,.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 900;
    transition: transform .15s, box-shadow .15s;
    text-decoration: none;
  }
  #wa-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(37,211,102,.6);
  }
  #wa-btn svg { width: 26px; height: 26px; }

  /* ── Botón flotante de ayuda ─────────────────────────────────────────── */
  #help-btn {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #1a2649;
    color: #fff;
    border: none;
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(26,38,73,.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 900;
    transition: background .15s, transform .15s;
    font-family: 'Inter', sans-serif;
  }
  #help-btn:hover {
    background: #2dd845;
    color: #1a2649;
    transform: scale(1.08);
  }
  #help-btn[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 52px;
    right: 0;
    background: #1a2649;
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    padding: 5px 10px;
    border-radius: 6px;
    pointer-events: none;
  }

  /* ── Drawer historial ───────────────────────────────────────────────── */
  #history-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.35);
    z-index: 1050;
  }
  #history-overlay.open { display: block; }
  #history-drawer {
    position: fixed;
    top: 0; right: -380px;
    width: 360px; max-width: 95vw;
    height: 100vh;
    background: #fff;
    z-index: 1051;
    display: flex; flex-direction: column;
    box-shadow: -4px 0 24px rgba(26,38,73,.18);
    transition: right .28s cubic-bezier(.4,0,.2,1);
  }
  #history-drawer.open { right: 0; }
  #history-drawer-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 18px;
    background: #1a2649; color: #fff;
    font-weight: 700; font-size: 15px;
  }
  #history-search-wrap { padding: 12px 14px 4px; border-bottom: 1px solid #eef0f5; }
  #history-search {
    width: 100%; box-sizing: border-box;
    padding: 8px 12px; border: 1px solid #dde2ef;
    border-radius: 8px; font-size: 13px; font-family: inherit;
    outline: none; color: #1a2649;
  }
  #history-search:focus { border-color: #1a2649; }
  #history-list { flex: 1; overflow-y: auto; padding: 8px 0; }
  #history-list::-webkit-scrollbar { width: 4px; }
  #history-list::-webkit-scrollbar-thumb { background: #d0d7ea; border-radius: 4px; }
  .history-item {
    padding: 11px 16px; cursor: pointer;
    border-bottom: 1px solid #f0f2f8;
    transition: background .15s;
    display: flex; align-items: flex-start; gap: 10px;
  }
  .history-item:hover { background: #f5f7fc; }
  .history-item-icon { font-size: 18px; margin-top: 1px; flex-shrink: 0; }
  .history-item-body { flex: 1; min-width: 0; }
  .history-item-titulo {
    font-size: 13px; font-weight: 600; color: #1a2649;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-bottom: 3px;
  }
  .history-item-meta { font-size: 11px; color: #8892ab; display: flex; gap: 8px; }
  .history-item-del {
    background: none; border: none; cursor: pointer;
    color: #c0c8d8; font-size: 16px; padding: 0 4px;
    flex-shrink: 0; line-height: 1;
    opacity: 0; transition: opacity .15s, color .15s;
  }
  .history-item:hover .history-item-del { opacity: 1; }
  .history-item-del:hover { color: #e53e3e; }
  .history-empty { padding: 32px 16px; text-align: center; color: #8892ab; font-size: 13px; }
  .history-load-btn {
    background: none; border: 1px solid #dde2ef; border-radius: 6px;
    padding: 6px 16px; font-size: 12px; cursor: pointer; color: #1a2649;
  }
  .history-load-btn:hover { background: #f0f2f8; }

  /* ── Comparador de normativas ───────────────────────────────────────── */
  .norma-chip {
    display: flex; align-items: center; gap: 6px;
    padding: 7px 10px; border: 1.5px solid #dde2ef;
    border-radius: 8px; cursor: pointer; font-size: 12px;
    font-family: inherit; background: #fff; color: #1a2649;
    transition: all .15s; text-align: left; font-weight: 500;
  }
  .norma-chip:hover { border-color: #1a2649; background: #f5f7fc; }
  .norma-chip.selected {
    border-color: #1a2649; background: #1a2649; color: #fff;
  }
  .norma-chip .norma-check { font-size: 10px; opacity: 0; transition: opacity .15s; }
  .norma-chip.selected .norma-check { opacity: 1; }
  .fmt-btn {
    padding: 6px 13px; border: 1.5px solid #dde2ef; border-radius: 20px;
    background: #fff; color: #6b7a99; font-size: 12px; font-weight: 600;
    cursor: pointer; font-family: inherit; transition: all .15s;
  }
  .fmt-btn:hover { border-color: #1a2649; color: #1a2649; }
  .fmt-btn.active { background: #1a2649; color: #fff; border-color: #1a2649; }
  #comparar-parametro:focus { border-color: #1a2649; }

  /* ── Modal vista de conversación ─────────────────────────────────────── */
  #history-view-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.45); z-index: 1060;
  }
  #history-view-overlay.open { display: block; }
  #history-view-modal {
    display: none; position: fixed;
    top: 50%; left: 50%; transform: translate(-50%,-50%);
    width: min(760px, 95vw); max-height: 88vh;
    background: #fff; border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    z-index: 1061; flex-direction: column;
    overflow: hidden;
  }
  #history-view-modal.open { display: flex; }
  #history-view-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; background: #1a2649; color: #fff;
    font-weight: 700; font-size: 14px; flex-shrink: 0;
  }
  .history-view-btn {
    background: #2dd845; color: #1a2649; border: none;
    padding: 6px 14px; border-radius: 6px; font-weight: 700;
    font-size: 12px; cursor: pointer;
  }
  .history-view-btn:hover { background: #25b839; }
  #history-view-messages {
    flex: 1; overflow-y: auto; padding: 16px 18px;
  }
  #history-view-messages::-webkit-scrollbar { width: 4px; }
  #history-view-messages::-webkit-scrollbar-thumb { background: #d0d7ea; border-radius: 4px; }
  .hv-msg { margin-bottom: 14px; }
  .hv-msg-label { font-size: 10px; font-weight: 700; letter-spacing: 1px;
    text-transform: uppercase; margin-bottom: 5px; }
  .hv-msg.user .hv-msg-label { color: #1a2649; }
  .hv-msg.assistant .hv-msg-label { color: #2dd845; }
  .hv-msg-content {
    background: #f5f7fc; border-radius: 8px; padding: 10px 14px;
    font-size: 13px; line-height: 1.6; color: #1a2649;
  }
  .hv-msg.user .hv-msg-content { background: #1a2649; color: #fff; }

  /* ── Modal manual ────────────────────────────────────────────────────── */
  #manual-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 1100;
    align-items: center;
    justify-content: center;
    padding: 16px;
  }
  #manual-overlay.open { display: flex; }
  #manual-panel {
    background: #fff;
    border-radius: 14px;
    width: 100%;
    max-width: 560px;
    max-height: 88vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,.28);
    position: relative;
    font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif;
    color: #1a2649;
  }
  #manual-panel::-webkit-scrollbar { width: 5px; }
  #manual-panel::-webkit-scrollbar-thumb { background: #d0d7ea; border-radius: 4px; }
  #manual-header {
    background: #1a2649;
    padding: 22px 28px 18px;
    border-radius: 14px 14px 0 0;
    position: sticky;
    top: 0;
    z-index: 1;
  }
  #manual-header h2 {
    margin: 0 0 4px;
    color: #2dd845;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -.3px;
  }
  #manual-header p {
    margin: 0;
    color: #8fa3c8;
    font-size: 13px;
  }
  #manual-close {
    position: absolute;
    top: 14px;
    right: 16px;
    background: none;
    border: none;
    color: #8fa3c8;
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    padding: 4px 6px;
    border-radius: 6px;
    transition: color .12s, background .12s;
  }
  #manual-close:hover { color: #fff; background: rgba(255,255,255,.1); }
  #manual-body { padding: 24px 28px 28px; }
  .manual-section { margin-bottom: 22px; }
  .manual-section:last-child { margin-bottom: 0; }
  .manual-section h3 {
    font-size: 14px;
    font-weight: 700;
    color: #1a2649;
    margin: 0 0 8px;
  }
  .manual-section p,
  .manual-section li {
    font-size: 13.5px;
    color: #3d4f70;
    line-height: 1.65;
    margin: 0;
  }
  .manual-section ul {
    margin: 4px 0 0 0;
    padding-left: 18px;
  }
  .manual-section ul li { margin-bottom: 3px; }
  .manual-example {
    background: #f4f6fa;
    border-left: 3px solid #2dd845;
    border-radius: 0 6px 6px 0;
    padding: 10px 14px;
    margin-top: 8px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 12.5px;
    color: #2d3a55;
    line-height: 1.6;
  }
  .manual-example + .manual-example { margin-top: 6px; }
  #manual-plan-box {
    background: #f0f4ff;
    border: 1.5px solid #c7d3f0;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 13px;
    color: #1a2649;
    line-height: 1.7;
  }
  #manual-plan-box strong { color: #1a2649; }

/* ── HVSR Modal ─────────────────────────────────────────────────────────── */
#hvsr-modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(10,16,38,.82);
  z-index: 9000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);
}
#hvsr-modal-overlay.open { display: flex; }
#hvsr-modal {
  background: #1a2649;
  border: 1px solid #2a3d6b;
  border-radius: 14px;
  width: min(680px, 96vw);
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px 32px 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
  position: relative;
}
#hvsr-modal h2 {
  color: #e6ecf5; margin: 0 0 6px; font-size: 1.2rem;
  display: flex; align-items: center; gap: 10px;
}
#hvsr-modal .hvsr-subtitle {
  color: #7a9cc0; font-size: .82rem; margin: 0 0 20px;
}
#hvsr-close {
  position: absolute; top: 14px; right: 16px;
  background: none; border: none; color: #7a9cc0;
  font-size: 1.4rem; cursor: pointer; line-height: 1;
  padding: 4px 8px; border-radius: 6px;
  transition: background .15s;
}
#hvsr-close:hover { background: #2a3d6b; color: #fff; }

/* Drop zone */
#hvsr-dropzone {
  border: 2px dashed #2a3d6b;
  border-radius: 10px;
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  background: #0f1a35;
  margin-bottom: 16px;
}
#hvsr-dropzone:hover, #hvsr-dropzone.drag-over {
  border-color: #2dd845; background: #0a1f2e;
}
#hvsr-dropzone .dz-icon { font-size: 2.2rem; margin-bottom: 8px; }
#hvsr-dropzone p { color: #c8d8f0; margin: 4px 0; font-size: .9rem; }
#hvsr-dropzone small { color: #5a7a99; font-size: .78rem; }
#hvsr-file-input-hidden { display: none; }

/* Nombre archivo seleccionado */
#hvsr-filename-display {
  font-size: .82rem; color: #2dd845;
  margin-bottom: 10px; min-height: 18px;
  word-break: break-all;
}

/* Config row */
.hvsr-config-row {
  display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.hvsr-config-row label {
  color: #7a9cc0; font-size: .8rem; display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 120px;
}
.hvsr-config-row input {
  background: #0f1a35; border: 1px solid #2a3d6b; border-radius: 6px;
  color: #e6ecf5; padding: 6px 10px; font-size: .85rem; width: 100%;
}
.hvsr-config-row input:focus { outline: none; border-color: #2dd845; }

/* Botón procesar */
#hvsr-process-btn {
  width: 100%; padding: 12px;
  background: #2dd845; color: #1a2649;
  border: none; border-radius: 8px; cursor: pointer;
  font-weight: 700; font-size: 1rem;
  transition: background .15s;
  margin-bottom: 16px;
}
#hvsr-process-btn:disabled { background: #1e5a2a; color: #4a8a55; cursor: not-allowed; }
#hvsr-process-btn:not(:disabled):hover { background: #25b839; }

/* Progress / spinner */
#hvsr-progress {
  display: none; text-align: center; padding: 20px 0; color: #7a9cc0;
}
#hvsr-progress .spinner {
  display: inline-block; width: 28px; height: 28px;
  border: 3px solid #2a3d6b; border-top-color: #2dd845;
  border-radius: 50%; animation: hvsrSpin .7s linear infinite;
  margin-bottom: 8px;
}
@keyframes hvsrSpin { to { transform: rotate(360deg); } }

/* Resultado */
#hvsr-result { display: none; }
#hvsr-result .hvsr-plot img { width: 100%; border-radius: 8px; margin-bottom: 16px; }
#hvsr-result .hvsr-metrics {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px;
}
.hvsr-metric-card {
  background: #0f1a35; border-radius: 8px; padding: 12px;
  text-align: center; border: 1px solid #2a3d6b;
}
.hvsr-metric-card .val { font-size: 1.4rem; font-weight: 700; color: #2dd845; }
.hvsr-metric-card .lbl { font-size: .72rem; color: #7a9cc0; margin-top: 2px; }
.hvsr-metric-card.warn .val { color: #ffcc00; }
.hvsr-metric-card.bad  .val { color: #ff6666; }

/* SESAME badge */
.sesame-badge {
  display: inline-block; padding: 4px 12px; border-radius: 20px;
  font-size: .8rem; font-weight: 700; margin-bottom: 12px;
}
.sesame-badge.ok  { background: #1a4a2a; color: #2dd845; border: 1px solid #2dd845; }
.sesame-badge.warn { background: #4a3a00; color: #ffcc00; border: 1px solid #ffcc00; }
.sesame-badge.bad  { background: #4a0000; color: #ff6666; border: 1px solid #ff6666; }

/* Criterios SESAME detalle */
.sesame-detail {
  background: #0f1a35; border-radius: 8px; padding: 12px 16px;
  margin-bottom: 16px; font-size: .8rem;
}
.sesame-detail h4 { color: #c8d8f0; margin: 0 0 8px; font-size: .85rem; }
.sesame-criteria-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px;
}
.sesame-crit { display: flex; align-items: center; gap: 6px; color: #7a9cc0; }
.sesame-crit .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-ok  { background: #2dd845; }
.dot-bad { background: #ff6666; }

/* Botones exportar */
#hvsr-export-pdf-btn:hover,
#hvsr-export-word-btn:hover { border-color: #2dd845; color: #2dd845; }

/* Botón enviar al chat */
#hvsr-inject-btn {
  width: 100%; padding: 10px;
  background: #1a2649; color: #2dd845;
  border: 1.5px solid #2dd845; border-radius: 8px;
  cursor: pointer; font-weight: 600; font-size: .9rem;
  transition: background .15s;
}
#hvsr-inject-btn:hover { background: #0f3020; }

/* Error display */
#hvsr-error {
  display: none; background: #3a0a0a; border: 1px solid #ff4444;
  color: #ff9999; border-radius: 8px; padding: 12px 16px;
  font-size: .83rem; margin-bottom: 12px;
}

/* Botón HVSR en input-row */
#hvsr-open-btn {
  background: none; border: none; cursor: pointer;
  font-size: 1.2rem; padding: 6px 8px; border-radius: 8px;
  color: #7a9cc0; transition: color .15s, background .15s;
}
#hvsr-open-btn:hover { color: #2dd845; background: #0f1a35; }

/* Footer colapsable: plegado en móvil (un tap para ver), expandido en desktop */
.footer-summary {
  cursor: pointer; list-style: none;
  font-weight: 700; color: var(--navy); font-size: 13px;
  padding: 8px 0; display: flex; align-items: center; gap: 6px;
}
.footer-summary::-webkit-details-marker { display: none; }
.footer-summary::after { content: "▾"; color: var(--muted); font-size: 11px; }
details.footer-collapse[open] > .footer-summary::after { content: "▴"; }
@media (min-width: 641px) {
  /* Desktop: se ve completo como antes (details cerrado pero forzamos contenido visible) */
  .footer-summary { display: none; }
  details.footer-collapse > :not(summary) { display: block; }
}

/* Overrides móviles colocados al final para ganar a las reglas base por orden de cascada */
@media (max-width: 640px) {
  .input-row { gap: 6px; }
  .attach-btn { width: 40px; height: 40px; }
  #hvsr-open-btn { padding: 4px 5px; }
  textarea#user-input { min-height: 50px; }
  textarea#user-input::placeholder { font-size: 12.5px; }
}


/* ━━━ Accesibilidad ━━━ */
/* Contraste AA: #6b7a99 sobre blanco daba ~3.9:1 en texto chico; #56648a da ≥4.6:1 */
:root { --muted: #56648a; }

/* Foco visible al navegar con teclado (sin afectar clicks de mouse) */
:focus-visible {
  outline: 2px solid var(--green, #2dd845);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Respetar la preferencia de movimiento reducido del sistema */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
