/* ============================================================
   Contaible – Corporate Theme
   Palette: Celeste (#0EA5E9) + White + Navy (#00193F)
   Inspired by cardee.me
   ============================================================ */

/* ---------- Design Tokens ---------- */
:root {
  /* Primary palette */
  --primary:        #0EA5E9;
  --primary-dark:   #0284C7;
  --primary-light:  #E0F2FE;
  --primary-50:     #F0F9FF;
  --secondary:      #00193F;
  --accent:         #38BDF8;

  /* Backgrounds */
  --bg:             #F8FAFC;
  --bg-white:       #FFFFFF;
  --chat-bg:        #F8FAFC;
  --panel:          #FFFFFF;
  --panel-2:        #F1F5F9;

  /* Text */
  --text:           #0F172A;
  --text-secondary: #475569;
  --text-muted:     #94A3B8;

  /* Borders & Shadows */
  --border:         #E2E8F0;
  --border-light:   #F1F5F9;
  --card-shadow:    0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --card-shadow-lg: 0 10px 25px rgba(0,0,0,0.06), 0 4px 10px rgba(0,0,0,0.04);

  /* Chat bubbles */
  --bubble-ai:        #F1F5F9;
  --bubble-ai-text:   #0F172A;
  --bubble-user:      #0EA5E9;
  --bubble-user-text: #FFFFFF;

  /* Form */
  --form-bg:        #FFFFFF;
  --form-border:    #CBD5E1;

  /* Buttons */
  --btn-primary-bg:   #0EA5E9;
  --btn-primary-text: #FFFFFF;
  --btn-outline-text: #334155;

  /* Status */
  --success:  #10B981;
  --warning:  #F59E0B;
  --error:    #EF4444;
  --info:     #0EA5E9;

  /* Typing */
  --typing-bg:   #E2E8F0;
  --typing-text: #475569;

  /* Scroll btn */
  --scroll-btn-bg:   #0EA5E9;
  --scroll-btn-text: #FFFFFF;

  /* Layout */
  --font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --bubble-radius: 16px;
  --bubble-pad-v: 10px;
  --bubble-pad-h: 14px;
  --chat-maxh: 70vh;
  --chat-pad: 20px;
  --avatar-size: 36px;
  --composer-h: 140px;

  /* Header/Footer */
  --header-bg:    #FFFFFF;
  --header-text:  #0F172A;
  --footer-bg:    #FFFFFF;
  --footer-text:  #475569;
  --chip-bg:      #E0F2FE;
  --chip-text:    #0369A1;
}

/* ---------- Base ---------- */
html, body,
input, button, select, textarea {
  font-family: var(--font-family) !important;
}

body {
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
}

/* ---------- Top Bar ---------- */
.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.app-topbar .container {
  max-width: 1080px;
  padding: 0.65rem 1rem;
}
.app-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--secondary);
  letter-spacing: -0.01em;
}
.app-brand .brand-icon {
  width: 28px;
  height: 28px;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 800;
  font-size: 14px;
}
.app-brand small {
  font-weight: 400;
  color: var(--text-secondary);
  margin-left: 0.25rem;
}
.top-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Nav buttons */
.btn-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-white);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.15s ease;
}
.btn-nav:hover {
  background: var(--primary-50);
  border-color: var(--primary);
  color: var(--primary-dark);
}

.btn-settings {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-white);
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.15s ease;
}
.btn-settings:hover {
  background: var(--primary-50);
  border-color: var(--primary);
  color: var(--primary-dark);
}

.btn-logout {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-white);
  color: var(--error);
  font-weight: 600;
  font-size: 0.875rem;
  text-decoration: none;
  transition: all 0.15s ease;
}
.btn-logout:hover {
  background: #FEF2F2;
  border-color: #FECACA;
}

/* ---------- Chat Container ---------- */
.chat-container {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding-bottom: calc(var(--composer-h) + env(safe-area-inset-bottom, 0px));
}

.chat-header {
  padding: 1rem 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.chat-header .agent-avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 18px;
}
.chat-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
  color: var(--text);
}
.chat-header .agent-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  background: var(--chip-bg);
  color: var(--chip-text);
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 500;
}

/* ---------- Chat Box ---------- */
.chat-box {
  max-height: none;
  height: auto;
  overflow-y: auto;
  padding: var(--chat-pad);
  background: var(--panel);
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.chat-box .message { overflow-anchor: none; }

/* ---------- Messages ---------- */
.message {
  display: flex;
  margin-bottom: 12px;
  opacity: 0;
  animation: slideIn 0.3s forwards;
}
.message.assistant {
  flex-direction: row;
  justify-content: flex-start;
}
.message.user {
  flex-direction: row-reverse;
  justify-content: flex-end;
}

.avatar {
  width: var(--avatar-size);
  height: var(--avatar-size);
  border-radius: 10px;
  object-fit: cover;
  margin: 0 8px;
}

.bubble {
  max-width: 65%;
  padding: var(--bubble-pad-v) var(--bubble-pad-h);
  border-radius: var(--bubble-radius);
  font-size: 0.9375rem;
  line-height: 1.5;
}
.message.assistant .bubble,
.message:not(.user) .bubble {
  background: var(--bubble-ai) !important;
  color: var(--bubble-ai-text) !important;
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.message.user .bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 4px;
}

.timestamp {
  display: block;
  text-align: right;
  font-size: 0.6875rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ---------- Typing Indicator ---------- */
.typing-bubble {
  background: var(--typing-bg);
  padding: 10px 15px;
  border-radius: 16px;
  font-size: 0.875rem;
  color: var(--typing-text);
  max-width: 200px;
  animation: pulse 1.5s infinite;
}
.typing-dots::after {
  content: '';
  display: inline-block;
  animation: dots 1.5s steps(3, end) infinite;
}
@keyframes dots {
  0%   { content: ''; }
  33%  { content: '.'; }
  66%  { content: '..'; }
  100% { content: '...'; }
}

/* ---------- Chat Form (fixed bottom) ---------- */
#chat-form {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-white);
  padding: 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -1px 3px rgba(0,0,0,0.06);
  z-index: 1000;
  border-top: 1px solid var(--border);
}
#chat-form .input-group {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  max-width: 800px;
  margin: 0 auto 0.5rem;
}
#chat-form input.form-control {
  flex-grow: 1;
  border-radius: 12px;
  padding: 10px 16px;
  border: 1px solid var(--form-border);
  background: var(--form-bg);
  color: var(--text);
  font-size: 0.9375rem;
  outline: none;
  transition: border-color 0.15s ease;
}
#chat-form input.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}
#chat-form button.btn-outline-secondary {
  height: 40px;
  width: 40px;
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-white);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
#chat-form button.btn-outline-secondary:hover {
  background: var(--primary-50);
  border-color: var(--primary);
  color: var(--primary);
}
#chat-form .d-grid {
  max-width: 800px;
  margin: 0 auto;
}
#chat-form .btn-primary {
  width: 100%;
  font-size: 0.9375rem;
  font-weight: 600;
  padding: 0.7rem;
  border-radius: 10px;
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  border: none;
  transition: background 0.15s ease;
}
#chat-form .btn-primary:hover {
  background: var(--primary-dark);
}

/* ---------- Bootstrap overrides ---------- */
.btn.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}
.form-control {
  background: var(--form-bg);
  border-color: var(--form-border);
  color: var(--text);
  border-radius: 10px;
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

/* ---------- Auth Card (login/register) ---------- */
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-white);
  border-radius: 16px;
  box-shadow: var(--card-shadow-lg);
  border: 1px solid var(--border);
}
.auth-card .form-label {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-secondary);
}
.auth-card .btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  border-radius: 10px;
  font-weight: 600;
}
.auth-card .btn-primary:hover {
  background: var(--primary-dark);
}
.auth-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}
.auth-logo .logo-icon {
  width: 40px;
  height: 40px;
  background: var(--primary);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 800;
  font-size: 20px;
}
.auth-logo .logo-text {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--secondary);
}

/* ---------- Media in chat ---------- */
.img-emocional, .video-emocional {
  width: 100%;
  max-height: 300px;
  margin-top: 5px;
  border-radius: 8px;
  cursor: zoom-in;
}
.audio-nota { width: 100%; margin-top: 5px; }
.img-subida { max-width: 200px; border-radius: 12px; margin-top: 8px; }
.img-subida-usuario {
  max-width: 200px;
  max-height: 200px;
  border-radius: 8px;
  margin-top: 5px;
  cursor: pointer;
  box-shadow: 0 0 4px rgba(0,0,0,0.1);
}

/* ---------- Scroll button ---------- */
.scroll-btn {
  position: absolute;
  bottom: 20px;
  right: 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--card-shadow);
  z-index: 50;
  cursor: pointer;
  display: none;
  transition: all 0.15s ease;
}
.scroll-btn:hover {
  background: var(--primary-dark);
}

/* ---------- Date divider ---------- */
.date-divider {
  text-align: center;
  font-weight: 600;
  font-size: 0.75rem;
  margin: 16px 0;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---------- Voice recording ---------- */
.rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--error);
  display: inline-block;
  margin-left: 0.25rem;
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%   { opacity: 0.4; }
  50%  { opacity: 1; }
  100% { opacity: 0.4; }
}
.msg { padding: 0.5rem 0.75rem; border-radius: 0.75rem; margin: 0.5rem 0; max-width: 75%; }
.msg.user { background: var(--primary-light); margin-left: auto; }
.msg.ai { background: var(--panel-2); }
.msg.status { background: #FEF3C7; border: 1px solid #FDE68A; color: #92400E; }
.msg audio, .msg video { width: 100%; max-width: 100%; }
.msg audio { height: 32px; }
.small-muted { font-size: 0.8rem; color: var(--text-muted); }

@keyframes blink {
  50% { opacity: 0.2; }
}

/* ---------- Animations ---------- */
@keyframes slideIn {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ---------- Safe area (mobile) ---------- */
.safe-bottom {
  padding-bottom: calc(var(--composer-h) + env(safe-area-inset-bottom, 0px));
}

/* ---------- Footer ---------- */
.app-footer-bar {
  margin-top: 2rem;
  background: var(--footer-bg);
  border-top: 1px solid var(--border);
}
.app-footer-bar .container {
  max-width: 1080px;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--footer-text);
  font-size: 0.875rem;
}
.footer-brand {
  font-weight: 600;
  color: var(--secondary);
}

/* ---------- Admin Panel ---------- */
.admin-sidebar {
  background: var(--bg-white);
  border-right: 1px solid var(--border);
  min-height: 100vh;
  padding: 1rem 0;
}
.admin-sidebar a {
  display: block;
  padding: 0.5rem 1rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.875rem;
  border-left: 3px solid transparent;
  transition: all 0.15s ease;
}
.admin-sidebar a:hover,
.admin-sidebar a.active {
  background: var(--primary-50);
  color: var(--primary-dark);
  border-left-color: var(--primary);
}

/* ---------- Responsive ---------- */
@media (max-width: 576px) {
  .chat-container { width: 100%; padding: 0 8px; }
  .chat-box { padding: 12px; border-radius: 0; }
  .message .bubble { max-width: 85% !important; font-size: 0.9375rem; }
  .app-brand { font-size: 1rem; }
  .app-topbar .container { padding: 0.5rem 0.75rem; }
}

/* ---------- Embed mode (iframe) ---------- */
body.embed-mode .app-topbar { display: none; }
body.embed-mode .app-footer-bar { display: none; }
body.embed-mode .chat-container {
  max-width: 100%;
  padding: 0;
}
body.embed-mode .chat-box {
  border-radius: 0;
  border: none;
  box-shadow: none;
}
