/* ========================================
   ECO — Estilos globales
   Los colores corporativos se cargan como
   CSS custom properties desde la BD
   ======================================== */

:root {
  --color-primary: #4338ca;
  --color-secondary: #1e1b4b;
  --color-tertiary: #6366f1;

  --color-bg: #f9fafb;
  --color-white: #ffffff;
  --color-text: #1f2937;
  --color-text-light: #6b7280;
  --color-border: #e5e7eb;
  --color-error: #dc2626;
  --color-success: #16a34a;

  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);
  --max-width: 800px;
  --header-height: 56px;
}

/* ========================================
   Reset y base
   ======================================== */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  height: 100vh;
  overflow: hidden;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

/* ========================================
   Botones
   ======================================== */

.btn-primary {
  background: var(--color-primary);
  color: white;
  border: none;
  padding: 8px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: var(--color-white);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  padding: 8px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-secondary:hover { background: var(--color-bg); }

.btn-text {
  background: none;
  border: none;
  color: var(--color-primary);
  font-size: 14px;
  cursor: pointer;
  padding: 4px 8px;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--color-text-light);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.btn-icon:hover { background: var(--color-border); }

/* ========================================
   Header (compartido chat + admin)
   ======================================== */

.chat-header, .admin-header {
  height: var(--header-height);
  background: var(--color-secondary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo {
  height: 32px;
  width: auto;
}

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

.header-user {
  font-size: 13px;
  opacity: 0.8;
}

.header-right .btn-icon { color: rgba(255, 255, 255, 0.8); }
.header-right .btn-icon:hover { background: rgba(255, 255, 255, 0.1); }
.header-right .btn-text { color: rgba(255, 255, 255, 0.8); }

/* ========================================
   Login
   ======================================== */

.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  background: var(--color-white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-logo { margin-bottom: 20px; }

.login-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--color-text-light);
  font-size: 14px;
  margin-bottom: 28px;
}

.login-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn-sso {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-white);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-sso:hover { background: var(--color-bg); }

.login-error {
  margin-top: 20px;
  padding: 10px;
  background: #fef2f2;
  color: var(--color-error);
  border-radius: var(--radius);
  font-size: 13px;
}

/* ========================================
   Chat
   ======================================== */

.chat-main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding-top: var(--header-height);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: var(--color-text-light);
}

.chat-welcome h2 {
  font-size: 22px;
  color: var(--color-text);
  margin-bottom: 8px;
}

.chat-welcome p { font-size: 14px; }

/* Mensajes */
.message {
  max-width: var(--max-width);
  margin: 0 auto 16px;
  display: flex;
  gap: 12px;
}

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

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
}

.message-user .message-avatar {
  background: var(--color-primary);
  color: white;
}

.message-assistant .message-avatar {
  background: var(--color-tertiary);
  color: white;
}

.message-content {
  padding: 10px 16px;
  border-radius: var(--radius-lg);
  max-width: 85%;
  line-height: 1.6;
}

.message-user .message-content {
  background: var(--color-primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.message-assistant .message-content {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: 4px;
}

.message-sources {
  margin-top: 8px;
  font-size: 12px;
  color: var(--color-text-light);
}

.btn-copy {
  background: none;
  border: none;
  color: var(--color-text-light);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.2s;
  position: absolute;
  top: 8px;
  right: 8px;
}

.btn-copy:hover {
  background: var(--color-border);
  color: var(--color-text);
}

.message-content {
  position: relative;
}

.message-content:hover .btn-copy {
  opacity: 1;
}

/* Input */
.chat-input-container {
  padding: 12px 20px 20px;
  background: var(--color-bg);
}

.chat-input-wrapper {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow);
}

.chat-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  max-height: 150px;
  background: transparent;
}

.btn-send {
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.2s;
}

.btn-send:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-send:hover:not(:disabled) { opacity: 0.9; }

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background: var(--color-text-light);
  border-radius: 50%;
  animation: typing 1.2s infinite;
}

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

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* Sidebar de sesiones */
.sessions-sidebar {
  position: fixed;
  top: var(--header-height);
  right: 0;
  bottom: 0;
  width: 300px;
  background: var(--color-white);
  border-left: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  z-index: 90;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--color-border);
}

.sidebar-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.sessions-list { padding: 8px; }

.session-item {
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}

.session-item:hover { background: var(--color-bg); }

.session-item-title {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item-date {
  font-size: 12px;
  color: var(--color-text-light);
}

/* ========================================
   Admin
   ======================================== */

.admin-main {
  padding-top: var(--header-height);
  max-width: 900px;
  margin: 0 auto;
  padding-left: 20px;
  padding-right: 20px;
}

/* Tabs */
.admin-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--color-border);
  margin-top: 20px;
  margin-bottom: 24px;
}

.tab {
  background: none;
  border: none;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-light);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s;
}

.tab:hover { color: var(--color-text); }

.tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Section headers */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-header h2 { font-size: 18px; }

.section-description {
  color: var(--color-text-light);
  font-size: 14px;
  margin-bottom: 20px;
  max-width: 600px;
}

/* Documents list */
.documents-list { display: flex; flex-direction: column; gap: 8px; }

.doc-card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: border-color 0.2s;
}

.doc-card:hover { border-color: var(--color-tertiary); }

.doc-info { flex: 1; min-width: 0; }

.doc-name {
  font-weight: 500;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-meta {
  font-size: 12px;
  color: var(--color-text-light);
  margin-top: 2px;
}

.doc-status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}

.doc-status.ready { background: #dcfce7; color: var(--color-success); }
.doc-status.processing { background: #fef3c7; color: #d97706; }
.doc-status.error { background: #fef2f2; color: var(--color-error); }

.doc-actions {
  display: flex;
  gap: 4px;
  margin-left: 12px;
}

.empty-state {
  text-align: center;
  color: var(--color-text-light);
  padding: 40px 20px;
  font-size: 14px;
}

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
}

.form-group input[type="text"],
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s;
}

.form-group input[type="text"]:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.form-group input[type="color"] {
  width: 50px;
  height: 36px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 2px;
}

.form-hint {
  font-size: 12px;
  color: var(--color-text-light);
  margin-top: 4px;
}

.form-row {
  display: flex;
  gap: 20px;
}

.textarea-large {
  min-height: 300px;
  line-height: 1.7;
}

.save-status {
  font-size: 13px;
  margin-left: 12px;
  color: var(--color-success);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-content {
  background: var(--color-white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 500px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
}

.modal-header h3 { font-size: 16px; }

.modal-body { padding: 20px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--color-border);
}

/* Progress bar */
.upload-progress { margin-top: 12px; }

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--color-border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: var(--color-primary);
  border-radius: 3px;
  transition: width 0.3s;
}

.progress-text {
  font-size: 12px;
  color: var(--color-text-light);
  margin-top: 6px;
}

/* Usage cards */
.usage-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.usage-card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}

.usage-value {
  display: block;
  font-size: 28px;
  font-weight: 700;
  color: var(--color-primary);
}

.usage-label {
  display: block;
  font-size: 13px;
  color: var(--color-text-light);
  margin-top: 4px;
}

/* ========================================
   Login — Formulario email/contraseña
   ======================================== */

.login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.login-form input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s;
}

.login-form input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.login-btn-submit {
  width: 100%;
  padding: 11px;
  font-size: 15px;
  margin-top: 4px;
}

.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  color: var(--color-text-light);
  font-size: 13px;
}

.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

/* ========================================
   Admin — Usuarios
   ======================================== */

.users-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: border-color 0.2s;
}

.user-card:hover { border-color: var(--color-tertiary); }

.user-info { flex: 1; min-width: 0; }

.user-name {
  font-weight: 500;
  font-size: 14px;
}

.user-you {
  font-weight: 400;
  font-size: 12px;
  color: var(--color-text-light);
}

.user-meta {
  font-size: 12px;
  color: var(--color-text-light);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.role-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}

.role-admin { background: #ede9fe; color: #7c3aed; }
.role-member { background: #e0f2fe; color: #0284c7; }

.user-actions {
  display: flex;
  gap: 4px;
  margin-left: 12px;
}

/* Form select */
.form-select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--color-white);
  cursor: pointer;
  transition: border-color 0.2s;
}

.form-select:focus {
  outline: none;
  border-color: var(--color-primary);
}

/* ========================================
   Admin — Logo preview
   ======================================== */

.logo-preview {
  background: var(--color-bg);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  margin-bottom: 8px;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-preview img {
  max-width: 200px;
}

.logo-preview-empty {
  color: var(--color-text-light);
  font-size: 13px;
}

/* ========================================
   Admin — Métodos de autenticación
   ======================================== */

.auth-methods-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 14px;
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 640px) {
  .sessions-sidebar { width: 100%; }
  .form-row { flex-direction: column; gap: 0; }
  .usage-cards { grid-template-columns: 1fr 1fr; }
  .modal-content { max-width: 100%; }
  .admin-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab { white-space: nowrap; padding: 10px 14px; }
  .header-left { gap: 6px; }
  .header-right { gap: 4px; }
  .header-user { display: none; }
  .header-title { font-size: 14px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chat-input-container { padding: 8px 12px 12px; }
  .btn-text { font-size: 12px; padding: 4px 4px; }
}
