﻿/* ======= CSS Variables (Design System) ======= */
:root {
    --bg-color: #f3f6f9;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --accent-color: #f43f5e;
    --success-color: #10b981;
    --warning-color: #f59e0b;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 25px -3px rgba(0,0,0,0.05), 0 4px 6px -4px rgba(0,0,0,0.02);
    --shadow-xl: 0 20px 40px rgba(0,0,0,0.08);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;

    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* Gantt color palette */
    --gantt-1: #3b82f6;
    --gantt-2: #8b5cf6;
    --gantt-3: #06b6d4;
    --gantt-4: #10b981;
    --gantt-5: #f59e0b;
    --gantt-6: #ef4444;
    --gantt-7: #ec4899;
    --gantt-8: #6366f1;
    --gantt-9: #14b8a6;
    --gantt-10: #f97316;
    --gantt-11: #84cc16;
    --gantt-12: #a855f7;
}

.dark-mode {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --primary-color: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-light: #1e3a5c;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 25px -3px rgba(0,0,0,0.5);
    --shadow-xl: 0 20px 40px rgba(0,0,0,0.6);
}

/* ======= Global Reset ======= */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.d-none { display: none !important; }
.mt-1 { margin-top: 0.5rem; }

/* ======= Layout ======= */
.app-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* ======= Header ======= */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 2rem;
}

.logo-link {
    text-decoration: none;
    color: inherit;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo {
    width: 40px;
    height: 40px;
}

.app-name {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}
.app-name span { color: var(--primary-color); }

.header-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}
.nav-link:hover { color: var(--primary-color); }

.icon-btn {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}
.icon-btn:hover {
    background: var(--primary-light);
    color: var(--primary-color);
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

/* ======= Main Content ======= */
.main-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2.5rem;
    align-items: start;
    padding-bottom: 4rem;
}

/* ======= Config Panel ======= */
.config-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: start;
}

.panel-section {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.section-title {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary-color);
}

.section-desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 1.25rem;
}

/* ======= Template Grid ======= */
.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
    gap: 0.75rem;
}

.template-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.85rem 0.5rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.82rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    transition: var(--transition);
    text-align: center;
    line-height: 1.3;
}

.template-btn i { font-size: 1.5rem; }

.template-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: var(--primary-light);
    transform: translateY(-2px);
}

.template-btn.active {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

/* ======= Forms ======= */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.input-group label {
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.input-group input:not([type="checkbox"]),
.input-group textarea,
.input-group select {
    width: 100%;
    padding: 0.7rem 1rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    transition: var(--transition);
    outline: none;
    font-family: 'Outfit', sans-serif;
}

.input-group textarea { resize: vertical; min-height: 60px; }

.input-group input:focus,
.input-group textarea:focus,
.input-group select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

option {
    background-color: var(--bg-color);
    color: var(--text-primary);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    font-size: 0.92rem;
    color: var(--text-primary);
    padding: 0.5rem 0;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary-color);
    cursor: pointer;
}

/* ======= Calendar Constraints ======= */
.excluded-dates-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    min-height: 20px;
}

.excluded-date-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--primary-light);
    color: var(--primary-color);
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.82rem;
    font-weight: 500;
    animation: fadeIn 0.3s ease;
}

.excluded-date-tag button {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    padding: 0;
    transition: var(--transition);
}
.excluded-date-tag button:hover { color: var(--accent-color); }

.add-date-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.add-date-row input {
    flex: 1;
    padding: 0.6rem 0.75rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    outline: none;
    font-family: 'Outfit', sans-serif;
    transition: var(--transition);
}
.add-date-row input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* ======= Steps Editor ======= */
.steps-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.step-card {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    transition: var(--transition);
    animation: slideIn 0.3s ease;
    position: relative;
}

.step-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-sm);
}

.step-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.step-number {
    background: var(--primary-color);
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.82rem;
    flex-shrink: 0;
}

.step-name-input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 500;
    outline: none;
    transition: var(--transition);
    font-family: 'Outfit', sans-serif;
}
.step-name-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.step-delete-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.25rem;
    padding: 0.25rem;
    transition: var(--transition);
    display: flex;
    align-items: center;
}
.step-delete-btn:hover { color: var(--accent-color); }

.step-card-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.step-card-body .input-group label {
    font-size: 0.82rem;
}

.step-card-body input,
.step-card-body select {
    padding: 0.5rem 0.7rem !important;
    font-size: 0.88rem !important;
}

.add-step-btn {
    width: 100%;
    border-style: dashed;
    border-width: 2px;
    color: var(--text-secondary);
    font-weight: 500;
}
.add-step-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: var(--primary-light);
}

/* ======= Buttons ======= */
.btn {
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-family: 'Outfit', sans-serif;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.2);
}
.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(37, 99, 235, 0.3);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}
.btn-outline:hover { background: var(--bg-color); }

.btn-small { padding: 0.5rem 1rem; font-size: 0.85rem; }

.btn-generate {
    width: 100%;
    padding: 1rem;
    font-size: 1.1rem;
    border-radius: var(--radius-lg);
    grid-column: 1 / -1;
}

/* ======= Preview Panel ======= */
.preview-panel {
    position: relative;
}

.sticky-container {
    position: sticky;
    top: 2rem;
}

.preview-placeholder {
    background: var(--card-bg);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 4rem 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    text-align: center;
    color: var(--text-secondary);
    min-height: 400px;
}

.preview-placeholder i {
    font-size: 4rem;
    color: var(--primary-color);
    opacity: 0.4;
}

.preview-placeholder p {
    font-size: 1rem;
    line-height: 1.5;
}

/* ======= Gantt Chart ======= */
.gantt-wrapper {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.gantt-header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--card-bg);
}

.gantt-header-bar h3 {
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary-color);
    font-weight: 600;
}

.gantt-container {
    padding: 1.5rem;
    overflow-x: auto;
}

.gantt-chart {
    min-width: 100%;
    position: relative;
}

/* Gantt Timeline Header */
.gantt-timeline-header {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 0.5rem;
    padding-left: 180px;
    position: relative;
}

.gantt-month-group {
    display: flex;
    flex-direction: column;
}

.gantt-month-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--primary-color);
    text-align: center;
    padding: 0.25rem 0;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.gantt-days-row {
    display: flex;
}

.gantt-day-cell {
    width: 24px;
    min-width: 24px;
    text-align: center;
    font-size: 0.68rem;
    color: var(--text-secondary);
    padding: 0.3rem 0;
    border-right: 1px solid var(--border-color);
    position: relative;
}

.gantt-day-cell.weekend {
    background: var(--primary-light);
    opacity: 0.6;
}

.gantt-day-cell.excluded {
    background: rgba(244, 63, 94, 0.1);
}

.gantt-day-cell.today {
    color: var(--primary-color);
    font-weight: 700;
}

/* Gantt Rows */
.gantt-rows {
    position: relative;
}

.gantt-row {
    display: flex;
    align-items: center;
    min-height: 42px;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.gantt-row:last-child {
    border-bottom: none;
}

.gantt-row-label {
    width: 180px;
    min-width: 180px;
    padding: 0.5rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-right: 2px solid var(--border-color);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gantt-row-label .step-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.gantt-row-bars {
    display: flex;
    flex: 1;
    position: relative;
    height: 42px;
}

.gantt-bar-bg {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 24px;
    border-right: 1px solid var(--border-color);
}

.gantt-bar-bg.weekend {
    background: var(--primary-light);
    opacity: 0.35;
}

.gantt-bar-bg.excluded {
    background: rgba(244, 63, 94, 0.07);
}

.gantt-bar {
    position: absolute;
    top: 8px;
    height: 26px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    padding: 0 8px;
    font-size: 0.72rem;
    font-weight: 600;
    color: #fff;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    z-index: 2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.gantt-bar:hover {
    transform: scaleY(1.15);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 10;
}

.gantt-bar .bar-label {
    overflow: hidden;
    text-overflow: ellipsis;
}

.gantt-bar .bar-dates {
    font-size: 0.65rem;
    font-weight: 400;
    opacity: 0.85;
    margin-left: 6px;
}

/* Today line */
.gantt-today-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--accent-color);
    z-index: 5;
    pointer-events: none;
}

.gantt-today-line::before {
    content: "Aujourd'hui";
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--accent-color);
    white-space: nowrap;
}

/* Margin bar */
.gantt-bar.margin-bar {
    opacity: 0.35;
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 3px,
        rgba(255,255,255,0.3) 3px,
        rgba(255,255,255,0.3) 6px
    );
}

/* Gantt Summary */
.gantt-summary {
    display: flex;
    gap: 1.5rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.gantt-summary-item {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.gantt-summary-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.gantt-summary-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ======= Toast ======= */
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.9rem;
    font-weight: 500;
    animation: slideUp 0.4s ease;
    color: var(--text-primary);
}

.toast.success { border-left: 4px solid var(--success-color); }
.toast.error { border-left: 4px solid var(--accent-color); }
.toast.info { border-left: 4px solid var(--primary-color); }

/* ======= Editable Step Modal Overlay ======= */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
    backdrop-filter: blur(4px);
}

.modal-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 440px;
    width: 90%;
    box-shadow: var(--shadow-xl);
    animation: scaleIn 0.25s ease;
}

.modal-card h3 {
    font-size: 1.15rem;
    margin-bottom: 1.25rem;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* ======= Animations ======= */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

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

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* ======= PNG Export Specific ======= */
.gantt-export-wrapper {
    background: var(--card-bg);
    padding: 2rem;
    font-family: 'Outfit', sans-serif;
}

.gantt-export-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.gantt-export-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

/* ======= Responsive ======= */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    .sticky-container {
        position: static;
    }
}

@media (max-width: 900px) {
    .config-panel {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .app-container {
        padding: 0 1rem;
    }
    .header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    .form-grid {
        grid-template-columns: 1fr;
    }
    .template-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    }
    .step-card-body {
        grid-template-columns: 1fr;
    }
    .gantt-timeline-header {
        padding-left: 120px;
    }
    .gantt-row-label {
        width: 120px;
        min-width: 120px;
        font-size: 0.75rem;
    }
    .gantt-summary {
        flex-direction: column;
        gap: 0.75rem;
    }
}

@media (max-width: 480px) {
    .gantt-day-cell {
        width: 24px;
        min-width: 24px;
        font-size: 0.6rem;
    }
    .gantt-timeline-header {
        padding-left: 100px;
    }
    .gantt-row-label {
        width: 100px;
        min-width: 100px;
    }
}
