/* === Rapport Word - Styles === */

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #16a34a;
    --warning: #d97706;
    --error: #dc2626;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-500: #6b7280;
    --gray-700: #374151;
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Nav */
.nav-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: white;
    border-bottom: 1px solid var(--gray-200);
    padding: 0.3rem 1.5rem;
    margin-bottom: 0.5rem;
}

.nav-brand {
    font-size: 0.85rem;
    white-space: nowrap;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    flex: 1;
}

.nav-sep {
    color: var(--gray-300);
    font-size: 0.8rem;
}

main.container {
    padding-top: 0;
}

main.container > section > h2 {
    margin-top: 0;
    margin-bottom: 0.5rem;
    font-size: 1.3rem;
}

.nav-links {
    gap: 0;
}

.nav-link {
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    text-decoration: none;
    color: var(--gray-700);
    font-size: 0.875rem;
}

.nav-link.active {
    background: var(--primary);
    color: white;
}

.nav-link:hover:not(.active) {
    background: var(--gray-100);
}

/* Role badge */
.role-badge {
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
    border-radius: 0.25rem;
    font-weight: 600;
    text-transform: uppercase;
}

.role-admin {
    background: #dbeafe;
    color: #1e40af;
}

.role-user {
    background: var(--gray-100);
    color: var(--gray-500);
}

#user-info-container {
    font-size: 0.75rem;
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
}

#user-display-name {
    font-size: 0.75rem;
}

.btn-logout {
    font-size: 0.7rem;
    color: var(--gray-500);
    margin-left: 0;
    cursor: pointer;
    white-space: nowrap;
}

/* Buttons */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
}

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

.btn-sm {
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
}

.sig-preview {
    max-height: 40px;
    max-width: 120px;
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    transition: transform 0.2s;
}

.sig-preview:hover {
    transform: scale(2.5);
    z-index: 100;
    position: relative;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.btn-outline, .btn-outline:is(button, label, a) {
    background: #fff !important;
    color: var(--primary) !important;
    border: 1px solid var(--primary) !important;
    border-radius: 0.375rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    line-height: 1;
    margin: 0;
}
.btn-outline:hover {
    background: var(--gray-100) !important;
}

.btn-icon {
    padding: 0.25rem;
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0.7;
}

.btn-icon:hover {
    opacity: 1;
}

/* Status badges */
.status-badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-draft { background: var(--gray-200); color: var(--gray-700); }
.status-generating { background: #dbeafe; color: #1e40af; animation: pulse 1.5s infinite; }
.status-editing { background: #fef3c7; color: #92400e; }
.status-signing { background: #ede9fe; color: #5b21b6; }
.status-signed { background: #d1fae5; color: #065f46; }
.status-error { background: #fee2e2; color: #991b1b; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Tables */
.table-wrapper {
    overflow-x: auto;
}

.empty-state {
    text-align: center;
    color: var(--gray-500);
    padding: 2rem;
    font-style: italic;
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
}

/* Generation form */
.generation-form {
    background: var(--gray-100);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
}

.generation-form label {
    margin-bottom: 0;
}

.generation-form input {
    margin-bottom: 0;
}

/* Editor layout */
.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 0.5rem;
}

.editor-toolbar span {
    flex: 1;
    font-weight: 600;
}

/* Editor toolbar actions */
.editor-toolbar-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.editor-toolbar-actions > button,
.editor-toolbar-actions > label,
.editor-toolbar-actions > a {
    font-size: 0.8rem;
    padding: 0.35rem 0.6rem;
    border-radius: 0.375rem;
    line-height: 1.2;
    display: inline-flex;
    align-items: center;
    margin: 0;
    white-space: nowrap;
    box-sizing: border-box;
}

/* Editor tabs */
.editor-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 0;
}

.editor-tab {
    padding: 0.5rem 1.25rem;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--gray-500);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
}

.editor-tab:hover {
    color: var(--primary);
}

.editor-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

/* Editor content area */
.editor-content {
    height: calc(100vh - 200px);
    border: 1px solid var(--gray-200);
    border-top: none;
    border-radius: 0 0 0.375rem 0.375rem;
    overflow: hidden;
}

.editor-tab-panel {
    height: 100%;
    overflow-y: auto;
}

/* Word Kizeo preview (mammoth) */
.word-preview-container {
    height: 100%;
    overflow-y: auto;
    padding: 1.5rem 2rem;
    background: white;
}

.mammoth-content {
    max-width: 800px;
    margin: 0 auto;
    font-size: 0.9rem;
    line-height: 1.6;
}

.mammoth-content img {
    max-width: 100%;
    height: auto;
    margin: 0.5rem 0;
}

.mammoth-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.5rem 0;
}

.mammoth-content table td,
.mammoth-content table th {
    border: 1px solid var(--gray-300);
    padding: 0.35rem 0.5rem;
    font-size: 0.85rem;
}

/* Rapport preview iframe */
.rapport-preview-iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.kizeo-warning-banner {
    background: #fde047;
    color: #713f12;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 0.45rem 1rem;
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.02em;
    flex-shrink: 0;
}
.btn-kizeo-dl {
    background: #f59e0b;
    color: #fff !important;
    padding: 0.15rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}
.btn-kizeo-dl:hover {
    background: #d97706;
}

.kizeo-panel-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Status card (generating/error) */
.editor-status-card {
    text-align: center;
    padding: 3rem 2rem;
    max-width: 500px;
    margin: 0 auto;
}

.editor-status-card .status-icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.editor-status-card.error h3 {
    color: var(--error);
}

.editor-status-card h3 {
    margin-bottom: 0.5rem;
}

/* Photos popup compact (1/5 ecran) */
#page-photos {
    padding: 0.5rem;
}

.photos-grid-compact {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.photo-card-compact {
    border: 1px solid var(--gray-200);
    border-radius: 0.25rem;
    overflow: hidden;
    position: relative;
}

.photo-card-compact .photo-img-wrapper {
    position: relative;
}

.photo-card-compact .photo-img-wrapper img {
    width: 100%;
    display: block;
    cursor: pointer;
}

.photo-card-compact .btn-copy-photo {
    position: absolute;
    bottom: 0.25rem;
    right: 0.25rem;
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    opacity: 0.85;
}

.btn-zoom-photo {
    position: absolute;
    bottom: 0.25rem;
    left: 0.25rem;
    width: 1.6rem;
    height: 1.6rem;
    padding: 0;
    margin: 0;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.85);
    font-size: 0.85rem;
    line-height: 1.6rem;
    text-align: center;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.15s, transform 0.15s;
    z-index: 2;
}

.btn-zoom-photo:hover {
    opacity: 1;
    transform: scale(1.15);
    background: white;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* Photo lightbox */
.photo-lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.photo-lightbox-content {
    position: relative;
    max-width: 92vw;
    max-height: 92vh;
    cursor: default;
}
.photo-lightbox-content img {
    max-width: 92vw;
    max-height: 88vh;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 4px 30px rgba(0,0,0,0.5);
}
.photo-lightbox-close {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: white;
    color: #333;
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
}
.photo-lightbox-close:hover {
    background: #ef4444;
    color: white;
}
.photo-lightbox-label {
    text-align: center;
    color: rgba(255,255,255,0.8);
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

/* Photo search bar */
.photo-search-bar {
    position: sticky;
    top: 0;
    z-index: 5;
    background: white;
    padding: 0.3rem 0;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 0.4rem;
}

.photo-search-input {
    width: 100%;
    padding: 0.3rem 0.5rem;
    font-size: 0.75rem;
    border: 1px solid var(--gray-200);
    border-radius: 0.25rem;
    margin: 0;
}

.photo-search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.photo-rows-container {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

/* Photo context groups */
.photo-context-group {
    margin-bottom: 0.3rem;
    border-radius: 0.25rem;
    transition: background 0.2s;
}

.photo-context-group.search-highlight {
    background: #fef9c3;
}

.photo-context-banner {
    background: #f0f4ff;
    border-left: 3px solid var(--primary);
    padding: 0.2rem 0.5rem;
    border-radius: 0 0.2rem 0.2rem 0;
}

.photo-ctx-left {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--gray-700);
    line-height: 1.25;
}

.photo-ctx-right {
    font-size: 0.65rem;
    color: var(--primary);
    margin-top: 0.1rem;
    line-height: 1.2;
}

.photo-group-grid {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

/* (photos-panel deplace dans popup photos-panel.js) */

/* Photos grid */
.photos-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.photo-card {
    border: 1px solid var(--gray-200);
    border-radius: 0.375rem;
    overflow: hidden;
}

.photo-card img {
    width: 100%;
    height: auto;
    display: block;
}

.photo-card .photo-info {
    padding: 0.5rem;
    font-size: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.photo-card .btn-insert,
.photo-card .btn-copy-photo {
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 0.25rem;
    cursor: pointer;
}

.photo-card .photo-label {
    padding: 0.4rem 0.5rem 0.2rem;
    font-size: 0.75rem;
    color: var(--gray-600, #4b5563);
    font-weight: 500;
}

.photo-card .btn-copy-photo {
    margin: 0 0.5rem 0.4rem;
}

/* Flash row animation */
.flash-green { animation: flashGreen 2s ease-out; }
.flash-yellow { animation: flashYellow 2s ease-out; }
.flash-red { animation: flashRed 2s ease-out; }

@keyframes flashGreen {
    from { background: #d1fae5; } to { background: transparent; }
}
@keyframes flashYellow {
    from { background: #fef3c7; } to { background: transparent; }
}
@keyframes flashRed {
    from { background: #fee2e2; } to { background: transparent; }
}

/* Modal */
dialog::backdrop {
    background: rgba(0, 0, 0, 0.4);
}

.modal-compact {
    max-width: 480px;
    margin: 0;
    padding: 1.5rem;
}

.modal-compact header {
    position: relative;
    padding: 0 0 0.75rem 0;
    margin-bottom: 0.75rem;
}

.modal-compact header h3 {
    margin: 0;
    font-size: 1.1rem;
    padding-right: 2rem;
}

.modal-compact .modal-close {
    position: absolute;
    right: -0.5rem;
    top: -0.5rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: var(--gray-500);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
}

.modal-compact .modal-close:hover {
    color: var(--gray-700);
    background: var(--gray-100);
}

.modal-compact label {
    font-size: 0.8rem;
    margin-bottom: 0.5rem;
    display: block;
}

.modal-compact input[type="text"],
.modal-compact select {
    font-size: 0.85rem;
    padding: 0.35rem 0.5rem;
    margin-top: 0.15rem;
}

.modal-compact footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1rem;
    padding: 0;
    border: 0;
}

.modal-compact footer button {
    margin: 0;
    width: auto;
    font-size: 0.85rem;
    padding: 0.4rem 1rem;
}

/* === Modale revue surlignages === */
.modal-highlights {
    max-width: 560px;
    margin: 0;
    padding: 1.5rem;
}

.modal-highlights header {
    position: relative;
    padding: 0 0 0.75rem 0;
    margin-bottom: 0.5rem;
}

.modal-highlights header h3 {
    margin: 0;
    font-size: 1.1rem;
    padding-right: 2rem;
}

.modal-highlights .modal-close {
    position: absolute;
    right: -0.5rem;
    top: -0.5rem;
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--gray-500);
    padding: 0.25rem;
    border-radius: 4px;
    line-height: 1;
}

.modal-highlights .modal-close:hover {
    color: var(--gray-700);
    background: var(--gray-100);
}

.highlights-progress {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.highlights-progress-bar {
    flex: 1;
    height: 6px;
    background: var(--gray-200);
    border-radius: 3px;
    overflow: hidden;
}

.highlights-progress-fill {
    height: 100%;
    background: #16a34a;
    border-radius: 3px;
    transition: width 0.3s ease;
    width: 0%;
}

.highlights-progress-text {
    font-size: 0.8rem;
    color: var(--gray-600);
    white-space: nowrap;
}

.highlights-list {
    list-style: none;
    padding: 0;
    margin: 0 0 1rem 0;
    max-height: 350px;
    overflow-y: auto;
}

.highlights-list li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.6rem;
    border-radius: 6px;
    margin-bottom: 0.35rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    transition: all 0.2s;
}

.highlights-list li.hl-removed {
    opacity: 0.45;
    background: #f0fdf4;
    border-color: #bbf7d0;
    text-decoration: line-through;
}

.hl-color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.hl-info {
    flex: 1;
    min-width: 0;
}

.hl-text {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hl-context {
    font-size: 0.75rem;
    color: var(--gray-500);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hl-btn-remove {
    flex-shrink: 0;
    font-size: 0.75rem;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    border: 1px solid var(--gray-300);
    background: white;
    cursor: pointer;
    color: var(--gray-700);
    transition: all 0.15s;
}

.hl-btn-remove:hover {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #dc2626;
}

.hl-btn-remove:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.hl-check {
    color: #16a34a;
    font-weight: bold;
    flex-shrink: 0;
}

.modal-highlights footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding: 0;
    border: 0;
}

.modal-highlights footer button {
    margin: 0;
    width: auto;
    font-size: 0.85rem;
    padding: 0.4rem 1rem;
}

.sign-signature-preview {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.75rem 0 0.25rem;
    padding: 0.5rem 0.75rem;
    background: var(--gray-50, #f9fafb);
    border: 1px solid var(--gray-200, #e5e7eb);
    border-radius: 6px;
}
.sign-signature-img {
    max-height: 50px;
    max-width: 160px;
    object-fit: contain;
}

/* Bouton danger (outline rouge) */
.btn-danger {
    background: var(--error);
    color: white;
    border: 1px solid var(--error);
    padding: 0.4rem 1rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.85rem;
}

.btn-danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
}

.btn-outline-danger {
    background: none;
    color: var(--error);
    border: 1px solid var(--error);
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.8rem;
}

.btn-outline-danger:hover {
    background: #fee2e2;
}

/* Inline label */
.label-inline {
    font-size: 0.7rem;
    white-space: nowrap;
}

/* Context cell in mapping table */
.context-cell {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.8rem;
}

/* Actions cell */
.actions-cell {
    white-space: nowrap;
}

.actions-cell button {
    margin-right: 0.25rem;
}

/* Fiche detail (hierarchical) */
.fiche-detail-row td {
    padding: 0 !important;
    background: var(--gray-100);
}

.fiche-detail-content {
    padding: 0.75rem 1rem;
}

.fiche-detail-inner {
    background: white;
    border-radius: 0.5rem;
    padding: 1rem;
    border: 1px solid var(--gray-200);
}

.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.detail-header h4 {
    margin: 0;
    font-size: 0.95rem;
}

.active-template-row {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 0.375rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
}

.active-template-row label {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.active-template-row select {
    font-size: 0.85rem;
    padding: 0.25rem 0.5rem;
    margin: 0;
    flex: 1;
    max-width: 400px;
}

.template-card {
    border: 1px solid var(--gray-200);
    border-radius: 0.375rem;
    margin-bottom: 0.5rem;
}

.template-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: var(--gray-100);
    border-radius: 0.375rem 0.375rem 0 0;
    font-size: 0.875rem;
}

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

.template-detail {
    padding: 0.75rem;
}

.tags-mapping-table {
    font-size: 0.85rem;
}

.tags-mapping-table th,
.tags-mapping-table td {
    padding: 0.3rem 0.4rem;
}

.tags-mapping-table input[type="text"] {
    width: 100%;
    min-width: 120px;
}

.tags-mapping-table select {
    min-width: 100px;
}

.tags-mapping-table .mapping-valeurs {
    width: 100%;
    min-width: 130px;
    font-size: 0.78rem;
    padding: 0.2rem 0.35rem;
    resize: vertical;
    line-height: 1.3;
}

.valeurs-cell {
    min-width: 140px;
}

.text-muted {
    color: var(--gray-500);
    font-size: 0.78rem;
}

.btn-delete-tag {
    margin-left: 0.15rem;
}

/* Modal wide pour fiches avec formulaires */
.modal-wide {
    max-width: 650px;
}

.kizeo-form-row input {
    font-size: 0.85rem;
    padding: 0.3rem 0.5rem;
}

.kizeo-form-row .btn-remove-kf {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

/* ===================== Formula Editor Modal ===================== */
.formula-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.formula-modal {
    background: white;
    border-radius: 0.5rem;
    width: 680px;
    max-width: 95vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.formula-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-200);
}

.formula-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-500);
    line-height: 1;
    padding: 0.25rem;
}

.formula-modal-close:hover {
    color: var(--gray-700);
}

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

.formula-expr-input {
    width: 100%;
    font-family: monospace;
    font-size: 0.9rem;
    padding: 0.5rem;
    border: 1px solid var(--gray-200);
    border-radius: 0.375rem;
    resize: vertical;
    margin-bottom: 0.5rem;
}

.formula-expr-input:focus {
    outline: 2px solid var(--primary);
    border-color: var(--primary);
}

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

.formula-valid {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.formula-invalid {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

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

.formula-toolbar-btn {
    font-size: 0.8rem;
    padding: 0.3rem 0.6rem;
    background: var(--primary);
    color: white;
    border: 1px solid var(--primary);
    border-radius: 0.25rem;
    cursor: pointer;
    white-space: nowrap;
    font-weight: 500;
}

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

.formula-sub-panel {
    border: 1px solid var(--gray-200);
    border-radius: 0.375rem;
    margin-bottom: 0.5rem;
    background: #fafafa;
}

.formula-sub-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--gray-200);
    background: var(--gray-100);
    font-size: 0.85rem;
}

.formula-fn-list {
    max-height: 200px;
    overflow-y: auto;
    padding: 0.3rem;
}

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

.formula-fn-row:hover {
    background: var(--gray-100);
}

.formula-fn-name {
    font-weight: 600;
    min-width: 80px;
    color: var(--primary);
}

.formula-fn-special {
    color: #d97706;
}

.formula-fn-syntax {
    font-size: 0.75rem;
    color: var(--gray-500);
    flex: 1;
}

.formula-fn-desc {
    font-size: 0.75rem;
    color: var(--gray-500);
    min-width: 120px;
}

.formula-fn-insert {
    font-size: 0.75rem;
    padding: 0.15rem 0.4rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 0.2rem;
    cursor: pointer;
    font-weight: bold;
    line-height: 1;
}

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

.formula-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--gray-200);
}

.formula-modal-footer button {
    font-size: 0.85rem;
    padding: 0.4rem 1rem;
    border-radius: 0.375rem;
    cursor: pointer;
}

.formula-modal-footer .secondary {
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    color: var(--gray-700);
}

.formula-modal-footer .secondary:hover {
    background: var(--gray-200);
}

.formula-help summary {
    user-select: none;
}

.formula-help code {
    background: var(--gray-100);
    padding: 0.1rem 0.3rem;
    border-radius: 0.2rem;
    font-size: 0.75rem;
}

/* Bouton flottant fixe — sauvegarder les mappings */
.mapping-save-bar {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 900;
}

.mapping-save-bar .btn-save-mappings {
    background: #2563eb;
    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;
}

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

/* Disabled mapping value input */
.tags-mapping-table input[type="text"]:disabled {
    background: var(--gray-100);
    color: var(--gray-500);
    cursor: not-allowed;
    border-color: var(--gray-200);
}

/* Responsive */
@media (max-width: 768px) {
    .editor-content {
        height: calc(100vh - 250px);
    }
}
