/* CSS Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Terms of Service specific colors that override design system where needed */
    --tos-primary-color: rgba(14, 71, 161, 0.95);
    --tos-secondary-color: rgba(24, 72, 146, 0.98);
    --tos-bg-gray: #edf2f7;
    
    /* Spacing System (8px base) */
    --space-1: 8px;
    --space-2: 16px;
    --space-3: 24px;
    --space-4: 32px;
    --space-5: 40px;
    --space-6: 48px;
    --space-8: 64px;
    --space-10: 80px;
    --space-12: 96px;
    
    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 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;
    
    /* Line Heights */
    --line-height-tight: 1.25;
    --line-height-normal: 1.5;
    --line-height-relaxed: 1.625;
    
    /* Transitions */
    --transition-fast: 0.15s ease-in-out;
    --transition-normal: 0.3s ease-in-out;
    --transition-slow: 0.5s ease-in-out;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    
    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --tos-bg-gray: #4a5568;
    }
}

/* Base Styles */
html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: var(--font-family);
    line-height: var(--line-height-normal);
    color: var(--text-primary);
    background-color: var(--surface);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* Page Container */
.page-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding-top: var(--navbar-height, 80px); /* Add top padding for fixed navbar */
}







/* Mobile TOC Toggle */
.mobile-toc-toggle {
    display: none;
    position: fixed;
    top: var(--space-2);
    right: var(--space-2);
    z-index: 1000;
    background: var(--tos-primary-color);
    border: none;
    border-radius: var(--radius-md);
    padding: var(--space-2);
    cursor: pointer;
    transition: var(--transition-fast);
    box-shadow: var(--shadow-lg);
}

.mobile-toc-toggle:hover {
    background: var(--tos-secondary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-xl);
}

.hamburger {
    display: block;
    width: 20px;
    height: 2px;
    background: white;
    margin: 4px 0;
    transition: var(--transition-fast);
    border-radius: 2px;
}

.mobile-toc-toggle.active .hamburger:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.mobile-toc-toggle.active .hamburger:nth-child(2) {
    opacity: 0;
}

.mobile-toc-toggle.active .hamburger:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -6px);
}

/* Main Container */
.main-container {
    display: flex;
    flex: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-6) var(--space-3);
    gap: var(--space-8);
    align-items: flex-start;
}

/* Table of Contents */
.toc-container {
    flex: 0 0 300px;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: var(--space-4);
    position: sticky;
    top: var(--space-4);
    max-height: calc(100vh - var(--space-8));
    overflow-y: auto;
    border: 1px solid var(--border-light);
}

.toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-3);
    padding-bottom: var(--space-2);
    border-bottom: 2px solid var(--border-light);
}

.toc-header h2 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.toc-close {
    display: none;
    background: none;
    border: none;
    font-size: var(--font-size-xl);
    cursor: pointer;
    color: var(--text-muted);
    padding: var(--space-1);
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
}

.toc-close:hover {
    background: var(--bg-gray);
    color: var(--text-primary);
}

/* TOC Search */
.toc-search {
    margin-bottom: var(--space-3);
}

.toc-search-input {
    width: 100%;
    padding: var(--space-2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    background: var(--bg-secondary);
    transition: var(--transition-fast);
}

.toc-search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.toc-search-input::placeholder {
    color: var(--text-muted);
}

/* TOC List */
.toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.toc-list li {
    margin-bottom: var(--space-1);
}

.toc-list a {
    display: block;
    padding: var(--space-2);
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    font-weight: 500;
    transition: var(--transition-fast);
    border-left: 3px solid transparent;
}

.toc-list a:hover {
    background: var(--bg-gray);
    color: var(--text-primary);
    transform: translateX(2px);
}

.toc-list a.active {
    background: var(--primary-light);
    color: var(--primary-color);
    border-left-color: var(--primary-color);
    font-weight: 600;
}

.toc-subsection {
    list-style: none;
    margin: var(--space-1) 0 0 var(--space-3);
    padding: 0;
}

.toc-subsection a {
    font-size: var(--font-size-xs);
    padding: var(--space-1) var(--space-2);
    color: var(--text-muted);
}

.toc-subsection a:hover {
    color: var(--text-secondary);
}

.toc-subsection a.active {
    color: var(--primary-color);
}

/* Content Container */
.content-container {
    flex: 1;
    min-width: 0;
}

.terms-content {
    background: var(--surface-elevated);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: var(--space-8);
    border: 1px solid var(--border-light);
}

/* Content Header */
.content-header {
    margin-bottom: var(--space-8);
    padding-bottom: var(--space-6);
    border-bottom: 3px solid var(--primary-light);
}

.content-header h1 {
    font-size: clamp(1.8rem, 4vw, 2.5rem);
    font-weight: 700;
    color: var(--primary);
    margin-bottom: var(--space-4);
    letter-spacing: -0.025em;
    line-height: var(--line-height-tight);
}

.meta-info {
    display: flex;
    gap: var(--space-6);
    flex-wrap: wrap;
}

.meta-item {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    font-weight: 500;
    padding: var(--space-2) var(--space-4);
    background: var(--bg-gray);
    border-radius: var(--radius-full);
    border: 1px solid var(--border-color);
    transition: all var(--transition-fast);
}

.meta-item:hover {
    background: var(--primary-light);
    color: var(--primary-color);
    border-color: var(--primary-color);
}

/* Content Sections */
.content-section {
    margin-bottom: var(--space-8);
    scroll-margin-top: var(--space-6);
}

.content-section:last-child {
    margin-bottom: 0;
}

.content-section h2 {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-2);
    border-bottom: 2px solid var(--border-light);
    position: relative;
}

.content-section h2::before {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 60px;
    height: 2px;
    background: var(--primary-color);
}

.subsection {
    margin: var(--space-6) 0;
    padding-left: var(--space-4);
    border-left: 3px solid var(--border-light);
    scroll-margin-top: var(--space-6);
}

.subsection h3 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-3);
}

.content-section p {
    font-size: var(--font-size-base);
    line-height: var(--line-height-relaxed);
    color: var(--text-secondary);
    margin-bottom: var(--space-3);
}

.content-section p:last-child {
    margin-bottom: 0;
}

.content-section strong {
    color: var(--text-primary);
    font-weight: 600;
}

.content-section ul {
    margin: var(--space-3) 0;
    padding-left: var(--space-4);
}

.content-section li {
    font-size: var(--font-size-base);
    line-height: var(--line-height-relaxed);
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
}

.content-section li:last-child {
    margin-bottom: 0;
}



/* Back to Top Button */
.back-to-top {
    position: fixed;
    bottom: var(--space-4);
    right: var(--space-4);
    width: 48px;
    height: 48px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    transition: var(--transition-fast);
    opacity: 0;
    visibility: hidden;
    z-index: 1000;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
}

.back-to-top:hover {
    background: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-xl);
}

.back-to-top svg {
    width: 20px;
    height: 20px;
}

/* Animations */
.fade-in {
    animation: fadeIn 0.6s ease-out;
}

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

/* Responsive Design */
@media (max-width: 1024px) {
    .main-container {
        gap: var(--space-6);
    }

    .toc-container {
        flex: 0 0 250px;
    }

    .terms-content {
        padding: var(--space-6);
    }
}

@media (max-width: 768px) {
    .mobile-toc-toggle {
        display: block;
    }

    .main-container {
        flex-direction: column;
        padding: var(--space-4) var(--space-2);
        gap: 0;
    }

    .toc-container {
        position: fixed;
        top: 0;
        left: -100%;
        width: 280px;
        height: 100vh;
        z-index: 999;
        transition: left var(--transition-normal);
        border-radius: 0;
        max-height: none;
        overflow-y: auto;
    }

    .toc-container.mobile-open {
        left: 0;
    }

    .toc-close {
        display: block;
    }

    .content-container {
        width: 100%;
    }

    .terms-content {
        padding: var(--space-4);
        border-radius: var(--radius-md);
    }

    .header-content {
        padding: 0 var(--space-2);
    }



    .content-header h1 {
        font-size: var(--font-size-2xl);
    }

    .meta-info {
        flex-direction: column;
        gap: var(--space-2);
    }

    .content-section h2 {
        font-size: var(--font-size-xl);
    }

    .subsection h3 {
        font-size: var(--font-size-lg);
    }

    .back-to-top {
        bottom: var(--space-3);
        right: var(--space-3);
        width: 44px;
        height: 44px;
    }
}

@media (max-width: 480px) {
    .terms-content {
        padding: var(--space-3);
    }

    .content-section {
        margin-bottom: var(--space-6);
    }

    .subsection {
        padding-left: var(--space-2);
    }

    .content-header {
        margin-bottom: var(--space-6);
        padding-bottom: var(--space-4);
    }

    .content-header h1 {
        font-size: var(--font-size-xl);
    }



    .content-section h2 {
        font-size: var(--font-size-lg);
    }

    .subsection h3 {
        font-size: var(--font-size-base);
    }
}

/* Print Styles */
@media print {
    .mobile-toc-toggle,
    .back-to-top,
    .toc-container {
        display: none !important;
    }

    .main-container {
        flex-direction: column;
        gap: 0;
    }

    .content-container {
        width: 100%;
    }

    .terms-content {
        box-shadow: none;
        border: none;
        padding: 0;
    }

    .content-section {
        page-break-inside: avoid;
        margin-bottom: var(--space-4);
    }

    .content-section h2 {
        page-break-after: avoid;
    }


}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    html {
        scroll-behavior: auto;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --border-light: #666666;
        --text-muted: #333333;
    }

    .toc-list a.active {
        background: #000000;
        color: #ffffff;
    }

    .content-section h2::before {
        background: #000000;
    }
}

/* RTL Support for Arabic */
[dir="rtl"] {
    text-align: right;
}

[dir="rtl"] .nav-section {
    flex-direction: row-reverse;
}

[dir="rtl"] .nav-actions {
    flex-direction: row-reverse;
}

[dir="rtl"] .logo-container {
    flex-direction: row-reverse;
}

[dir="rtl"] .main-container {
    flex-direction: row-reverse;
}

[dir="rtl"] .toc-container {
    order: 2;
}

[dir="rtl"] .content-container {
    order: 1;
}

[dir="rtl"] .toc-list a {
    border-left: none;
    border-right: 3px solid transparent;
}

[dir="rtl"] .toc-list a.active {
    border-right-color: var(--primary-color);
}

[dir="rtl"] .toc-list a:hover {
    transform: translateX(-2px);
}

[dir="rtl"] .subsection {
    padding-left: 0;
    padding-right: var(--space-4);
    border-left: none;
    border-right: 3px solid var(--border-light);
}

[dir="rtl"] .content-section h2::before {
    left: auto;
    right: 0;
}



[dir="rtl"] .back-to-top {
    left: var(--space-4);
    right: auto;
}

/* RTL Mobile adjustments */
@media (max-width: 768px) {
    [dir="rtl"] .mobile-toc-toggle {
        left: var(--space-2);
        right: auto;
    }

    [dir="rtl"] .toc-container {
        left: auto;
        right: -100%;
    }

    [dir="rtl"] .toc-container.mobile-open {
        right: 0;
    }

    [dir="rtl"] .back-to-top {
        left: var(--space-3);
        right: auto;
    }
}
