/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Theme Variables */
:root {
  --header-height: 80px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* Light Theme */
[data-theme="light"] {
  --primary-color: #3b82f6;
  --primary-dark: #1d4ed8;
  --secondary-color: #64748b;
  --accent-color: #06d6a0;
  --background-color: #ffffff;
  --surface-color: #f8fafc;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;
  --header-bg: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  --header-text: #1e293b;
  --header-subtitle: #64748b;
  --header-border: #e2e8f0;
}

/* Dark Theme */
[data-theme="dark"] {
  --primary-color: #60a5fa;
  --primary-dark: #3b82f6;
  --secondary-color: #94a3b8;
  --accent-color: #34d399;
  --background-color: #0f172a;
  --surface-color: #1e293b;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --border-color: #334155;
  --header-bg: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  --header-text: #ffffff;
  --header-subtitle: rgba(255, 255, 255, 0.8);
  --header-border: #334155;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--background-color);
  color: var(--text-primary);
  line-height: 1.7;
  font-size: 16px;
  padding-top: var(--header-height);
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Fixed Progress Bar - Always Visible */
.progress-container-fixed {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: rgba(0, 0, 0, 0.1);
  z-index: 1002;
  transition: background 0.3s ease;
}

[data-theme="dark"] .progress-container-fixed {
  background: rgba(255, 255, 255, 0.1);
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
  width: 0%;
  transition: width 0.3s ease;
}

/* Smart Auto-Hide Header */
.main-header {
  position: fixed;
  top: 3px;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--header-bg);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--header-border);
  z-index: 1001;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
              box-shadow 0.3s ease,
              background 0.3s ease;
  box-shadow: var(--shadow-md);
}

.main-header.hidden {
  transform: translateY(-100%);
}

.main-header.scrolled {
  box-shadow: var(--shadow-lg);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 2rem;
}

/* Logo Section with Bank Icon */
.header-left {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-icon {
  transition: transform 0.3s ease;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-icon:hover {
  transform: scale(1.05) rotate(2deg);
}

.logo-text h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--header-text);
  margin: 0;
  line-height: 1.2;
  white-space: nowrap;
}

.subtitle {
  font-size: 0.75rem;
  color: var(--header-subtitle);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

/* Enhanced Navigation with Hover Dropdowns */
.main-nav {
  flex: 1;
  display: flex;
  justify-content: center;
}

.nav-list {
  display: flex;
  list-style: none;
  gap: 0.5rem;
  align-items: center;
}

.nav-list li {
  position: relative;
}

/* Navigation Links */
.nav-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  color: var(--header-text);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
  border-radius: 0.5rem;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  white-space: nowrap;
}

.nav-link::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.1), transparent);
  transition: left 0.5s ease;
}

.nav-link:hover::before {
  left: 100%;
}

.nav-link:hover {
  background: rgba(59, 130, 246, 0.1);
  transform: translateY(-2px);
}

.nav-link.active {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: white;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
  transform: translateY(-1px);
}

/* Dropdown Arrow */
.dropdown-arrow {
  transition: transform 0.3s ease;
  margin-left: 0.25rem;
}

.nav-dropdown-item:hover .dropdown-arrow {
  transform: rotate(180deg);
}

/* Navigation Dropdown Menus */
.nav-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 0.5rem;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 0.75rem;
  min-width: 250px;
  max-height: 400px;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) translateY(-10px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1003;
}

.nav-dropdown-item:hover .nav-dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.nav-dropdown-menu ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-dropdown-menu li {
  margin-bottom: 0.25rem;
}

.nav-dropdown-menu a {
  display: block;
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  text-decoration: none;
  border-radius: 0.5rem;
  transition: all 0.2s ease;
  font-size: 0.9rem;
}

.nav-dropdown-menu a:hover {
  background: var(--background-color);
  color: var(--primary-color);
  transform: translateX(4px);
}

.nav-dropdown-menu a.active {
  background: var(--primary-color);
  color: white;
}

/* Header Right Section */
.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}

/* Simple Theme Toggle */
.theme-toggle-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 0.5rem;
  background: rgba(59, 130, 246, 0.1);
  color: var(--header-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  border: 1px solid rgba(59, 130, 246, 0.2);
  position: relative;
}

.theme-toggle-btn:hover {
  background: rgba(59, 130, 246, 0.2);
  transform: scale(1.05);
}

.theme-icon {
  position: absolute;
  transition: all 0.3s ease;
}

[data-theme="light"] .light-icon {
  opacity: 1;
  transform: scale(1);
}

[data-theme="light"] .dark-icon {
  opacity: 0;
  transform: scale(0.5);
}

[data-theme="dark"] .light-icon {
  opacity: 0;
  transform: scale(0.5);
}

[data-theme="dark"] .dark-icon {
  opacity: 1;
  transform: scale(1);
}

/* Main Content */
.main-content {
  padding: 2rem;
  max-width: 1200px;
  margin: 0 auto;
  min-height: calc(100vh - var(--header-height));
}

.content-wrapper {
  animation: fadeInUp 0.6s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Enhanced Table Styling */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 2rem 0;
  background: var(--surface-color);
  border-radius: 0.75rem;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
}

table thead {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: white;
}

table th {
  padding: 1.25rem 1.5rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.9rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

table td {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: top;
  transition: background-color 0.2s ease;
}

table tbody tr {
  transition: all 0.2s ease;
}

table tbody tr:nth-child(even) {
  background-color: var(--background-color);
}

table tbody tr:hover {
  background-color: var(--border-color);
  transform: scale(1.01);
}

table tbody tr:last-child td {
  border-bottom: none;
}

/* Typography improvements */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-primary);
  font-weight: 700;
  line-height: 1.25;
  margin-top: 2.5rem;
  margin-bottom: 1.5rem;
}

h1 {
  font-size: 2.5rem;
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  border-bottom: 3px solid var(--primary-color);
  padding-bottom: 0.5rem;
}

h2 {
  font-size: 2rem;
  color: var(--primary-color);
}

h3 {
  font-size: 1.5rem;
  color: var(--primary-dark);
}

p {
  margin-bottom: 1.5rem;
  color: var(--text-primary);
}

/* Chapter cross-reference links */
a[href^="#"] {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.2s ease;
  border-bottom: 1px solid transparent;
}

a[href^="#"]:hover {
  color: var(--primary-dark);
  border-bottom-color: var(--primary-color);
}

/* Scroll to Top Button */
.scroll-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 50px;
  height: 50px;
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-lg);
  z-index: 999;
}

.scroll-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.scroll-to-top:hover {
  transform: translateY(-5px);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

/* Mermaid diagram styling - FIXED COLORS */
.mermaid {
  background: linear-gradient(135deg, #1e293b, #334155) !important;
  margin: 2rem 0;
  padding: 2rem;
  border-radius: 0.75rem;
  overflow-x: auto;
  border: 1px solid #334155;
  box-shadow: var(--shadow-lg);
}

/* Responsive design */
@media (max-width: 1024px) {
  .header-content {
    padding: 0 1rem;
  }
  
  .logo-text h1 {
    font-size: 1.25rem;
  }
  
  .nav-link {
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
  }
  
  .nav-dropdown-menu {
    min-width: 220px;
  }
}

@media (max-width: 768px) {
  :root {
    --header-height: 70px;
  }
  
  .header-content {
    padding: 0 1rem;
  }
  
  .logo-text h1 {
    font-size: 1.1rem;
  }
  
  .nav-list {
    gap: 0.25rem;
  }
  
  .nav-link {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
  }
  
  .main-content {
    padding: 1rem;
  }
  
  .nav-dropdown-menu {
    min-width: 200px;
    left: 0;
    transform: translateX(0);
  }
  
  .nav-dropdown-item:hover .nav-dropdown-menu {
    transform: translateX(0) translateY(0);
  }
}

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--background-color);
}

::-webkit-scrollbar-thumb {
  background: var(--secondary-color);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}