/* ══════════════════════════════════════════════════════════════
   Assistente Digital MegaFarma — Style Sheet
   ══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  --bg-primary: #dc2626;
  /* Bright Red */
  --bg-secondary: #ef4444;
  /* Light Red */
  --bg-card: #f87171;
  /* Soft Red */
  --bg-input: #fff5f5;
  /* Very Light Red/White for inputs */
  --surface-hover: #f87171;
  --accent: #ffffff;
  /* White buttons/accents */
  --accent-glow: rgba(255, 255, 255, 0.3);
  --accent-secondary: #f3f4f6;

  --text-primary: #ffffff;
  --text-secondary: #fee2e2;
  --text-muted: #fecaca;
  --border: rgba(255, 255, 255, 0.25);
  --user-bubble: linear-gradient(135deg, #ffffff, #f3f4f6);
  --user-text: #dc2626;
  --bot-bubble: #ef4444;
  --danger: #b91c1c;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* ── App Container ─────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 100%;
  position: relative;
  background: linear-gradient(180deg, var(--bg-primary) 0%, var(--bg-secondary) 50%, var(--bg-primary) 100%);
}

/* ── Header ────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(127, 29, 29, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logo {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.header-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.header-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.header-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: white;
  color: #b91c1c;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.btn-icon:hover,
.btn-icon:active {
  background: #f8fafc;
  color: #991b1b;
  border-color: white;
}

/* ── Welcome Screen ────────────────────────────────────────── */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 24px;
  text-align: center;
  gap: 24px;
}

.welcome-screen.hidden {
  display: none;
}

/* Avatar */
.avatar-container {
  position: relative;
  width: 160px;
  height: 160px;
  margin-bottom: 8px;
}

.avatar-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  background: linear-gradient(135deg, white, var(--bg-card)) border-box;
  -webkit-mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: ringRotate 6s linear infinite;
}

@keyframes ringRotate {
  to {
    transform: rotate(360deg);
  }
}

.avatar {
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--bg-card), var(--bg-secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 0 40px var(--accent-glow);
}

.avatar-face {
  display: none;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-6px);
  }
}

.avatar-container.listening .avatar-ring {
  border-width: 3px;
  animation: ringPulse 1s ease-in-out infinite, ringRotate 3s linear infinite;
}

.avatar-container.listening .avatar {
  box-shadow: 0 0 60px var(--accent-glow), 0 0 100px rgba(34, 211, 238, 0.15);
}

@keyframes ringPulse {

  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }

  50% {
    transform: scale(1.06);
    opacity: 0.8;
  }
}

.welcome-title {
  font-size: 26px;
  font-weight: 700;
  color: white;
  letter-spacing: -0.5px;
}

.welcome-text {
  font-size: 15px;
  color: var(--text-secondary);
  max-width: 380px;
  line-height: 1.6;
}

.welcome-actions {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 28px;
  border-radius: var(--radius);
  border: none;
  background: white;
  color: #b91c1c;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  min-width: 110px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.action-btn .icon {
  font-size: 32px;
  line-height: 1;
}

.action-btn:hover,
.action-btn:active {
  background: #f8fafc;
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.action-btn.mic-btn:hover,
.action-btn.mic-btn:active {
  background: white;
  box-shadow: 0 0 30px var(--accent-glow);
}

/* ── Chat Area ─────────────────────────────────────────────── */
.chat-container {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.chat-container.active {
  display: flex;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 4px;
}

/* Message bubbles */
.message {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: messageIn 0.3s ease-out;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message.bot {
  align-self: flex-start;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.message.bot .message-avatar {
  background: white;
  color: #b91c1c;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.message.user .message-avatar {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message.user .bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
  font-weight: 500;
}

.message.bot .bubble {
  background: var(--bot-bubble);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  padding: 0 4px;
}

.message-time {
  font-size: 10px;
  color: var(--text-muted);
}

.message.user .message-meta {
  justify-content: flex-end;
}

.btn-listen {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: var(--accent);
  font-size: 11px;
  font-family: inherit;
  padding: 3px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-listen:hover,
.btn-listen:active {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--accent);
  transform: scale(1.05);
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 16px;
  align-items: center;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {

  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }

  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

/* ── Input Bar ─────────────────────────────────────────────── */
.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(127, 29, 29, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrapper {
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  transition: var(--transition);
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-wrapper textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #1a202c;
  font-family: inherit;
  font-size: 15px;
  padding: 10px 12px;
  resize: none;
  max-height: 120px;
  min-height: 44px;
  line-height: 1.4;
}

.input-wrapper textarea::placeholder {
  color: var(--text-muted);
}

.input-actions {
  display: flex;
  gap: 4px;
  padding: 4px;
}

.input-actions .btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 16px;
  border: none;
}

.btn-send {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  border: none;
  background: white;
  color: #b91c1c;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.btn-send:hover {
  transform: scale(1.05);
  box-shadow: 0 0 24px var(--accent-glow);
}

.btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* Mic active state */
.btn-mic.active {
  background: var(--danger) !important;
  color: white !important;
  animation: micPulse 1.5s ease-in-out infinite;
}

@keyframes micPulse {

  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
  }

  50% {
    box-shadow: 0 0 0 12px rgba(239, 68, 68, 0);
  }
}

/* ── Footer / Legal ────────────────────────────────────────── */
.footer-legal {
  text-align: center;
  padding: 8px 16px;
  font-size: 10px;
  color: var(--text-secondary);
  background: rgba(127, 29, 29, 0.9);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  line-height: 1.5;
}

/* ── Config Modal ──────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow);
  animation: modalIn 0.3s ease-out;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-field {
  margin-bottom: 16px;
}

.modal-field label,
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: #ff3b3b;
  /* Bright Red */
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.modal-field input,
.modal-field select,
.form-group input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: #1a202c;
  /* Dark text for visibility on light background */
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: var(--transition);
}

.modal-field input:focus,
.modal-field select:focus,
.form-group input:focus {
  border-color: #ff3b3b;
  box-shadow: 0 0 0 3px rgba(255, 59, 59, 0.2);
}

.modal-field input::placeholder {
  color: rgba(255, 59, 59, 0.6);
  font-style: italic;
}

.modal-field select option {
  background: var(--bg-secondary);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

.btn-modal {
  flex: 1;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
}

.btn-modal.primary {
  background: white;
  color: #b91c1c;
  border: none;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.btn-modal.primary:hover {
  background: #f8fafc;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.btn-modal.secondary {
  background: transparent;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.btn-modal:hover {
  transform: translateY(-1px);
}

/* ── Coupon Modal ──────────────────────────────────────────── */
.coupon-bar {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 16px;
  background: linear-gradient(135deg, rgba(185, 28, 28, 0.15), rgba(220, 38, 38, 0.1));
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition);
}

.coupon-bar.visible {
  display: flex;
}

.coupon-bar:hover {
  background: linear-gradient(135deg, rgba(185, 28, 28, 0.25), rgba(220, 38, 38, 0.15));
}

.coupon-bar span {
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
}

/* ── Toast Notification ────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 13px;
  color: var(--text-primary);
  box-shadow: var(--shadow);
  opacity: 0;
  transition: var(--transition);
  z-index: 200;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Image preview ─────────────────────────────────────────── */
.image-preview {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  position: relative;
}

.image-preview.visible {
  display: flex;
}

.image-preview img {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
}

.image-preview .remove-img {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  border: none;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-preview span {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 480px) {
  .welcome-title {
    font-size: 22px;
  }

  .action-btn {
    padding: 16px 20px;
    min-width: 95px;
  }

  .action-btn .icon {
    font-size: 28px;
  }

  .avatar-container {
    width: 130px;
    height: 130px;
  }

  .avatar-face {
    font-size: 52px;
  }
}

@media (min-width: 768px) {
  .chat-messages {
    padding: 20px 40px;
  }

  .input-bar {
    padding: 14px 40px;
  }

  .message {
    max-width: 70%;
  }
}

/* Image in chat bubble */
.bubble img {
  max-width: 200px;
  border-radius: 8px;
  margin-top: 8px;
  display: block;
}

/* ── PWA Install Banner ───────────────────────────────────── */
.install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 150;
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.install-banner.visible {
  transform: translateY(0);
}

.install-banner-content {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  background: linear-gradient(135deg, #1a1a2e, #16213e);
  border-top: 2px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.4);
}

.install-banner-icon {
  font-size: 36px;
  flex-shrink: 0;
  animation: bounceIcon 2s ease-in-out infinite;
}

@keyframes bounceIcon {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-4px);
  }
}

.install-banner-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.install-banner-text strong {
  font-size: 15px;
  color: #fff;
}

.install-banner-text span {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}

.install-edge-tip {
  color: #fbbf24 !important;
  font-size: 11px !important;
  margin-top: 2px;
}

.install-banner-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.install-btn {
  padding: 10px 22px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: white;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
  white-space: nowrap;
}

.install-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(34, 197, 94, 0.4);
}

.install-dismiss {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: transparent;
  color: rgba(255, 255, 255, 0.6);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.install-dismiss:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}