/* ─── SISTEMA DE DESEÑO ALE (AZUL CELTA) ─── */
:root {
  --azul-xunta: #58A5DA; /* Azul Celeste (Celta) */
  --fondo-app: #f4f7fb;
  --gris-bordo: #e2e8f0;
  --texto-principal: #1e293b;
  
  /* Auxiliares */
  --blanco: #ffffff;
  --xunta-light: #8cbce2;
  --accent: #f0f9ff;
  --orange-xunta: #f59e0b;
  --txt-muted: #64748b;
  --radius-lg: 20px;
  --radius-md: 12px;
  --shadow-sutil: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.025);
}

.badge-ia { font-size: 0.65rem; background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; padding: 0.15rem 0.5rem; border-radius: 4px; font-weight: 700; letter-spacing: normal; }

/* EULA Modal */
.eula-box {
  background: var(--fondo-app); border: 1px solid var(--gris-bordo); border-radius: 8px;
  padding: 1rem; max-height: 200px; overflow-y: auto; text-align: left;
  font-size: 0.75rem; color: var(--txt-muted); margin-bottom: 1rem; line-height: 1.6;
}
.eula-check-wrap { display: flex; align-items: flex-start; gap: 0.6rem; text-align: left; margin-bottom: 1.5rem; }
.eula-check-wrap input { margin-top: 0.2rem; cursor: pointer; width: 1.2rem; height: 1.2rem; }
.eula-check-wrap label { font-size: 0.8rem; font-weight: 600; cursor: pointer; color: var(--texto-principal); }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { 
  height: 100vh; 
  overflow: hidden; 
  background: var(--fondo-app); 
  color: var(--texto-principal);
  font-family: 'Inter', sans-serif;
  line-height: 1.6;
}

body {
  display: flex;
  flex-direction: column;
}

h1, h2, h3, .tb-name { font-family: 'Outfit', sans-serif; }

/* ─── ESTRUTURA PRINCIPAL (FIX SOLAPAMENTO) ─── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
}

/* ─── PREGUNTA NORMATIVA DIARIA (V118 DISCRETA) ─── */
#dd-fab {
  position: fixed; bottom: 85px; left: 20px;
  width: 44px; height: 44px; background: #0077c8;
  color: #fff; border-radius: 50%; display: flex;
  align-items: center; justify-content: center;
  font-family: inherit; font-weight: 700; font-size: 1.2rem;
  cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 3000; transition: all 0.3s ease;
  border: none;
}
#dd-fab:hover { transform: scale(1.1); background: var(--xunta-light); }
#dd-fab.activo { background: var(--orange-xunta); transform: rotate(360deg); }

.daily-card {
  position: fixed; bottom: 140px; left: 20px;
  width: 420px; padding: 1.4rem;
  background: var(--blanco); border: 1px solid var(--gris-bordo);
  border-radius: 16px; box-shadow: 0 10px 30px rgba(0,0,0,0.12);
  text-align: left; animation: fadeInUp 0.4s ease-out;
  z-index: 3001;
  max-height: 75vh; overflow-y: auto;
}
.daily-card.oculto { display: none; }
.daily-q { font-size: 0.92rem; color: var(--texto-principal); line-height: 1.6; margin-bottom: 0.9rem; font-weight: 600; }
.daily-reveal-btn {
  width: 100%; background: var(--accent); border: none; color: var(--azul-xunta);
  padding: 0.5rem; border-radius: 8px; cursor: pointer; font-size: 0.8rem;
  font-weight: 700; transition: all 0.2s;
}
.daily-reveal-btn:hover { background: var(--azul-xunta); color: #fff; }
.daily-answer { display: none; margin-top: 0.8rem; padding-top: 0.8rem; border-top: 1px dashed var(--gris-bordo); }
.daily-answer.vis { display: block; animation: fadeInUp 0.3s ease; }
.daily-answer-text { font-size: 0.9rem; color: var(--texto-principal); line-height: 1.55; margin-bottom: 0.6rem; }
.daily-source { font-size: 0.7rem; color: var(--txt-muted); margin-bottom: 0.8rem; font-style: italic; }
.daily-source a { color: var(--azul-xunta); text-decoration: none; font-weight: 600; }
.daily-btns { display: flex; gap: 0.6rem; align-items: center; }
.daily-btn-ok, .daily-btn-fail {
  flex: 1; padding: 0.4rem; border-radius: 6px; cursor: pointer;
  font-size: 0.7rem; font-weight: 700; border: none; transition: background 0.2s;
}
.daily-btn-ok { background: #dcfce7; color: #166534; }
.daily-btn-fail { background: #fee2e2; color: #991b1b; }
.daily-stats { font-size: 0.65rem; color: var(--txt-muted); margin-left: auto; }
.daily-done { font-size: 0.8rem; color: var(--azul-xunta); font-weight: 600; text-align: center; }

@keyframes fadeInUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* TOPBAR */
.topbar { 
  background: rgba(255, 255, 255, 0.85); 
  backdrop-filter: blur(12px);
  padding: 0.8rem 2rem; 
  border-bottom: 1px solid rgba(226, 232, 240, 0.8); 
  flex-shrink: 0;
  z-index: 1000; 
}
.topbar-in { max-width: 1200px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; }
.tb-brand { display: flex; align-items: center; gap: 12px; }
.tb-ico {
  width: 45px; height: 45px; background: transparent !important;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.tb-ico img { max-width: 100%; max-height: 100%; object-fit: contain; }
.tb-name { font-size: 1.2rem; font-weight: 700; color: #0072bc; }
.tb-stats { display: flex; gap: 1rem; background: #f8fafc; padding: 0.4rem 1.2rem; border-radius: 50px; border: 1px solid var(--gris-bordo); }
.tb-stat { font-size: 0.75rem; color: var(--txt-muted); font-weight: 600; }
.tb-badge { background: var(--orange-xunta); color: #fff; padding: 0.2rem 0.6rem; border-radius: 4px; font-size: 0.6rem; font-weight: 800; }

/* ÁREA DE CONVERSACIÓN (SCROLL INDEPENDENTE) */
#conv-area { 
  flex-grow: 1; 
  overflow-y: auto; 
  background: var(--fondo-app); 
  padding-bottom: 40px;
  position: relative;
}
#conv-hilo { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; }

/* MENSAXES */
.msg-u { display: flex; justify-content: flex-end; margin-bottom: 2rem; }
.msg-u-bubble { 
  background: var(--azul-xunta); color: #fff; padding: 1rem 1.5rem; 
  border-radius: 20px 20px 4px 20px; max-width: 85%; font-size: 0.95rem; 
  box-shadow: var(--shadow-sutil);
}

.msg-ale { display: flex; gap: 1rem; margin-bottom: 2.5rem; align-items: flex-start; }
.msg-ale-ico { 
  width: 40px; height: 40px; background: var(--blanco); border: 1px solid var(--gris-bordo); border-radius: 10px; 
  display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0;
}
.msg-ale-content { flex: 1; min-width: 0; }
.msg-ale-name { font-size: 0.7rem; font-weight: 800; color: var(--azul-xunta); text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 0.5rem; }
.msg-ale-text { 
  font-size: 0.9rem; color: var(--texto-principal); 
  background: var(--blanco); padding: 1.5rem; border-radius: 4px 20px 20px 20px; 
  border: 1px solid var(--gris-bordo); box-shadow: var(--shadow-sutil);
  height: auto !important; max-height: none !important; overflow: visible !important;
}

/* FEEDBACK MSG (P0-5) */
.msg-feedback {
  margin-top: 15px; display: flex; gap: 8px; justify-content: flex-end;
  border-top: 1px dashed var(--gris-bordo); padding-top: 10px;
}
.fb-btn {
  background: transparent; border: 1px solid transparent; color: #64748b;
  font-size: 1rem; cursor: pointer; padding: 4px 8px; border-radius: 6px;
  transition: all 0.2s; display: flex; align-items: center; gap: 4px;
}
.fb-btn:hover { background: #f1f5f9; color: var(--azul-xunta); }
.fb-btn.active { background: #e0f2fe; color: var(--azul-xunta); border-color: #bae6fd; }
.fb-btn:disabled { opacity: 0.5; cursor: default; pointer-events: none; }

/* ZONA DE ENTRADA (DINÁMICA) */
#input-zone { 
  flex-shrink: 0; 
  z-index: 2000;
  transition: all 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
#input-zone.iz-centered {
  flex-grow: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--fondo-app);
  border-top: none;
  padding: 0;
}
#input-zone.iz-bottom {
  background: var(--blanco);
  border-top: 1px solid var(--gris-bordo);
  padding: 0.4rem 0 0.5rem;
  flex-grow: 0;
}
.iz-inner { max-width: 800px; width: 100%; margin: 0 auto; padding: 0 1.5rem; transition: all 0.5s ease; }
/* En modo chat (iz-bottom): compacto, sen etiquetas nin empty-state */
#input-zone.iz-bottom .legal-bar { margin-top: 0.2rem; font-size: 0.6rem; opacity: 0.5; }
#input-zone.iz-bottom #history-wrap { margin-top: 0.2rem; }
#input-zone.iz-bottom #tags-wrap { display: none !important; }
#input-zone.iz-bottom #empty-state { display: none !important; }
#input-zone.iz-bottom .iz-inner { max-width: 1100px; }
/* En modo inicial (iz-centered): mostrar tarxetas, ocultar so empty-state e historial */
#input-zone.iz-centered #empty-state { display: none !important; }
#input-zone.iz-centered #history-wrap { display: none !important; }
#input-zone.iz-centered .iz-inner { max-width: 700px; }

.inp-box { 
  background: var(--blanco); border: 1.5px solid var(--gris-bordo); 
  border-radius: 16px; padding: 0.5rem; transition: border-color 0.3s;
  box-sizing: border-box;
}
.inp-box:focus-within { border-color: var(--azul-xunta); }

.inp-row { display: flex; gap: 0.8rem; align-items: flex-end; }
#inp { 
  flex: 1; border: none; background: transparent; padding: 0.6rem; 
  font-size: 1rem; font-family: inherit; outline: none; resize: none; 
  max-height: 150px; color: var(--texto-principal);
}

#btn-b { 
  width: 44px; height: 44px; background: var(--azul-xunta); border: none; 
  border-radius: 12px; color: #fff; cursor: pointer; display: flex; 
  align-items: center; justify-content: center; font-size: 1.2rem; transition: transform 0.2s;
}
#btn-b:hover { transform: scale(1.05); background: var(--xunta-light); }
#btn-b:disabled { background: var(--gris-bordo); cursor: not-allowed; }

/* ── Historial de consultas recentes ── */
#history-wrap {
  margin-top: 0.5rem; display: none;
}
#history-toggle {
  background: none; border: none; color: var(--texto-secundario);
  font-size: 0.8rem; cursor: pointer; padding: 0.3rem 0.5rem;
  font-family: inherit; opacity: 0.7; transition: opacity 0.2s;
}
#history-toggle:hover { opacity: 1; color: var(--azul-xunta); }
#history-list {
  display: none; margin-top: 0.3rem;
  border-top: 1px solid var(--gris-bordo);
  padding-top: 0.3rem;
}
#history-list.open { display: block; }
.history-item {
  padding: 0.4rem 0.6rem; font-size: 0.82rem;
  color: var(--texto-principal); cursor: pointer;
  border-radius: 8px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  transition: background 0.15s;
}
.history-item:hover { background: #f0f7ff; color: var(--azul-xunta); }

.dog-link {
  display: inline-block; font-size: 0.85em; color: #666; 
  text-decoration: none; margin-top: 0.4rem; padding: 0.2rem 0;
}
.dog-link:hover { text-decoration: underline; color: var(--azul-xunta); }

.tags { display: flex; gap: 0.6rem; overflow-x: auto; padding-bottom: 1rem; scrollbar-width: none; }
.tags::-webkit-scrollbar { display: none; }
.tag { 
  background: var(--blanco); border: 1px solid var(--gris-bordo); 
  padding: 0.5rem 1rem; border-radius: 50px; font-size: 0.85rem; 
  font-weight: 600; color: var(--azul-xunta); cursor: pointer; white-space: nowrap;
}
.tag:hover { border-color: var(--azul-xunta); background: #f0f7ff; }

/* OCULTACIÓN DE DEPURACIÓN E INXECCIÓN MANUAL */
#doc-expand, .inf-doc, #txt-doc { display: none !important; }

/* MODAL */
#ovl { position: fixed; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(8px); z-index: 9999; display: flex; align-items: center; justify-content: center; }
#modal { background: #fff; max-width: 500px; width: 90%; border-radius: 20px; overflow: hidden; box-shadow: 0 20px 40px rgba(0,0,0,0.2); }
.mhd { background: var(--azul-xunta); color: #fff; padding: 2rem; text-align: center; }
.mbd { padding: 2rem; }
#btn-ac { width: 100%; padding: 0.75rem; background: var(--azul-xunta); color: #fff; border: none; border-radius: 12px; font-weight: 700; cursor: pointer; }

/* ─── AUTH MODAL: Fase 5 ARQ-ORD-AUTH-001 ─── */
#modal { max-height: 92vh; overflow-y: auto; }
.ale-input {
  width: 100%; padding: 0.65rem 0.9rem; margin-bottom: 0.6rem;
  border: 1.5px solid var(--gris-bordo); border-radius: 8px;
  font-family: 'Inter', sans-serif; font-size: 0.9rem;
  color: var(--texto-principal); background: #fff;
  transition: border-color 0.2s; display: block;
}
.ale-input:focus { outline: none; border-color: var(--azul-xunta); }
.ale-btn-primary {
  width: 100%; padding: 0.75rem; background: var(--azul-xunta); color: #fff;
  border: none; border-radius: 10px; font-weight: 700; font-size: 0.9rem;
  cursor: pointer; transition: background 0.2s; font-family: 'Inter', sans-serif;
}
.ale-btn-primary:hover { background: #4a8fc0; }
.ale-tab-btn {
  flex: 1; padding: 0.6rem; border: none; background: transparent;
  font-family: 'Inter', sans-serif; font-size: 0.85rem; font-weight: 600;
  color: var(--txt-muted); cursor: pointer; border-bottom: 2px solid transparent;
  transition: all 0.2s; margin-bottom: -2px;
}
.ale-tab-active { color: var(--azul-xunta) !important; border-bottom-color: var(--azul-xunta) !important; }


/* ESPECÍFICOS */
/* --- MINIBOTÓNS IA --- */
.miniboton {
  background-color: var(--accent);
  color: var(--azul-xunta);
  border: 1px solid var(--xunta-light);
  border-radius: 20px;
  padding: 6px 14px;
  margin: 6px 6px 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-block;
  box-shadow: var(--shadow-sutil);
}
.miniboton:hover {
  background-color: var(--azul-xunta);
  color: var(--blanco);
  transform: translateY(-1px);
}
.normas-toggle { margin-top: 1rem; color: var(--azul-xunta); font-weight: 700; cursor: pointer; font-size: 0.85rem; display: block; width: 100%; }
.normas-content { margin-top: 10px; display: block; }
.norma-item { background: #fefefe; border: 1px solid var(--gris-bordo); border-radius: 12px; padding: 1.2rem; margin-top: 0.8rem; border-left: 4px solid var(--azul-xunta); display: block; }
.ni-titulo { font-weight: 700; color: var(--azul-xunta); text-decoration: none; display: block; margin-bottom: 0.3rem; }
.btn-f, .btn-copy { background: #f8fafc; border: 1px solid var(--gris-bordo); padding: 4px 10px; border-radius: 6px; font-size: 0.75rem; cursor: pointer; margin-right: 5px; }
.btn-f:hover { background: #eff6ff; border-color: var(--azul-xunta); color: var(--azul-xunta); }

/* --- CITAS INLINE CON POPUP (V67) --- */
.cite-mark {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--azul-xunta); color: #fff;
  font-size: 0.6rem; font-weight: 700;
  width: 16px; height: 16px; border-radius: 50%;
  cursor: pointer; vertical-align: super;
  margin: 0 1px; position: relative;
  transition: transform 0.15s;
}
.cite-mark:hover { transform: scale(1.3); }
.cite-popup {
  position: absolute; bottom: 130%; left: 50%; transform: translateX(-50%);
  background: #fff; border: 1px solid var(--gris-bordo);
  border-radius: 12px; padding: 0.8rem 1rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  min-width: 240px; max-width: 340px;
  font-size: 0.8rem; color: var(--texto-principal);
  z-index: 5000; display: none;
  line-height: 1.4;
}
.cite-popup.visible { display: block; }
.cite-popup-title { font-weight: 700; color: var(--azul-xunta); margin-bottom: 4px; }
.cite-popup-link { font-size: 0.7rem; color: var(--xunta-light); text-decoration: none; }
.cite-popup-link:hover { text-decoration: underline; }

/* ALE V70: Indicador de progreso con animación */
.ale-loading { display: flex; align-items: center; gap: 12px; padding: 1.2rem 1.5rem; }
.ale-loading-dot { display: flex; gap: 4px; }
.ale-loading-dot span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--azul-xunta);
  animation: alePulse 1.4s ease-in-out infinite;
}
.ale-loading-dot span:nth-child(2) { animation-delay: 0.2s; }
.ale-loading-dot span:nth-child(3) { animation-delay: 0.4s; }
@keyframes alePulse {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}
.ale-loading-text { font-size: 0.85rem; color: var(--azul-xunta); font-weight: 600; }
.ale-loading-phase { font-size: 0.7rem; color: var(--txt-muted); font-weight: 400; margin-top: 2px; }

.chat-bar { background: #e0f2fe; color: #0369a1; padding: 0.5rem 1rem; border-radius: 8px; margin-bottom: 1rem; display: none; align-items: center; justify-content: space-between; font-size: 0.8rem; font-weight: 600; }
.chat-bar.vis { display: flex; }
.chat-bar a { color: var(--azul-xunta); text-decoration: none; cursor: pointer; font-size: 0.75rem; }

.legal-bar { font-size: 0.65rem; color: var(--txt-muted); text-align: center; margin-top: 0.8rem; }

/* Utilidade */
.oculto { display: none !important; }

/* DESAFÍO NORMATIVO DIARIO */
.daily-card {
  background: var(--blanco); border: 1px solid var(--gris-bordo);
  border-radius: 16px; padding: 1.5rem; margin-top: 2rem;
  box-shadow: var(--shadow-sutil);
  animation: fadeIn 0.5s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.daily-q { font-size: 0.95rem; color: var(--texto-principal); font-weight: 600; line-height: 1.5; margin-bottom: 1rem; }
.daily-reveal-btn {
  background: var(--azul-xunta); color: #fff; border: none; border-radius: 8px;
  padding: 0.5rem 1.2rem; font-size: 0.85rem; font-weight: 600; cursor: pointer;
  transition: background 0.2s;
}
.daily-reveal-btn:hover { background: var(--xunta-light); }
.daily-answer { display: none; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--gris-bordo); }
.daily-answer.visible { display: block; }
.daily-answer-text { font-size: 0.9rem; color: var(--texto-principal); line-height: 1.5; margin-bottom: 0.5rem; }
.daily-source { font-size: 0.75rem; color: var(--txt-muted); margin-bottom: 0.8rem; }
.daily-btns { display: flex; gap: 0.5rem; align-items: center; }
.daily-btn-ok { background: #16a34a; color: #fff; border: none; border-radius: 6px; padding: 0.4rem 1rem; font-size: 0.8rem; cursor: pointer; }
.daily-btn-fail { background: #dc2626; color: #fff; border: none; border-radius: 6px; padding: 0.4rem 1rem; font-size: 0.8rem; cursor: pointer; }
.daily-stats { font-size: 0.75rem; color: var(--txt-muted); margin-left: 0.5rem; }
.daily-trigger-btn {
  background: #f8fafc; border: 1.5px solid var(--gris-bordo); color: var(--azul-xunta);
  padding: 0.8rem 1.5rem; border-radius: 12px; font-weight: 700; cursor: pointer;
  margin-top: 1.5rem; transition: all 0.2s; display: inline-flex; align-items: center; gap: 8px;
}
.daily-trigger-btn:hover { border-color: var(--azul-xunta); background: #f0f7ff; transform: translateY(-2px); }
.daily-trigger-btn:disabled { opacity: 0.6; cursor: wait; }

@media(max-width: 600px) {
  .tb-stats { display: none; }
  .topbar { padding: 0.8rem 1rem; }
  .daily-card { left: 12px; right: 12px; width: auto; }
}