/**
 * Farbsehen & Kontrast Simulator
 * Main Stylesheet
 *
 * Mobile-first responsive design
 * WCAG 2.1 AA compliant
 *
 * Breakpoints:
 * - sm: 640px
 * - md: 768px
 * - lg: 1024px
 * - xl: 1280px
 */

/* ========================================
   CSS Custom Properties (Design Tokens)
   ======================================== */

:root {
    /* Color Palette - Light Mode */
    --color-primary: #0066cc;
    --color-primary-hover: #0052a3;
    --color-primary-active: #004080;
    --color-secondary: #6b7280;
    --color-accent: #10b981;
    --color-error: #dc2626;
    --color-warning: #f59e0b;
    --color-success: #16a34a;
    --color-info: #0ea5e9;

    /* Neutral Colors - Light Mode */
    --color-bg: #ffffff;
    --color-bg-secondary: #f9fafb;
    --color-bg-tertiary: #f3f4f6;
    --color-surface: #ffffff;
    --color-surface-elevated: #ffffff;
    --color-border: #e5e7eb;
    --color-border-strong: #d1d5db;

    /* Text Colors - Light Mode */
    --color-text: #111827;
    --color-text-secondary: #4b5563;
    --color-text-muted: #6b7280;
    --color-text-inverse: #ffffff;

    /* Typography */
    --font-family-base: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-family-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;

    /* Font Sizes (fluid typography) */
    --font-size-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
    --font-size-sm: clamp(0.875rem, 0.8rem + 0.375vw, 1rem);
    --font-size-base: clamp(1rem, 0.9rem + 0.5vw, 1.125rem);
    --font-size-lg: clamp(1.125rem, 1rem + 0.625vw, 1.25rem);
    --font-size-xl: clamp(1.25rem, 1.1rem + 0.75vw, 1.5rem);
    --font-size-2xl: clamp(1.5rem, 1.25rem + 1.25vw, 2rem);
    --font-size-3xl: clamp(1.875rem, 1.5rem + 1.875vw, 2.5rem);
    --font-size-4xl: clamp(2.25rem, 1.75rem + 2.5vw, 3rem);

    /* Font Weights */
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;

    /* Line Heights */
    --line-height-tight: 1.25;
    --line-height-normal: 1.5;
    --line-height-relaxed: 1.75;

    /* Spacing Scale */
    --space-1: 0.25rem;   /* 4px */
    --space-2: 0.5rem;    /* 8px */
    --space-3: 0.75rem;   /* 12px */
    --space-4: 1rem;      /* 16px */
    --space-5: 1.25rem;   /* 20px */
    --space-6: 1.5rem;    /* 24px */
    --space-8: 2rem;      /* 32px */
    --space-10: 2.5rem;   /* 40px */
    --space-12: 3rem;     /* 48px */
    --space-16: 4rem;     /* 64px */
    --space-20: 5rem;     /* 80px */

    /* Border Radius */
    --radius-sm: 0.25rem;
    --radius-md: 0.375rem;
    --radius-lg: 0.5rem;
    --radius-xl: 0.75rem;
    --radius-2xl: 1rem;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;

    /* Focus Ring */
    --focus-ring-width: 3px;
    --focus-ring-color: var(--color-primary);
    --focus-ring-offset: 2px;

    /* Container */
    --container-max-width: 1280px;
    --container-padding: var(--space-4);

    /* Z-Index Scale */
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-modal: 300;
    --z-tooltip: 400;
    --z-skip-link: 500;
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
    :root {
        --color-primary: #3b82f6;
        --color-primary-hover: #60a5fa;
        --color-primary-active: #93c5fd;
        --color-accent: #34d399;
        --color-error: #f87171;
        --color-warning: #fbbf24;
        --color-success: #4ade80;
        --color-info: #38bdf8;

        --color-bg: #0f172a;
        --color-bg-secondary: #1e293b;
        --color-bg-tertiary: #334155;
        --color-surface: #1e293b;
        --color-surface-elevated: #334155;
        --color-border: #334155;
        --color-border-strong: #475569;

        --color-text: #f8fafc;
        --color-text-secondary: #cbd5e1;
        --color-text-muted: #94a3b8;
        --color-text-inverse: #0f172a;

        --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
        --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.3);
        --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.3);
    }
}

/* Manual theme override classes */
[data-theme="light"] {
    --color-primary: #0066cc;
    --color-primary-hover: #0052a3;
    --color-primary-active: #004080;
    --color-accent: #10b981;
    --color-error: #dc2626;
    --color-warning: #f59e0b;
    --color-success: #16a34a;
    --color-info: #0ea5e9;

    --color-bg: #ffffff;
    --color-bg-secondary: #f9fafb;
    --color-bg-tertiary: #f3f4f6;
    --color-surface: #ffffff;
    --color-surface-elevated: #ffffff;
    --color-border: #e5e7eb;
    --color-border-strong: #d1d5db;

    --color-text: #111827;
    --color-text-secondary: #4b5563;
    --color-text-muted: #6b7280;
    --color-text-inverse: #ffffff;
}

[data-theme="dark"] {
    --color-primary: #3b82f6;
    --color-primary-hover: #60a5fa;
    --color-primary-active: #93c5fd;
    --color-accent: #34d399;
    --color-error: #f87171;
    --color-warning: #fbbf24;
    --color-success: #4ade80;
    --color-info: #38bdf8;

    --color-bg: #0f172a;
    --color-bg-secondary: #1e293b;
    --color-bg-tertiary: #334155;
    --color-surface: #1e293b;
    --color-surface-elevated: #334155;
    --color-border: #334155;
    --color-border-strong: #475569;

    --color-text: #f8fafc;
    --color-text-secondary: #cbd5e1;
    --color-text-muted: #94a3b8;
    --color-text-inverse: #0f172a;
}

/* ========================================
   CSS Reset & Base Styles
   ======================================== */

*,
*::before,
*::after {
    box-sizing: border-box;
}

* {
    margin: 0;
    padding: 0;
}

html {
    font-size: 100%;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

body {
    font-family: var(--font-family-base);
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
    color: var(--color-text);
    background-color: var(--color-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1;
}

img,
picture,
video,
canvas,
svg {
    display: block;
    max-width: 100%;
    height: auto;
}

input,
button,
textarea,
select {
    font: inherit;
    color: inherit;
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
    overflow-wrap: break-word;
}

/* ========================================
   Skip Links (Accessibility)
   ======================================== */

.skip-link {
    position: absolute;
    top: -100%;
    left: var(--space-4);
    z-index: var(--z-skip-link);
    padding: var(--space-3) var(--space-4);
    background-color: var(--color-primary);
    color: var(--color-text-inverse);
    font-weight: var(--font-weight-semibold);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: top var(--transition-fast);
}

.skip-link:focus {
    top: var(--space-4);
    outline: var(--focus-ring-width) solid var(--color-text-inverse);
    outline-offset: var(--focus-ring-offset);
}

/* ========================================
   Focus Styles (Accessibility)
   ======================================== */

:focus {
    outline: none;
}

:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
    border-radius: var(--radius-sm);
}

/* Enhanced focus for interactive elements */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
}

/* ========================================
   Typography
   ======================================== */

h1, h2, h3, h4, h5, h6 {
    font-weight: var(--font-weight-bold);
    line-height: var(--line-height-tight);
    color: var(--color-text);
}

h1 {
    font-size: var(--font-size-4xl);
    letter-spacing: -0.025em;
}

h2 {
    font-size: var(--font-size-3xl);
    letter-spacing: -0.02em;
}

h3 {
    font-size: var(--font-size-2xl);
}

h4 {
    font-size: var(--font-size-xl);
}

h5 {
    font-size: var(--font-size-lg);
}

h6 {
    font-size: var(--font-size-base);
}

p {
    margin-bottom: var(--space-4);
}

p:last-child {
    margin-bottom: 0;
}

a {
    color: var(--color-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--color-primary-hover);
}

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

/* ========================================
   Layout
   ======================================== */

.container {
    width: 100%;
    max-width: var(--container-max-width);
    margin-inline: auto;
    padding-inline: var(--container-padding);
}

@media (min-width: 768px) {
    .container {
        --container-padding: var(--space-6);
    }
}

@media (min-width: 1024px) {
    .container {
        --container-padding: var(--space-8);
    }
}

.section {
    padding-block: var(--space-10);
}

@media (min-width: 768px) {
    .section {
        padding-block: var(--space-16);
    }
}

.section-description {
    color: var(--color-text-secondary);
    font-size: var(--font-size-lg);
    max-width: 65ch;
    margin-bottom: var(--space-8);
}

/* ========================================
   Header
   ======================================== */

.site-header {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    background-color: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    padding-block: var(--space-4);
}

.site-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
}

.logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--color-text);
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-xl);
}

.logo:hover {
    color: var(--color-primary);
}

/* Navigation */
.main-nav {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.nav-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: var(--radius-md);
}

@media (min-width: 768px) {
    .nav-toggle {
        display: none;
    }
}

.nav-toggle-icon {
    display: block;
    position: relative;
    width: 24px;
    height: 2px;
    background-color: var(--color-text);
    transition: background-color var(--transition-fast);
}

.nav-toggle-icon::before,
.nav-toggle-icon::after {
    content: '';
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    background-color: var(--color-text);
    transition: transform var(--transition-fast);
}

.nav-toggle-icon::before {
    top: -8px;
}

.nav-toggle-icon::after {
    top: 8px;
}

.nav-menu {
    display: none;
    list-style: none;
    gap: var(--space-2);
}

@media (min-width: 768px) {
    .nav-menu {
        display: flex;
    }
}

.nav-menu.is-open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-4);
    box-shadow: var(--shadow-lg);
}

.nav-menu a {
    display: block;
    padding: var(--space-2) var(--space-4);
    color: var(--color-text);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

.nav-menu a:hover {
    background-color: var(--color-bg-secondary);
    color: var(--color-primary);
}

.nav-menu a[aria-current="page"] {
    background-color: var(--color-primary);
    color: var(--color-text-inverse);
}

/* Theme Toggle */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--color-text);
    transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.theme-toggle:hover {
    background-color: var(--color-bg-secondary);
    border-color: var(--color-border-strong);
}

.theme-icon--dark {
    display: none;
}

@media (prefers-color-scheme: dark) {
    .theme-icon--light {
        display: none;
    }

    .theme-icon--dark {
        display: block;
    }
}

[data-theme="dark"] .theme-icon--light {
    display: none;
}

[data-theme="dark"] .theme-icon--dark {
    display: block;
}

[data-theme="light"] .theme-icon--light {
    display: block;
}

[data-theme="light"] .theme-icon--dark {
    display: none;
}

/* ========================================
   Hero Section
   ======================================== */

.hero {
    background-color: var(--color-bg-secondary);
    padding-block: var(--space-12);
    text-align: center;
}

@media (min-width: 768px) {
    .hero {
        padding-block: var(--space-20);
    }
}

.hero h1 {
    margin-bottom: var(--space-4);
}

.hero-subtitle {
    font-size: var(--font-size-lg);
    color: var(--color-text-secondary);
    max-width: 60ch;
    margin-inline: auto;
}

@media (min-width: 768px) {
    .hero-subtitle {
        font-size: var(--font-size-xl);
    }
}

/* ========================================
   Content Sections
   ======================================== */

.color-input-section {
    background-color: var(--color-bg);
}

.simulation-section {
    background-color: var(--color-bg-secondary);
}

.results-section {
    background-color: var(--color-bg);
}

.suggestions-section {
    background-color: var(--color-bg-secondary);
}

.export-section {
    background-color: var(--color-bg);
}

/* Results Cards */
.results-card {
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    margin-bottom: var(--space-6);
    box-shadow: var(--shadow-sm);
}

.results-card:last-child {
    margin-bottom: 0;
}

.results-card h3 {
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--color-border);
}

/* Grid Layouts */
.simulation-grid {
    display: grid;
    gap: var(--space-6);
}

@media (min-width: 640px) {
    .simulation-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .simulation-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ========================================
   Footer
   ======================================== */

.site-footer {
    background-color: var(--color-bg-secondary);
    border-top: 1px solid var(--color-border);
    padding-block: var(--space-10);
    margin-top: auto;
}

.footer-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
    margin-bottom: var(--space-6);
}

@media (min-width: 768px) {
    .footer-content {
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-start;
    }
}

.footer-info p {
    color: var(--color-text-secondary);
}

.footer-tagline {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.footer-nav ul {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    list-style: none;
}

.footer-nav a {
    color: var(--color-text-secondary);
    text-decoration: none;
}

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

.footer-accessibility {
    padding-top: var(--space-6);
    border-top: 1px solid var(--color-border);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.footer-accessibility strong {
    color: var(--color-text-secondary);
}

/* ========================================
   No-JS Warning
   ======================================== */

.noscript-warning {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--color-bg);
    text-align: center;
    padding: var(--space-8);
}

.noscript-warning h2 {
    margin-bottom: var(--space-4);
    color: var(--color-warning);
}

/* ========================================
   Utility Classes
   ======================================== */

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.text-center {
    text-align: center;
}

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

/* Status Indicators */
.status-pass {
    color: var(--color-success);
}

.status-fail {
    color: var(--color-error);
}

.status-warning {
    color: var(--color-warning);
}

/* ========================================
   Button Base Styles
   ======================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    font-weight: var(--font-weight-medium);
    text-decoration: none;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: background-color var(--transition-fast),
                color var(--transition-fast),
                box-shadow var(--transition-fast);
    min-height: 44px; /* Touch target size */
}

.btn--primary {
    background-color: var(--color-primary);
    color: var(--color-text-inverse);
}

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

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

.btn--secondary {
    background-color: transparent;
    color: var(--color-text);
    border: 1px solid var(--color-border-strong);
}

.btn--secondary:hover {
    background-color: var(--color-bg-secondary);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

/* ========================================
   Form Elements Base
   ======================================== */

.form-group {
    margin-bottom: var(--space-4);
}

.form-label {
    display: block;
    font-weight: var(--font-weight-medium);
    margin-bottom: var(--space-2);
    color: var(--color-text);
}

.form-input {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background-color: var(--color-bg);
    color: var(--color-text);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    min-height: 44px; /* Touch target size */
}

.form-input:hover {
    border-color: var(--color-border-strong);
}

.form-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.15);
}

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

/* Color Input Specific */
input[type="color"] {
    width: 100%;
    height: 60px;
    padding: var(--space-1);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-lg);
    cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: var(--radius-md);
}

/* ========================================
   Loading States
   ======================================== */

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-8);
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ========================================
   Web Component Placeholder Styles
   ======================================== */

color-input-panel,
cvd-simulation-panel,
wcag-results,
apca-results,
delta-e-results,
color-suggestions,
export-panel {
    display: block;
}

/* Placeholder content before components load */
color-input-panel:not(:defined),
cvd-simulation-panel:not(:defined),
wcag-results:not(:defined),
apca-results:not(:defined),
delta-e-results:not(:defined),
color-suggestions:not(:defined),
export-panel:not(:defined) {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    background-color: var(--color-bg-tertiary);
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-lg);
    color: var(--color-text-muted);
}

color-input-panel:not(:defined)::before {
    content: 'Farbeingabe lädt...';
}

cvd-simulation-panel:not(:defined)::before {
    content: 'Simulation lädt...';
}

wcag-results:not(:defined)::before,
apca-results:not(:defined)::before,
delta-e-results:not(:defined)::before {
    content: 'Ergebnisse laden...';
}

color-suggestions:not(:defined)::before {
    content: 'Vorschläge laden...';
}

export-panel:not(:defined)::before {
    content: 'Export lädt...';
}

/* ========================================
   Print Styles
   ======================================== */

@media print {
    .skip-link,
    .theme-toggle,
    .nav-toggle,
    .export-section {
        display: none !important;
    }

    body {
        background: white;
        color: black;
    }

    .site-header {
        position: static;
        border-bottom: 1px solid #000;
    }

    a {
        color: inherit;
        text-decoration: underline;
    }

    .results-card {
        break-inside: avoid;
        border: 1px solid #000;
    }
}
