/**
 * Xentral Helpbot - Modern CSS Architecture
 * Using BEM methodology and CSS Custom Properties
 * Author: Modernized for better maintainability
 */

/* Import component-specific styles */
@import url('./components.css');

/* ===== CSS CUSTOM PROPERTIES (DESIGN TOKENS) ===== */
:root {
  /* Brand Colors */
  --brand-50: #f5f3ff;
  --brand-100: #ede9fe;
  --brand-200: #ddd6fe;
  --brand-300: #c4b5fd;
  --brand-400: #a78bfa;
  --brand-500: #8b5cf6;
  --brand-600: #7c3aed;
  --brand-700: #6d28d9;
  --brand-800: #5b21b6;
  --brand-900: #4c1d95;

  /* Neutral Colors */
  --neutral-50: #f8fafc;
  --neutral-100: #f1f5f9;
  --neutral-200: #e2e8f0;
  --neutral-300: #cbd5e1;
  --neutral-400: #94a3b8;
  --neutral-500: #64748b;
  --neutral-600: #475569;
  --neutral-700: #334155;
  --neutral-800: #1e293b;
  --neutral-900: #0f172a;

  /* Semantic Colors */
  --success-500: #10b981;
  --success-600: #059669;
  --error-500: #ef4444;
  --error-600: #dc2626;

  /* Typography */
  --font-family-base: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 1.875rem;
  --font-size-4xl: 2.25rem;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;
  --font-weight-extrabold: 800;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;

  /* Border Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.5rem;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

  /* Layout */
  --container-max-width: 790px;
  --chat-max-width: 880px;
  --input-height: 120px;

  /* Z-Index Scale */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-popover: 1060;
  --z-tooltip: 1070;
}

/* ===== RESET & BASE STYLES ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  scroll-behavior: smooth;
}

body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: var(--font-family-base);
  font-size: var(--font-size-base);
  line-height: 1.6;
  color: var(--neutral-900);
  background: linear-gradient(135deg, #f5f7fe 0%, #eef2fb 100%);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== ACCESSIBILITY UTILITIES ===== */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: var(--space-6);
  background: var(--brand-600);
  color: white;
  padding: var(--space-2) var(--space-4);
  text-decoration: none;
  border-radius: var(--radius-md);
  z-index: var(--z-tooltip);
  transition: top 0.3s;
}

.skip-link:focus {
  top: var(--space-6);
}

/* ===== MAIN APPLICATION LAYOUT ===== */
.chat-application {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: var(--chat-max-width);
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
  padding-bottom: calc(var(--input-height) + var(--space-8));
}

/* ===== CHAT HEADER ===== */
.chat-header {
  text-align: center;
  margin-bottom: var(--space-8);
}

.chat-header__title {
  font-size: clamp(var(--font-size-2xl), 4vw, var(--font-size-4xl));
  font-weight: var(--font-weight-extrabold);
  line-height: 1.2;
  letter-spacing: -0.025em;
  margin: 0 0 var(--space-3) 0;
  color: var(--neutral-900);
}

.chat-header__brand {
  background: linear-gradient(90deg, var(--brand-600), var(--brand-400));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.chat-header__subtitle {
  font-size: var(--font-size-lg);
  color: var(--neutral-600);
  margin: 0;
  font-weight: var(--font-weight-medium);
}

/* ===== ROLE SELECTOR ===== */
.role-selector {
  margin-bottom: var(--space-8);
}

.role-selector__group {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
  max-width: var(--container-max-width);
  margin: 0 auto;
}

.role-selector__button {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-xl);
  background: white;
  color: var(--neutral-700);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-base);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  position: relative;
}

.role-selector__button:hover {
  transform: translateY(-2px);
  border-color: var(--brand-300);
  box-shadow: var(--shadow-lg);
  background: linear-gradient(180deg, white, var(--brand-50));
}

.role-selector__button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px var(--brand-100), var(--shadow-sm);
  border-color: var(--brand-300);
}

.role-selector__button--active {
  border-color: var(--brand-300);
  background: linear-gradient(180deg, white, var(--brand-50));
  box-shadow: var(--shadow-md);
}

.role-selector__button--active::after {
  content: '';
  position: absolute;
  right: var(--space-4);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-600), var(--brand-400));
  box-shadow: var(--shadow-sm);
}

/* ===== CHAT CONVERSATION ===== */
.chat-conversation {
  flex: 1;
  position: relative;
}

.chat-conversation__container {
  max-width: var(--container-max-width);
  margin: 0 auto;
  background: white;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 220px);
  position: relative;
  overflow: hidden;
}

.chat-conversation__log {
  flex: 1;
  padding: var(--space-6);
  overflow-y: auto;
  scroll-behavior: smooth;
}

.chat-conversation__scroll-btn {
  position: absolute;
  bottom: var(--space-20);
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  border: none;
  background: white;
  box-shadow: var(--shadow-lg);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: var(--z-fixed);
  color: var(--neutral-600);
  transition: all 0.2s ease;
}

.chat-conversation__scroll-btn:hover {
  transform: translateX(-50%) translateY(-2px);
  box-shadow: var(--shadow-xl);
  color: var(--brand-600);
}

.chat-conversation__scroll-btn svg {
  width: 20px;
  height: 20px;
}

/* ===== CHAT MESSAGES ===== */
.chat-message {
  margin-bottom: var(--space-6);
  display: flex;
  flex-direction: column;
  clear: both;
}

.chat-message__bubble {
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-xl);
  max-width: 90%;
  word-wrap: break-word;
}

.chat-message--user {
  align-items: flex-end;
}

.chat-message--user .chat-message__bubble {
  background: linear-gradient(135deg, var(--brand-400), var(--brand-300));
  color: white;
  border-bottom-right-radius: var(--radius-md);
}

.chat-message--bot {
  align-items: flex-start;
}

.chat-message--bot .chat-message__bubble {
  background: white;
  color: var(--neutral-800);
  border-bottom-left-radius: var(--radius-md);
}

.chat-message__bubble--loading {
  padding: var(--space-3) var(--space-4);
}

.chat-message__content {
  line-height: 1.6;
}

.chat-message__content h1,
.chat-message__content h2,
.chat-message__content h3,
.chat-message__content h4,
.chat-message__content h5,
.chat-message__content h6 {
  margin-top: var(--space-4);
  margin-bottom: var(--space-2);
  font-weight: var(--font-weight-semibold);
}

.chat-message__content h1 { font-size: var(--font-size-xl); }
.chat-message__content h2 { font-size: var(--font-size-lg); }
.chat-message__content h3 { font-size: var(--font-size-base); }

.chat-message__content p {
  margin: var(--space-2) 0;
}

.chat-message__content a {
  color: var(--brand-600);
  text-decoration: none;
  border-bottom: 1px dashed var(--brand-200);
}

.chat-message__content a:hover {
  color: var(--brand-700);
  border-bottom-color: var(--brand-400);
}

.chat-message__sources {
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--neutral-100);
  font-size: var(--font-size-sm);
}

.chat-message__sources strong {
  display: block;
  margin-bottom: var(--space-2);
  color: var(--neutral-700);
}

.chat-message__sources a {
  display: block;
  color: var(--brand-600);
  text-decoration: none;
  margin-bottom: var(--space-1);
}

.chat-message__sources a:hover {
  text-decoration: underline;
}

/* ===== FEEDBACK COMPONENT ===== */
.chat-message__feedback {
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--neutral-100);
}

.feedback__question {
  font-size: var(--font-size-sm);
  color: var(--neutral-600);
  margin-bottom: var(--space-3);
}

.feedback__buttons {
  display: flex;
  gap: var(--space-2);
}

.feedback__btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border: 1px solid;
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  transition: all 0.2s ease;
  background: white;
}

.feedback__btn svg {
  width: 14px;
  height: 14px;
}

.feedback__btn--positive {
  border-color: var(--success-500);
  color: var(--success-600);
}

.feedback__btn--positive:hover {
  background: var(--success-500);
  color: white;
}

.feedback__btn--negative {
  border-color: var(--error-500);
  color: var(--error-600);
}

.feedback__btn--negative:hover {
  background: var(--error-500);
  color: white;
}

/* ===== LOADING INDICATOR ===== */
.loading-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) 0;
}

.loading-indicator__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--neutral-400);
  animation: loading-pulse 1.4s infinite ease-in-out both;
}

.loading-indicator__dot:nth-child(1) { animation-delay: -0.32s; }
.loading-indicator__dot:nth-child(2) { animation-delay: -0.16s; }
.loading-indicator__dot:nth-child(3) { animation-delay: 0; }

@keyframes loading-pulse {
  0%, 80%, 100% { 
    transform: scale(0);
    opacity: 0.5;
  }
  40% { 
    transform: scale(1);
    opacity: 1;
  }
}

/* ===== ORIGINAL SPINNER ANIMATION ===== */
.dots {
  display: inline-block;
  width: 40px;
  text-align: center;
  margin-top: 4px;
}

.dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin: 0 2px;
  background-color: #bbb;
  border-radius: 50%;
  animation: dots 1.4s infinite ease-in-out both;
}

.dots span:nth-child(1) { animation-delay: -0.32s; }
.dots span:nth-child(2) { animation-delay: -0.16s; }
.dots span:nth-child(3) { animation-delay: 0; }

@keyframes dots {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* ===== PULSE TEXT ANIMATION ===== */
@keyframes pulse-text {
  0%, 100% {
    opacity: 0.6;
    color: #999;
  }
  50% {
    opacity: 1;
    color: #666;
  }
}

/* ===== INPUT SECTION ===== */
.input-section {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: var(--space-6);
  max-width: var(--container-max-width);
  width: calc(100% - var(--space-6));
  z-index: var(--z-fixed);
}

.input-section__container {
  background: white;
  display: flex;
  align-items: flex-end;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--neutral-200);
}

.input-section__textarea {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-lg);
  font-family: inherit;
  font-size: var(--font-size-base);
  line-height: 1.5;
  resize: none;
  outline: none;
  transition: border-color 0.2s ease;
}

.input-section__textarea:focus {
  border-color: var(--brand-300);
  box-shadow: 0 0 0 3px var(--brand-100);
}

.input-section__textarea::placeholder {
  color: var(--neutral-400);
}

.input-section__send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--brand-600);
  color: white;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.input-section__send-btn:hover:not(:disabled) {
  background: var(--brand-700);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.input-section__send-btn:disabled {
  background: var(--neutral-300);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.input-section__send-btn svg {
  width: 18px;
  height: 18px;
}

.input-section__help {
  text-align: center;
  font-size: var(--font-size-xs);
  color: var(--neutral-500);
  margin-top: var(--space-2);
  line-height: 1.4;
}

.input-section__help a {
  color: var(--neutral-500);
  text-decoration: underline;
}

.input-section__help a:hover {
  color: var(--brand-600);
}

/* ===== LANGUAGE SELECTOR ===== */
.language-selector {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: var(--space-2);
}

.language-selector__label {
  font-size: var(--font-size-xs);
  color: var(--neutral-500);
}

.language-selector__button {
  background: none;
  border: none;
  color: var(--neutral-500);
  font-size: var(--font-size-xs);
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.language-selector__button:hover {
  color: var(--brand-600);
  background: var(--brand-50);
}

.language-selector__button--active {
  color: var(--brand-600);
  font-weight: var(--font-weight-medium);
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
  .chat-application {
    padding: var(--space-4) var(--space-3);
  }

  .role-selector__group {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }

  .chat-conversation__container {
    height: calc(100vh - 180px);
  }

  .chat-message__bubble {
    max-width: 95%;
  }

  .input-section {
    width: calc(100% - var(--space-4));
  }

  .input-section__help {
    display: none;
  }
}

@media (max-width: 480px) {
  .chat-header__title {
    font-size: var(--font-size-2xl);
  }

  .role-selector__button {
    padding: var(--space-3) var(--space-4);
    font-size: var(--font-size-sm);
  }

  .chat-conversation__log {
    padding: var(--space-4);
  }
}

/* ===== PRINT STYLES ===== */
@media print {
  .input-section,
  .chat-conversation__scroll-btn,
  .feedback__buttons {
    display: none !important;
  }

  .chat-application {
    padding-bottom: 0;
  }

  .chat-conversation__container {
    height: auto;
    box-shadow: none;
    border: 1px solid var(--neutral-300);
  }
}

/* ===== HIGH CONTRAST MODE ===== */
@media (prefers-contrast: high) {
  :root {
    --neutral-100: #e5e5e5;
    --neutral-200: #cccccc;
    --neutral-600: #333333;
    --neutral-900: #000000;
  }

  .chat-message__bubble {
    border-width: 2px;
  }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  html {
    scroll-behavior: auto;
  }
}