/* ============================================
   Variables globales
   ============================================ */
:root {
    --primary-color: #4a90e2;
    --secondary-color: #7b68ee;
    --danger-color: #e74c3c;
    --success-color: #2ecc71;
    --bg-dark: #2c3e50;
    --bg-light: #ecf0f1;
    --text-dark: #2c3e50;
    --border-color: #bdc3c7;
}

/* ============================================
   Base
   ============================================ */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--text-dark);
    min-height: 100vh;
}

h1 {
    color: white;
    text-align: center;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

h2 {
    color: var(--text-dark);
    margin-bottom: 15px;
    font-size: 1.3em;
}

/* ============================================
   Contrôles principaux
   ============================================ */
.controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

button {
    padding: 12px 24px;
    font-size: 14px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

button:active:not(:disabled) {
    transform: translateY(0);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#connectBtn {
    background: var(--primary-color);
    color: white;
}

#startSyncBtn {
    background: var(--success-color);
    color: white;
}

#stopSyncBtn {
    background: var(--danger-color);
    color: white;
}

/* ============================================
   Vidéo
   ============================================ */
.video-container {
    background: white;
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

.video-selector {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
    padding: 15px;
    background: rgba(52, 152, 219, 0.1);
    border-radius: 8px;
    border: 2px solid rgba(52, 152, 219, 0.3);
}

.video-selector label {
    font-weight: 600;
    color: var(--text-dark);
    white-space: nowrap;
}

#videoIdInput {
    flex: 1;
    max-width: 300px;
    padding: 10px 15px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    font-family: 'Courier New', monospace;
    transition: border-color 0.3s ease;
}

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

#loadVideoBtn {
    padding: 10px 20px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

#loadVideoBtn:hover {
    background: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

#player {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    display: block;
}

.video-controls {
    margin-top: 15px;
    display: flex;
    gap: 15px;
    align-items: center;
    justify-content: center;
}

#videoTime {
    font-family: 'Courier New', monospace;
    font-size: 16px;
    font-weight: bold;
    color: var(--text-dark);
}

/* ============================================
   Timeline Section
   ============================================ */
.timeline-section {
    background: white;
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

.timeline-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
    align-items: center;
}

.timeline-controls button {
    background: var(--primary-color);
    color: white;
    padding: 8px 16px;
    font-size: 13px;
}

.zoom-controls {
    margin-left: auto;
    display: flex;
    gap: 5px;
}

/* ============================================
   Timeline Ruler & Container
   ============================================ */
.timeline-wrapper {
    position: relative;
    background: #f8f9fa;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.timeline-ruler {
    height: 30px;
    background: linear-gradient(to bottom, #e9ecef, #dee2e6);
    border-bottom: 2px solid var(--border-color);
    position: relative;
    font-size: 11px;
    color: #495057;
}

.timeline-ruler .tick {
    position: absolute;
    bottom: 0;
    width: 1px;
    background: #adb5bd;
}

.timeline-ruler .tick.major {
    height: 15px;
    background: #495057;
}

.timeline-ruler .tick.minor {
    height: 8px;
}

.timeline-ruler .tick-label {
    position: absolute;
    top: 2px;
    transform: translateX(-50%);
    font-weight: 600;
}

.timeline-container {
    position: relative;
    height: 200px;
    max-height: 400px;
    overflow-x: auto;
    overflow-y: auto;
    background: white;
}

/* ============================================
   Playhead (curseur de lecture)
   ============================================ */
.timeline-playhead {
    position: absolute;
    top: 0;
    left: 0;
    width: 2px;
    height: 100%;
    background: #e74c3c;
    z-index: 100;
    pointer-events: none;
    transition: left 0.05s linear;
}

.timeline-playhead::before {
    content: '';
    position: absolute;
    top: -5px;
    left: -5px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 8px solid #e74c3c;
}

/* ============================================
   Timeline Events
   ============================================ */
.timeline-events {
    position: relative;
    height: 100%;
    min-width: 100%;
    min-height: 200px;
}

/* Conteneur pour chaque layer */
.timeline-layer {
    position: absolute;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.timeline-layer:nth-child(even) {
    background: rgba(255, 255, 255, 0.06);
}

.timeline-layer-label {
    position: sticky;
    left: 5px;
    top: 5px;
    display: inline-block;
    padding: 4px 10px;
    background: rgba(52, 152, 219, 0.8);
    color: white;
    font-size: 11px;
    font-weight: bold;
    border-radius: 4px;
    z-index: 50;
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.timeline-event {
    position: absolute;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border: 2px solid rgba(0,0,0,0.2);
    border-radius: 6px;
    cursor: grab;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    overflow: visible;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    user-select: none;
}

.timeline-event:active {
    cursor: grabbing;
}

.timeline-event:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 10;
}

.timeline-event.selected {
    border-color: #f39c12;
    border-width: 3px;
    box-shadow: 0 0 0 3px rgba(243, 156, 18, 0.3);
}

/* Poignées de resize */
.timeline-event-resize-left,
.timeline-event-resize-right {
    position: absolute;
    top: 0;
    width: 8px;
    height: 100%;
    cursor: ew-resize;
    z-index: 5;
    background: rgba(255, 255, 255, 0.2);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.timeline-event-resize-left {
    left: 0;
    border-left: 2px solid rgba(255, 255, 255, 0.6);
}

.timeline-event-resize-right {
    right: 0;
    border-right: 2px solid rgba(255, 255, 255, 0.6);
}

.timeline-event:hover .timeline-event-resize-left,
.timeline-event:hover .timeline-event-resize-right {
    opacity: 1;
}

.timeline-event-content {
    padding: 6px;
    color: white;
    font-size: 11px;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    pointer-events: none;
}

.timeline-event-title {
    font-weight: bold;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.timeline-event-time {
    font-size: 10px;
    opacity: 0.9;
}

.timeline-event-color-bar {
    height: 4px;
    border-radius: 2px;
    margin-top: 4px;
}

/* ============================================
   Modal
   ============================================ */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.6);
    backdrop-filter: blur(5px);
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.close {
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    color: #aaa;
    line-height: 20px;
}

.close:hover {
    color: #000;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-dark);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.3s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group input[type="range"] {
    padding: 0;
}

#intensityValue,
#opacityValue {
    margin-left: 10px;
    font-weight: bold;
    color: var(--primary-color);
}

.form-section {
    margin: 25px 0;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.form-section h3 {
    margin: 0 0 15px 0;
    font-size: 16px;
    color: var(--primary-color);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.form-group small {
    display: block;
    margin-top: 5px;
    font-size: 11px;
    color: #6c757d;
    font-style: italic;
}

.color-picker-container {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 6px;
}

.color-picker-container label {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

.color-picker-container input[type="color"] {
    width: 80px;
    height: 40px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    padding: 2px;
}

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

.color-picker-container input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

.btn-small {
    padding: 8px 15px;
    font-size: 13px;
    background: var(--success-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-small:hover {
    background: #27ae60;
}

.colors-group .color-inputs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.color-inputs > div {
    display: flex;
    flex-direction: column;
}

.color-inputs label {
    font-size: 12px;
    margin-bottom: 4px;
}

.color-inputs input {
    width: 100%;
}

.color-preview {
    grid-column: 1 / -1;
    height: 40px;
    border-radius: 6px;
    border: 2px solid var(--border-color);
    margin-top: 10px;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    margin-top: 25px;
    justify-content: flex-end;
}

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

.btn-secondary {
    background: #95a5a6;
    color: white;
}

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

/* ============================================
   Console
   ============================================ */
.console-section {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

#console {
    background: #1e1e1e;
    color: #00ff00;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    padding: 15px;
    border-radius: 6px;
    height: 150px;
    overflow-y: auto;
    border: 2px solid var(--border-color);
}

#console p {
    margin: 3px 0;
    line-height: 1.4;
}

/* ============================================
   Menu contextuel
   ============================================ */
.context-menu {
    position: fixed;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    min-width: 180px;
    padding: 5px 0;
    font-size: 14px;
}

.context-menu-item {
    padding: 8px 15px;
    cursor: pointer;
    transition: background 0.15s;
    user-select: none;
}

.context-menu-item:hover:not(.disabled) {
    background: var(--primary-color);
    color: white;
}

.context-menu-item.disabled {
    color: #999;
    cursor: not-allowed;
}

.context-menu-time {
    padding: 5px 15px;
    font-size: 12px;
    color: #666;
    border-top: 1px solid var(--border-color);
    margin-top: 5px;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .controls {
        flex-direction: column;
    }
    
    button {
        width: 100%;
    }
    
    .timeline-controls {
        flex-direction: column;
    }
    
    .zoom-controls {
        margin-left: 0;
        width: 100%;
    }
    
    .modal-content {
        padding: 20px;
        width: 95%;
    }
    
    .colors-group .color-inputs {
        grid-template-columns: repeat(2, 1fr);
    }
}
