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

:root {
  --primary: #a8183a;
  --primary-light: #c33a5b;
  --primary-bg: #fbeaee;
  --user-bg: #a8183a;
  --user-text: #ffffff;
  --bot-bg: #f4f6f9;
  --bot-text: #1a1a2e;
  --border: #d1dce8;
  --text-muted: #6b7280;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
  font-family: var(--font);
  font-size: 14px;
  background: #fff;
  color: var(--bot-text);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background: var(--primary);
  color: #fff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.header-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
}
.header-icon-img { width: 24px; height: 24px; object-fit: contain; }
.header-title { font-weight: 600; font-size: 15px; line-height: 1.2; }
.header-subtitle { font-size: 11px; opacity: 0.8; }
.btn-new {
  margin-left: auto;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.btn-new:hover { background: rgba(255,255,255,0.25); }
.btn-history {
  margin-left: auto;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.btn-history:hover { background: rgba(255,255,255,0.25); }
/* Cuando existe el botón de historial, es él quien empuja el resto a la derecha */
.btn-history ~ .btn-new { margin-left: 6px; }

/* Category selector */
.category-bar {
  padding: 8px 14px;
  background: var(--primary-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.category-bar label { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.category-bar select {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  background: #fff;
  color: var(--bot-text);
}

/* Messages area */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: 85%;
  line-height: 1.5;
}
.msg.user { align-self: flex-end; }
.msg.bot  { align-self: flex-start; }

.msg-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  white-space: normal;
  word-break: break-word;
}
.msg-bubble > :first-child { margin-top: 0; }
.msg-bubble > :last-child { margin-bottom: 0; }
.msg-bubble p { margin: 0 0 0.55em; }
.msg-bubble ul, .msg-bubble ol { margin: 0 0 0.55em 1.2em; }
.msg-bubble li { margin: 0.2em 0; }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3, .msg-bubble h4 {
  margin: 0.4em 0 0.3em;
  line-height: 1.3;
}
.msg-bubble h1 { font-size: 1.05rem; }
.msg-bubble h2 { font-size: 1rem; }
.msg-bubble h3 { font-size: 0.95rem; }
.msg-bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.9em;
  background: rgba(148, 163, 184, 0.22);
  padding: 0.08em 0.35em;
  border-radius: 4px;
}
.msg-bubble pre {
  margin: 0.55em 0;
  background: rgba(15, 23, 42, 0.88);
  color: #f8fafc;
  padding: 0.65em 0.8em;
  border-radius: 8px;
  overflow-x: auto;
}
.msg-bubble pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}
.msg-bubble a {
  color: var(--primary);
  text-decoration: underline;
}
.msg.user .msg-bubble {
  background: var(--user-bg);
  color: var(--user-text);
  border-bottom-right-radius: 3px;
}
.msg.bot .msg-bubble {
  background: var(--bot-bg);
  color: var(--bot-text);
  border-bottom-left-radius: 3px;
}

/* Citations */
.citations {
  margin-top: 6px;
  font-size: 11px;
}
.citations-toggle {
  color: var(--primary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  background: none;
  border: none;
  padding: 0;
}
.citations-toggle:hover { text-decoration: underline; }
.citations-list {
  margin-top: 4px;
  padding: 6px 10px;
  background: #f0f4fa;
  border-left: 3px solid var(--primary);
  border-radius: 0 6px 6px 0;
  display: none;
}
.citations-list.open { display: block; }
.citation-item {
  color: var(--text-muted);
  padding: 2px 0;
  font-size: 11px;
}

/* Feedback (pulgar arriba/abajo) */
.feedback {
  margin-top: 6px;
  display: flex;
  gap: 4px;
}
.fb-btn {
  background: none;
  border: none;
  padding: 3px;
  cursor: pointer;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  line-height: 0;
}
.fb-btn:hover { color: var(--primary); background: var(--primary-bg); }
.fb-up.selected { color: #16a34a; }
.fb-down.selected { color: #dc2626; }
.fb-btn.selected svg { fill: currentColor; }

/* Modal de feedback */
.feedback-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.feedback-overlay.hidden { display: none; }
.feedback-card {
  background: #fff;
  border-radius: 16px;
  padding: 24px 22px;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.feedback-card h3 { color: var(--primary); font-size: 16px; margin-bottom: 4px; }
.feedback-card p { color: var(--text-muted); font-size: 12px; margin-bottom: 14px; }
.feedback-card textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font);
  font-size: 14px;
  resize: vertical;
  min-height: 80px;
}
.feedback-card textarea:focus { outline: none; border-color: var(--primary); }
.feedback-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
.feedback-btn-secondary,
.feedback-btn-primary {
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.feedback-btn-secondary {
  background: #fff;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.feedback-btn-secondary:hover { background: var(--bot-bg); }
.feedback-btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
}
.feedback-btn-primary:hover { background: var(--primary-light); }

/* Typing indicator */
.typing { display: flex; gap: 4px; align-items: center; padding: 12px 14px; }
.typing span {
  width: 7px; height: 7px;
  background: #bcc5d0;
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* Welcome message */
.welcome {
  text-align: center;
  color: var(--text-muted);
  padding: 30px 20px;
}
.welcome h3 { color: var(--primary); margin-bottom: 8px; font-size: 15px; }
.welcome p { font-size: 13px; line-height: 1.6; }
.examples { margin-top: 16px; display: flex; flex-direction: column; gap: 6px; }
.example-btn {
  background: var(--primary-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--bot-text);
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
}
.example-btn:hover { background: #dce9f7; }
.example-tag {
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Recomendaciones de uso (bienvenida) */
.usage-tips {
  margin-top: 16px;
  text-align: left;
  background: var(--primary-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--bot-text);
}
.usage-tips strong { color: var(--primary); }
.usage-tips ul { margin: 6px 0 0 1.1em; }
.usage-tips li { margin: 3px 0; }
.usage-example {
  margin-top: 10px;
  padding: 8px 10px;
  background: #fff;
  border-left: 3px solid var(--primary);
  border-radius: 0 6px 6px 0;
  font-style: italic;
  color: var(--text-muted);
}
.usage-example-label {
  display: inline-block;
  font-style: normal;
  font-weight: 600;
  font-size: 10px;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 6px;
}

/* Aviso importante (bienvenida) */
.welcome-notice {
  margin-top: 16px;
  text-align: left;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.welcome-notice strong { color: var(--primary); }

/* Banner de aviso fijo (sobre el input) */
.disclaimer-bar {
  flex-shrink: 0;
  background: var(--primary-bg);
  color: var(--primary);
  border-top: 1px solid var(--border);
  font-size: 11px;
  line-height: 1.4;
  text-align: center;
  padding: 6px 14px;
}

/* Input area */
.input-area {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  background: #fff;
}
.input-area textarea {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: var(--font);
  font-size: 14px;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.4;
}
.input-area textarea:focus { outline: none; border-color: var(--primary); }
.btn-send {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  width: 44px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.btn-send:hover { background: var(--primary-light); }
.btn-send:disabled { background: #9ab0cc; cursor: not-allowed; }

/* Footer */
.footer {
  text-align: center;
  font-size: 10px;
  color: #b0b8c4;
  padding: 6px;
  flex-shrink: 0;
}
.footer-logo { height: 18px; vertical-align: middle; margin-right: 6px; opacity: 0.85; }

/* Login overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}
.login-overlay.hidden { display: none; }
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 32px 28px;
  width: 100%;
  max-width: 300px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-icon { display: flex; justify-content: center; margin-bottom: 14px; color: var(--primary); }
.login-icon-img { width: 64px; height: 64px; object-fit: contain; }
.login-card h2 { color: var(--primary); font-size: 18px; margin-bottom: 4px; }
.login-card p { color: var(--text-muted); font-size: 12px; margin-bottom: 24px; }
.login-card input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 12px;
  font-family: var(--font);
  box-sizing: border-box;
}
.login-card input:focus { outline: none; border-color: var(--primary); }
.password-wrapper {
  position: relative;
  margin-bottom: 12px;
}
.password-wrapper input {
  margin-bottom: 0;
  padding-right: 40px;
  width: 100%;
}
.btn-eye {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  display: flex;
  align-items: center;
}
.btn-eye:hover { color: var(--primary); }
.login-card button[type="submit"] {
  width: 100%;
  padding: 11px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}
.login-card button[type="submit"]:hover { background: var(--primary-light); }
.login-card button[type="submit"]:disabled { background: #9ab0cc; cursor: not-allowed; }
.login-error { color: #dc2626; font-size: 12px; margin-top: 10px; min-height: 16px; }
.btn-logout {
  margin-left: 4px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.btn-logout:hover { background: rgba(255,255,255,0.25); }

/* Panel lateral de historial */
.history-drawer {
  position: fixed;
  inset: 0;
  z-index: 1001;
}
.history-drawer.hidden { display: none; }
.history-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
}
.history-panel {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 82%;
  max-width: 320px;
  background: #fff;
  box-shadow: -8px 0 32px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  animation: history-slide-in 0.2s ease-out;
}
@keyframes history-slide-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}
.history-header {
  background: var(--primary);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}
.history-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 2px;
  border-radius: 6px;
}
.history-close:hover { background: rgba(255,255,255,0.2); }
.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.history-item {
  text-align: left;
  background: var(--bot-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}
.history-item:hover { background: var(--primary-bg); border-color: var(--primary-light); }
.history-item-title {
  font-size: 13px;
  color: var(--bot-text);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.history-item-date {
  font-size: 11px;
  color: var(--text-muted);
}
.history-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding: 24px 16px;
}

@media (max-width: 480px) {
  .header { padding: 10px 12px; }
  .messages { padding: 12px 10px; }
  .input-area { padding: 10px; }
}
