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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f7fa;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
header {
    background: #2c3e50;
    color: white;
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

nav {
    display: flex;
    gap: 0.5rem;
}

.nav-btn {
    padding: 0.6rem 1.5rem;
    border: 2px solid rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.1);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s;
}

.nav-btn:hover {
    background: rgba(255,255,255,0.2);
}

.nav-btn.active {
    background: white;
    color: #2c3e50;
    border-color: white;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.header-actions button {
    padding: 0.5rem 1rem;
    border: none;
    background: rgba(255,255,255,0.9);
    color: #2c3e50;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s;
}

.header-actions button:hover {
    background: white;
    transform: translateY(-2px);
}

/* Views */
.view {
    display: none;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
}

.view.active {
    display: flex;
}



/* Definition Container */
.definition-container {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.left-panels {
    width: 280px;
    background: white;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    box-shadow: 2px 0 8px rgba(0,0,0,0.05);
}

.collapsible-panel {
    border-bottom: 1px solid #e0e0e0;
}

.panel-header {
    height: 50px;
    padding: 0 1rem;
    background: #34495e;
    color: white;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.panel-header:hover {
    background: #2c3e50;
}

.panel-header h3 {
    font-size: 1rem;
    margin: 0;
    flex: 1;
}

.collapse-icon {
    font-size: 0.8rem;
    transition: transform 0.3s;
}

.panel-header.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

.panel-content {
    max-height: 400px;
    overflow-y: auto;
    transition: max-height 0.3s ease-out;
}

.panel-content.collapsed {
    max-height: 0;
    overflow: hidden;
}

.add-btn-inner {
    width: calc(100% - 1rem);
    margin: 0.5rem;
    padding: 0.6rem;
    border: 2px dashed #3498db;
    background: rgba(52, 152, 219, 0.05);
    color: #3498db;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.add-btn-inner:hover {
    background: rgba(52, 152, 219, 0.1);
    border-color: #2980b9;
}

.machines-panel {
    width: 250px;
    background: white;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 8px rgba(0,0,0,0.05);
}

.machines-header {
    height: 50px;
    padding: 1rem;
    background: #34495e;
    border-bottom: 1px solid #2c3e50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.machines-header h3 {
    font-size: 1rem;
    color: white;
    margin: 0;
}

.canvas-header {
    height: 50px;
    background: #34495e;
    border-bottom: 1px solid #2c3e50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
}

.canvas-header h3 {
    font-size: 1rem;
    color: white;
    margin: 0;
}

.add-btn {
    padding: 0.4rem 0.8rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
}

.add-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
}

#machineList, #projectList {
    padding: 0.5rem;
}

.machine-item, .project-item {
    padding: 0.8rem;
    margin-bottom: 0.5rem;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.machine-item:hover, .project-item:hover {
    border-color: #3498db;
    box-shadow: 0 2px 8px rgba(52, 152, 219, 0.2);
}

.project-item.active {
    border-color: #3498db;
    background: rgba(52, 152, 219, 0.05);
}

.machine-color {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid #ccc;
}

.machine-name {
    flex: 1;
    font-weight: 600;
}

.machine-actions {
    display: flex;
    gap: 0.3rem;
}

.machine-actions button {
    padding: 0.2rem 0.5rem;
    border: none;
    background: #f0f0f0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.machine-actions button:hover {
    background: #e0e0e0;
}

/* Canvas Container */
.canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #fafbfc;
}

canvas {
    display: block;
    cursor: grab;
}

canvas:active {
    cursor: grabbing;
}

/* Gantt View */
.gantt-controls {
    background: white;
    padding: 0.8rem 2rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.gantt-controls select,
.gantt-controls input {
    padding: 0.5rem 0.8rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
    background: white;
    cursor: pointer;
}

.gantt-controls select:focus,
.gantt-controls input:focus {
    outline: none;
    border-color: #3498db;
}

.gantt-container {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.task-list-panel {
    width: 280px;
    background: white;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 8px rgba(0,0,0,0.05);
}

.task-list-panel h3 {
    padding: 1rem;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    font-size: 1rem;
    color: #333;
    height: 60px;
}

#taskList {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.task-item {
    padding: 0.8rem;
    margin-bottom: 0.5rem;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: move;
    transition: all 0.3s;
    user-select: none;
}

.task-item:hover {
    border-color: #3498db;
    box-shadow: 0 2px 8px rgba(52, 152, 219, 0.2);
    transform: translateX(4px);
}

.task-item.used {
    opacity: 0.4;
    cursor: not-allowed;
}

.task-item-name {
    font-weight: 600;
    margin-bottom: 0.3rem;
    font-size: 0.95rem;
}

.task-item-duration {
    font-size: 0.8rem;
    color: #666;
}

/* Project Accordion in Gantt */
#projectAccordion {
    flex: 1;
    overflow-y: auto;
}

.project-accordion-item {
    border-bottom: 1px solid #e0e0e0;
}

.project-accordion-header {
    padding: 1rem;
    background: #f8f9fa;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background 0.2s;
    user-select: none;
}

.project-accordion-header:hover {
    background: #ecf0f1;
}

.project-accordion-header.active {
    background: rgba(52, 152, 219, 0.1);
}

.project-accordion-icon {
    font-size: 0.8rem;
    transition: transform 0.3s;
}

.project-accordion-header.collapsed .project-accordion-icon {
    transform: rotate(-90deg);
}

.project-accordion-title {
    flex: 1;
    font-weight: 600;
    font-size: 0.95rem;
}

.project-accordion-badge {
    background: #e74c3c;
    color: white;
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: bold;
}

.project-accordion-content {
    max-height: 500px;
    overflow-y: auto;
    transition: max-height 0.3s ease-out;
}

.project-accordion-content.collapsed {
    max-height: 0;
    overflow: hidden;
}

.gantt-chart-panel {
    flex: 1;
    background: #fafbfc;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: row;
}

.gantt-machines-panel {
    width: 180px;
    background: white;
    border-right: 1px solid #bdc3c7;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 4px rgba(0,0,0,0.05);
    z-index: 10;
}

.gantt-machines-header {
    height: 60px;
    background: #34495e;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1rem;
    border-bottom: 1px solid #2c3e50;
}

.gantt-machines-list {
    flex: 1;
    overflow-y: auto;
    margin-top: 4px;
}

.gantt-machine-row {
    height: 50px;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    border-bottom: 1px solid #e0e0e0;
    cursor: move;
    transition: background 0.2s;
    font-weight: 600;
    color: #333;
}

.gantt-machine-row:hover {
    background: #f5f7fa;
}

.gantt-machine-row.dragging {
    opacity: 0.5;
}

.gantt-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.gantt-header-wrapper {
    height: 60px;
    background: white;
    border-bottom: 1px solid #bdc3c7;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    z-index: 10;
    position: relative;
}

.gantt-chart-wrapper {
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    min-width: 400px;
    max-width: 500px;
    width: 90%;
}

.modal-content h2 {
    margin-bottom: 1.5rem;
    color: #333;
    font-size: 1.5rem;
}

/* Grille pour les formulaires */
#machineForm,
#projectForm,
#taskForm {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#taskForm label,
#machineForm label,
#projectForm label {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: #555;
}

#taskForm input,
#taskForm select,
#taskForm textarea,
#machineForm input,
#projectForm input {
    width: 100%;
    padding: 0.7rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    transition: border-color 0.3s;
}

#taskForm input:focus,
#taskForm select:focus,
#taskForm textarea:focus,
#machineForm input:focus,
#projectForm input:focus {
    outline: none;
    border-color: #3498db;
}

#taskForm textarea {
    resize: vertical;
    min-height: 60px;
}

#taskForm input[type="color"],
#machineForm input[type="color"],
#projectForm input[type="color"] {
    height: 45px;
    cursor: pointer;
    padding: 0.3rem;
}

.modal-actions {
    display: flex;
    gap: 0.8rem;
    margin-top: 1.5rem;
}

/* Modale de planning plus petite */
#planningModal .modal-content {
    max-width: 450px;
}

#planningModalMessage {
    white-space: pre-line;
    line-height: 1.6;
    color: #555;
    margin: 1rem 0;
}

.modal-actions button {
    flex: 1;
    padding: 0.7rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.3s;
}

.modal-actions button[type="submit"] {
    background: #3498db;
    color: white;
}

.modal-actions button[type="submit"]:hover {
    background: #2980b9;
}

.modal-actions button[type="button"] {
    background: #e0e0e0;
    color: #333;
}

.modal-actions button[type="button"]:hover {
    background: #d0d0d0;
}

/* Context Menu */
.context-menu {
    display: none;
    position: fixed;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1001;
    min-width: 150px;
}

.context-menu.active {
    display: block;
}

.context-menu-item {
    padding: 0.7rem 1rem;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.context-menu-separator {
    height: 1px;
    background: #e0e0e0;
    margin: 0.3rem 0;
}

.context-menu-item:hover {
    background: #f5f5f5;
    color: #e74c3c;
}

/* Task Node Styles (for canvas) */
.task-node {
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.task-node.selected {
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.5);
}

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

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

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

/* Tooltip */
.tooltip {
    position: fixed;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 0.8rem 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    max-width: 300px;
    pointer-events: none;
    z-index: 1002;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    display: none;
    word-wrap: break-word;
}

.tooltip.active {
    display: block;
}

.tooltip strong {
    display: block;
    margin-bottom: 0.3rem;
    color: #3498db;
}

/* Hours Summary */
.hours-summary {
    padding: 0.75rem;
    background: #f8f9fa;
    border-radius: 6px;
    font-size: 0.85rem;
    color: #555;
    margin-top: 0.5rem;
}

.hours-summary div {
    padding: 0.25rem 0;
}

/* Hours Modal */
.hours-modal-content {
    max-width: 700px;
}

.hours-config {
    max-height: 400px;
    overflow-y: auto;
    padding: 0.5rem;
}

.day-hours {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    border-bottom: 1px solid #eee;
}

.day-hours:last-child {
    border-bottom: none;
}

.day-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 100px;
    cursor: pointer;
}

.day-label input[type="checkbox"] {
    cursor: pointer;
}

.day-label span {
    font-weight: 500;
    color: #2c3e50;
}

.day-hours input[type="time"] {
    padding: 0.4rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

.day-hours input[type="time"]:disabled {
    background: #f5f5f5;
    color: #999;
    cursor: not-allowed;
}

.day-hours span:not(.day-label span) {
    color: #666;
    font-size: 0.85rem;
}

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

.task-item {
    animation: fadeIn 0.3s ease-out;
}

/* Modal Statistiques */
.stats-modal-content {
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
}

.stats-section {
    margin-bottom: 2rem;
}

.stats-section h3 {
    margin-bottom: 1rem;
    color: #2c3e50;
    font-size: 1.1rem;
    border-bottom: 2px solid #3498db;
    padding-bottom: 0.5rem;
}

.stat-bar {
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: #f8f9fa;
    border-radius: 6px;
}

.stat-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.stat-name {
    font-weight: 600;
    color: #2c3e50;
}

.stat-value {
    font-weight: bold;
    color: #3498db;
}

.stat-progress {
    height: 24px;
    background: #e0e0e0;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
}

.stat-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #3498db, #2980b9);
    transition: width 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 8px;
    color: white;
    font-size: 0.85rem;
    font-weight: bold;
}

.stat-progress-bar.warning {
    background: linear-gradient(90deg, #f39c12, #e67e22);
}

.stat-progress-bar.danger {
    background: linear-gradient(90deg, #e74c3c, #c0392b);
}

.stat-details {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: #7f8c8d;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 8px;
    border-left: 4px solid #3498db;
}

.stat-card-value {
    font-size: 2rem;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 0.25rem;
}

.stat-card-label {
    font-size: 0.9rem;
    color: #7f8c8d;
}

/* Spinner pour modal de travail */
.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

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

/* Palette de couleurs */
.color-picker-group {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.color-palette {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.5rem;
}

.color-swatch {
    width: 100%;
    height: 40px;
    border: 2px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;
}

.color-swatch:hover {
    transform: scale(1.1);
    border-color: #3498db;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.color-swatch:active {
    transform: scale(0.95);
}
