@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* Variables and Reset */
:root {
  --bg-color: #f0f2f5;
  --bg-gradient: linear-gradient(135deg, #e0eafc, #cfdef3);
  --sidebar-bg: rgba(255, 255, 255, 0.85);
  --sidebar-text: #2c3e50;
  --sidebar-border: rgba(255, 255, 255, 0.4);
  --text-main: #1a1a1a;
  --primary: #4f46e5;
  --primary-hover: #3b35b5;
  --message-assistant-bg: #ffffff;
  --message-user-bg: linear-gradient(135deg, #7c5aff, #4f46e5);
  --message-user-text: #ffffff;
  --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);
  --glass-border: rgba(255, 255, 255, 0.5);
  --input-bg: rgba(255, 255, 255, 0.9);
}

html.dark-theme body,
body.dark-theme {
  --bg-color: #121212;
  --bg-gradient: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
  --sidebar-bg: rgba(32, 33, 35, 0.7);
  --sidebar-text: #e0e0e0;
  --sidebar-border: rgba(255, 255, 255, 0.05);
  --text-main: #f0f0f0;
  --message-assistant-bg: #1e1e1e;
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
  --glass-border: rgba(255, 255, 255, 0.1);
  --input-bg: rgba(30, 30, 30, 0.9);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', sans-serif;
}

body {
  background: var(--bg-gradient);
  background-attachment: fixed;
  background-size: cover;
  color: var(--text-main);
  transition: background 0.5s ease, color 0.5s ease;
}

/* Glassmorphism General */
.glass-panel {
  background: var(--sidebar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}

/* Contenedor principal */
.app-container {
  display: flex;
  flex-direction: row;
  height: 100dvh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--sidebar-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid var(--sidebar-border);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
  z-index: 1000;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.05);
}

.sidebar.active {
  transform: translateX(-100%);
}

.sidebar-header {
  padding: 30px 20px 20px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--sidebar-text);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  font-size: 1.2rem;
}

.icon-btn:hover {
  background: rgba(128, 128, 128, 0.1);
}

.icon-btn:active {
  transform: scale(0.95);
}

.menu-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.5;
  margin-bottom: 8px;
  font-weight: 700;
  display: block;
}

.company-selector-wrapper {
  margin-top: 10px;
}

.select-glass {
  position: relative;
  display: flex;
  align-items: center;
}

.select-glass .select-icon {
  position: absolute;
  left: 12px;
  color: var(--sidebar-text);
  opacity: 0.6;
  pointer-events: none;
}

.select-glass select {
  width: 100%;
  padding: 12px 12px 12px 36px;
  appearance: none;
  background: rgba(128, 128, 128, 0.03);
  border: 1px solid var(--sidebar-border);
  border-radius: 10px;
  color: var(--sidebar-text);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  outline: none;
}

.select-glass select:hover,
.select-glass select:focus {
  background: rgba(128, 128, 128, 0.08);
  border-color: var(--primary);
}

.select-glass select option {
  color: #1a1a1a;
  background-color: #ffffff;
}

.sidebar-menu {
  flex: 1;
  padding: 0 20px;
  overflow-y: auto;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s ease;
  margin-bottom: 4px;
}

.menu-item:hover {
  background: rgba(128, 128, 128, 0.1);
  color: var(--primary);
}

.sidebar-footer {
  padding: 20px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.sidebar-footer button {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background-color: rgba(231, 76, 60, 0.9);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(4px);
}

.sidebar-footer button:hover {
  background-color: rgba(231, 76, 60, 1);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
}

/* User Profile Dropdown */
.user-profile-container {
  position: relative;
  width: 100%;
}

.user-profile-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px;
  background: transparent;
  border: 1px solid var(--sidebar-border);
  border-radius: 12px;
  color: var(--sidebar-text);
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
  text-align: left;
}

.user-profile-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  overflow: hidden;
}

.user-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.8rem;
  opacity: 0.7;
  margin-top: 2px;
}

.dropdown-menu {
  position: absolute;
  bottom: 100%;
  left: 0;
  width: 100%;
  margin-bottom: 8px;
  background: var(--sidebar-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--sidebar-border);
  border-radius: 12px;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
  padding: 8px;
  display: none;
  flex-direction: column;
  gap: 4px;
  z-index: 2000;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s, transform 0.2s;
}

.dropdown-menu.show {
  display: flex;
  opacity: 1;
  transform: translateY(0);
}

.dropdown-item {
  padding: 10px 14px;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  transition: background 0.2s;
}

.dropdown-item:hover {
  background: rgba(0, 0, 0, 0.05);
}

html.dark-theme body .dropdown-item:hover,
body.dark-theme .dropdown-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.dropdown-item.text-danger {
  color: #e74c3c;
}

.dropdown-item.text-danger:hover {
  background: rgba(231, 76, 60, 0.1);
}

/* Modal System */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  z-index: 3000;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-window {
  width: 90%;
  max-width: 1000px;
  height: 85vh;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  transform: translateY(20px) scale(0.98);
  transition: transform 0.3s ease;
  background: var(--sidebar-bg);
  /* Use theme bg for fallback */
}

.modal-overlay.show .modal-window {
  transform: translateY(0) scale(1);
}

.modal-header {
  padding: 15px 20px;
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0, 0, 0, 0.02);
}

.modal-header h3 {
  margin: 0;
  color: var(--text-main);
  font-weight: 600;
  font-size: 1.1rem;
}

.close-modal-btn {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 1.4rem;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.close-modal-btn:hover {
  opacity: 1;
}

.modal-body {
  flex: 1;
  position: relative;
  background: transparent;
}

.modal-loader {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-main);
  font-weight: 500;
}

#modalIframe {
  opacity: 0;
  transition: opacity 0.3s ease;
  width: 100%;
  height: 100%;
  border: none;
}

.gadortech-footer {
  margin-top: 15px;
  font-size: 0.8rem;
  opacity: 0.7;
  text-align: center;
}

.gadortech-footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.gadortech-footer a:hover {
  text-decoration: underline;
}

/* Main content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}

.mobile-header {
  display: none;
  align-items: center;
  background: var(--sidebar-bg);
  backdrop-filter: blur(10px);
  color: var(--sidebar-text);
  padding: 15px 20px;
  border-bottom: 1px solid var(--sidebar-border);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.mobile-header h1 {
  flex: 1;
  font-size: 1.1rem;
  text-align: center;
  font-weight: 600;
}

/* Chat box */
.chat-box {
  flex: 1;
  padding: 30px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: calc(85px + env(safe-area-inset-bottom));
  scroll-behavior: smooth;
}

/* Mensajes */
.message {
  max-width: 85%;
  line-height: 1.6;
  word-wrap: break-word;
  font-size: 1rem;
}

.message strong {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.9;
}

/* Usuario */
.user-message {
  padding: 16px 20px;
  border-radius: 18px;
  background: var(--message-user-bg);
  color: var(--message-user-text);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.25);
  animation: slideUp 0.4s cubic-bezier(0.25, 0.8, 0.25, 1) forwards;
}

/* Asistente */
.assistant-message {
  background-color: transparent;
  color: var(--text-main);
  align-self: flex-start;
  width: 100%;
  max-width: 100%;
  padding: 10px 0;
  border: none;
  box-shadow: none;
  animation: slideUp 0.4s cubic-bezier(0.25, 0.8, 0.25, 1) forwards;
}

.assistant-message strong {
  color: var(--primary);
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Markdown styling inside assistant */
.markdown-content p {
  margin: 8px 0;
}

.markdown-content ul,
.markdown-content ol {
  margin: 8px 0 8px 24px;
}

.markdown-content code {
  background-color: rgba(128, 128, 128, 0.15);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9em;
}

.markdown-content pre {
  background-color: rgba(0, 0, 0, 0.05);
  padding: 12px 16px;
  border-radius: 8px;
  overflow-x: auto;
  font-family: monospace;
  margin: 10px 0;
  border: 1px solid rgba(128, 128, 128, 0.2);
}

html.dark-theme body .markdown-content pre,
body.dark-theme .markdown-content pre {
  background-color: rgba(255, 255, 255, 0.05);
}

/* Indicador escribiendo */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  font-style: normal;
  opacity: 0.8;
}

.typing-dots {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  margin-top: 10px;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  background-color: var(--primary);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) {
  animation-delay: -0.32s;
}

.typing-dots span:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes bounce {

  0%,
  80%,
  100% {
    transform: scale(0);
  }

  40% {
    transform: scale(1);
  }
}

/* Input container */
.input-container {
  display: flex;
  align-items: center;
  padding: 15px 20px;
  background: var(--sidebar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--sidebar-border);
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  gap: 12px;
  z-index: 500;
}

.input-container textarea {
  flex: 1;
  padding: 14px 18px;
  border-radius: 12px;
  border: 1px solid var(--sidebar-border);
  background: var(--input-bg);
  color: var(--text-main);
  font-size: 1rem;
  resize: none;
  min-height: 48px;
  max-height: 240px;
  overflow-y: auto;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.input-container textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}

.input-container button {
  padding: 14px 24px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(79, 70, 229, 0.4);
  transition: all 0.3s ease;
}

.input-container button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.6);
}

.menu-toggle,
.close-sidebar {
  display: none;
  background: none;
  border: none;
  color: var(--sidebar-text);
  font-size: 1.5rem;
  cursor: pointer;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    transform: translateX(-100%);
  }

  .sidebar.active {
    transform: translateX(0);
  }

  .close-sidebar,
  .menu-toggle {
    display: inline-block;
  }

  .mobile-header {
    display: flex;
  }

  .chat-box {
    padding: 15px;
    margin-bottom: calc(85px + env(safe-area-inset-bottom));
  }

  .message {
    max-width: 90%;
  }
}