/* ============================================================ */
/* PROMPT MANAGER - STYLE ACCESSIBLE (RGAA / WCAG 2.1 AA)      */
/* ============================================================ */

/* Container principal */
#prompt-manager-container {
    max-width: 1000px;
    margin: 20px 0;
    padding: 20px;
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #1a1a2e;
}

/* ============================================================ */
/* HEADER - Accessible                                           */
/* ============================================================ */

.prompt-manager-header {
    padding: 16px 20px;
    background: #f8fafc;
    border-radius: 8px 8px 0 0;
    border-bottom: 2px solid #e2e8f0;
    margin: -20px -20px 16px -20px;
    padding: 1.25rem 2rem;
}

.prompt-manager-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #1a1a2e;
    margin: 0 0 4px 0;
}

.prompt-manager-header p {
    font-size: 1rem;
    color: #475569;
    margin: 0 0 12px 0;
}

.prompt-manager-header .pm-stats {
    background: #ffffff;
    padding: 10px 16px;
    border-radius: 6px;
    border: 1px solid #d1d5db;
    font-size: 0.9rem;
    color: #475569;
    display: flex;
    flex-wrap: wrap;
    gap: 16px 24px;
    margin: 0;
}

.prompt-manager-header .pm-stats span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.prompt-manager-header .pm-stats strong {
    color: #1a1a2e;
    font-weight: 600;
}

/* ============================================================ */
/* ZONE DE GESTION DES PROMPTS - Accessible                     */
/* ============================================================ */

.pm-prompt-zone {
    background: #f8fafc;
    padding: 16px 18px;
    border-radius: 8px;
    margin-bottom: 16px;
    border: 1px solid #d1d5db;
}

.pm-prompt-zone .pm-add-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.pm-prompt-zone .pm-add-row label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.pm-prompt-zone .pm-add-row input {
    padding: 8px 12px;
    border: 2px solid #64748b;
    border-radius: 6px;
    font-size: 0.95rem;
    transition: border-color 0.2s ease;
    background: #ffffff;
    color: #1a1a2e;
    min-height: 44px;
}

.pm-prompt-zone .pm-add-row input:focus {
    border-color: #4f46e5;
    outline: 3px solid rgba(79, 70, 229, 0.3);
    outline-offset: 2px;
}

.pm-prompt-zone .pm-add-row input#pm-new-label {
    flex: 1;
    min-width: 150px;
}

.pm-prompt-zone .pm-add-row input#pm-new-text {
    flex: 2;
    min-width: 200px;
}

.pm-prompt-zone .pm-hint {
    font-size: 0.85rem;
    color: #475569;
    margin: 4px 0 0 0;
}

/* ============================================================ */
/* LISTE DES PROMPTS - Accessible                               */
/* ============================================================ */

.pm-prompt-list {
    margin-top: 12px;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #ffffff;
}

.pm-prompt-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid #e2e8f0;
}

.pm-prompt-item:last-child {
    border-bottom: none;
}

.pm-prompt-item .pm-prompt-label {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    overflow: hidden;
}

.pm-prompt-item .pm-prompt-label strong {
    color: #1a1a2e;
    font-size: 0.9rem;
    white-space: nowrap;
}

.pm-prompt-item .pm-prompt-label .pm-prompt-preview {
    color: #475569;
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pm-prompt-item .pm-prompt-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

/* ============================================================ */
/* BOUTONS - Accessibles (WCAG 2.1 AA)                          */
/* ============================================================ */

.pm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 20px;
    border: 2px solid transparent;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px;
    text-decoration: none;
    line-height: 1.2;
}

/* Primary */
.pm-btn-primary {
    background: #4f46e5;
    color: #ffffff;
    border-color: #4f46e5;
}

.pm-btn-primary:hover {
    background: #4338ca;
    border-color: #4338ca;
}

.pm-btn-primary:focus-visible {
    outline: 3px solid #4f46e5;
    outline-offset: 3px;
}

/* Success */
.pm-btn-success {
    background: #16a34a;
    color: #ffffff;
    border-color: #16a34a;
}

.pm-btn-success:hover {
    background: #15803d;
    border-color: #15803d;
}

.pm-btn-success:focus-visible {
    outline: 3px solid #16a34a;
    outline-offset: 3px;
}

/* Secondary */
.pm-btn-secondary {
    background: #f1f5f9;
    color: #1a1a2e;
    border-color: #64748b;
}

.pm-btn-secondary:hover {
    background: #e2e8f0;
    border-color: #475569;
}

.pm-btn-secondary:focus-visible {
    outline: 3px solid #64748b;
    outline-offset: 3px;
}

/* Danger */
.pm-btn-danger {
    background: #fee2e2;
    color: #991b1b;
    border-color: #991b1b;
}

.pm-btn-danger:hover {
    background: #fecaca;
}

.pm-btn-danger:focus-visible {
    outline: 3px solid #991b1b;
    outline-offset: 3px;
}

/* Small */
.pm-btn-sm {
    padding: 4px 12px;
    font-size: 0.85rem;
    min-height: 34px;
}

/* Disabled */
.pm-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.pm-btn:disabled:hover {
    transform: none !important;
    box-shadow: none !important;
}

/* ============================================================ */
/* CHAT / MESSAGES - Accessible                                 */
/* ============================================================ */

.pm-chat {
    border: 1px solid #d1d5db;
    border-radius: 8px;
    overflow: hidden;
}

.pm-messages {
    max-height: 300px;
    overflow-y: auto;
    padding: 12px 16px;
    background: #fafafa;
}

.pm-messages:focus-visible {
    outline: 2px solid #4f46e5;
    outline-offset: 2px;
}

.pm-message {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 0.95rem;
    line-height: 1.7;
}

.pm-message.bot {
    background: #ffffff;
    border-left: 4px solid #4f46e5;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.pm-message.user {
    background: #eef2ff;
    border-left: 4px solid #4f46e5;
}

.pm-message .message-content {
    color: #1a1a2e;
}

.pm-message .message-content strong {
    color: #1a1a2e;
    font-weight: 700;
}

.pm-message .message-content h1,
.pm-message .message-content h2,
.pm-message .message-content h3 {
    margin: 8px 0 4px 0;
    color: #1a1a2e;
}

.pm-message .message-content h1 { font-size: 1.3rem; }
.pm-message .message-content h2 { font-size: 1.15rem; }
.pm-message .message-content h3 { font-size: 1rem; }

.pm-message .message-content ul,
.pm-message .message-content ol {
    margin: 4px 0 8px 0;
    padding-left: 24px;
}

.pm-message .message-content li {
    margin: 2px 0;
}

.pm-message .message-content a {
    color: #4f46e5;
    text-decoration: underline;
}

.pm-message .message-content a:hover {
    color: #4338ca;
}

.pm-message .message-content a:focus-visible {
    outline: 2px solid #4f46e5;
    outline-offset: 2px;
}

.pm-message .message-content code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.9rem;
}

.pm-message .message-content pre {
    background: #f1f5f9;
    padding: 10px 14px;
    border-radius: 4px;
    overflow-x: auto;
    font-size: 0.9rem;
    margin: 6px 0;
    border: 1px solid #d1d5db;
}

/* ============================================================ */
/* INPUT AREA - Accessible                                      */
/* ============================================================ */

.pm-input-area {
    padding: 12px 16px;
    background: #ffffff;
    border-top: 1px solid #d1d5db;
}

.pm-input-area .pm-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

/* Sélecteur accessible */
.pm-prompt-select {
    padding: 8px 12px;
    border: 2px solid #64748b;
    border-radius: 6px;
    font-size: 0.95rem;
    background: #ffffff;
    cursor: pointer;
    flex: 1;
    min-width: 180px;
    min-height: 44px;
    transition: border-color 0.2s ease;
    color: #1a1a2e;
}

.pm-prompt-select:hover {
    border-color: #4f46e5;
}

.pm-prompt-select:focus {
    border-color: #4f46e5;
    outline: 3px solid rgba(79, 70, 229, 0.3);
    outline-offset: 2px;
}

.pm-prompt-select:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Textarea accessible */
.pm-input {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #64748b;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    resize: vertical;
    min-height: 80px;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
    color: #1a1a2e;
    background: #ffffff;
}

.pm-input:focus {
    border-color: #4f46e5;
    outline: 3px solid rgba(79, 70, 229, 0.3);
    outline-offset: 2px;
}

.pm-input::placeholder {
    color: #94a3b8;
}

/* ============================================================ */
/* PREVIEW AREA - Accessible                                    */
/* ============================================================ */

.pm-prompt-preview-area {
    background: #f8fafc;
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 8px;
    border: 1px solid #d1d5db;
    display: none;
}

.pm-prompt-preview-area .pm-preview-label {
    font-size: 0.85rem;
    color: #475569;
    margin-bottom: 4px;
}

.pm-prompt-preview-area .pm-preview-label strong {
    color: #1a1a2e;
}

.pm-prompt-preview-area .pm-preview-text {
    font-size: 0.9rem;
    padding: 8px 10px;
    background: #ffffff;
    border-radius: 4px;
    max-height: 80px;
    overflow-y: auto;
    border: 1px solid #d1d5db;
    color: #1a1a2e;
}

.pm-prompt-preview-area .pm-preview-length {
    font-size: 0.85rem;
    color: #475569;
    margin-top: 4px;
}

/* ============================================================ */
/* STATUS - Accessible                                          */
/* ============================================================ */

.pm-status {
    font-size: 0.95rem;
    padding: 6px 0;
    color: #475569;
    min-height: 28px;
}

.pm-status[role="status"] {
    border: 0;
    clip: rect(0 0 0 0);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
}

.pm-status.visible {
    position: relative;
    clip: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    width: auto;
}

.pm-status.loading {
    color: #4f46e5;
}

.pm-status.success {
    color: #16a34a;
}

.pm-status.error {
    color: #991b1b;
}

.pm-status.warning {
    color: #b45309;
}

/* ============================================================ */
/* SPINNER - Accessible                                         */
/* ============================================================ */

.pm-spinner {
    display: none;
    width: 24px;
    height: 24px;
    border: 3px solid #e2e8f0;
    border-top-color: #4f46e5;
    border-radius: 50%;
    animation: pm-spin 0.6s linear infinite;
    vertical-align: middle;
}

.pm-spinner.active {
    display: inline-block;
}

.pm-spinner[aria-hidden="true"] {
    display: none;
}

@keyframes pm-spin {
    to { transform: rotate(360deg); }
}

/* ============================================================ */
/* DEBUG - Accessible (admin only)                              */
/* ============================================================ */

.pm-debug {
    margin-top: 12px;
    padding: 10px 14px;
    background: #f8fafc;
    border-radius: 6px;
    border: 1px solid #d1d5db;
    font-size: 0.85rem;
    font-family: monospace;
    max-height: 150px;
    overflow-y: auto;
}

.pm-debug strong {
    color: #475569;
    font-weight: 700;
}

.pm-debug .debug-line .time {
    color: #64748b;
    margin-right: 8px;
}

.pm-debug .debug-line .success {
    color: #16a34a;
}

.pm-debug .debug-line .error {
    color: #991b1b;
}

.pm-debug .debug-line .warning {
    color: #b45309;
}

.pm-debug .debug-line .info {
    color: #475569;
}

/* ============================================================ */
/* FOCUS VISIBLE - Accessible                                   */
/* ============================================================ */

*:focus-visible {
    outline: 3px solid #4f46e5;
    outline-offset: 2px;
}

/* ============================================================ */
/* SCROLLBAR - Accessible                                       */
/* ============================================================ */

.pm-messages::-webkit-scrollbar,
.pm-prompt-list::-webkit-scrollbar,
.pm-debug::-webkit-scrollbar,
.pm-preview-text::-webkit-scrollbar {
    width: 8px;
}

.pm-messages::-webkit-scrollbar-track,
.pm-prompt-list::-webkit-scrollbar-track,
.pm-debug::-webkit-scrollbar-track,
.pm-preview-text::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.pm-messages::-webkit-scrollbar-thumb,
.pm-prompt-list::-webkit-scrollbar-thumb,
.pm-debug::-webkit-scrollbar-thumb,
.pm-preview-text::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 4px;
}

.pm-messages::-webkit-scrollbar-thumb:hover,
.pm-prompt-list::-webkit-scrollbar-thumb:hover,
.pm-debug::-webkit-scrollbar-thumb:hover,
.pm-preview-text::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* ============================================================ */
/* RESPONSIVE - Accessible                                      */
/* ============================================================ */

@media (max-width: 768px) {
    #prompt-manager-container {
        padding: 12px;
    }
    
    .prompt-manager-header {
        margin: -12px -12px 12px -12px;
        padding: 1rem 1.25rem;
    }
    
    .prompt-manager-header .pm-stats {
        flex-direction: column;
        gap: 6px;
    }
    
    .pm-prompt-zone .pm-add-row {
        flex-direction: column;
    }
    
    .pm-prompt-zone .pm-add-row input {
        width: 100%;
    }
    
    .pm-input-area .pm-row {
        flex-direction: column;
    }
    
    .pm-prompt-select {
        width: 100%;
    }
    
    .pm-prompt-item {
        flex-wrap: wrap;
        gap: 4px;
    }
    
    .pm-prompt-item .pm-prompt-label {
        width: 100%;
    }
    
    .pm-prompt-item .pm-prompt-label .pm-prompt-preview {
        max-width: 100%;
    }
    
    .pm-btn {
        min-height: 44px;
        padding: 8px 16px;
    }
}

@media (max-width: 480px) {
    #prompt-manager-container {
        padding: 10px;
    }
    
    .prompt-manager-header {
        margin: -10px -10px 10px -10px;
        padding: 0.75rem 1rem;
    }
    
    .prompt-manager-header h3 {
        font-size: 1.1rem;
    }
    
    .pm-messages {
        padding: 8px 10px;
        max-height: 200px;
    }
    
    .pm-input-area {
        padding: 8px 10px;
    }
    
    .pm-input {
        font-size: 0.9rem;
        min-height: 60px;
    }
    
    .pm-btn {
        width: 100%;
        justify-content: center;
    }
    
    .pm-prompt-item .pm-prompt-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

/* ============================================================ */
/* IMPRESSION - Accessible                                      */
/* ============================================================ */

@media print {
    #prompt-manager-container {
        border: 1px solid #000;
        background: #fff;
    }
    
    .pm-btn {
        border: 1px solid #000;
        background: #fff !important;
        color: #000 !important;
    }
    
    .pm-debug {
        display: none !important;
    }
}

/* ============================================================ */
/* RÉDUCTION DE MOUVEMENT - Accessible                          */
/* ============================================================ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .pm-spinner {
        animation: none;
        border-top-color: #4f46e5;
    }
}

/* ============================================================ */
/* CONTRAST ÉLEVÉ - Accessible                                  */
/* ============================================================ */

@media (prefers-contrast: high) {
    #prompt-manager-container {
        border-width: 2px;
        border-color: #000;
    }
    
    .pm-btn {
        border-width: 2px;
    }
    
    .pm-btn-primary {
        background: #000;
        color: #fff;
        border-color: #000;
    }
    
    .pm-btn-primary:hover {
        background: #1a1a2e;
    }
    
    .pm-btn-secondary {
        background: #fff;
        color: #000;
        border-color: #000;
    }
    
    .pm-btn-secondary:hover {
        background: #f1f5f9;
    }
    
    .pm-prompt-select,
    .pm-input {
        border-width: 2px;
        border-color: #000;
    }
    
    .pm-message.bot {
        border-left-width: 6px;
    }
}