/* CSS Reset & Base Styles */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* CSS Variables for Theme Support */
:root {
    --primary-color: #00897B;
    --primary-hover: #00695C;
    --secondary-color: #26A69A;
    --accent-color: #FFAB40;
    --accent-hover: #FF9800;
    --background: #F5F5F5;
    --surface: #FFFFFF;
    --text-primary: #212121;
    --text-secondary: #757575;
    --text-light: #FAFAFA;
    --border: #E0E0E0;
    --border-focus: #00897B;
    --success: #4CAF50;
    --warning: #FFAB40;
    --error: #F44336;
    --shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px 0 rgba(0, 137, 123, 0.15);
    --border-radius: 8px;
    --border-radius-lg: 16px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Additional variables for related sites */
    --border-color: #E0E0E0;
    --card-bg: #FFFFFF;
    --success-color: #4CAF50;
}

/* Dark Mode Variables */
@media (prefers-color-scheme: dark) {
    :root {
        --background: #121212;
        --surface: #1E1E1E;
        --text-primary: #FAFAFA;
        --text-secondary: #BDBDBD;
        --border: #424242;
        --shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 8px 24px 0 rgba(0, 0, 0, 0.3);
    }
}

/* Base HTML & Body */
html {
    font-size: 16px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
}

/* Header Styles */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: var(--text-light);
    padding: 1.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-lg);
}

.header-content {
    flex: 1;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: var(--text-light);
}

.header-description {
    font-size: 0.875rem;
    opacity: 0.9;
    margin: 0;
    font-weight: 400;
    line-height: 1.4;
}

.language-selector select {
    background-color: rgba(255, 255, 255, 0.9);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: var(--border-radius);
    padding: 0.625rem 0.875rem;
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    backdrop-filter: blur(8px);
}

.language-selector select:focus {
    outline: none;
    border-color: var(--accent-color);
    background-color: rgba(255, 255, 255, 1);
    box-shadow: 0 0 0 3px rgba(255, 171, 64, 0.2);
}

/* Main Container */
.main-container {
    flex: 1;
    padding: 1rem;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

/* Tab Navigation */
.tab-nav {
    display: flex;
    background-color: var(--surface);
    border-radius: var(--border-radius-lg);
    border: 2px solid var(--primary-color);
    overflow: hidden;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

.tab-btn {
    flex: 1;
    padding: 1rem 1.25rem;
    background: none;
    border: none;
    color: var(--primary-color);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.tab-btn.active {
    color: var(--text-light);
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    font-weight: 700;
}

.tab-btn:hover:not(.active) {
    background-color: rgba(0, 137, 123, 0.1);
    color: var(--primary-color);
}

/* Tab Content */
.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

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

/* Input Section */
.input-section {
    margin-bottom: 1.5rem;
}

.input-section label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.input-section textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    background-color: var(--background);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
    transition: var(--transition);
}

.input-section textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.char-counter {
    text-align: right;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Button Styles */
.button-section {
    text-align: center;
    margin-bottom: 1.5rem;
}

.primary-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.875rem 1.5rem;
    border-radius: var(--border-radius);
    font-weight: 500;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    min-width: 150px;
}

.primary-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.primary-btn:disabled {
    background-color: var(--text-secondary);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.secondary-btn {
    background-color: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 0.75rem 1.25rem;
    border-radius: var(--border-radius);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.secondary-btn:hover {
    background-color: var(--border);
    transform: translateY(-1px);
}

/* QR Output Section */
.qr-output {
    text-align: center;
    background-color: var(--surface);
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
    border: 1px solid var(--border);
}

#qrCanvas {
    max-width: 100%;
    height: auto;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.download-section {
    margin-top: 1rem;
}

/* Camera Section */
.camera-section {
    text-align: center;
}

.camera-container {
    position: relative;
    background-color: var(--surface);
    border-radius: var(--border-radius-lg);
    overflow: hidden;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    aspect-ratio: 4/3;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

#videoElement {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.scan-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.scan-frame {
    width: 200px;
    height: 200px;
    border: 3px solid var(--accent-color);
    border-radius: var(--border-radius);
    position: relative;
    opacity: 0.9;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { 
        opacity: 0.9;
        transform: scale(1);
    }
    50% { 
        opacity: 1;
        transform: scale(1.02);
    }
}

.scan-frame::before,
.scan-frame::after {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    border: 4px solid var(--accent-color);
}

.scan-frame::before {
    top: -4px;
    left: -4px;
    border-right: none;
    border-bottom: none;
}

.scan-frame::after {
    bottom: -4px;
    right: -4px;
    border-left: none;
    border-top: none;
}

.camera-controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 1.5rem;
}

/* Result Section */
.result-section {
    background-color: var(--surface);
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
    border: 1px solid var(--border);
}

.result-section label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.result-output {
    position: relative;
}

.result-output textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    background-color: var(--background);
    color: var(--text-primary);
    font-family: inherit;
    resize: vertical;
}

.copy-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.5rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.875rem;
    transition: var(--transition);
}

.copy-btn:hover {
    background-color: var(--primary-hover);
}

/* Status Message */
.status-message {
    text-align: center;
    padding: 1rem;
    background-color: var(--surface);
    border-radius: var(--border-radius);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--text-primary);
    color: var(--background);
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 1000;
    max-width: calc(100% - 2rem);
    text-align: center;
}

.toast.show {
    opacity: 1;
}

.toast.success {
    background: linear-gradient(135deg, var(--accent-color) 0%, var(--accent-hover) 100%);
    color: var(--text-primary);
}

.toast.error {
    background-color: var(--error);
}

.toast.warning {
    background-color: var(--warning);
    color: var(--text-primary);
}

/* Loading Spinner */
.loading-spinner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive Design */
@media (max-width: 480px) {
    .main-container {
        padding: 0.75rem;
    }
    
    .header {
        padding: 1rem 0.75rem;
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .header-content {
        text-align: center;
    }
    
    .header h1 {
        font-size: 1.25rem;
    }
    
    .header-description {
        font-size: 0.8rem;
    }
    
    .camera-controls {
        flex-direction: column;
        align-items: center;
    }
    
    .camera-controls button {
        width: 100%;
        max-width: 200px;
    }
    
    .scan-frame {
        width: 150px;
        height: 150px;
    }
    
    .primary-btn {
        min-width: 140px;
        padding: 0.875rem 1.25rem;
    }
}

@media (min-width: 768px) {
    .main-container {
        padding: 2rem;
    }
    
    .header {
        padding: 2rem;
    }
    
    .header h1 {
        font-size: 1.75rem;
    }
    
    .header-description {
        font-size: 1rem;
    }
    
    .tab-nav {
        max-width: 400px;
        margin-left: auto;
        margin-right: auto;
    }
}

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

/* Focus Visible for Better Accessibility */
button:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    :root {
        --border: #000000;
        --text-secondary: var(--text-primary);
    }
}

/* Footer Styles */
.footer {
    margin-top: auto;
    background-color: var(--surface);
    border-top: 1px solid var(--border);
    padding: 2rem 1rem 1rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.6;
}

.footer-content {
    max-width: 800px;
    margin: 0 auto;
}

.footer-copyright {
    text-align: center;
    margin-bottom: 1.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.footer-section {
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.footer-section summary {
    background-color: var(--background);
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.footer-section summary:hover {
    background-color: var(--border);
}

.footer-section summary::marker {
    display: none;
}

.footer-section summary::after {
    content: '+';
    font-size: 1.2rem;
    font-weight: bold;
    transition: var(--transition);
}

.footer-section[open] summary::after {
    content: '−';
}

.footer-details {
    padding: 1rem;
    background-color: var(--surface);
}

.footer-details h4 {
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    margin-top: 1rem;
}

.footer-details h4:first-child {
    margin-top: 0;
}

.footer-details p {
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

.footer-details p:last-child {
    margin-bottom: 0;
}

.footer-details a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.footer-details a:hover {
    text-decoration: underline;
}

@media (max-width: 480px) {
    .footer {
        padding: 1.5rem 0.75rem 1rem;
    }
    
    .footer-details {
        padding: 0.75rem;
    }
    
    .footer-details h4 {
        font-size: 0.85rem;
    }
}

@media (min-width: 768px) {
    .footer {
        padding: 3rem 2rem 2rem;
    }
}

/* Related Sites Section */
.related-sites-section {
    margin-bottom: 2rem;
    padding: 1.5rem 1rem;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--background);
}

.related-sites-section h3 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-size: 1.25rem;
    text-align: center;
}

.related-sites-section p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    text-align: center;
    font-size: 0.9rem;
}

.sites-categories {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    max-width: 1200px;
    margin: 0 auto;
}

.category {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1rem;
    box-shadow: var(--shadow);
}

.category h4 {
    color: var(--primary-color);
    margin-bottom: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.sites-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sites-list li {
    margin-bottom: 0.5rem;
}

.sites-list a {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s ease;
    display: block;
    padding: 0.25rem 0;
}

.sites-list a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

.current-site {
    color: var(--success-color);
    font-weight: 500;
    font-size: 0.9rem;
    display: block;
    padding: 0.25rem 0;
}

/* Mobile responsiveness for related sites */
@media (max-width: 768px) {
    .related-sites-section {
        padding: 1rem 0.75rem;
    }
    
    .sites-categories {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .category {
        padding: 0.75rem;
    }
    
    .related-sites-section h3 {
        font-size: 1.1rem;
    }
}

@media (max-width: 480px) {
    .related-sites-section {
        padding: 0.75rem 0.5rem;
    }
    
    .sites-categories {
        gap: 0.75rem;
    }
    
    .category {
        padding: 0.5rem;
    }
    
    .category h4 {
        font-size: 0.9rem;
    }
    
    .sites-list a,
    .current-site {
        font-size: 0.85rem;
    }
}