/* Main Stylesheet for Nazarban Analytics
  Contains all styles for:
  - Base & Variables
  - Navigation (Desktop & Mobile)
  - Chat Page
  - Content Pages (About, Blog, etc.)
  - PDF Viewer
  - RTL Adjustments
*/

/* --- 1. Base & Variables --- */


/* Custom Font - Tahrir Regular */
@font-face {
  font-family: 'Tahrir';
  src: url('/fonts/TahrirRegular.eot'); /* IE9 Compat */
  src: url('/fonts/TahrirRegular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
       url('/fonts/TahrirRegular.woff2') format('woff2'), /* Modern Browsers */
       url('/fonts/TahrirRegular.woff') format('woff'), /* Modern Browsers */
       url('/fonts/TahrirRegular.ttf') format('truetype'); /* Safari, Android, iOS */
  font-weight: normal;
  font-style: normal;
  font-display: swap; /* Improves loading performance */
}


:root {
  --bg: #020617;
  --panel: #0f172a;
  --panel-glass: rgba(15, 23, 42, 0.75);
  --ink: #f8fafc;
  --muted: #94a3b8;
  --border: rgba(148, 163, 184, 0.15);
  --shadow-color: rgba(129, 140, 248, 0.4);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-xl: 0 20px 50px rgba(0, 0, 0, 0.5);

  --brand1: #818cf8;
  --brand2: #c084fc;
  --brand3: #fb7185;

  --radius-md: 12px;
  --radius-lg: 18px;

  --font-en: 'Tahrir';
  --font-fa: 'Tahrir';
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-family: var(--font-en);
  color: var(--ink);
  background-color: var(--bg);
  scroll-behavior: smooth;
  height: 100%;
}

body {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  text-align: left;
}

/* --- 2. Site-wide Navigation --- */
.header {
  position: sticky;
  top: 0;
  z-index: 900;
  backdrop-filter: blur(20px);
  background: var(--panel-glass);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
}

.logo-badge {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: #ffffff;
  border: 1px solid rgba(71, 85, 105, 0.28);
  box-shadow: 0 6px 24px rgba(129, 140, 248, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.logo {
  width: 34px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-name {
  font-size: 20px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--brand1), var(--brand2), var(--brand3));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-tagline {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.1em;
  font-weight: 600;
}

.header-right-group {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

/* Desktop Navigation */
.nav-desktop {
  display: flex;
  gap: 1.5rem;
  list-style: none;
}

.nav-desktop a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 1rem;
  padding: 0.5rem;
  border-radius: var(--radius-md);
  transition: color 0.2s, background-color 0.2s;
}

.nav-desktop a:hover {
  color: var(--ink);
  background-color: rgba(148, 163, 184, 0.1);
}

.nav-desktop a.active-page {
  color: var(--brand1);
  font-weight: 700;
}

/* Language Switcher */
.language-switcher {
  display: flex;
  gap: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.25rem;
  background-color: rgba(0, 0, 0, 0.2);
}

.language-switcher a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.3rem 0.6rem;
  border-radius: 9px;
  transition: all 0.2s ease;
  line-height: 1;
}

.language-switcher a:hover {
  color: var(--ink);
  background-color: rgba(148, 163, 184, 0.1);
}

.language-switcher a.active {
  color: var(--ink);
  background-color: var(--brand1);
  font-weight: 700;
}

/* Mobile Menu Button */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  z-index: 1001;
  padding: 10px;
  width: 44px;
  height: 44px;
}

.menu-toggle .bar {
  display: block;
  width: 24px;
  height: 3px;
  background-color: var(--ink);
  border-radius: 3px;
  margin: 5px auto;
  transition: all 0.3s ease-in-out;
}

/* Mobile Navigation Overlay */
.nav-mobile-overlay {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  z-index: 1000;
  list-style: none;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-10px);
  transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out, visibility 0.3s;
}

.nav-mobile-overlay.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

.nav-mobile-overlay li {
  margin: 1rem 0;
}

.nav-mobile-overlay a {
  color: var(--muted);
  text-decoration: none;
  font-size: 1.75rem;
  font-weight: 600;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-md);
  transition: color 0.2s, background-color 0.2s;
}

.nav-mobile-overlay a:hover {
  color: var(--ink);
  background-color: rgba(148, 163, 184, 0.1);
}

.nav-mobile-overlay a.active-page {
  color: var(--brand1);
  font-weight: 700;
}

/* --- 3. Chat Page (index.html) --- */
body.chat-page {
  overflow: hidden;
}

.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 75px);
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  scroll-behavior: smooth;
}

.messages-container::-webkit-scrollbar {
  width: 4px;
}

.messages-container::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.28);
  border-radius: 2px;
}

.welcome-section {
  text-align: center;
  padding: 40px 20px;
  margin: auto 0;
  max-width: 900px;
}

.welcome-title {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  margin-bottom: 16px;
  background: linear-gradient(135deg, #fff, #cbd5e1);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.welcome-subtitle {
  font-size: clamp(1rem, 2.5vw, 1.125rem);
  color: var(--muted);
  line-height: 1.7;
  max-width: 680px;
  margin: 0 auto;
}

.message {
  width: 100%;
  display: flex;
  justify-content: center;
  margin: 16px 0;
  animation: slideInFade 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

@keyframes slideInFade {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.bubble-row {
  width: 100%;
  max-width: 900px;
  display: grid;
  align-items: start;
  gap: 12px;
}

.bot .bubble-row {
  grid-template-columns: 38px 1fr;
}

.bot .avatar {
  grid-column: 1;
}

.bot .message-content {
  grid-column: 2;
}

.user .bubble-row {
  grid-template-columns: 1fr 38px;
}

.user .avatar {
  grid-column: 2;
}

.user .message-content {
  grid-column: 1;
  justify-self: end;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}

.bot .avatar {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  box-shadow: 0 4px 16px var(--shadow-color);
}

.user .avatar {
  background: linear-gradient(135deg, #06b6d4, #3b82f6);
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.35);
}

.message-content {
  max-width: 95%;
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  font-size: 16px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.bot .message-content {
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid rgba(129, 140, 248, 0.2);
  box-shadow: var(--shadow-lg);
}

.user .message-content {
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  box-shadow: 0 10px 32px rgba(59, 130, 246, 0.35);
}

.typing-indicator {
  padding: 18px 20px;
  border-radius: var(--radius-lg);
  max-width: 86px;
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid rgba(129, 140, 248, 0.2);
}

.typing-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  animation: typing 1.4s infinite;
}

.dot:nth-child(2) {
  animation-delay: 0.2s;
}

.dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-8px);
  }
}

.input-section {
  padding: 12px 16px;
  backdrop-filter: blur(20px);
  background: var(--panel-glass);
  border-top: 1px solid var(--border);
}

.input-container {
  max-width: 900px;
  margin: 0 auto;
  position: relative;
  display: flex;
  align-items: flex-end;
  padding: 6px 56px 6px 8px;
  border-radius: 20px;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transition: box-shadow 0.2s ease;
}

.input-container:focus-within {
  box-shadow: 0 0 0 3px var(--shadow-color);
}

#messageInput {
  width: 100%;
  min-height: 48px;
  max-height: 140px;
  resize: none;
  outline: none;
  border: none;
  background: rgba(51, 65, 85, 0.82);
  color: var(--ink);
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 16px;
  font-family: inherit;
  transition: background 0.2s ease;
}

#messageInput:focus {
  background: rgba(51, 65, 85, 1);
}

#messageInput::placeholder {
  color: #94a3b8;
}

#sendButton {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 20px var(--shadow-color);
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

#sendButton:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(99, 102, 241, 0.55);
}

#sendButton:active:not(:disabled) .send-icon {
  transform: scale(0.9) rotate(5deg);
}

#sendButton:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.send-icon {
  width: 18px;
  height: 18px;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.contact-section {
  max-width: 900px;
  margin: 12px auto 0;
  padding: 0 16px;
}

.contact-links {
  display: flex;
  justify-content: center;
  gap: 24px;
  align-items: center;
  flex-wrap: wrap;
}

.contact-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-radius: 10px;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.contact-link:hover {
  color: var(--ink);
  background: rgba(148, 163, 184, 0.08);
  border-color: rgba(148, 163, 184, 0.15);
  transform: translateY(-1px);
}

.contact-icon {
  width: 16px;
  height: 16px;
  opacity: 0.8;
  transition: opacity 0.2s ease;
}

.contact-link:hover .contact-icon {
  opacity: 1;
}

/* --- 4. Content Pages (About, Blog, etc.) --- */
.content-wrapper {
  flex: 1;
  max-width: 900px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem;
}

.content-wrapper h1 {
  font-size: 2.75rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  margin-bottom: 1rem;
  background: linear-gradient(135deg, #fff, #cbd5e1);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.content-wrapper h2 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--brand1);
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

.content-wrapper p,
.content-wrapper li {
  font-size: 1.1rem;
  color: var(--muted);
  line-height: 1.7;
  margin-bottom: 1.25rem;
}

.content-wrapper ul {
  list-style-position: inside;
  padding-left: 0.5rem;
}

.content-wrapper a {
  color: var(--brand1);
  text-decoration: none;
  font-weight: 500;
  transition: opacity 0.2s;
}

.content-wrapper a:hover {
  opacity: 0.8;
  text-decoration: underline;
}

/* --- 5. PDF Viewer & Download Button --- */
.download-button-wrapper {
  text-align: center;
  margin: 2.5rem 0;
}

.download-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--brand1);
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 1rem;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-md);
  box-shadow: 0 6px 20px var(--shadow-color);
  transition: all 0.2s ease;
  border: none;
  cursor: pointer;
}

.download-button .button-text {
  display: inline;
  line-height: 1;
  color: var(--ink);
  visibility: visible;
  opacity: 1;
  text-align: center;
}

.download-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(99, 102, 241, 0.55);
}

.pdf-viewer-container {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-xl);
  margin-top: 1rem;
  transition: all 0.3s ease;
}

.pdf-viewer-container object {
  display: block;
  width: 100%;
  height: 80vh;
  border-radius: var(--radius-md);
  border: none;
}

/* --- 6. RTL Adjustments --- */
/* Force navbar to always stay LTR */
html[dir="rtl"] .header {
  direction: ltr;
  text-align: left;
}

html[dir="rtl"] .logo-section {
  direction: ltr;
}

html[dir="rtl"] .nav-desktop,
html[dir="rtl"] .nav-mobile-overlay {
  direction: ltr;
}

html[dir="rtl"] .language-switcher {
  direction: ltr;
}

/* Apply Farsi font to body and header text */
html[dir="rtl"] body {
  font-family: var(--font-fa);
  text-align: right;
}

html[dir="rtl"] .header,
html[dir="rtl"] .header * {
  font-family: var(--font-fa);
}

html[dir="rtl"] .brand-tagline {
  letter-spacing: normal;
}

/* RTL Content Pages */
html[dir="rtl"] .content-wrapper {
  text-align: right;
  direction: rtl;
}

html[dir="rtl"] .content-wrapper h1,
html[dir="rtl"] .content-wrapper h2,
html[dir="rtl"] .content-wrapper h3,
html[dir="rtl"] .content-wrapper p {
  text-align: right;
  direction: rtl;
}

html[dir="rtl"] .content-wrapper ul {
  list-style-position: inside;
  padding-right: 0.5rem;
  padding-left: 0;
  text-align: right;
  direction: rtl;
}

html[dir="rtl"] .content-wrapper li {
  text-align: right;
  direction: rtl;
}

/* Fix for LTR phone number in RTL mode */
html[dir="rtl"] [data-lang-key="contact_phone"] {
  unicode-bidi: embed;
  direction: ltr;
  display: inline-block;
}

/* --- 7. Mobile & Responsive --- */
@media (max-width: 768px) {
  .nav-desktop {
    display: none;
  }

  .menu-toggle {
    display: block;
  }

  .menu-toggle.active .bar:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
  }

  .menu-toggle.active .bar:nth-child(2) {
    opacity: 0;
  }

  .menu-toggle.active .bar:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
  }

  .brand-tagline {
    display: none;
  }

  .content-wrapper {
    padding: 2rem 1rem;
  }

  .content-wrapper h1 {
    font-size: 2.25rem;
  }

  .pdf-viewer-container {
    padding: 0.75rem;
  }

  .pdf-viewer-container object {
    height: 70vh;
  }

  body.chat-page {
    overflow: auto;
  }

  .chat-container {
    height: auto;
    min-height: calc(100vh - 71px);
  }

  .header {
    padding: 12px 16px;
  }

  .messages-container {
    padding: 12px;
  }

  .message-content {
    padding: 14px 18px;
  }

  .input-section {
    padding: 12px;
  }

  #messageInput {
    font-size: 16px;
  }

  .contact-links {
    gap: 12px;
  }

  .contact-link {
    font-size: 13px;
    padding: 10px;
  }

  .contact-section {
    margin-top: 16px;
  }

  .header-right-group {
    margin-left: auto;
    gap: 0.5rem;
  }

  html[dir="rtl"] .header-right-group {
    margin-left: 0;
    margin-right: auto;
    flex-direction: row;
  }

  .language-switcher,
  html[dir="rtl"] .language-switcher,
  .menu-toggle,
  html[dir="rtl"] .menu-toggle {
    margin: 0;
  }
}

/* --- Mobile Language Switcher Fix --- */
@media (max-width: 768px) {
  /* Hide language switcher from header on mobile */
  .header .language-switcher {
    display: none;
  }

  /* Add language switcher to mobile menu */
  .nav-mobile-overlay {
    gap: 0.5rem; /* Add spacing between items */
  }

  /* Mobile menu language switcher styling */
  .nav-mobile-overlay .language-switcher {
    display: flex;
    justify-content: center;
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
  }

  /* Make the buttons slightly larger in mobile menu */
  .nav-mobile-overlay .language-switcher a {
    font-size: 1rem;
    padding: 0.5rem 1rem;
  }
}

/* Keep hamburger menu always on the right side */
html[dir="rtl"] .menu-toggle {
  order: 999; /* Force it to be last in flex order */
}

/* Also ensure header-right-group doesn't reverse on mobile RTL */
@media (max-width: 768px) {
  html[dir="rtl"] .header-right-group {
    margin-left: auto;
    margin-right: 0;
  }
}