/* App CSS - Procedure Editor */

/* Reset et base */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ==================== HEADER ==================== */
.app-header {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    background: var(--primary-gradient);
    color: white;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-md);
}

.app-header__title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
}

.app-header__title svg {
    width: 28px;
    height: 28px;
}

.app-header__actions {
    display: flex;
    gap: 0.5rem;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.15);
    color: white;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ==================== TOOLBAR ==================== */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
}

.toolbar__group {
    display: flex;
    gap: 0.25rem;
}

.toolbar__separator {
    width: 1px;
    background: var(--border-color);
    margin: 0 0.5rem;
}

.toolbar button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-color);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
}

.toolbar button:hover {
    background: var(--bg-color);
    border-color: var(--primary);
}

.toolbar button.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ==================== MAIN LAYOUT ==================== */
.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.editor-container {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Panneau editeur */
.editor-panel {
    flex: 1 1 300px;
    display: flex;
    flex-direction: column;
    min-width: 300px;
}

.editor-panel__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
}

.editor-panel__title {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.editor-panel__content {
    flex: 1;
    overflow: hidden;
}

#yaml-editor {
    width: 100%;
    height: 100%;
    padding: 1rem;
    border: none;
    resize: none;
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    background: var(--bg-code);
    color: #e2e8f0;
    tab-size: 2;
}

#yaml-editor:focus {
    outline: none;
}

/* Panneau preview */
.preview-panel {
    flex: 1 1 300px;
    display: flex;
    flex-direction: column;
    min-width: 300px;
    background: var(--bg-card);
    border-left: 1px solid var(--border-color);
}

.preview-panel__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
}

.preview-panel__title {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.preview-panel__content {
    flex: 1;
    overflow: auto;
    padding: 1.5rem;
}

/* ==================== PREVIEW CONTENT ==================== */
.procedure-preview {
    max-width: 800px;
    margin: 0 auto;
}

.procedure-preview h1 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.procedure-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.procedure-meta__item {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Tags */
.procedure-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-bottom: 1rem;
}

.tag {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    background: var(--primary);
    background: rgba(15, 118, 110, 0.15);
    color: var(--primary);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
}

.badge--brouillon { background: #e2e8f0; color: #475569; }
.badge--revision { background: var(--warning-bg); color: #92400e; }
.badge--validee { background: var(--success-bg); color: #166534; }
.badge--archivee { background: #f1f5f9; color: #64748b; }

.badge--critique { background: #fee2e2; color: #991b1b; }
.badge--haute { background: #ffedd5; color: #9a3412; }
.badge--moyenne { background: #fef3c7; color: #92400e; }
.badge--basse { background: var(--success-bg); color: #166534; }

.section {
    margin-bottom: 1.5rem;
}

.section__title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--primary);
    color: var(--primary);
}

.section__content {
    padding-left: 0.5rem;
}

/* Actions */
.action-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.action-item {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--bg-color);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--primary);
}

.action-item__number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    font-size: 0.875rem;
    font-weight: 600;
    flex-shrink: 0;
}

.action-item__content {
    flex: 1;
}

.action-item__title {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.action-item__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* Escalade */
.escalade-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.escalade-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-color);
    border-radius: var(--radius-md);
}

.escalade-item__time {
    display: inline-block;
    min-width: 60px;
    padding: 0.25rem 0.5rem;
    background: var(--warning-bg);
    color: #92400e;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-weight: 500;
    text-align: center;
}

/* Ressources */
.resources-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.resource-category h4 {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.resource-category ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.resource-category li {
    padding: 0.375rem 0;
    font-size: 0.875rem;
}

/* Mermaid */
.mermaid-container {
    background: var(--bg-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    overflow-x: auto;
}

.mermaid-container svg {
    max-width: 100%;
    height: auto;
}

/* ==================== VALIDATION ==================== */
.validation-panel {
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
}

.validation-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.validation-status.valid {
    color: var(--success);
}

.validation-status.invalid {
    color: var(--danger);
}

.validation-errors {
    margin-top: 0.5rem;
    max-height: 150px;
    overflow-y: auto;
}

.validation-error {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.5rem;
    margin-bottom: 0.25rem;
    background: var(--danger-bg);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    color: #991b1b;
}

/* ==================== SIDEBAR ==================== */
.sidebar {
    flex: 0 0 280px;
    width: 280px;
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar.collapsed {
    display: none;
}

.sidebar.collapsed + .editor-panel {
    margin-left: 1.5rem;
}

.sidebar__header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
}

.sidebar__content {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
}

/* Barre de recherche */
.sidebar__search {
    position: relative;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar__search input {
    width: 100%;
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 0.875rem;
}

.sidebar__search input:focus {
    outline: none;
    border-color: var(--primary);
}

.search-clear {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.25rem;
    padding: 0.25rem;
    line-height: 1;
}

.search-clear:hover {
    color: var(--text-color);
}

/* Filtres */
.filters-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.filters-bar select {
    flex: 1;
    min-width: 80px;
    padding: 0.375rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 0.75rem;
    cursor: pointer;
}

.filters-bar select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Résultats de recherche */
.search-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

#search-results-count {
    background: var(--primary);
    color: white;
    padding: 0.125rem 0.5rem;
    border-radius: 10px;
    font-size: 0.75rem;
}

/* Liste des procedures sauvegardees */
.procedure-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.procedure-list__item {
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--bg-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

.procedure-list__item:hover {
    background: var(--border-color);
}

.procedure-list__item.active {
    border-left: 3px solid var(--primary);
}

.procedure-list__title {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.procedure-list__meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Templates */
.template-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.template-item {
    position: relative;
    padding: 0.625rem 0.75rem;
    padding-right: 2rem;
    margin-bottom: 0.375rem;
    background: var(--bg-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

.template-item:hover {
    background: var(--border-color);
}

.template-item__title {
    font-weight: 500;
    font-size: 0.875rem;
    margin-bottom: 0.125rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.template-item__desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.template-item__complete {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    flex-shrink: 0;
}

.template-item__skeleton {
    display: inline-block;
    width: 8px;
    height: 8px;
    border: 1.5px solid var(--text-muted);
    border-radius: 50%;
    flex-shrink: 0;
}

/* Bouton favori */
.template-item__favorite {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.25rem;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s;
}

.template-item:hover .template-item__favorite {
    opacity: 1;
}

.template-item__favorite:hover {
    color: #f59e0b;
}

.template-item__favorite.is-favorite {
    opacity: 1;
    color: #f59e0b;
}

/* Catégories */
.category {
    margin-bottom: 0.5rem;
}

.category-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
    background: var(--bg-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.2s;
    user-select: none;
}

.category-header:hover {
    background: var(--border-color);
}

.category-icon {
    font-size: 1rem;
    width: 1.5rem;
    text-align: center;
}

.category-name {
    flex: 1;
    font-weight: 500;
    font-size: 0.875rem;
}

.category-count {
    background: var(--bg-card);
    color: var(--text-muted);
    padding: 0.125rem 0.5rem;
    border-radius: 10px;
    font-size: 0.75rem;
}

.category-chevron {
    color: var(--text-muted);
    transition: transform 0.2s;
    font-size: 0.75rem;
}

.category.expanded .category-chevron {
    transform: rotate(90deg);
}

.category-templates {
    display: none;
    padding-left: 1.5rem;
    padding-top: 0.375rem;
}

.category.expanded .category-templates {
    display: block;
}

/* Catégorie générique */
.category--generic {
    margin-bottom: 1rem;
}

.category--generic .category-header {
    background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
}

[data-theme="dark"] .category--generic .category-header {
    background: linear-gradient(135deg, #312e81 0%, #3730a3 100%);
}

.category-type-icon {
    font-size: 0.625rem;
    color: var(--primary);
    margin-right: -0.25rem;
}

/* Section header pour exemples */
.category-section-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 0.5rem 0.5rem;
    margin-top: 0.5rem;
    border-top: 1px solid var(--border-color);
}

.category-section-header .section-icon {
    font-size: 0.625rem;
    color: var(--text-muted);
}

.category-section-header .section-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Favoris section */
.favorites-section {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.favorites-header {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
}

[data-theme="dark"] .favorites-header {
    background: linear-gradient(135deg, #78350f 0%, #92400e 100%);
}

/* Type badge dans les templates */
.template-item__type {
    display: inline-block;
    padding: 0.125rem 0.375rem;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    font-size: 0.625rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-top: 0.25rem;
}

/* ==================== MODALS ==================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    padding: 1rem;
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal__title {
    font-size: 1.125rem;
    font-weight: 600;
    margin: 0;
}

.modal__close {
    border: none;
    background: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    line-height: 1;
}

.modal__body {
    padding: 1.5rem;
    overflow-y: auto;
}

.modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
}

/* ==================== TOASTS ==================== */
.toast-container {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.3s ease;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info { border-left: 3px solid var(--info); }

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ==================== DIAGRAM EDITOR MODAL ==================== */
.diagram-editor-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.diagram-editor-modal.visible {
    display: flex;
}

.diagram-editor-container {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.diagram-editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--primary-gradient);
    color: white;
    flex-shrink: 0;
}

.diagram-editor-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.diagram-editor-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.15);
    color: white;
    cursor: pointer;
    transition: background 0.2s;
}

.diagram-editor-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

.diagram-editor-body {
    flex: 1;
    overflow: hidden;
    background: #e5e7eb;
}

.diagram-editor-body iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.diagram-editor-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    gap: 1rem;
}

.diagram-editor-hint {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin: 0;
}

.diagram-editor-actions {
    display: flex;
    gap: 0.5rem;
}

.diagram-editor-actions .btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.diagram-editor-actions .btn-secondary {
    background: var(--bg-card);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.diagram-editor-actions .btn-secondary:hover {
    background: var(--bg-color);
}

.diagram-editor-actions .btn-primary {
    background: var(--primary);
    color: white;
    border: none;
}

.diagram-editor-actions .btn-primary:hover {
    background: var(--primary-hover);
}

/* Bouton ouvrir editeur diagramme dans le champ schema */
.btn-diagram-editor {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 0.5rem;
}

.btn-diagram-editor:hover {
    background: var(--primary-hover);
}

.btn-diagram-editor svg {
    width: 14px;
    height: 14px;
}

/* ==================== RESPONSIVE ==================== */

/* Ecrans moyens : sidebar plus étroite */
@media (max-width: 1200px) {
    .sidebar {
        flex: 0 0 260px;
        width: 260px;
    }

    .filters-bar {
        flex-direction: column;
    }

    .filters-bar select {
        width: 100%;
    }
}

/* Petits écrans : layout vertical, sidebar fixe */
@media (max-width: 768px) {
    .editor-container {
        flex-direction: column;
    }

    .editor-panel {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        height: 50%;
    }

    .preview-panel {
        height: 50%;
        border-left: none;
        border-top: 1px solid var(--border-color);
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: var(--z-modal);
        box-shadow: var(--shadow-lg);
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        border-right: 1px solid var(--border-color);
    }

    .sidebar.visible {
        transform: translateX(0);
    }
}

@media (max-width: 600px) {
    .app-header {
        padding: 0.5rem 0.75rem;
    }

    .app-header__title {
        font-size: 1rem;
    }

    .toolbar {
        padding: 0.5rem;
    }

    .toolbar button span {
        display: none;
    }
}
