/* Horae - Design System */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --blue: #003DA5;
    --blue-light: #E8EEF7;
    --blue-hover: #002d7a;
    --green: #10B981;
    --green-hover: #059669;
    --red: #EF4444;
    --red-hover: #DC2626;
    --red-light: #FEF2F2;
    --orange: #F59E0B;
    --orange-light: #FFFBEB;
    --grey-bg: #F8FAFC;
    --grey-border: #E2E8F0;
    --grey-text: #64748B;
    --text: #1E293B;
    --text-secondary: #475569;
    --white: #FFFFFF;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.08), 0 4px 6px rgba(0,0,0,0.04);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    /* Badge type colors */
    --badge-cm: #003DA5;
    --badge-td: #7C3AED;
    --badge-tp: #0D9488;
    --badge-ds: #D97706;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--grey-bg);
    color: var(--text);
    line-height: 1.6;
    font-size: 14px;
}

/* ====== LAYOUT ====== */
.container { max-width: 1400px; margin: 0 auto; padding: 24px; }

/* ====== HEADER (Dashboard) ====== */
.header {
    background: var(--white);
    color: var(--text);
    padding: 0;
    margin-bottom: 28px;
    box-shadow: var(--shadow);
    border-bottom: 1px solid var(--grey-border);
}
.header .container {
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 20px; padding-top: 20px; padding-bottom: 20px;
}
.header-top {
    display: flex; justify-content: space-between; align-items: center;
    width: 100%; margin-bottom: 12px;
}
.header-logo { height: 30px; width: auto; }
.header h1 { font-size: 24px; font-weight: 700; color: var(--blue); }

/* Stats bar */
.stats-bar { display: flex; gap: 16px; align-items: stretch; flex-wrap: wrap; }
.stat-box {
    background: var(--white); border-radius: var(--radius-sm); padding: 12px 20px;
    border: 1px solid var(--grey-border); min-width: 140px; text-align: center;
    position: relative;
}
.stat-box:nth-child(1) { border-left: 4px solid var(--blue); }
.stat-box:nth-child(2) { border-left: 4px solid var(--green); }
.stat-box:nth-child(3) { border-left: 4px solid var(--orange); }
.stat-number { font-size: 28px; font-weight: 700; color: var(--text); }
.stat-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--grey-text); }

.progress-bar-container {
    width: 200px; height: 10px; background: var(--grey-border);
    border-radius: 5px; overflow: hidden;
}
.progress-bar-fill {
    height: 100%; background: var(--green);
    border-radius: 5px; transition: width 0.5s ease;
}

/* ====== CARDS ====== */
.card {
    background: var(--white); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 28px; margin-bottom: 24px;
    border: 1px solid var(--grey-border);
}
.card h2 {
    font-size: 18px; font-weight: 600; margin-bottom: 20px; color: var(--text);
    padding-left: 14px; border-left: 4px solid var(--blue);
}

/* ====== FORMS ====== */
.form-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.form-group { display: flex; flex-direction: column; flex: 1; min-width: 180px; }
.form-group label { font-size: 14px; font-weight: 500; margin-bottom: 6px; color: var(--text-secondary); }
.form-group input, .form-group select, .form-group textarea {
    padding: 10px 14px; border: 1px solid var(--grey-border); border-radius: var(--radius-xs);
    font-size: 14px; font-family: inherit; color: var(--text); background: var(--white);
    transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,61,165,0.15);
}
.form-group input::placeholder, .form-group textarea::placeholder { color: #94A3B8; }

/* ====== BUTTONS ====== */
.btn {
    padding: 10px 20px; border: none; border-radius: var(--radius-xs);
    font-size: 14px; font-weight: 600; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    transition: all 0.2s; font-family: inherit;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--blue-hover); box-shadow: var(--shadow-md); }
.btn-success { background: var(--green); color: white; }
.btn-success:hover:not(:disabled) { background: var(--green-hover); box-shadow: var(--shadow-md); }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover:not(:disabled) { background: var(--red-hover); }
.btn-outline {
    background: transparent; border: 1px solid var(--grey-border); color: var(--text-secondary);
}
.btn-outline:hover:not(:disabled) { background: var(--grey-bg); border-color: #CBD5E1; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-copy { background: var(--blue-light); color: var(--blue); border: 1px solid transparent; }
.btn-copy:hover { background: #D0DAF0; }

/* Add enseignement dashed button */
.btn-add-dashed {
    background: transparent; border: 2px dashed #CBD5E1; color: var(--blue);
    padding: 16px; border-radius: var(--radius); width: 100%; font-size: 14px;
    font-weight: 600; transition: all 0.2s;
}
.btn-add-dashed:hover { border-color: var(--blue); background: var(--blue-light); }

/* ====== TABLE ====== */
.table-container { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--grey-border); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
    background: var(--blue); color: white; font-weight: 600; text-align: left;
    padding: 12px 16px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.3px;
}
th:first-child { border-radius: var(--radius-sm) 0 0 0; }
th:last-child { border-radius: 0 var(--radius-sm) 0 0; }
td { padding: 12px 16px; border-bottom: 1px solid var(--grey-border); vertical-align: middle; }
tr:nth-child(even) td { background: var(--grey-bg); }
tr:hover td { background: #EDF2F7; }

/* ====== BADGES ====== */
.badge {
    display: inline-block; padding: 3px 10px; border-radius: 4px;
    font-size: 12px; font-weight: 600; letter-spacing: 0.3px;
}
.badge-matiere { background: var(--blue-light); color: var(--blue); }
.badge-complete { background: #D1FAE5; color: #065F46; }
.badge-attente { background: #FEF3C7; color: #92400E; }
.badge-ecart { background: #FEF3C7; color: #92400E; }

/* Status dot */
.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 8px; }
.status-complete { background: var(--green); }
.status-attente { background: var(--orange); animation: pulse-attente 2s ease-in-out infinite; }

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

/* Actions */
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ====== MODAL ====== */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15,23,42,0.5); z-index: 1000; justify-content: center; align-items: flex-start;
    padding: 40px 20px; overflow-y: auto; backdrop-filter: blur(2px);
}
.modal-overlay.active { display: flex; animation: fadeIn 0.2s ease; }
.modal {
    background: white; border-radius: var(--radius); max-width: 800px; width: 100%;
    max-height: 90vh; overflow-y: auto; padding: 32px; position: relative;
    box-shadow: var(--shadow-lg); animation: slideUp 0.2s ease;
}
.modal-close {
    position: absolute; top: 16px; right: 20px; background: none; border: none;
    font-size: 24px; cursor: pointer; color: var(--grey-text); width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center; border-radius: 50%;
    transition: background 0.2s;
}
.modal-close:hover { background: var(--grey-bg); }

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

/* Global actions */
.global-actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* ====== TOAST ====== */
.toast {
    position: fixed; bottom: 24px; right: 24px; background: var(--text); color: white;
    padding: 14px 24px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500;
    z-index: 2000; opacity: 0; transition: opacity 0.3s; pointer-events: none;
    box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; }

/* ====== FORM PAGE ====== */
.form-header {
    background: var(--blue); color: white; padding: 32px 0; margin-bottom: 28px;
}
.form-header .container {
    display: flex; justify-content: space-between; align-items: center; gap: 20px;
}
.form-header .form-header-center { text-align: center; flex: 1; }
.form-header-logo { height: 25px; width: auto; flex-shrink: 0; }
.form-header h1 { font-size: 22px; font-weight: 700; }
.form-header .subtitle { opacity: 0.9; font-size: 15px; margin-top: 6px; font-weight: 400; }

/* Dispo grid */
.dispo-grid {
    display: grid; grid-template-columns: 100px repeat(5, 1fr);
    gap: 8px; margin-bottom: 16px;
}
.dispo-header {
    font-weight: 600; font-size: 13px; text-align: center; padding: 8px;
    color: #1E293B; background: #E8EEF7; border-radius: var(--radius-xs);
    border-bottom: 2px solid #003DA5;
}
.dispo-label {
    font-size: 13px; display: flex; align-items: center; font-weight: 500;
    color: var(--text-secondary); background: #F0F4FA; border-radius: var(--radius-xs); padding: 4px 8px;
}
.dispo-cell {
    padding: 12px 8px; text-align: center; border-radius: var(--radius-sm);
    cursor: pointer; font-size: 13px; font-weight: 600;
    transition: all 0.2s; border: 2px solid var(--grey-border);
    background: #F1F5F9; color: var(--grey-text); user-select: none;
    min-height: 44px; display: flex; align-items: center; justify-content: center;
}
.dispo-cell:hover { border-color: #CBD5E1; }
.dispo-cell.active { background: var(--green); color: white; border-color: var(--green); }

/* ====== ENSEIGNEMENT CARD ====== */
.ens-card {
    background: var(--white); border: 1px solid var(--grey-border); border-radius: var(--radius);
    border-left: 4px solid var(--blue); padding: 24px; margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}
.ens-card h3 { font-size: 16px; color: var(--text); font-weight: 600; margin-bottom: 4px; }
.ens-ref { font-size: 13px; color: var(--grey-text); margin-bottom: 16px; }
.ens-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.ens-calc {
    margin-top: 16px; padding: 12px 16px; background: var(--grey-bg);
    border-left: 3px solid var(--green); border-radius: var(--radius-sm);
    font-size: 13px; color: var(--text-secondary); font-style: italic;
}

/* Enseignement structured rows */
.ens-row {
    display: flex; align-items: center; gap: 12px; padding: 14px 0;
    border-bottom: 1px solid #F1F5F9; flex-wrap: wrap;
}
.ens-row:last-of-type { border-bottom: none; }
.ens-row-label {
    font-weight: 600; font-size: 13px; min-width: 80px; padding: 6px 12px;
    border-radius: var(--radius-xs); text-align: center; flex-shrink: 0; color: white;
}
.ens-row-label-cm { background: var(--badge-cm); }
.ens-row-label-td { background: var(--badge-td); }
.ens-row-label-tp { background: var(--badge-tp); }
.ens-row-label-ds { background: var(--badge-ds); }
.ens-row-label-part { background: #7C3AED; }
.ens-row-label-prog { background: #0D9488; }

/* Row fields container */
.ens-row-fields { display: flex; gap: 16px; flex-wrap: wrap; flex: 1; }
.ens-row input[type="number"] {
    width: 80px; padding: 8px 10px; border: 1px solid var(--grey-border);
    border-radius: var(--radius-xs); font-size: 14px; font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.ens-row input[type="text"] {
    width: 100%; padding: 8px 10px; border: 1px solid var(--grey-border);
    border-radius: var(--radius-xs); font-size: 14px; font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.ens-row select {
    padding: 8px 10px; border: 1px solid var(--grey-border);
    border-radius: var(--radius-xs); font-size: 14px; font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s; background: white;
}
.ens-row textarea {
    width: 100%; padding: 8px 10px; border: 1px solid var(--grey-border);
    border-radius: var(--radius-xs); font-size: 14px; font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.ens-row input:focus, .ens-row select:focus, .ens-row textarea:focus {
    outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,61,165,0.15);
}
.ens-row-block { align-items: flex-start; }

/* Labeled field */
.ens-labeled-field { display: flex; flex-direction: column; gap: 4px; }
.ens-field-label { font-size: 13px; font-weight: 500; color: var(--text-secondary); }

/* Help text */
.ens-help-text { font-size: 12px; color: var(--grey-text); font-style: italic; margin-top: 4px; margin-bottom: 10px; padding-left: 92px; }

/* Sub-fields */
.ens-sub-fields {
    padding-left: 92px; padding-top: 8px; padding-bottom: 8px;
    display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end;
}
.ens-sub-fields input, .ens-sub-fields select, .ens-sub-fields textarea {
    padding: 8px 10px; border: 1px solid var(--grey-border); border-radius: var(--radius-xs);
    font-size: 14px; font-family: inherit;
}
.ens-sub-fields input:focus, .ens-sub-fields select:focus, .ens-sub-fields textarea:focus {
    outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,61,165,0.15);
}
.ens-sub-fields input[type="number"] { width: 80px; }
.ens-sub-fields textarea { flex: 1; min-width: 200px; }

.input-ecart { border-color: var(--orange) !important; }
.ecart-hint { font-size: 12px; color: var(--orange); margin-top: 2px; }

/* Total display */
.ens-total-display {
    font-size: 14px; font-weight: 600; color: var(--green); white-space: nowrap;
    align-self: flex-end; padding: 8px 0;
}

/* ====== PLANNING GRID ====== */
.planning-section {
    margin-top: 20px; padding-top: 20px; border-top: 2px solid #E2E8F0;
}
.planning-title {
    font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px;
}
.planning-explainer {
    font-size: 13px; color: var(--grey-text); font-style: italic; margin-bottom: 16px; line-height: 1.5;
}
.planning-grid-wrapper {
    overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px;
}
.planning-grid {
    display: grid; gap: 3px; min-width: max-content;
}
.planning-corner {
    background: transparent;
}
.planning-col-header {
    text-align: center; font-size: 12px; font-weight: 600; color: var(--text-secondary);
    padding: 6px 4px;
}
.planning-row-label {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    padding: 4px 6px; border-radius: 4px; min-width: 80px;
    min-height: 50px; position: sticky; left: 0; z-index: 2;
    background: var(--grey-bg); overflow: hidden;
}
.planning-badge {
    display: inline-block; padding: 4px 12px; border-radius: 4px;
    color: white; font-weight: 700; font-size: 13px; text-align: center;
}
.planning-counter {
    font-size: 11px; font-weight: 400; color: var(--grey-text); white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.planning-cell {
    min-width: 60px; min-height: 50px; background: #F1F5F9; border-radius: 4px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    cursor: pointer; transition: background 0.15s, transform 0.1s; user-select: none;
}
.planning-cell:hover:not(.selected) {
    background: #E2E8F0; transform: scale(1.03);
}
.planning-cell.selected {
    border-radius: 4px;
}
.planning-cell-type {
    font-size: 14px; font-weight: 700;
}
.planning-cell-dur {
    font-size: 11px; opacity: 0.85;
}
.planning-cell-salle {
    font-size: 10px; opacity: 0.8; white-space: nowrap; overflow: hidden;
    text-overflow: ellipsis; max-width: 100%; padding: 0 2px;
}
.planning-cell-rem {
    font-size: 10px; opacity: 0.7; font-style: italic; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; max-width: 100%; padding: 0 2px;
}
.planning-cell.disabled:hover { transform: none; background: #F1F5F9 !important; }

/* All done message */
.planning-done-msg {
    margin-top: 12px; padding: 12px 16px; background: #ECFDF5;
    border-left: 4px solid #10B981; border-radius: 8px;
    font-size: 14px; color: #065F46;
}

/* Gear row */
.planning-gear-cell {
    display: flex; align-items: center; justify-content: center; padding: 2px 0;
}
.planning-gear-btn {
    font-size: 20px; color: #94A3B8; cursor: pointer; line-height: 1;
    transition: color 0.15s; user-select: none;
}
.planning-gear-btn:hover { color: #003DA5; }
.planning-gear-btn.active { color: #003DA5; }

/* Shared options panel */
.planning-opt-panel {
    margin-top: 12px; padding: 16px; background: var(--grey-bg);
    border: 1px solid var(--grey-border); border-radius: 8px;
}
.planning-opt-title {
    font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 12px;
}
.planning-opt-body { display: flex; flex-direction: column; gap: 6px; }
.planning-opt-row {
    display: flex; align-items: center; gap: 6px; font-size: 13px;
    color: var(--text); cursor: pointer;
}
.planning-opt-row input[type="checkbox"] { margin: 0; width: 16px; height: 16px; }
.planning-opt-hint {
    font-size: 11px; color: var(--grey-text); font-style: italic;
    padding-left: 22px; margin-bottom: 4px;
}
.planning-opt-select {
    width: 180px; padding: 6px 8px; font-size: 13px; border: 1px solid var(--grey-border);
    border-radius: 4px; background: white; margin-left: 22px; margin-bottom: 4px;
}
.planning-opt-row-label {
    font-size: 13px; font-weight: 500; color: var(--text); margin-top: 6px;
}
.planning-opt-remarque {
    width: 100%; max-width: 350px; padding: 6px 8px; font-size: 13px;
    border: 1px solid var(--grey-border); border-radius: 4px;
}

/* Dates indispo */
.date-indispo-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.date-indispo-row input { flex: 1; }

/* ====== RECAP SECTION ====== */
.recap-ens-card {
    margin-bottom: 16px; padding: 16px; background: white;
    border: 1px solid #E2E8F0; border-radius: 8px;
}
.recap-ens-title {
    font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 10px;
}
.recap-table {
    width: 100%; border-collapse: collapse; font-size: 13px;
}
.recap-table th {
    text-align: left; padding: 8px 10px; background: #F8FAFC; border: 1px solid #E2E8F0;
    font-weight: 600; font-size: 12px; color: var(--text-secondary);
}
.recap-table td {
    padding: 7px 10px; border: 1px solid #E2E8F0;
}
.recap-total-row {
    background: #F0F4FA; font-weight: 700;
}
.recap-type-badge {
    display: inline-block; padding: 2px 10px; border-radius: 4px;
    color: white; font-weight: 600; font-size: 12px; text-align: center; min-width: 32px;
}
.recap-variable-note {
    font-size: 12px; color: var(--grey-text); font-style: italic; margin-top: 6px;
}
.recap-grand-total {
    background: #E8EEF7; padding: 16px; border-radius: 8px; margin-top: 4px;
}
.recap-grand-title {
    font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 10px;
}
.recap-grand-total .recap-table { font-size: 14px; }
.recap-grand-total .recap-total-row { font-size: 16px; }

/* Confirmation */
.confirmation-box { text-align: center; padding: 60px 20px; }
.confirmation-box h2 { color: var(--green); margin-bottom: 12px; font-size: 24px; }

/* Referentiel hover buttons */
.ref-row .ref-actions { opacity: 0; transition: opacity 0.2s; }
.ref-row:hover .ref-actions { opacity: 1; }

/* Matiere checkboxes (kept for compatibility) */
.matieres-grid { max-height: 300px; overflow-y: auto; border: 1px solid var(--grey-border); border-radius: var(--radius-xs); padding: 12px; }
.matieres-section h3 { font-size: 14px; color: var(--blue); margin: 8px 0 4px; }
.matiere-checkbox { display: flex; align-items: center; gap: 6px; padding: 3px 0; font-size: 14px; }
.matiere-checkbox input { margin: 0; }

/* ====== RESPONSIVE ====== */
@media (max-width: 768px) {
    .container { padding: 16px; }
    .form-row { flex-direction: column; }
    .form-group { min-width: 100%; }
    .dispo-grid { grid-template-columns: 80px repeat(5, 1fr); font-size: 12px; gap: 4px; }
    .dispo-cell { padding: 8px 4px; min-height: 38px; font-size: 12px; }
    .ens-grid { grid-template-columns: 1fr; }
    .ens-row { flex-direction: column; align-items: flex-start; }
    .ens-row-fields { width: 100%; }
    .ens-sub-fields { padding-left: 0; }
    .ens-help-text { padding-left: 0; }
    .ens-labeled-field { width: 100%; }
    .ens-labeled-field input[type="number"] { width: 100%; }
    .planning-grid-wrapper { margin-left: -16px; margin-right: -16px; padding-left: 16px; }
    .header-logo { height: 30px; }
    .header .container { flex-direction: column; text-align: center; }
    .stats-bar { justify-content: center; width: 100%; }
    .stat-box { flex: 1; min-width: 100px; }
    th, td { padding: 8px 10px; font-size: 13px; }
    .card { padding: 20px; }
    .card h2 { font-size: 16px; }
    .modal { padding: 20px; margin: 10px; }
}

@media (max-width: 480px) {
    .stats-bar { flex-direction: column; }
    .stat-box { width: 100%; }
    .actions { flex-direction: column; }
}
