/* === Syntheses PNCEE - Styles === */

:root {
    --primary-color: #0d6efd;
    --success-color: #198754;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --muted-color: #6c757d;
}

/* === Navigation === */
nav .nav-link {
    font-size: 0.9rem;
    opacity: 0.7;
    transition: opacity 0.2s;
}

nav .nav-link.active {
    opacity: 1;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 4px;
}

nav .nav-link:hover {
    opacity: 1;
}

/* === Page Sections === */
.page-section[hidden] {
    display: none;
}

.page-section {
    animation: fadeIn 0.3s ease;
}

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

/* Actions bar with search left, button right */
.config-actions-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    gap: 0.75rem;
}
.config-actions-bar input[type="search"] {
    margin: 0 !important;
    max-width: 20rem;
}

/* === Config Section Cards === */
.config-section {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}

.config-section h3 {
    margin-top: 0;
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

/* === Form Groups === */
.form-group {
    margin-bottom: 0.75rem;
}

.form-group label {
    font-weight: 600;
}

/* === Actions === */
.actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 0.75rem;
}

/* === Action Buttons === */
.btn-action-blue,
.btn-action-green,
.btn-action-outline {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    padding: 0 0.9rem;
    margin: 0;
    color: #fff;
    border: none;
    border-radius: 0.3rem;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    line-height: 2rem;
    box-sizing: border-box;
    height: 2rem;
    vertical-align: middle;
}

.btn-action-blue { background: #1976d2; }
.btn-action-green { background: #2e7d32; }
.btn-action-outline {
    background: #fff;
    color: #555;
    border: 1px solid #adb5bd;
}

.btn-action-blue:hover,
.btn-action-green:hover { opacity: 0.88; }
.btn-action-outline:hover { background: #f1f3f5; }
.btn-action-outline.danger { color: #c62828; border-color: #c62828; }
.btn-action-outline.danger:hover { background: #ffebee; }

.btn-action-blue:disabled,
.btn-action-green:disabled,
.btn-action-outline:disabled { opacity: 0.5; cursor: default; }

/* === Small action buttons (edit/delete in tables) === */
.btn-sm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.15rem 0.5rem;
    font-size: 0.75rem;
    color: #333;
    border: 1px solid #dee2e6;
    border-radius: 0.2rem;
    background: #fff;
    cursor: pointer;
    gap: 0.2rem;
}

.btn-sm:hover {
    background: #f1f3f5;
}

.btn-sm.danger {
    color: var(--danger-color);
    border-color: var(--danger-color);
}

.btn-sm.danger:hover {
    background: rgba(220, 53, 69, 0.1);
}

.btn-sm.insert {
    color: var(--success-color);
    border-color: var(--success-color);
    font-weight: 700;
}

.btn-sm.insert:hover {
    background: rgba(25, 135, 84, 0.1);
}

.btn-sm.insert-int {
    color: var(--muted-color);
    border-color: var(--muted-color);
    font-size: 0.65rem;
    font-weight: 700;
}

.btn-sm.insert-int:hover {
    background: rgba(108, 117, 125, 0.1);
}

/* === Info Icon (tooltip) === */
.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    font-size: 0.65rem;
    font-style: normal;
    font-weight: 600;
    color: #6b7280;
    background: transparent;
    border: 1.5px solid #9ca3af;
    border-radius: 50%;
    cursor: help;
    margin-left: 0.35rem;
    vertical-align: middle;
    position: relative;
    transition: color 0.15s, border-color 0.15s;
}
.info-icon:hover {
    color: #2563eb;
    border-color: #2563eb;
}


/* === Color Combo (hex + swatch + picker) === */
.color-combo {
    display: inline-flex !important;
    align-items: center !important;
    gap: 0.3rem;
}
.color-combo .color-swatch {
    display: inline-block;
    width: 1.4rem;
    height: 1.4rem;
    border-radius: 3px;
    border: 1.5px solid #ccc;
    cursor: pointer;
    flex-shrink: 0;
    vertical-align: middle;
}
.color-combo .color-swatch:hover { border-color: #888; }
.color-combo .col-color-hex {
    width: 5.5rem !important;
    max-width: 5.5rem !important;
    font-family: monospace !important;
    font-size: 0.8rem !important;
    padding: 0.15rem 0.3rem !important;
    margin: 0 !important;
    height: 1.6rem !important;
    text-transform: uppercase;
}
.color-combo .col-color-input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
}

/* === Status Badges === */
.status-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 0.3rem;
    font-size: 0.78rem;
    font-weight: 600;
}

.status-badge.success {
    background: #d1e7dd;
    color: #0f5132;
}

.status-badge.running {
    background: #cfe2ff;
    color: #084298;
}

.status-badge.pending {
    background: #e2e3e5;
    color: #41464b;
}

.status-badge.needs-validation {
    background: var(--warning-color, #e6a817);
    color: #fff;
}

.status-badge.error {
    background: #f8d7da;
    color: #842029;
}

/* === History alert icons === */
#history-table td:nth-child(6) {
    white-space: nowrap;
}
.history-alert {
    cursor: help;
    font-size: 0.9rem;
    vertical-align: middle;
    margin-left: 0.35rem;
}
.history-alert-error {
    color: #dc3545;
}
.history-alert-warning {
    color: #e6a817;
}

/* === Download Button === */
.btn-download {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.8rem;
    background: var(--success-color);
    color: white;
    border: none;
    border-radius: 0.3rem;
    cursor: pointer;
    font-size: 0.85rem;
    text-decoration: none;
}

.btn-download:hover {
    opacity: 0.9;
}

.btn-sharepoint {
    background: #0078d4;
}

.btn-sharepoint-done {
    background: #107c10;
}

/* === Warnings === */
.warnings {
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    list-style: none;
}

.warnings li {
    padding: 0.15rem 0;
    color: #856404;
    font-size: 0.85rem;
}

/* === Loading Overlay === */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-overlay[hidden] {
    display: none;
}

/* === Compact layout overrides (PicoCSS) === */
main.container h2 {
    margin-bottom: 0.75rem;
}

main.container h3 {
    margin-bottom: 0.5rem;
}

main.container p {
    margin-bottom: 0.5rem;
}

main.container table {
    margin-bottom: 0.5rem;
}

main.container table th,
main.container table td {
    padding: 0.35rem 0.5rem;
}

/* === Mapping Editor === */
.mapping-editor {
    overflow-x: auto;
}

.mapping-editor table {
    font-size: 0.85rem;
    min-width: 700px;
}

.mapping-editor input,
.mapping-editor select,
.mapping-editor textarea {
    font-size: 0.85rem;
    padding: 0.15rem 0.4rem;
    margin-bottom: 0;
    height: auto;
    line-height: 1.3;
}

.mapping-editor td {
    overflow: hidden;
}

.mapping-editor td input,
.mapping-editor td select {
    max-width: 100%;
    box-sizing: border-box;
}

/* Masquer la fleche dropdown des datalist (Chrome/Edge) */
.mapping-editor td input[list]::-webkit-calendar-picker-indicator {
    display: none !important;
}

.mapping-label-cell .label-text {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
    max-height: calc(1.3em * 3);
    word-break: break-word;
}

/* Stats config table: compact inputs */
#stats-config-table input,
#stats-config-table select {
    font-size: 0.85rem;
    padding: 0.15rem 0.4rem;
    margin-bottom: 0;
    height: auto;
    line-height: 1.3;
}

/* Column label textarea: auto-height */
.col-label-textarea {
    width: 100%;
    min-height: 1.6rem;
    resize: vertical;
    overflow: hidden;
    font-family: inherit;
    field-sizing: content;
}

/* === Validation values textarea === */
.validation-values-textarea {
    width: 100%;
    min-height: 2.5rem;
    max-height: 7.5rem;
    resize: vertical;
    font-family: inherit;
    font-size: 0.8rem;
    padding: 0.2rem 0.4rem;
    border: 1px solid #dee2e6;
    border-radius: 0.2rem;
    field-sizing: content;
    overflow-y: auto;
}

/* === Color swatch input === */
input[type="color"] {
    width: 3rem;
    height: 1.8rem;
    padding: 0.1rem;
    border: 1px solid #dee2e6;
    border-radius: 0.2rem;
    cursor: pointer;
}

/* === Mapping source indicators === */
.source-indicator {
    display: inline-block;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    margin-right: 0.3rem;
}

.source-indicator.mapped {
    background: var(--primary-color);
}

.source-indicator.unmapped {
    background: var(--warning-color);
}

.source-indicator.intermediate {
    background: var(--danger-color);
}

/* === Intermediate column rows === */
tr.intermediate-row {
    background: #f8f9fa;
}

tr.intermediate-row td:first-child {
    color: var(--muted-color);
    font-style: italic;
}

/* === Formula display in mapping === */
.formula-preview {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.78rem;
    color: #555;
    background: #e9ecef;
    padding: 0.15rem 0.4rem;
    border-radius: 0.15rem;
    max-width: 20rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
}

/* === Button for opening formula editor === */
.btn-open-formula {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    font-size: 0.7rem;
    color: #333;
    border: 1px solid #dee2e6;
    border-radius: 0.2rem;
    background: #f8f9fa;
    cursor: pointer;
    flex-shrink: 0;
    margin-left: 0.2rem;
}

.btn-open-formula:hover {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

/* === Kizeo forms table === */
#forms-table input,
#forms-table select {
    font-size: 0.8rem;
    padding: 0.15rem 0.35rem;
    margin-bottom: 0;
    height: auto;
}

/* === User info in nav === */
.user-info {
    font-size: 0.85rem;
    color: var(--muted-color);
}

.role-badge {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 0.3rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-left: 0.4rem;
    vertical-align: middle;
}

.role-badge.role-admin {
    background: #0d6efd;
    color: #fff;
}

.role-badge.role-user {
    background: #e9ecef;
    color: #555;
}

.logout-link {
    font-size: 0.8rem;
    color: var(--danger-color) !important;
    text-decoration: underline;
    cursor: pointer;
    margin-left: 0.5rem;
}

.logout-link:hover {
    opacity: 0.8;
}

/* === Progress steps === */
.progress-step {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0;
    font-size: 0.85rem;
}

.progress-step .step-icon {
    width: 1.2rem;
    text-align: center;
}

.progress-step.done .step-icon {
    color: var(--success-color);
}

.progress-step.running .step-icon {
    color: var(--primary-color);
}

.progress-step.pending .step-icon {
    color: var(--muted-color);
}

/* === Formula Editor Modal === */
.formula-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.formula-modal-overlay[hidden] {
    display: none;
}

.formula-modal {
    background: #fff;
    border-radius: 0.75rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    width: 95%;
    max-width: 700px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.formula-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #dee2e6;
    background: #f8f9fa;
}

.formula-modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: none;
    background: transparent;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--muted-color);
    border-radius: 0.3rem;
}

.formula-modal-close:hover {
    background: #e9ecef;
    color: var(--danger-color);
}

.formula-modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
}

.formula-modal-footer {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    padding: 1rem 1.25rem;
    border-top: 1px solid #dee2e6;
    background: #f8f9fa;
}

.formula-modal-footer button {
    padding: 0.4rem 1.2rem;
    font-size: 0.9rem;
}

.formula-expr-input {
    width: 100%;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.9rem;
    padding: 0.6rem 0.75rem;
    border: 2px solid #dee2e6;
    border-radius: 0.4rem;
    resize: vertical;
    min-height: 3rem;
    margin-bottom: 0.5rem;
}

.formula-expr-input:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.formula-validation {
    font-size: 0.8rem;
    padding: 0.35rem 0.6rem;
    border-radius: 0.3rem;
    margin-bottom: 0.5rem;
}

.formula-valid {
    color: #0f5132;
    background: #d1e7dd;
}

.formula-invalid {
    color: #842029;
    background: #f8d7da;
}

.formula-toolbar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.formula-toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
    border: 1px solid #dee2e6;
    border-radius: 0.3rem;
    background: #f8f9fa;
    cursor: pointer;
    color: #333;
}

.formula-toolbar-btn:hover {
    background: #e9ecef;
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.formula-sub-panel {
    border: 1px solid #dee2e6;
    border-radius: 0.4rem;
    margin-bottom: 0.5rem;
    background: #fafbfc;
    max-height: 12rem;
    overflow-y: auto;
}

.formula-sub-panel[hidden] {
    display: none;
}

.formula-sub-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.6rem;
    background: #f0f1f3;
    border-bottom: 1px solid #dee2e6;
    font-size: 0.8rem;
}

.formula-fn-list {
    padding: 0.25rem;
}

.formula-fn-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.4rem;
    border-radius: 0.2rem;
    font-size: 0.78rem;
}

.formula-fn-row:hover {
    background: #e9ecef;
}

.formula-fn-name {
    font-weight: 700;
    color: var(--primary-color);
    min-width: 5rem;
}

.formula-fn-syntax {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.72rem;
    color: #555;
    background: #e9ecef;
    padding: 0.1rem 0.3rem;
    border-radius: 0.15rem;
    min-width: 10rem;
}

.formula-fn-desc {
    color: var(--muted-color);
    flex: 1;
    font-size: 0.72rem;
}

.formula-fn-insert {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.4rem;
    height: 1.4rem;
    padding: 0;
    font-size: 0.75rem;
    font-weight: bold;
    border: 1px solid var(--primary-color);
    border-radius: 0.2rem;
    background: transparent;
    color: var(--primary-color);
    cursor: pointer;
    flex-shrink: 0;
}

.formula-fn-insert:hover {
    background: var(--primary-color);
    color: #fff;
}

.formula-mapping-list {
    padding: 0.25rem;
}

.formula-mapping-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.25rem 0.4rem;
    border-radius: 0.2rem;
    font-size: 0.8rem;
}

.formula-mapping-row:hover {
    background: #e9ecef;
}

.formula-help p {
    margin: 0.2rem 0;
}

.formula-help code {
    font-size: 0.75rem;
    background: #e9ecef;
    padding: 0.1rem 0.3rem;
    border-radius: 0.15rem;
}

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

.modal-overlay[hidden] {
    display: none;
}

.modal {
    background: #fff;
    border-radius: 0.75rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    width: 95%;
    max-width: 500px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: fadeIn 0.15s ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #dee2e6;
    background: #f8f9fa;
}

.modal-header h4 {
    margin: 0;
    font-size: 1rem;
}

.modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: none;
    background: transparent;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--muted-color);
    border-radius: 0.3rem;
}

.modal-close:hover {
    background: #e9ecef;
    color: var(--danger-color);
}

.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
}

.modal-body p {
    margin: 0;
    font-size: 0.95rem;
}

.modal-form-group {
    margin-bottom: 0.75rem;
}

.modal-form-group:last-child {
    margin-bottom: 0;
}

.modal-form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
}

.modal-form-group input,
.modal-form-group select {
    width: 100%;
    font-size: 0.9rem;
    padding: 0.4rem 0.6rem;
    margin-bottom: 0;
}

.modal-checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-checkbox-row input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.modal-checkbox-row label {
    display: inline;
    font-weight: normal;
    margin-bottom: 0;
}

.field-error {
    border-color: var(--danger-color) !important;
    box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.15);
}

.modal-footer {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    padding: 1rem 1.25rem;
    border-top: 1px solid #dee2e6;
    background: #f8f9fa;
}

.modal-footer button {
    padding: 0.4rem 1.2rem;
    font-size: 0.9rem;
}

/* === Collapsible Sections === */
.collapsible-section .section-toggle {
    cursor: pointer;
    user-select: none;
    margin-bottom: 0;
}

.collapsible-section .section-toggle:hover {
    color: var(--primary-color);
}

.collapsible-section .chevron {
    display: inline-block;
    font-size: 0.7em;
    transition: transform 0.2s ease;
    vertical-align: middle;
}

.collapsible-section.collapsed .chevron {
    transform: rotate(-90deg);
}

.collapsible-section.collapsed .section-content {
    display: none;
}

.collapsible-section:not(.collapsed) .section-toggle {
    margin-bottom: 0.5rem;
}

/* === Floating Save Button === */
.btn-save-floating {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 900;
    background: #2e7d32;
    color: #fff;
    border: none;
    border-radius: 0.5rem;
    padding: 0.6rem 1.4rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: opacity 0.2s, transform 0.2s;
}

.btn-save-floating:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-save-floating[hidden] {
    display: none;
}

/* === Inline progress in history === */
.inline-progress {
    margin-top: 0.25rem;
}

.mini-progress {
    width: 100%;
    height: 0.35rem;
    border-radius: 0.2rem;
    appearance: none;
    -webkit-appearance: none;
}

.mini-progress::-webkit-progress-bar {
    background: #e9ecef;
    border-radius: 0.2rem;
}

.mini-progress::-webkit-progress-value {
    background: #3b82f6;
    border-radius: 0.2rem;
    transition: width 0.3s;
}

.mini-progress::-moz-progress-bar {
    background: #3b82f6;
    border-radius: 0.2rem;
}

.mini-step {
    display: block;
    font-size: 0.68rem;
    color: #6c757d;
    margin-top: 0.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* === Icon buttons in actions === */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.2rem 0.35rem;
    line-height: 1;
    border: 1px solid #dee2e6;
    background: #fff;
    cursor: pointer;
    border-radius: 0.25rem;
    text-decoration: none;
    color: inherit;
    margin-right: 0.2rem;
}

.btn-icon:hover {
    background: #f8f9fa;
}

.btn-icon svg {
    vertical-align: middle;
}

.btn-cancel {
    color: #dc3545;
    border-color: #dc3545;
}

.btn-cancel:hover {
    background: rgba(220, 53, 69, 0.1);
}

.btn-sp {
    color: #0078d4;
    border-color: #0078d4;
}

.btn-sp:hover {
    background: rgba(0, 120, 212, 0.1);
}

.btn-sp-done {
    color: #198754;
    border-color: #198754;
    cursor: default;
    font-weight: bold;
}

/* === Cancelled status badge === */
.status-badge.cancelled {
    background: #e2e3e5;
    color: #6c757d;
}

/* === Responsive === */
@media (max-width: 768px) {
    #nav-links {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .actions {
        flex-direction: column;
    }

    .mapping-editor table {
        min-width: unset;
    }
}
