/* Swiss Style Design System */
:root {
    --primary-dark: #1A1A2E;
    --secondary-dark: #16213E;
    --tertiary-dark: #0F3460;
    --accent-red: #E94560;
    --white: #FFFFFF;
    
    /* Typography */
    --font-primary: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --font-weight-regular: 400;
    --font-weight-medium: 500;
    --font-weight-bold: 700;
    
    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;
    
    /* Border Radius */
    --border-radius-sm: 0.375rem;
    --border-radius-md: 0.5rem;
    --border-radius-lg: 0.75rem;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    
    /* Transitions */
    --transition-fast: 0.15s ease-in-out;
    --transition-normal: 0.3s ease-in-out;
    --transition-slow: 0.5s ease-in-out;
}

/* Dark Mode Variables */
[data-theme="dark"] {
    --bg-primary: var(--primary-dark);
    --bg-secondary: var(--secondary-dark);
    --bg-tertiary: var(--tertiary-dark);
    --text-primary: var(--white);
    --text-secondary: rgba(255, 255, 255, 0.8);
    --text-muted: rgba(255, 255, 255, 0.6);
    --border-color: rgba(255, 255, 255, 0.1);
    --card-bg: var(--secondary-dark);
}

/* Light Mode Variables */
[data-theme="light"] {
    --bg-primary: var(--white);
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: var(--primary-dark);
    --text-secondary: var(--secondary-dark);
    --text-muted: #6c757d;
    --border-color: #dee2e6;
    --card-bg: var(--white);
}

/* Base Styles */
* {
    box-sizing: border-box;
}

body {
    font-family: var(--font-primary);
    font-weight: var(--font-weight-regular);
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    transition: background-color var(--transition-normal), color var(--transition-normal);
    margin: 0;
    padding: 0;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: var(--font-weight-bold);
    line-height: 1.2;
    margin-bottom: var(--spacing-sm);
    color: var(--text-primary);
}

.hero-title {
    font-size: clamp(2rem, 5vw, 3.5rem);
    font-weight: var(--font-weight-bold);
    margin-bottom: var(--spacing-md);
}

.hero-subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xl);
}

.section-title {
    font-size: 2.5rem;
    margin-bottom: var(--spacing-sm);
}

.section-subtitle {
    font-size: 1.125rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-lg);
}

.text-accent {
    color: var(--accent-red);
}

/* Custom accent background helper */
.bg-accent {
    background-color: var(--accent-red) !important;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-dark), var(--secondary-dark));
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 1020;
}

.navbar-brand {
    font-size: 1.5rem;
    font-weight: var(--font-weight-bold);
}

/* Logo image sizing */
.logo {
    height: 28px;
    width: auto;
    display: inline-block;
}

.footer .logo {
    height: 24px;
}

.navbar-nav .nav-link {
    font-weight: var(--font-weight-medium);
    transition: color var(--transition-fast);
}

.navbar-nav .nav-link:hover {
    color: var(--accent-red) !important;
}

/* Hero Section */
.hero-section {
    background: linear-gradient(135deg, var(--bg-primary), var(--bg-secondary));
    padding: var(--spacing-xl) 0;
    min-height: 80vh;
    display: flex;
    align-items: center;
}

.hero-buttons {
    display: flex;
    gap: var(--spacing-md);
    flex-wrap: wrap;
}

.hero-image {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 400px;
}

.posture-illustration {
    background: linear-gradient(135deg, var(--accent-red), #ff6b8a);
    border-radius: 50%;
    width: 200px;
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
}

/* Buttons */
.btn {
    border-radius: var(--border-radius-md);
    font-weight: var(--font-weight-medium);
    padding: var(--spacing-xs) var(--spacing-md);
    transition: all var(--transition-fast);
    border: none;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-red), #ff4757);
    color: var(--white);
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #d63447, var(--accent-red));
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    color: var(--white);
}

.btn-outline-primary {
    border: 2px solid var(--accent-red);
    color: var(--accent-red);
    background: transparent;
}

.btn-outline-primary:hover {
    background: var(--accent-red);
    color: var(--white);
    transform: translateY(-2px);
}

.btn-outline-light {
    border: 1px solid rgba(255, 255, 255, 0.5);
    color: var(--white);
}

.btn-outline-light:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--white);
}

/* Form Styles */
.posture-form {
    background: var(--card-bg);
    border-radius: var(--border-radius-lg);
    padding: var(--spacing-xl);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
}

.form-section {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: var(--spacing-lg);
    background: var(--bg-secondary);
}

.form-section-title {
    font-size: 1.25rem;
    font-weight: var(--font-weight-bold);
    color: var(--accent-red);
    margin-bottom: var(--spacing-md);
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

/* Prevent overflow in form sections on small screens */
.form-section-title {
    flex-wrap: wrap;
}

.form-section-title .btn {
    margin-top: var(--spacing-xs);
}

.form-section {
    max-width: 100%;
}

.form-check-label {
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
}

@media (max-width: 576px) {
    .form-section {
        padding: var(--spacing-md);
    }
}

.form-label {
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
    margin-bottom: var(--spacing-xs);
}

.form-control, .form-select {
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: var(--spacing-xs) var(--spacing-sm);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color var(--transition-fast);
}

.form-control:focus, .form-select:focus {
    border-color: var(--accent-red);
    box-shadow: 0 0 0 0.2rem rgba(233, 69, 96, 0.25);
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

.form-check {
    margin-bottom: var(--spacing-xs);
}

.form-check-input {
    border: 2px solid var(--border-color);
    background-color: var(--bg-primary);
}

.form-check-input:checked {
    background-color: var(--accent-red);
    border-color: var(--accent-red);
}

.form-check-input:focus {
    box-shadow: 0 0 0 0.2rem rgba(233, 69, 96, 0.25);
}

.form-check-label {
    color: var(--text-primary);
    cursor: pointer;
}

.form-actions {
    margin-top: var(--spacing-xl);
    padding-top: var(--spacing-lg);
    border-top: 1px solid var(--border-color);
}

/* Results Section */
.results-section {
    background: var(--bg-secondary);
}

.result-card {
    background: var(--card-bg);
    border-radius: var(--border-radius-lg);
    padding: var(--spacing-xl);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    text-align: center;
}

.result-score {
    font-size: 3rem;
    font-weight: var(--font-weight-bold);
    margin-bottom: var(--spacing-md);
}

.result-level {
    font-size: 1.5rem;
    font-weight: var(--font-weight-bold);
    margin-bottom: var(--spacing-lg);
}

.result-level.excellent {
    color: #28a745;
}

.result-level.good {
    color: #ffc107;
}

.result-level.needs-improvement {
    color: var(--accent-red);
}

.recommendations {
    text-align: left;
    margin-top: var(--spacing-lg);
}

.recommendation-item {
    background: var(--bg-secondary);
    border-radius: var(--border-radius-md);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
    border-left: 4px solid var(--accent-red);
}

/* History Section */
.history-section {
    background: var(--bg-primary);
}

.history-item {
    background: var(--card-bg);
    border-radius: var(--border-radius-md);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-date {
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
}

.history-score {
    font-size: 1.25rem;
    font-weight: var(--font-weight-bold);
}

/* FAQ Section */
.faq-section {
    background: var(--bg-secondary);
}

.accordion-item {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    margin-bottom: var(--spacing-sm);
    border-radius: var(--border-radius-md);
    overflow: hidden;
}

.accordion-button {
    background: var(--card-bg);
    color: var(--text-primary);
    border: none;
    font-weight: var(--font-weight-medium);
    padding: var(--spacing-md) var(--spacing-lg);
}

.accordion-button:not(.collapsed) {
    background: var(--accent-red);
    color: var(--white);
    box-shadow: none;
}

.accordion-button:focus {
    box-shadow: 0 0 0 0.2rem rgba(233, 69, 96, 0.25);
}

.accordion-body {
    background: var(--card-bg);
    color: var(--text-primary);
    padding: var(--spacing-md) var(--spacing-lg);
}

/* Modal Styles */
.modal-content {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
}

.modal-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.modal-body {
    background: var(--card-bg);
    color: var(--text-primary);
}

/* Improve legibility of illustrations inside modals */
.modal .posture-illustration {
    width: 240px;
    height: 240px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    margin-left: auto;
    margin-right: auto;
}

.modal .posture-illustration .bi {
    color: var(--text-primary);
    font-size: 3.5rem;
    text-shadow: 0 1px 2px rgba(0,0,0,0.25);
}

@media (max-width: 576px) {
    .modal .posture-illustration {
        width: 180px;
        height: 180px;
    }
    .modal .posture-illustration .bi {
        font-size: 2.75rem;
    }
}

.btn-close {
    filter: var(--bs-btn-close-white-filter, invert(1) grayscale(100%) brightness(200%));
}

[data-theme="light"] .btn-close {
    filter: none;
}

/* Reserve bottom space for ad banner when modals are open */
.modal.show .modal-dialog {
    margin-bottom: 120px;
}

/* Ensure modal body content remains scrollable above reserved area if needed */
.modal-body {
    max-height: calc(100vh - 240px);
    overflow: auto;
}

/* Offcanvas Styles */
.offcanvas {
    background: var(--card-bg);
    border-left: 1px solid var(--border-color);
}

.offcanvas-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.offcanvas-body {
    color: var(--text-primary);
}

/* Offcanvas responsive improvements */
.offcanvas-body {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    padding-bottom: 120px; /* preserve space for ad banner at page bottom */
}

.offcanvas-navigation .btn-group {
    flex-wrap: wrap;
    gap: var(--spacing-xs);
}

/* Accessibility helpers */
.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;
}

.offcanvas-navigation .category-btn {
    flex: 1 1 30%;
    min-width: 120px;
    padding: var(--spacing-sm) var(--spacing-md);
}

#offcanvasContentArea {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Content spacing inside offcanvas */
.tips-container, .exercises-container, .resources-container {
    display: grid;
    gap: var(--spacing-sm);
}

/* Iframe resource view */
.resource-frame {
    width: 100%;
    height: 70vh;
    border: 0;
    background: var(--card-bg);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-sm);
}

/* Fixed bottom spacer for pages with bottom overlays */
.page-bottom-spacer {
    height: 120px;
}

@media print {
    .page-bottom-spacer { display: none; }
}

.tip-item, .resource-item {
    padding: var(--spacing-sm);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    background: var(--card-bg);
}

.exercise-item .btn.w-100 {
    padding: var(--spacing-sm);
}

@media (max-width: 576px) {
    .offcanvas-navigation .category-btn {
        flex: 1 1 100%;
        min-width: 0;
    }
    .offcanvas {
        width: 100% !important;
    }
}

.exercise-item {
    background: var(--bg-secondary);
    border-radius: var(--border-radius-md);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-md);
    border: 1px solid var(--border-color);
}

.exercise-title {
    font-weight: var(--font-weight-bold);
    color: var(--accent-red);
    margin-bottom: var(--spacing-xs);
}

/* Footer */
.footer {
    background: linear-gradient(135deg, var(--primary-dark), var(--secondary-dark));
    color: var(--white);
    padding: var(--spacing-xl) 0 var(--spacing-lg);
    margin-top: var(--spacing-xl);
}

.footer h5 {
    color: var(--white);
    margin-bottom: var(--spacing-sm);
}

.footer p {
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 0;
}

/* Ad Banner */
.ad-banner {
    background: var(--bg-secondary);
    border-radius: var(--border-radius-md);
    padding: var(--spacing-md);
    text-align: center;
    border: 1px solid var(--border-color);
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Utility Classes */
.min-vh-75 {
    min-height: 75vh;
}

.text-muted {
    color: var(--text-muted) !important;
}

/* Dark Mode Toggle */
#darkModeToggle {
    transition: all var(--transition-fast);
}

#darkModeToggle:hover {
    transform: scale(1.1);
}

/* Responsive Design */
@media (max-width: 768px) {
    .hero-section {
        padding: var(--spacing-lg) 0;
        text-align: center;
    }
    
    .hero-buttons {
        justify-content: center;
    }
    
    .hero-image {
        margin-top: var(--spacing-lg);
        height: 300px;
    }
    
    .posture-illustration {
        width: 150px;
        height: 150px;
    }
    
    .section-title {
        font-size: 2rem;
    }
    
    .hero-title {
        font-size: 2.5rem;
    }
    
    .posture-form {
        padding: var(--spacing-lg);
    }
    
    .form-section {
        padding: var(--spacing-md);
    }
    
    .btn-lg {
        padding: var(--spacing-sm) var(--spacing-lg);
        font-size: 1rem;
    }
    
    .history-item {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-xs);
    }
}

@media (max-width: 576px) {
    .hero-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .btn {
        width: 100%;
        justify-content: center;
    }
    
    .section-title {
        font-size: 1.75rem;
    }
    
    .hero-title {
        font-size: 2rem;
    }
    
    .result-score {
        font-size: 2rem;
    }
    
    .result-level {
        font-size: 1.25rem;
    }
}

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

/* Focus styles for accessibility */
.btn:focus,
.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    outline: 2px solid var(--accent-red);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
        --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.3);
    }
    
    .btn {
        border: 2px solid currentColor;
    }
}

/* Print styles */
@media print {
    .header,
    .footer,
    .btn,
    .ad-banner {
        display: none !important;
    }
    
    .posture-form {
        box-shadow: none;
        border: 1px solid #000;
    }
    
    body {
        background: white !important;
        color: black !important;
    }
}

/* Loading states */
.loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--accent-red);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

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

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

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

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

::-webkit-scrollbar-thumb:hover {
    background: #d63447;
}
