/* ==========================================================================
   DIBUJANTES LAB — Chat Dibujantes Lab
   Paleta: navy #0B2545 · gold #B8902E
   ========================================================================== */

:root {
  --dib-navy: #0B2545;
  --dib-navy-light: #163a63;
  --dib-gold: #B8902E;
  --dib-gold-light: #F3E6C8;
  --dib-bg: #f4f5f7;
  --dib-white: #ffffff;
  --dib-text: #1c2430;
  --dib-radius: 16px;
  --dib-shadow: 0 12px 40px rgba(11, 37, 69, 0.28);
}

#dib-chat-root, #dib-chat-root * {
  box-sizing: border-box;
  font-family: 'Segoe UI', Arial, Helvetica, sans-serif;
}

.dib-header {
  background: linear-gradient(120deg, var(--dib-navy), var(--dib-navy-light));
  color: var(--dib-white);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.dib-header img { width: 38px; height: 38px; object-fit: contain; border-radius: 8px; background: #fff; padding: 3px; }
.dib-header .dib-titles { flex: 1; line-height: 1.25; }
.dib-header .dib-titles b { font-size: 14px; display: block; }
.dib-header .dib-titles span { font-size: 11px; color: var(--dib-gold-light); }
.dib-header .dib-status { display:flex; align-items:center; gap:5px; font-size: 11px; color: var(--dib-gold-light); }
.dib-header .dib-status i { width:7px; height:7px; border-radius:50%; background:#3ddc84; display:inline-block; }
.dib-close {
  background: none; border: none; color: var(--dib-white);
  font-size: 20px; cursor: pointer; line-height: 1; opacity: .8;
}
.dib-close:hover { opacity: 1; }
.dib-reset {
  background: none; border: none; color: var(--dib-white);
  font-size: 15px; cursor: pointer; line-height: 1; opacity: .75; margin-right: 4px;
}
.dib-reset:hover { opacity: 1; transform: rotate(-45deg); }

.dib-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--dib-bg);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.dib-messages::-webkit-scrollbar { width: 6px; }
.dib-messages::-webkit-scrollbar-thumb { background: #d7d7d7; border-radius: 3px; }

.dib-msg {
  max-width: 84%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: dibIn .18s ease;
}
@keyframes dibIn { from { opacity:0; transform: translateY(6px);} to {opacity:1; transform:translateY(0);} }
.dib-msg.bot {
  background: var(--dib-white);
  color: var(--dib-text);
  border: 1px solid #e6e6ea;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.dib-msg.user {
  background: var(--dib-navy);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.dib-msg.system {
  align-self: center;
  background: var(--dib-gold-light);
  color: var(--dib-navy);
  font-size: 12px;
  border-radius: 10px;
}

.dib-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: var(--dib-white);
  border: 1px solid #e6e6ea;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.dib-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: #9aa3b0; display: inline-block;
  animation: dibBlink 1.2s infinite ease-in-out;
}
.dib-typing span:nth-child(2) { animation-delay: .2s; }
.dib-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes dibBlink { 0%,80%,100%{opacity:.3;} 40%{opacity:1;} }

.dib-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-self: stretch;
  max-width: 100%;
  padding-bottom: 2px;
}
.dib-quick button {
  background: var(--dib-white);
  border: 1.5px solid var(--dib-navy);
  color: var(--dib-navy);
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.dib-quick button:hover { background: var(--dib-navy); color: #fff; }

/* --- Tarjeta de ficha / resumen --- */
.dib-card {
  background: var(--dib-white);
  border: 1.5px solid var(--dib-gold);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 12.5px;
  align-self: stretch;
}
.dib-card h4 { margin: 0 0 8px; color: var(--dib-navy); font-size: 13px; }
.dib-card table { width: 100%; border-collapse: collapse; }
.dib-card td { padding: 3px 0; vertical-align: top; }
.dib-card td.k { color: #777; width: 40%; white-space: nowrap; }
.dib-card td.v { color: var(--dib-text); font-weight: 600; }
.dib-card .dib-form { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.dib-card input {
  border: 1px solid #ddd; border-radius: 8px; padding: 8px 10px; font-size: 13px;
}
.dib-card .dib-send {
  margin-top: 4px;
  background: var(--dib-gold);
  color: var(--dib-navy);
  border: none;
  padding: 10px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  font-size: 13px;
}
.dib-card .dib-send:hover { filter: brightness(1.05); }
.dib-card .dib-send:disabled { opacity: .6; cursor: default; }

.dib-inputbar {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 10px;
  background: var(--dib-white);
  border-top: 1px solid #eee;
}
.dib-inputbar textarea {
  flex: 1;
  resize: none;
  border: 1px solid #ddd;
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 13.5px;
  max-height: 80px;
  outline: none;
}
.dib-inputbar textarea:focus { border-color: var(--dib-navy); }
.dib-inputbar button {
  background: var(--dib-navy) !important;
  color: #fff !important;
  border: none !important;
  width: 42px !important;
  height: 42px !important;
  min-width: 42px !important;
  border-radius: 50% !important;
  cursor: pointer;
  flex-shrink: 0;
  display: flex !important; align-items: center !important; justify-content: center !important;
  padding: 0 !important;
  box-shadow: 0 2px 8px rgba(11,37,69,.25);
  transition: transform .15s ease, box-shadow .15s ease;
}
#dibSend:hover:not(:disabled) { transform: scale(1.08); box-shadow: 0 4px 14px rgba(11,37,69,.4); }
.dib-inputbar button:disabled { opacity: .5; cursor: default; }
.dib-inputbar button svg { width: 18px; height: 18px; fill: #fff; }
.dib-inputbar .dib-attach {
  background: var(--dib-gold-light) !important;
}
.dib-inputbar .dib-attach svg { fill: none !important; stroke: var(--dib-navy); }

.dib-footer-note {
  text-align: center;
  font-size: 10px;
  color: #aaa;
  padding: 4px 0 8px;
  background: var(--dib-white);
}

/* Referencias visuales seleccionables */
.dib-referencias { display: grid !important; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.dib-ref { position: relative; padding: 0; border: 2px solid #e3e8ef; border-radius: 8px; overflow: hidden; background: #fff; cursor: pointer; aspect-ratio: 4 / 3; transition: border-color .15s, transform .15s; }
.dib-ref img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dib-ref span { position: absolute; top: 4px; left: 4px; background: var(--dib-navy, #0b2a4a); color: #fff; font: 700 11px/1 Arial, sans-serif; padding: 3px 6px; border-radius: 10px; }
.dib-ref:hover { border-color: #B8902E; transform: scale(1.02); }
.dib-ref-sel { border-color: #1fd28a; box-shadow: 0 0 0 2px #1fd28a; }
.dib-ref-done .dib-ref:not(.dib-ref-sel) { opacity: .45; pointer-events: none; }

/* Cotización estimada en PDF */
.dib-cot { margin-top: 8px; background: #B8902E; }
.dib-pdf { display: inline-block; padding: 10px 14px; background: #0b2a4a; color: #fff !important; border-radius: 8px; font-weight: 700; text-decoration: none; }
.dib-pdf:hover { background: #B8902E; }



/* ==========================================================================
   v1.7 — Ventana de chat tradicional: barra minimizada + panel anclado abajo a la derecha
   ========================================================================== */
#dib-chat-root .dib-launcher {
  position: fixed; right: 24px; bottom: 0; width: 330px; max-width: calc(100vw - 16px);
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--dib-navy); color: #fff; cursor: pointer; z-index: 999998;
  border-radius: 10px 10px 0 0; border: 1px solid rgba(255,255,255,.14); border-bottom: 0;
  box-shadow: 0 -4px 22px rgba(11,37,69,.35); transition: transform .18s ease, box-shadow .18s ease;
}
#dib-chat-root .dib-launcher:hover { transform: translateY(-2px); box-shadow: 0 -6px 26px rgba(11,37,69,.45); }
#dib-chat-root .dib-launcher:focus-visible { outline: 2px solid var(--dib-gold); outline-offset: 2px; }
#dib-chat-root .dib-launcher.dib-hide { display: none; }
#dib-chat-root .dib-launcher > img { width: 34px; height: 34px; object-fit: contain; background: #fff; border-radius: 8px; padding: 3px; flex-shrink: 0; }
#dib-chat-root .dib-lmain { flex: 1; min-width: 0; line-height: 1.3; }
#dib-chat-root .dib-ltitle { font-weight: 600; font-size: 13.5px; display: flex; align-items: center; gap: 6px; }
#dib-chat-root .dib-ltitle i { width: 7px; height: 7px; border-radius: 50%; background: #2ee59d; display: inline-block; flex-shrink: 0; }
#dib-chat-root .dib-teaser {
  position: static; transform: none; max-width: none; background: none; border: 0; box-shadow: none; padding: 0;
  font-size: 12px; font-weight: 400; color: #c9d6e6; opacity: 1; pointer-events: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: opacity .25s ease;
}
#dib-chat-root .dib-teaser::after { display: none; }
#dib-chat-root .dib-teaser.dib-fade { opacity: 0; }
#dib-chat-root .dib-lbadge { background: var(--dib-gold); color: var(--dib-navy); font-weight: 700; font-size: 11px; border-radius: 10px; padding: 1px 7px; flex-shrink: 0; }
#dib-chat-root .dib-lbadge.dib-hide { display: none; }
#dib-chat-root .dib-lchev { width: 16px; height: 16px; flex-shrink: 0; opacity: .8; }
#dib-chat-root .dib-launcher.dib-pulse { animation: dibPulse 1.4s ease-out 2; }
@keyframes dibPulse { 0% { box-shadow: 0 -4px 22px rgba(11,37,69,.35), 0 0 0 0 rgba(184,144,46,.6); } 100% { box-shadow: 0 -4px 22px rgba(11,37,69,.35), 0 0 0 16px rgba(184,144,46,0); } }

#dib-chat-root .dib-window {
  position: fixed; right: 24px; bottom: 0; top: auto; left: auto; transform: translateY(24px);
  width: 380px; max-width: calc(100vw - 16px); height: min(620px, calc(100vh - 24px)); max-height: none;
  background: var(--dib-white); border-radius: 10px 10px 0 0; border: 1px solid rgba(11,37,69,.25); border-bottom: 0;
  box-shadow: 0 -8px 40px rgba(11,37,69,.35); display: flex; flex-direction: column; overflow: hidden;
  z-index: 999999; opacity: 0; pointer-events: none; visibility: hidden; transition: opacity .18s ease, transform .18s ease, visibility 0s .18s;
}
#dib-chat-root .dib-window.dib-open { opacity: 1; transform: none; pointer-events: all; visibility: visible; transition: opacity .18s ease, transform .18s ease; }
#dib-chat-root .dib-header { padding: 12px 14px; }
#dib-chat-root .dib-header .dib-titles b { font-size: 14px; font-weight: 600; }
#dib-chat-root .dib-min { background: none; border: 0; color: #fff; font-size: 22px; line-height: 1; cursor: pointer; padding: 2px 8px; opacity: .85; }
#dib-chat-root .dib-min:hover, #dib-chat-root .dib-reset:hover { opacity: 1; }
#dib-chat-root .dib-refnota { font-size: 11px; color: #667; margin-top: 4px; }
@media (max-width: 480px) {
  #dib-chat-root .dib-launcher { right: 8px; left: 8px; width: auto; }
  #dib-chat-root .dib-window { right: 0; left: 0; width: 100%; max-width: 100%; height: 100dvh; border-radius: 0; border: 0; }
}
@media (prefers-reduced-motion: reduce) { #dib-chat-root * { animation: none !important; transition: none !important; } }


/* ==========================================================================
   v1.9 — Pestaña lateral sobria (mitad de pantalla, derecha) + ventana animada
   ========================================================================== */
#dib-chat-root .dib-launcher {
  right: 0; left: auto; bottom: auto; top: 50%; width: 50px; max-width: 92vw; transform: translateY(-50%);
  flex-direction: column; gap: 10px; padding: 12px 7px; align-items: center; overflow: visible;
  background: linear-gradient(180deg, #0f2f57, #0b2545); color: #fff; border: 1px solid #b8902e; border-right: 0; border-radius: 10px 0 0 10px;
  box-shadow: -4px 6px 20px rgba(0,0,0,.4);
  transition: width .38s cubic-bezier(.22,.8,.3,1), padding .2s ease, box-shadow .2s ease, opacity .45s ease;
}
#dib-chat-root .dib-launcher:hover, #dib-chat-root .dib-launcher:focus-visible { width: 300px; flex-direction: row; gap: 12px; padding: 12px 16px; box-shadow: -6px 8px 26px rgba(0,0,0,.5); }
#dib-chat-root .dib-launcher.dib-away { opacity: 0; pointer-events: none; }
#dib-chat-root .dib-launcher > img, #dib-chat-root .dib-lchev { display: none !important; }
#dib-chat-root .dib-mark { width: 36px; height: 36px; flex-shrink: 0; }
#dib-chat-root .dib-lmain { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; }
#dib-chat-root .dib-launcher:hover .dib-lmain { align-items: flex-start; }
#dib-chat-root .dib-ltitle { display: none; font-size: 10.5px; font-weight: 700; letter-spacing: 1.4px; text-transform: uppercase; color: #d9b45a; }
#dib-chat-root .dib-launcher:hover .dib-ltitle { display: flex; }
#dib-chat-root .dib-ltitle i { background: #2ee59d; }
#dib-chat-root .dib-teaser { writing-mode: vertical-rl; transform: rotate(180deg); max-height: 180px; color: #e8eef8; font-size: 12.5px; font-weight: 600; letter-spacing: .4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#dib-chat-root .dib-launcher:hover .dib-teaser { writing-mode: horizontal-tb; transform: none; max-height: none; white-space: normal; font-size: 13.5px; line-height: 1.3; text-align: left; }
#dib-chat-root .dib-lbadge { position: absolute; top: -7px; left: -7px; background: #b8902e; color: #0b2545; font-size: 10px; padding: 1px 6px; }
#dib-chat-root .dib-launcher.dib-pulse { animation: dibRing 1.6s ease-out 2; }
@keyframes dibRing { 0% { box-shadow: -4px 6px 20px rgba(0,0,0,.4), 0 0 0 0 rgba(184,144,46,.6); } 100% { box-shadow: -4px 6px 20px rgba(0,0,0,.4), 0 0 0 14px rgba(184,144,46,0); } }
#dib-chat-root .dib-window {
  right: 12px; left: auto; bottom: auto; top: 50%; height: min(620px, calc(100vh - 32px)); transform-origin: right center;
  transform: translate(28px, -50%) scale(.94); border: 1px solid rgba(11,37,69,.45); border-radius: 12px; box-shadow: 0 14px 44px rgba(0,0,0,.4);
  transition: opacity .2s ease, transform .2s ease, visibility 0s .2s;
}
#dib-chat-root .dib-window.dib-open { transform: translate(0, -50%) scale(1); transition: opacity .25s ease, transform .35s cubic-bezier(.22,.8,.3,1); }
@media (max-width: 480px) {
  #dib-chat-root .dib-launcher { width: 44px; }
  #dib-chat-root .dib-launcher:hover { width: min(290px, 88vw); }
  #dib-chat-root .dib-window { right: 0; left: 0; top: 0; width: 100%; height: 100dvh; border-radius: 0; border: 0; transform: translateY(30px); }
  #dib-chat-root .dib-window.dib-open { transform: none; }
}
@media (prefers-reduced-motion: reduce) { #dib-chat-root * { animation: none !important; transition: none !important; } }


/* ==========================================================================
   v2.0 — La ventana abierta sube 50 px y limita su altura: ya no tapa el botón "subir" de la web
   ========================================================================== */
#dib-chat-root .dib-window {
  top: calc(50% - 50px); height: min(620px, calc(100vh - 140px));
}
@media (max-width: 480px) {
  #dib-chat-root .dib-window { top: 0; height: 100dvh; }
}

/* v3.0 — desglose por lámina */
.dib-desglose { max-width: 100% !important; }
.dib-desglose .dib-des-t { font: 700 12px/1.3 Arial, sans-serif; color: var(--dib-navy, #0b2a4a); margin-bottom: 6px; }
.dib-desglose table { width: 100%; border-collapse: collapse; font: 12px/1.35 Arial, sans-serif; }
.dib-desglose td { padding: 3px 4px; border-bottom: 1px solid #e3e8ef; vertical-align: top; }
.dib-desglose td.n { text-align: right; white-space: nowrap; }
.dib-desglose tr.rp td { color: #778; font-style: italic; }
.dib-desglose tr.aj td { color: #138a5a; }
.dib-desglose tr.tt td { font-weight: 700; border-top: 2px solid var(--dib-navy, #0b2a4a); border-bottom: 0; padding-top: 6px; }


/* ==========================================================================
   v3.2 — "CHAT DIBUJANTES LAB": ventana de ayuda acoplada a la derecha, a la
   mitad de la pantalla. Plegada = pestaña vertical; abierta = panel de media
   altura pegado al borde derecho. (Sin "AI" en ningún texto.)
   ========================================================================== */
#dib-chat-root .dib-launcher,
#dib-chat-root .dib-launcher:hover,
#dib-chat-root .dib-launcher:focus-visible {
  right: 0; left: auto; bottom: auto; top: 50%;
  width: 46px; height: auto; padding: 14px 6px; gap: 10px;
  flex-direction: column; align-items: center;
  transform: translateY(-50%); border-radius: 12px 0 0 12px;
  box-shadow: -4px 6px 20px rgba(0,0,0,.4);
}
#dib-chat-root .dib-launcher:hover { transform: translateY(-50%) translateX(-3px); box-shadow: -8px 8px 26px rgba(0,0,0,.5); }
#dib-chat-root .dib-launcher.dib-away { opacity: 1 !important; pointer-events: auto !important; } /* siempre visible */
#dib-chat-root .dib-launcher .dib-lmain, #dib-chat-root .dib-launcher:hover .dib-lmain { align-items: center; flex: 0 0 auto; }
#dib-chat-root .dib-launcher .dib-teaser,
#dib-chat-root .dib-launcher:hover .dib-teaser { display: none !important; }
#dib-chat-root .dib-launcher .dib-ltitle,
#dib-chat-root .dib-launcher:hover .dib-ltitle {
  display: flex !important; writing-mode: vertical-rl; transform: rotate(180deg);
  font-size: 12px; font-weight: 800; letter-spacing: 2px; text-transform: uppercase; color: #fff; white-space: nowrap;
}
#dib-chat-root .dib-launcher .dib-ltitle i { display: none; }
#dib-chat-root .dib-launcher .dib-mark { width: 30px; height: 30px; }

#dib-chat-root .dib-window {
  right: 0; left: auto; bottom: auto; top: 50%;
  width: min(390px, 100vw); height: clamp(430px, 52vh, 640px); max-height: calc(100dvh - 24px);
  border-radius: 12px 0 0 12px; border-right: 0;
  transform-origin: right center; transform: translate(100%, -50%); opacity: 0;
  box-shadow: -8px 10px 40px rgba(0,0,0,.42);
}
#dib-chat-root .dib-window.dib-open { transform: translate(0, -50%); opacity: 1; }
#dib-chat-root .dib-header { padding: 12px 14px; }
#dib-chat-root .dib-titles b { text-transform: uppercase; letter-spacing: 1.2px; font-size: 13.5px; }
#dib-chat-root .dib-min { font-size: 26px; line-height: 1; font-weight: 400; }
@media (max-width: 480px) {
  #dib-chat-root .dib-launcher, #dib-chat-root .dib-launcher:hover { width: 40px; padding: 12px 4px; }
  #dib-chat-root .dib-window { top: 50%; width: 100vw; height: min(78dvh, 640px); border-radius: 12px 0 0 12px; transform: translate(100%, -50%); }
  #dib-chat-root .dib-window.dib-open { transform: translate(0, -50%); }
}
