/**
 * Dys-Play - Styles CSS Modernes avec Variables Personnalisées
 * Conforme WCAG 2.1 AA - Ratio de contraste 7:1 minimum
 * Performance: Transitions < 100ms pour feedback immédiat
 */

/* ============================================
   1. VARIABLES CSS (Custom Properties)
   ============================================ */

:root {
    /* Couleurs - Thème Clair (défaut) */
    --color-bg: #ffffff;
    --color-bg-secondary: #f8fafc;
    --color-bg-tertiary: #f1f5f9;
    --color-text: #1e293b;
    --color-text-secondary: #475569;
    --color-text-muted: #64748b;
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-primary-light: #dbeafe;
    --color-accent: #7c3aed;
    --color-success: #16a34a;
    --color-warning: #ea580c;
    --color-danger: #dc2626;
    --color-border: #e2e8f0;
    --color-focus: #2563eb;
    
    /* Typographie */
    --font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-size: 20px;
    --line-height: 1.7;
    --letter-spacing: 0.12em;
    --word-spacing: 0.25em;
    
    /* Focus Mask */
    --mask-opacity: 0.7;
    --mask-height: 60px;
    --mask-top: 0px;
    --mask-bottom: 60px;
    
    /* Transitions - Rapides pour UX */
    --transition-fast: 100ms ease-out;
    --transition-normal: 200ms ease;
    --transition-slow: 300ms ease;
    
    /* Espacements */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    
    /* Bordures */
    --radius-sm: 0.5rem;
    --radius-md: 1rem;
    --radius-lg: 1.5rem;
    --radius-xl: 2rem;
    
    /* Ombres */
    --shadow-sm: 0 1px 2px 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);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    
    /* Cibles tactiles - Minimum 44x44px */
    --touch-target: 44px;
}

/* Thème Crème */
[data-theme="cream"] {
    --color-bg: #fdf6e3;
    --color-bg-secondary: #f5ecc8;
    --color-bg-tertiary: #f0e4b8;
    --color-text: #5d4e37;
    --color-text-secondary: #6b5a45;
    --color-text-muted: #8a7a60;
    --color-primary: #b8860b;
    --color-primary-hover: #9a7209;
    --color-primary-light: #f5e6c8;
    --color-border: #e6d9b8;
}

/* Thème Sépia */
[data-theme="sepia"] {
    --color-bg: #f4ecd8;
    --color-bg-secondary: #e8dfc3;
    --color-bg-tertiary: #ddd2a5;
    --color-text: #5c4a32;
    --color-text-secondary: #6d5a3e;
    --color-text-muted: #8a7554;
    --color-primary: #a0522d;
    --color-primary-hover: #8b4513;
    --color-primary-light: #e8d5c4;
    --color-border: #d4c4a8;
}

/* Thème Sombre */
[data-theme="dark"] {
    --color-bg: #0f172a;
    --color-bg-secondary: #1e293b;
    --color-bg-tertiary: #334155;
    --color-text: #f1f5f9;
    --color-text-secondary: #cbd5e1;
    --color-text-muted: #94a3b8;
    --color-primary: #3b82f6;
    --color-primary-hover: #60a5fa;
    --color-primary-light: #1e3a5f;
    --color-border: #334155;
}

/* ============================================
   2. RESET ET BASE
   ============================================ */

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

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

body {
    font-family: var(--font-family);
    font-size: var(--font-size);
    line-height: var(--line-height);
    letter-spacing: var(--letter-spacing);
    word-spacing: var(--word-spacing);
    background-color: var(--color-bg-secondary);
    color: var(--color-text);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* ============================================
   3. ACCESSIBILITÉ - WCAG 2.1 AA
   ============================================ */

/* Skip Links - Cachés mais accessibles au focus */
.skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    padding: var(--space-md);
    background: var(--color-primary);
    color: white;
    z-index: 9999;
    text-decoration: none;
    font-weight: bold;
    border-radius: 0 0 var(--radius-md) 0;
}

.skip-link:focus {
    top: 0;
    outline: 4px solid var(--color-focus);
    outline-offset: 4px;
}

/* sr-only - Pour les lecteurs d'écran */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus visible - Contraste élevé */
:focus-visible {
    outline: 4px solid var(--color-focus);
    outline-offset: 4px;
}

:focus:not(:focus-visible) {
    outline: none;
}

/* Cibles tactiles - Minimum 44x44px */
button, 
input[type="range"],
input[type="checkbox"],
input[type="radio"],
select,
a {
    min-height: var(--touch-target);
    min-width: var(--touch-target);
}

/* ============================================
   4. HEADER
   ============================================ */

.header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md) var(--space-lg);
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.app-title {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--color-text);
}

.title-sub {
    color: var(--color-primary);
}

.connection-status {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
}

.connection-status.online {
    color: var(--color-success);
    background: rgba(22, 163, 74, 0.1);
}

.connection-status.offline {
    color: var(--color-warning);
    background: rgba(234, 88, 12, 0.1);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 4px;
    background: var(--color-danger);
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   5. ICÔNES ET BOUTONS
   ============================================ */

.icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.icon-large {
    width: 32px;
    height: 32px;
}

.icon-huge {
    width: 64px;
    height: 64px;
}

button {
    cursor: pointer;
    border: none;
    background: none;
    font-family: inherit;
    font-size: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    transition: all var(--transition-fast);
}

.btn {
    padding: var(--space-sm) var(--space-lg);
    border-radius: var(--radius-md);
    font-weight: 600;
    text-decoration: none;
    min-height: var(--touch-target);
}

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

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

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

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

.btn-danger {
    background: rgba(220, 38, 38, 0.1);
    color: var(--color-danger);
    border: 1px solid var(--color-danger);
}

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

.btn-play {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--color-primary);
    color: white;
    box-shadow: var(--shadow-lg);
    transition: all var(--transition-fast);
}

.btn-play:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: var(--shadow-xl);
}

.btn-play:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-toggle {
    width: 100%;
    padding: var(--space-md);
    background: var(--color-bg-tertiary);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    font-weight: 600;
}

.btn-toggle[aria-pressed="true"] {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.btn-close {
    width: var(--touch-target);
    height: var(--touch-target);
    border-radius: 50%;
    background: var(--color-bg-tertiary);
}

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

/* ============================================
   6. DASHBOARD ET CARTES
   ============================================ */

.dashboard {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--space-md);
    padding: var(--space-md);
    max-width: 1400px;
    margin: 0 auto;
}

.card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-fast);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-title {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    margin-bottom: var(--space-md);
}

.card-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.voice-controls {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.rate-control {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.rate-control label {
    font-size: 0.75rem;
    font-weight: bold;
    color: var(--color-text-muted);
}

.opacity-control {
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--color-border);
}

.opacity-control label {
    display: block;
    font-size: 0.75rem;
    font-weight: bold;
    color: var(--color-text-muted);
    margin-bottom: var(--space-xs);
}

/* ============================================
   7. ZONE DE LECTURE (READER AREA)
   ============================================ */

.reader-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 var(--space-lg) var(--space-xl);
}

.reader-area {
    position: relative;
    background: var(--color-bg);
    border-radius: var(--radius-xl);
    padding: var(--space-2xl);
    min-height: 50vh;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

/* Focus Mask - CSS Mask pour fenêtre de lecture */
.focus-mask {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    background: #000000;
    mask-image: linear-gradient(
        to bottom,
        black 0%,
        black var(--mask-top),
        transparent var(--mask-top),
        transparent var(--mask-bottom),
        black var(--mask-bottom),
        black 100%
    );
    -webkit-mask-image: linear-gradient(
        to bottom,
        black 0%,
        black var(--mask-top),
        transparent var(--mask-top),
        transparent var(--mask-bottom),
        black var(--mask-bottom),
        black 100%
    );
    opacity: var(--mask-opacity);
    transition: opacity var(--transition-fast);
}

.ruler-guide {
    position: absolute;
    left: 0;
    width: 100%;
    height: var(--mask-height);
    top: var(--mask-top);
    border-top: 3px solid var(--color-primary);
    border-bottom: 3px solid var(--color-primary);
    background: rgba(37, 99, 235, 0.05);
    pointer-events: none;
    z-index: 11;
    transition: top var(--transition-fast);
}

.text-content {
    font-size: var(--font-size);
    line-height: var(--line-height);
    letter-spacing: var(--letter-spacing);
    word-spacing: var(--word-spacing);
}

/* Mode Zèbre */
.zebra-mode p:nth-child(even) {
    background-color: rgba(0, 0, 0, 0.04);
    padding: var(--space-sm) 0;
    border-radius: var(--radius-sm);
}

/* Coloration syllabique */
.syllable-s1 {
    color: #d946ef;
    font-weight: 800;
}

.syllable-s2 {
    color: #0ea5e9;
    font-weight: 800;
}

/* Highlight mot lu par TTS */
.speaking-word {
    background-color: #fde047;
    color: #000;
    border-radius: 4px;
    padding: 0 2px;
    box-shadow: 0 0 0 2px #fde047;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 40vh;
    color: var(--color-text-muted);
    text-align: center;
}

.empty-state p {
    margin-top: var(--space-lg);
    font-weight: 500;
}

/* ============================================
   8. INPUT SECTION
   ============================================ */

.input-section {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 var(--space-lg) var(--space-xl);
}

#text-input {
    width: 100%;
    padding: var(--space-lg);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-bg);
    color: var(--color-text);
    font-family: inherit;
    font-size: var(--font-size);
    line-height: var(--line-height);
    resize: vertical;
    transition: border-color var(--transition-fast);
}

#text-input:focus {
    border-color: var(--color-primary);
    outline: none;
}

/* ============================================
   9. DRAWERS (Panneaux escamotables)
   ============================================ */

.drawer {
    position: fixed;
    top: 0;
    height: 100vh;
    width: 100%;
    max-width: 400px;
    background: var(--color-bg);
    box-shadow: var(--shadow-xl);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
    overflow-y: auto;
}

@media (max-width: 480px) {
    .drawer {
        max-width: 100%;
    }
    
    .dashboard {
        grid-template-columns: 1fr;
        padding: var(--space-sm);
        gap: var(--space-sm);
    }
    
    .card {
        padding: var(--space-md);
    }
    
    .reader-area {
        padding: var(--space-lg);
        border-radius: var(--radius-md);
    }
    
    .input-section {
        padding: 0 var(--space-sm) var(--space-lg);
    }
    
    .header {
        padding: var(--space-sm) var(--space-md);
    }
    
    .app-title {
        font-size: 1rem;
    }
}

.drawer-left {
    left: 0;
}

.drawer-right {
    right: 0;
}

.drawer.open {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    background: var(--color-bg);
    z-index: 10;
}

.drawer-header h2 {
    font-size: 1.25rem;
    font-weight: 800;
}

.drawer-content {
    padding: var(--space-lg);
}

/* Navigation Drawer */
.nav-list {
    list-style: none;
}

.nav-list li {
    margin-bottom: var(--space-xs);
}

.nav-list a {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    color: var(--color-text);
    text-decoration: none;
    border-radius: var(--radius-md);
    font-weight: 500;
    min-height: var(--touch-target);
    transition: background var(--transition-fast);
}

.nav-list a:hover,
.nav-list a:focus {
    background: var(--color-bg-tertiary);
}

/* Library */
.library-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.library-item {
    display: flex;
    flex-direction: column;
    padding: var(--space-md);
    background: var(--color-bg-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    min-height: var(--touch-target);
    transition: background var(--transition-fast);
}

.library-item:hover,
.library-item:focus {
    background: var(--color-bg-tertiary);
}

.library-item-title {
    font-weight: 600;
    margin-bottom: var(--space-xs);
}

.library-item-date {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.library-empty {
    text-align: center;
    padding: var(--space-xl);
    color: var(--color-text-muted);
}

/* Settings */
.settings-section {
    margin-bottom: var(--space-xl);
    padding-bottom: var(--space-xl);
    border-bottom: 1px solid var(--color-border);
}

.settings-section:last-child {
    border-bottom: none;
}

.settings-section h3 {
    font-size: 0.875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    margin-bottom: var(--space-md);
}

.settings-section select {
    width: 100%;
    padding: var(--space-md);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 1rem;
    font-weight: 500;
}

.theme-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
}

.theme-btn {
    flex-direction: column;
    padding: var(--space-md);
    background: var(--color-bg-secondary);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
}

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

.theme-preview {
    width: 100%;
    height: 40px;
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-xs);
}

.theme-preview.light { background: #ffffff; border: 1px solid #e2e8f0; }
.theme-preview.cream { background: #fdf6e3; border: 1px solid #e6d9b8; }
.theme-preview.sepia { background: #f4ecd8; border: 1px solid #d4c4a8; }
.theme-preview.dark { background: #0f172a; border: 1px solid #334155; }

.setting-row {
    margin-bottom: var(--space-md);
}

.setting-row label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: var(--space-sm);
}

.setting-row input[type="range"] {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: var(--color-bg-tertiary);
    appearance: none;
    cursor: pointer;
}

.setting-row input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--color-primary);
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.setting-row input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md);
    background: var(--color-bg-secondary);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-sm);
}

.toggle-row input[type="checkbox"] {
    width: 48px;
    height: 28px;
    appearance: none;
    background: var(--color-border);
    border-radius: 14px;
    position: relative;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.toggle-row input[type="checkbox"]::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 24px;
    height: 24px;
    background: white;
    border-radius: 50%;
    transition: transform var(--transition-fast);
}

.toggle-row input[type="checkbox"]:checked {
    background: var(--color-primary);
}

.toggle-row input[type="checkbox"]:checked::before {
    transform: translateX(20px);
}

/* ============================================
   10. OVERLAY
   ============================================ */

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.overlay.visible {
    opacity: 1;
}

/* ============================================
   11. LOADER
   ============================================ */

.loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
    gap: var(--space-md);
}

.loader.hidden {
    display: none;
}

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

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

/* ============================================
   12. TOAST NOTIFICATIONS
   ============================================ */

.toast-container {
    position: fixed;
    bottom: var(--space-xl);
    right: var(--space-xl);
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.toast {
    padding: var(--space-md) var(--space-lg);
    background: var(--color-text);
    color: var(--color-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
}

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

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

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ============================================
   13. INPUTS RANGE STYLisés
   ============================================ */

input[type="range"] {
    appearance: none;
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: var(--color-bg-tertiary);
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--color-primary);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: var(--shadow-sm);
}

input[type="range"]:focus::-webkit-slider-thumb {
    box-shadow: 0 0 0 4px var(--color-primary-light);
}

/* ============================================
   14. RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .dashboard {
        grid-template-columns: 1fr;
        padding: var(--space-md);
    }
    
    .header {
        padding: var(--space-sm) var(--space-md);
    }
    
    .reader-area {
        padding: var(--space-lg);
        border-radius: var(--radius-lg);
    }
    
    .card-actions {
        flex-direction: row;
    }
    
    .drawer {
        max-width: 100%;
    }
    
    .toast-container {
        bottom: var(--space-md);
        right: var(--space-md);
        left: var(--space-md);
    }
}

@media (max-width: 480px) {
    :root {
        --font-size: 18px;
    }
    
    .btn-play {
        width: 56px;
        height: 56px;
    }
    
    .icon-large {
        width: 28px;
        height: 28px;
    }
}

/* ============================================
   15. PRINT STYLES
   ============================================ */

@media print {
    .header,
    .dashboard,
    .input-section,
    .drawer,
    .overlay,
    .loader {
        display: none !important;
    }
    
    .reader-container {
        padding: 0;
        max-width: 100%;
    }
    
    .reader-area {
        box-shadow: none;
        border-radius: 0;
    }
}

/* ============================================
   16. HIGH CONTRAST MODE
   ============================================ */

@media (prefers-contrast: high) {
    :root {
        --color-border: #000000;
        --shadow-sm: none;
        --shadow-md: none;
        --shadow-lg: none;
    }
    
    .card,
    .reader-area {
        border: 2px solid var(--color-text);
    }
    
    .btn-play {
        border: 2px solid white;
    }
}
