/* Panagas Bot Simulator — WhatsApp-style UI */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #d9d3cb;
  height: 100%;
  color: #111b21;
}

body {
  display: flex;
  justify-content: center;
  min-height: 100vh;
}

#app-shell {
  width: 100%;
  max-width: 420px;
  background: #ECE5DD;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.12);
}

@media (min-width: 421px) {
  #app-shell { min-height: 100vh; max-height: 100vh; }
}

/* ---------- Header ---------- */
#header {
  position: sticky;
  top: 0;
  background: #075E54;
  color: #fff;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 30;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
#header .avatar {
  width: 36px;
  height: 36px;
  background: #128C7E;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
#header .title {
  flex: 1;
  min-width: 0;
}
#header .title .line1 { font-weight: 600; font-size: 15px; }
#header .title .line2 { font-size: 11px; opacity: 0.85; }
#header .actions { display: flex; gap: 6px; }
#header button {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 14px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.1s;
}
#header button:hover { background: rgba(255, 255, 255, 0.15); }
#header button:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

/* ---------- Validation banner ---------- */
#validation-banner {
  background: #fdecea;
  color: #5f2120;
  border-bottom: 2px solid #d32f2f;
  padding: 10px 12px;
  font-size: 13px;
  max-height: 40vh;
  overflow-y: auto;
}
#validation-banner.warn { background: #fff4e5; border-color: #ed6c02; color: #663c00; }
#validation-banner .banner-title { font-weight: 700; margin-bottom: 6px; }
#validation-banner ul { margin: 4px 0 8px 18px; padding: 0; }
#validation-banner li { margin-bottom: 3px; font-family: ui-monospace, "Cascadia Code", Menlo, monospace; font-size: 11px; }
#validation-banner .banner-actions { display: flex; gap: 8px; margin-top: 8px; }
#validation-banner button {
  background: #d32f2f;
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
}
#validation-banner.warn button { background: #ed6c02; }
#validation-banner a { color: #0b5cab; }

/* ---------- Chat area ---------- */
#chat {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px 16px;
  background-color: #ECE5DD;
  background-image:
    radial-gradient(circle at 25px 25px, rgba(0, 0, 0, 0.015) 2px, transparent 2px),
    radial-gradient(circle at 75px 75px, rgba(0, 0, 0, 0.015) 2px, transparent 2px);
  background-size: 100px 100px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ---------- Bubbles ---------- */
.bubble-row {
  display: flex;
  margin: 2px 0;
  max-width: 100%;
}
.bubble-row.bot   { justify-content: flex-start; }
.bubble-row.user  { justify-content: flex-end; }
.bubble {
  max-width: 85%;
  padding: 7px 10px 20px;
  border-radius: 8px;
  position: relative;
  font-size: 14.2px;
  line-height: 1.35;
  word-wrap: break-word;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.13);
  white-space: normal;
}
.bubble-row.bot  .bubble { background: #FFFFFF; border-top-left-radius: 2px; }
.bubble-row.user .bubble { background: #DCF8C6; border-top-right-radius: 2px; }

.bubble .stamp {
  position: absolute;
  right: 8px;
  bottom: 4px;
  font-size: 10px;
  color: #667781;
}
.bubble strong { font-weight: 700; }
.bubble em { font-style: italic; }

/* Header/footer on list bubbles */
.bubble .wa-header {
  font-weight: 700;
  color: #111b21;
  margin-bottom: 4px;
}
.bubble .wa-footer {
  color: #667781;
  font-size: 12px;
  margin-top: 6px;
  padding-top: 2px;
}

/* List CTA (the "Ver opciones" button under a list bubble) */
.list-cta {
  margin-top: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  padding-top: 6px;
  text-align: center;
}
.list-cta button {
  background: transparent;
  color: #075E54;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 10px;
  width: 100%;
  letter-spacing: 0.4px;
}
.list-cta button:hover { color: #128C7E; }
.list-cta button::before { content: "☰ "; }

/* Button pills under an interactive_button bubble */
.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-top: 6px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}
.btn-stack button, .btn-stack a {
  display: block;
  background: transparent;
  color: #075E54;
  border: none;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  font-family: inherit;
}
.btn-stack > *:first-child { border-top: none; }
.btn-stack button:hover, .btn-stack a:hover { color: #128C7E; background: rgba(0, 0, 0, 0.02); }
.btn-stack button:focus-visible, .btn-stack a:focus-visible {
  outline: 2px solid #075E54; outline-offset: -2px;
}

/* Limit-violation ribbon above a bubble */
.limit-ribbon {
  background: #b71c1c;
  color: #fff;
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-family: ui-monospace, Menlo, monospace;
  margin-bottom: 4px;
  align-self: flex-start;
  max-width: 85%;
}

/* Typing indicator */
.typing {
  display: flex;
  gap: 3px;
  padding: 8px 12px;
  background: #fff;
  border-radius: 8px;
  border-top-left-radius: 2px;
  width: fit-content;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.13);
}
.typing span {
  width: 6px; height: 6px;
  background: #8696a0;
  border-radius: 50%;
  animation: typing 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* Document bubble (PDF / brochure) */
.doc-card {
  background: #f0f2f5;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 6px;
  padding: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 4px;
}
.doc-card .doc-icon {
  width: 36px; height: 44px;
  background: #d32f2f;
  color: #fff;
  border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 11px;
  flex-shrink: 0;
}
.doc-card .doc-meta { flex: 1; min-width: 0; }
.doc-card .doc-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-card .doc-size { font-size: 11px; color: #667781; }
.doc-card a { color: #075E54; font-size: 12px; text-decoration: none; }

/* ---------- Composer ---------- */
#composer {
  background: #f0f2f5;
  padding: 8px 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}
#composer input {
  flex: 1;
  padding: 9px 12px;
  border: none;
  border-radius: 20px;
  background: #fff;
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
#composer input:focus { box-shadow: 0 0 0 2px rgba(7, 94, 84, 0.3); }
#composer button {
  background: #075E54;
  color: #fff;
  border: none;
  width: 38px; height: 38px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
#composer button:disabled { opacity: 0.4; cursor: not-allowed; }

#privacy-foot {
  font-size: 10.5px;
  color: #667781;
  text-align: center;
  padding: 4px 8px 6px;
  background: #f0f2f5;
  border-top: 1px solid rgba(0, 0, 0, 0.04);
}

/* ---------- List overlay (bottom sheet) ---------- */
#list-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
  animation: fadeIn 0.15s;
}
#list-overlay.open { display: flex; }
#list-overlay .sheet {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  max-height: 82vh;
  overflow-y: auto;
  padding: 12px 0 14px;
  animation: slideUp 0.2s;
}
#list-overlay .sheet-header {
  padding: 4px 16px 10px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  font-size: 15px;
  font-weight: 600;
  color: #111b21;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#list-overlay .sheet-header button {
  background: transparent; border: none; font-size: 22px; cursor: pointer; color: #8696a0; padding: 0 4px;
}
#list-overlay .section-title {
  padding: 10px 16px 4px;
  font-size: 12px;
  text-transform: uppercase;
  color: #667781;
  letter-spacing: 0.4px;
  font-weight: 600;
}
#list-overlay .row {
  padding: 11px 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: #fff;
  border-left: none;
  border-right: none;
  border-top: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
#list-overlay .row:last-child { border-bottom: none; }
#list-overlay .row:hover { background: #f5f6f6; }
#list-overlay .row:focus-visible { background: #e6f4f1; outline: 2px solid #075E54; outline-offset: -2px; }
#list-overlay .row .r-title { font-size: 14.5px; color: #111b21; font-weight: 500; }
#list-overlay .row .r-desc { font-size: 12.5px; color: #667781; }

@keyframes slideUp { from { transform: translateY(100%);} to { transform: translateY(0);} }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Debug panel ---------- */
#debug-panel {
  position: fixed;
  top: 0; right: 0;
  height: 100vh;
  width: 340px;
  background: #0b141a;
  color: #d1d7db;
  z-index: 80;
  overflow-y: auto;
  padding: 14px;
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  font-size: 12px;
  transform: translateX(100%);
  transition: transform 0.2s ease-out;
  box-shadow: -2px 0 16px rgba(0, 0, 0, 0.3);
}
#debug-panel.open { transform: translateX(0); }
#debug-panel h3 { color: #00a884; margin: 12px 0 6px; font-size: 13px; }
#debug-panel h3:first-child { margin-top: 0; }
#debug-panel .kv { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px solid #1f2c33; }
#debug-panel .kv span:last-child { color: #00a884; }
#debug-panel pre {
  background: #1f2c33;
  padding: 8px;
  border-radius: 4px;
  overflow-x: auto;
  margin: 4px 0;
  font-size: 11px;
  color: #aebac1;
  max-height: 180px;
  overflow-y: auto;
}
#debug-panel .btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
#debug-panel .btn-row button {
  background: #00a884;
  color: #fff;
  border: none;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
}
#debug-panel .btn-row button:hover { background: #06cf9c; }
#debug-panel .close-dbg {
  position: absolute;
  top: 8px; right: 8px;
  background: transparent;
  color: #aebac1;
  border: none;
  font-size: 18px;
  cursor: pointer;
}
#debug-panel .event-line {
  padding: 2px 0;
  border-bottom: 1px dashed #1f2c33;
  font-size: 11px;
}
#debug-panel .event-line .ev-name { color: #ffd60a; }

@media (max-width: 520px) {
  #debug-panel {
    width: 100%;
    height: 72vh;
    top: auto;
    bottom: 0;
    transform: translateY(100%);
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
  }
  #debug-panel.open { transform: translateY(0); }
}

/* ---------- Utility ---------- */
.hidden { display: none !important; }
a { color: #027EB5; }
