/* ============================================================
   CHAT — Panel, mensajes, input, header
   ============================================================ */

/* chat.css v2 */
#screen-work { display: flex; flex-direction: row; height: 100vh; height: 100dvh; }

.chat-panel {
  flex: 1; min-width: 0; height: 100%;
  display: flex; flex-direction: column;
  background: var(--bg); border-right: none; overflow: visible;
  position: relative;
}
.chat-panel.with-map {
  flex: 1 1 0; min-width: 280px;
  border-right: 0.5px solid var(--border);
}
body.day, html.day .chat-panel { background: var(--bg); border-right-color: var(--border); }

/* Mensajes */
.chat-messages {
  flex: 1; overflow-y: auto;
  padding: 24px 20px 16px;
  display: flex; flex-direction: column; gap: 14px;
  scroll-behavior: smooth;
  position: relative; z-index: 1;
}
.chat-panel:not(.with-map) .chat-messages {
  padding-left: max(24px, calc((100% - 680px) / 2));
  padding-right: max(24px, calc((100% - 680px) / 2));
  transition: padding .22s ease;
}
.chat-messages { scrollbar-width: thin; }
.chat-messages::-webkit-scrollbar { width: 2px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.msg {
  max-width: 80%; line-height: 1.7; font-size: 16px;
  animation: msgIn .2s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg.assistant {
  background: transparent !important; border: none !important;
  align-self: flex-start; color: var(--cream);
  padding: 2px 0; max-width: 90%;
}
body.day, html.day .msg.assistant { color: #1a1814; }

/* Tarjeta de error de capa — misma estructura que msg-map-card */
.msg-error-card {
  width: 100%; max-width: 90%;
  background: rgba(180, 60, 60, 0.06);
  border: 0.5px solid rgba(200, 80, 80, 0.25);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex; align-items: center; gap: 14px;
  box-sizing: border-box;
}
body.day, html.day .msg-error-card {
  background: rgba(180, 60, 60, 0.04);
  border-color: rgba(180, 60, 60, 0.18);
}

.error-card-left { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }

.error-card-icon {
  font-size: 24px !important;
  color: #c07070;
  flex-shrink: 0;
}
body.day, html.day .error-card-icon { color: #a04040; }

.error-card-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }

.error-card-title {
  font-size: 15px; font-weight: 600;
  color: #d08080;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
body.day, html.day .error-card-title { color: #a04040; }

.error-card-desc {
  font-size: 13px; color: var(--cream2); line-height: 1.4;
}
body.day, html.day .error-card-desc { color: #6a6560; }

.error-card-btn {
  flex-shrink: 0; padding: 0 12px; height: 30px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #c07070;
  border: 0.5px solid rgba(200, 80, 80, 0.35);
  font-size: 11px; font-family: var(--font-sans);
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}
.error-card-btn:hover { background: rgba(200, 80, 80, 0.1); color: #e06060; }
body.day, html.day .error-card-btn { color: #a04040; border-color: rgba(160, 60, 60, 0.3); }
body.day, html.day .error-card-btn:hover { background: rgba(180, 60, 60, 0.08); }

/* ── Markdown en mensajes del asistente ──────────────────────── */
.msg.assistant p  { margin: 0 0 .6rem; line-height: 1.65; }
.msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant ul,
.msg.assistant ol { margin: 0 0 .6rem; padding-left: 1.4rem; }
.msg.assistant li { margin-bottom: .2rem; line-height: 1.6; }
.msg.assistant h1,
.msg.assistant h2,
.msg.assistant h3 {
  font-weight: 600; margin: .8rem 0 .3rem; line-height: 1.3;
}
.msg.assistant h1 { font-size: 16px; }
.msg.assistant h2 { font-size: 15px; }
.msg.assistant h3 { font-size: 14px; }
.msg.assistant strong { font-weight: 600; }
.msg.assistant em { font-style: italic; }
.msg.assistant code {
  font-family: var(--font-mono); font-size: 12px;
  background: var(--bg3); border: 0.5px solid var(--border-md);
  border-radius: 3px; padding: 1px 5px;
}
body.day, html.day .msg.assistant code { background: rgba(0,0,0,0.06); }
.msg.assistant pre {
  background: var(--bg3); border: 0.5px solid var(--border-md);
  border-radius: 6px; padding: 10px 14px;
  overflow-x: auto; margin: .5rem 0 .7rem;
}
.msg.assistant pre code {
  background: none; border: none; padding: 0;
  font-size: 12px; line-height: 1.6;
}
body.day, html.day .msg.assistant pre { background: rgba(0,0,0,0.05); }
.msg.assistant blockquote {
  border-left: 2px solid var(--border-md);
  margin: 0 0 .6rem; padding: 2px 0 2px 12px;
  color: var(--cream2);
}
.msg.assistant hr {
  border: none; border-top: 0.5px solid var(--border-md); margin: .8rem 0;
}
.msg.assistant a { color: var(--accent); text-decoration: none; }
.msg.assistant a:hover { text-decoration: underline; }

/* Confirmación de exportación */
.msg-export-confirm {
  color: var(--cream2); padding: 4px 0;
}
body.day, html.day .msg-export-confirm { color: #6a6560; }

.msg.user {
  background: var(--bg2); border: none; color: var(--cream);
  align-self: flex-end; padding: 10px 16px; border-radius: 14px;
}
body.day, html.day .msg.user { background: #e0dcd6; color: #1a1814; }

.msg.thinking {
  background: transparent !important; border: none !important;
  align-self: flex-start; color: var(--accent);
  font-size: 13px; padding: 2px 0; font-family: var(--font-mono); letter-spacing: 0.01em;
}
.msg.thinking::after {
  content: '';
  display: inline-block;
  width: 5px; height: 5px; margin-left: 6px;
  border-radius: 50%; background: var(--accent);
  animation: blink 1.2s infinite; vertical-align: middle;
}
@keyframes blink {
  0%, 100% { opacity: .2; }
  50%       { opacity: 1; }
}
body.day, html.day .msg.thinking { background: var(--bg2); border-color: var(--border); }

/* Tarjeta de mapa listo */
.msg-map-card {
  width: 100%; max-width: 90%; background: var(--bg2);
  border: 0.5px solid var(--border-md); border-radius: var(--radius);
  padding: 14px 16px; display: flex; align-items: center; gap: 14px;
  box-sizing: border-box;
}
.map-card-left { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.map-card-icon { font-size: 28px !important; color: var(--cream2); flex-shrink: 0; }
.map-card-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.map-card-title {
  font-size: 15px; font-weight: 600; color: var(--cream);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
body.day, html.day .map-card-title { color: #1a1814; }
.map-card-layers { font-size: 13px; color: var(--cream2); white-space: pre-line; line-height: 1.5; }
.map-card-btn {
  flex-shrink: 0; padding: 0 12px; height: 30px;
  border-radius: var(--radius-sm);
  background: transparent; color: var(--cream2);
  border: 0.5px solid var(--border-md);
  font-size: 11px; font-family: var(--font-sans);
  letter-spacing: 0.04em;
  cursor: pointer; transition: background var(--transition), color var(--transition), border-color var(--transition);
  white-space: nowrap;
}
.map-card-btn:hover { background: var(--cream3); color: var(--cream); border-color: var(--accent); }
body.day, html.day .map-card-btn { color: #5a5650; border-color: #c8c4be; }
body.day, html.day .map-card-btn:hover { background: rgba(0,0,0,0.06); color: var(--accent); border-color: var(--accent); }

/* Input area */
.chat-input-area {
  padding: 16px 16px 0; border-top: none; flex-shrink: 0;
  width: 100%; transition: padding .22s ease;
}
.chat-panel:not(.with-map) .chat-input-area {
  padding-left: max(24px, calc((100% - 680px) / 2));
  padding-right: max(24px, calc((100% - 680px) / 2));
  max-width: none; margin: 0;
}
body.day, html.day .chat-input-area { border-top-color: var(--border); }
body.day, html.day .prompt-box.compact { background: var(--bg2); }

.chat-legend {
  text-align: center; font-size: 13.5px; color: var(--cream2);
  padding: 10px 16px 20px; letter-spacing: 0.01em;
  max-width: 680px; width: 100%; margin: 0 auto;
}

/* Header bar */
.chat-header-bar {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  border-bottom: 0.5px solid var(--border);
  height: 52px; box-sizing: border-box;
  flex-shrink: 0;
  display: flex; align-items: center;
}
body.day, html.day .chat-header-bar { background: var(--bg); }
.chat-header-inner {
  flex: 1; display: flex; align-items: center;
  gap: 6px; padding: 0 20px; height: 100%;
  min-width: 0;
}
.chat-header-title-input {
  font-family: var(--font-sans); font-size: 15px; font-weight: 500;
  color: var(--cream); background: transparent; border: none; outline: none;
  min-width: 120px; max-width: 400px; width: 100%;
  cursor: text;
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition);
}
.chat-header-title-input:focus { border-bottom-color: var(--accent); }
.chat-header-title-input::placeholder { color: var(--cream2); }
body.day, html.day .chat-header-title-input { color: #1a1814; }
.chat-header-delete-btn {
  width: 36px; height: 36px; border-radius: 6px; flex-shrink: 0;
  background: transparent; border: none; color: var(--cream2);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; margin-right: 10px;
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition), background var(--transition), color var(--transition);
}
.chat-header-bar:hover .chat-header-delete-btn {
  opacity: 1; pointer-events: auto;
}
.chat-header-delete-btn .material-icons { font-size: 18px; }
.chat-header-delete-btn:hover { background: rgba(200,80,80,0.12); color: #e06060; }
body.day, html.day .chat-header-delete-btn { color: #9a9690; }
body.day, html.day .chat-header-delete-btn:hover { background: rgba(200,80,80,0.1); color: #c04040; }

/* Scroll to bottom */
.btn-scroll-bottom {
  position: absolute; bottom: 130px; left: 50%;
  transform: translateX(-50%);
  width: 36px; height: 36px; border-radius: 50%;
  background: #3a3a3a; border: none;
  color: #b0aba4; display: flex; align-items: center; justify-content: center;
  cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  transition: background var(--transition), color var(--transition); z-index: 50;
  opacity: 0; pointer-events: none;
}
body.day, html.day .btn-scroll-bottom { background: rgba(0,0,0,0.22); color: #6a6560; box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
.btn-scroll-bottom.visible { opacity: 1; pointer-events: auto; }
.btn-scroll-bottom:hover { background: #555; color: #e2ddd4; }
body.day, html.day .btn-scroll-bottom:hover { background: rgba(0,0,0,0.32); color: #1a1814; }
.btn-scroll-bottom .material-icons { font-size: 18px; }

/* ── Metadata de mensajes ────────────────────────────────── */
.msg-meta {
  font-size: 11px;
  color: var(--cream2);
  margin-top: 5px;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  opacity: 0.35;
  transition: opacity .15s ease;
  pointer-events: none;
}
.msg-user-wrap:hover .msg-meta,
.msg.assistant:hover .msg-meta,
.msg-user-wrap:hover .msg-meta-user {
  opacity: 0.75;
}
.msg.user .msg-meta { text-align: right; }
.msg.assistant .msg-meta { text-align: left; }

/* ── Wrapper mensaje usuario ─────────────────────────────── */
.msg-user-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  align-self: flex-end;
  max-width: 80%;
}
.msg-user-wrap .msg.user {
  align-self: unset;
  max-width: 100%;
}
.msg-meta-user {
  text-align: right;
  padding-right: 2px;
}

/* ── Expandir mensaje largo ──────────────────────────────── */
.msg.user { position: relative; }

.msg-expand-btn {
  display: inline-block;
  border: none; cursor: pointer;
  font-size: 11px; font-family: var(--font-mono);
  letter-spacing: 0.02em;
  color: var(--cream2);
  opacity: 0.7;
  transition: opacity var(--transition);
  text-align: left; padding: 0;
  background: transparent;
}
.msg-expand-btn:hover { opacity: 1; }
body.day, html.day .msg-expand-btn { color: #5a5650; }

/* Colapsado: wrapper con gradiente y botón en flujo normal */
.msg-collapse-wrap { position: relative; }
.msg-collapse-content { display: block; }
.msg-collapse-fade {
  height: 40px; margin-top: -40px;
  background: linear-gradient(to bottom, transparent 0%, var(--bg2) 75%);
  pointer-events: none;
}
body.day, html.day .msg-collapse-fade {
  background: linear-gradient(to bottom, transparent 0%, #e0dcd6 75%);
}
.msg-expand-collapsed,
.msg-expand-expanded {
  display: block; margin-top: 6px;
}

/* Export choice card */
.msg-export-choice {
  width: 100%; max-width: 90%; display: flex; flex-direction: column;
  gap: 4px; box-sizing: border-box;
}
.export-choice-btn {
  display: flex; align-items: baseline; gap: 8px;
  padding: 8px 12px; cursor: pointer;
  background: var(--bg2); border: 0.5px solid var(--border-md);
  border-radius: var(--radius-sm);
  transition: background var(--transition), border-color var(--transition);
  text-align: left;
}
.export-choice-btn:hover { background: var(--cream3); border-color: var(--border-md); }
body.day, html.day .export-choice-btn { background: rgba(0,0,0,0.02); }
body.day, html.day .export-choice-btn:hover { background: rgba(0,0,0,0.05); }

.export-choice-label {
  font-size: 13px; font-weight: 500; color: var(--cream);
}
.export-choice-sub { font-size: 11px; color: var(--cream2); font-family: var(--font-mono); }
body.day, html.day .export-choice-label { color: #1a1814; }
body.day, html.day .export-choice-sub { color: #6a6560; }

/* ── Style flow — grilla 2x2 / 4 en línea ───────────────────── */
.style-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px; width: 100%;
}
@media (max-width: 600px) {
  .style-grid { grid-template-columns: repeat(2, 1fr); }
}
.style-grid-btn {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 6px;
  padding: 10px 6px; cursor: pointer;
  background: var(--bg2); border: 0.5px solid var(--border-md);
  border-radius: var(--radius-sm);
  transition: background var(--transition), border-color var(--transition);
  min-height: 64px;
}
.style-grid-btn:hover { background: var(--cream3); border-color: var(--border-md); }
.style-grid-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.style-grid-btn.selected {
  background: var(--cream3);
  border-color: var(--border-md);
}
body.day, html.day .style-grid-btn { background: rgba(0,0,0,0.02); }
body.day, html.day .style-grid-btn:hover { background: rgba(0,0,0,0.05); }
body.day, html.day .style-grid-btn.selected { background: rgba(0,0,0,0.05); }
.style-grid-swatch {
  width: 28px; height: 28px; border-radius: 4px;
  border: 1.5px solid rgba(255,255,255,0.15);
  flex-shrink: 0;
}
body.day, html.day .style-grid-swatch { border-color: rgba(0,0,0,0.15); }
.style-grid-icon {
  width: 28px; height: 28px; display: flex;
  align-items: center; justify-content: center;
}
.style-grid-icon img { width: 22px; height: 22px; }
.style-grid-label {
  font-size: 10px; color: var(--cream2);
  font-family: var(--font-mono); text-align: center;
  line-height: 1.2; word-break: break-all;
}
body.day, html.day .style-grid-label { color: #6a6560; }

/* ── Style flow — slider inline ─────────────────────────────── */
.style-slider-wrap {
  width: 100%; display: flex; flex-direction: column; gap: 8px;
  padding: 10px 12px;
  background: var(--bg2); border: 0.5px solid var(--border-md);
  border-radius: var(--radius-sm);
}
.style-slider-row {
  display: flex; align-items: center; gap: 10px;
}
.style-slider-row input[type=range] {
  flex: 1;
}
.style-slider-val {
  font-size: 12px; font-family: var(--font-mono);
  color: var(--cream2); min-width: 28px; text-align: right;
}


/* ── Prompts sugeridos — mismo estilo que .map-card-btn ───────── */
.suggested-prompts {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  padding: 12px 16px 4px;
  justify-content: center;
}
.suggested-prompt-btn {
  flex-shrink: 0;
  padding: 0 12px;
  height: 30px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--cream2);
  border: 0.5px solid var(--border-md);
  font-size: 11px;
  font-family: var(--font-sans);
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  white-space: nowrap;
}
.suggested-prompt-btn:hover {
  background: rgba(122, 154, 191, 0.15);
  color: var(--accent);
  border-color: var(--accent);
  border-width: 1px;
}
body.day .suggested-prompt-btn,
html.day .suggested-prompt-btn {
  color: #5a5650;
  border-color: #c8c4be;
}
body.day .suggested-prompt-btn:hover,
html.day .suggested-prompt-btn:hover {
  background: rgba(42, 100, 150, 0.10);
  color: var(--accent);
  border-color: var(--accent);
  border-width: 1px;
}

/* ── Selector de modo de respuesta ──────────────────────────── */
.mode-selector-label {
  font-size: 13px;
  color: var(--cream2);
  padding: 2px 2px 6px;
  margin: 0;
  font-family: var(--font-sans);
}
body.day, html.day .mode-selector-label { color: #6a6560; }
