/**
 * section-container.css - Container de Seção
 * BO Inteligente v1.0
 */

/* ============================================ */
/* CONTAINER DE SEÇÃO - ESTILOS */
/* ============================================ */

.section-container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Durante in_progress: container tem altura fixa para o chat ter scroll */
/* v0.16.0: Ajustado para progress strip menor (44px vs ~70px antigo) */
.section-container[data-state="in_progress"] {
    min-height: calc(100dvh - 115px);
    /* height: calc(100vh - 170px); */
    /* overflow: hidden; */
}

/* Durante completed: container volta ao tamanho do conteúdo */
.section-container[data-state="completed"],
.section-container[data-state="skipped"] {
    height: auto;
    overflow: visible;
}

.section-container--hidden {
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    position: absolute;
}

.section-container--visible {
    opacity: 1;
    transform: translateY(0);
}

/* Botão para expandir/colapsar chat */
.section-chat-toggle {
    width: 100%;
    padding: 14px 24px;
    background: #f8fafc;
    border: none;
    border-bottom: 1px solid #e5e7eb;
    text-align: left;
    cursor: pointer;
    font-weight: 600;
    color: #1e3a5f;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
    flex: 0 0 auto;
}

/* Área de chat - Accordion (colapsável) */
.section-chat {
    padding: 24px;
    padding-left: 24px;
    /* Espaço para o botão de editar (30px + margem) */
    display: none;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    overflow-x: visible;
    /* Permitir que botão de editar apareça fora do container */
    min-height: 0;
}

/* Durante in_progress: chat ocupa espaço com flex e scroll */
.section-container[data-state="in_progress"] .section-chat {
    flex: 1;
    display: flex;
    /* Garante que aparece mesmo sem --expanded */
}

.section-chat--expanded {
    display: flex;
    min-height: 400px;
}

.section-chat-toggle:hover {
    background: #f1f5f9;
}

.section-chat-toggle::before {
    content: '▼';
    font-size: 12px;
    transition: transform 0.2s;
}

.section-chat-toggle--collapsed::before {
    transform: rotate(-90deg);
}

/* Mensagem do bot */
.chat-message--bot {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: 75%;
}

.chat-message__bubble--bot {
    background: #F3F4F6;
    border: 1px solid #E5E7EB;
    border-radius: 16px 16px 16px 4px;
    padding: 14px 18px;
    color: #374151;
}

.chat-message__text {
    font-size: 15px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    text-wrap: pretty;
}

.chat-message__hint {
    margin-top: 8px;
    font-size: 13px;
    color: #6b7280;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-message__hint::before {
    content: '💡';
}

/* Question ID Badge */
.question-id {
    display: inline-block;
    padding: 4px 8px;
    margin-right: 6px;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 600;
    background-color: #f3f4f6;
    border: 1px solid #e5e7eb;
    color: #6b7280;
    white-space: nowrap;
}

/* Mensagem do usuário */
.chat-message--user {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    max-width: 75%;
    align-self: flex-end;
}

.chat-message__bubble--user {
    position: relative;
    background: #2563EB;
    border-radius: 16px 16px 4px 16px;
    padding: 14px 30px 14px 18px;
    color: white;
}

/* Área de input */
.section-input {
    padding: 16px 20px;
    border-top: 1px solid #e5e7eb;
    background: #f8fafc;
    flex: 0 0 auto;
}

.section-input__form {
    display: flex;
    gap: 12px;
}

.section-input__field {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    font-size: 15px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.section-input__field:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.section-input__field::placeholder {
    color: #9ca3af;
}

.section-input__button {
    padding: 12px 24px;
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.2s;
}

.section-input__button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.3);
}

.section-input__button:active {
    transform: translateY(0);
}

.section-input__button:disabled {
    background: #d1d5db;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Área de texto gerado */
.section-generated {
    padding: 20px;
    background: #F0FDF4;
    border-top: 2px solid #10B981;
}

.section-generated__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.section-generated__title {
    font-weight: 600;
    color: #166534;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-generated__actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.section-generated__copy {
    padding: 8px 16px;
    background: #16a34a;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.section-generated__copy:hover {
    background: #15803d;
}

.section-generated__retry {
    padding: 8px 16px;
    background: #d97706;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.section-generated__retry:hover {
    background: #b45309;
}

.section-generated__retry:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.section-generated__text {
    background: white;
    border: 1px solid #86efac;
    border-radius: 8px;
    padding: 16px;
    font-size: 14px;
    line-height: 1.7;
    color: #374151;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Área de transição (próxima seção) */
.section-transition {
    padding: 12px;
    background: #f8fafc;
    border-top: 1px solid #e5e7eb;
    border: 2px dashed #cbd5e1;
    border-radius: 12px;
    margin: 16px;
}

.section-transition__preview {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px;
    background: white;
    margin-bottom: 8px;
}

.section-transition__preview-emoji {
    font-size: 32px;
}

.section-transition__preview-info {
    text-align: center;
}

.section-transition__preview-label {
    font-size: 12px;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.section-transition__preview-name {
    font-size: 16px;
    font-weight: 600;
    color: #1e3a5f;
}

.section-transition__question {
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    color: #1e3a5f;
    padding: 8px 12px;
    margin: 6px 0;
}

.section-transition__hint {
    text-align: center;
    font-size: 13px;
    color: #6b7280;
    margin: 2px 0 4px;
}

.section-transition__hint::before {
    content: '💡 ';
}

.section-transition__buttons {
    display: flex;
    flex-direction: row-reverse;
    gap: 12px;
    margin-top: 8px;
    width: 90%;
    margin-left: auto;
    margin-right: auto;
}

.section-transition__btn {
    flex: 1;
    padding: 14px 20px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.1s, box-shadow 0.2s;
}

.section-transition__btn:hover {
    transform: translateY(-2px);
}

.section-transition__btn:active {
    transform: translateY(0);
}

.section-transition__btn--start {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

.section-transition__btn--start:hover {
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.section-transition__btn--skip {
    background: #f3f4f6;
    color: #6b7280;
    border: 2px solid #e5e7eb;
}

.section-transition__btn--skip:hover {
    background: #e5e7eb;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Modo leitura (seção anterior) */
.section-container--readonly .section-input {
    display: none;
}

.section-container--readonly .section-chat {
    padding-bottom: 20px;
}

.section-readonly-notice {
    padding: 12px 20px;
    background: #fef3c7;
    border-top: 1px solid #fcd34d;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
}

.section-readonly-notice__text {
    color: #92400e;
    font-size: 14px;
}

/* Loading state */
.section-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #6b7280;
}

.section-loading__spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 12px;
}

/* Mensagem para seção pulada (chat vazio) */
.section-skipped-message {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px 20px;
    color: #6b7280;
    font-size: 16px;
    font-weight: 500;
    text-align: center;
}

.section-skipped-message span {
    font-size: 20px;
}

/* Mensagem de skip (pre tag) */
.section-skip-message {
    padding: 16px 20px;
    margin: 16px;
    background: #f9fafb;
    border-left: 3px solid #d1d5db;
    color: #6b7280;
    font-size: 0.95rem;
    font-weight: 400;
    font-family: inherit;
    white-space: pre-wrap;
    word-wrap: break-word;
    text-align: left;
}

/* v0.13.9: Container para skip message + botão unlock */
.section-skip-container {
    padding: 16px;
}

/* v0.13.9: Botão unlock (sempre visível) */
.section-unlock-btn {
    margin: 0 16px 16px 16px;
    padding: 10px 18px;
    background: transparent;
    border: 1px solid #3b82f6;
    color: #3b82f6;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
    width: calc(100% - 32px);
    text-align: center;
}

.section-unlock-btn:hover {
    background: #3b82f6;
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.section-unlock-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(59, 130, 246, 0.3);
}

/* Section colors removed in Phase 1 redesign - unified palette */

/* ========================================
   EDIT FUNCTIONALITY
   ======================================== */

/* Edit button on user messages */
.chat-message--user {
    position: relative;
}

.chat-message__edit-btn {
    position: absolute;
    top: 50%;
    right: 4px;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
    transition: opacity 0.2s, background 0.2s;
    color: rgba(255, 255, 255, 0.9);
    padding: 0;
}

.chat-message__edit-btn:hover {
    background: rgba(255, 255, 255, 0.35);
    color: white;
    opacity: 1;
}

/* Hide edit button when section is skipped (completed sections are editable since v2.0) */
.section-container[data-state="skipped"] .chat-message__edit-btn {
    display: none;
}

/* Edit mode container - compound selector for higher specificity than .chat-message--user */
.chat-message.chat-message--editing {
    max-width: 85%;
    min-width: 75%;
    align-self: flex-end;
}

.chat-message__edit-container {
    background: #f8fafc;
    border: 2px solid #3b82f6;
    border-radius: 12px;
    padding: 12px;
    width: 100%;
}

.chat-message__edit-container .input-component {
    padding: 10px;
    border-top: none;
}

.chat-message__edit-input {
    /* margin-bottom: 12px; */
}

/* For text edits - expandable textarea */
.chat-message__edit-input .text-input__field {
    max-height: 200px;
    overflow-y: auto;
}

.chat-message__edit-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.chat-message__edit-save {
    padding: 8px 16px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
}

.chat-message__edit-save:hover {
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
    transform: translateY(-1px);
}

.chat-message__edit-save:active {
    transform: translateY(0);
}

.chat-message__edit-cancel {
    padding: 8px 16px;
    background: #f3f4f6;
    color: #6b7280;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
}

.chat-message__edit-cancel:hover {
    background: #e5e7eb;
    color: #374151;
}

.chat-message__edit-error {
    margin-top: 8px;
    padding: 8px 12px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 6px;
    color: #dc2626;
    font-size: 13px;
    display: none;
}

.chat-message__edit-error.show {
    display: block;
}

/* Success feedback */
.chat-message__saved-feedback {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: -30px;
    z-index: 10;
    padding: 6px 12px;
    background: #d1fae5;
    color: #059669;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    animation: feedbackFadeOut 2.5s ease-in-out forwards;
}

@keyframes feedbackFadeOut {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px);
    }

    10% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }

    90% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }

    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(10px);
    }
}

/* --- Typing indicator --- */
.chat-message--typing {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    background: #f3f4f6;
    border-radius: 12px 12px 12px 2px;
    align-self: flex-start;
    min-width: 56px;
    margin-bottom: 4px;
}

.chat-message__typing-dots {
    display: flex;
    gap: 5px;
    align-items: center;
    height: 20px;
}

.chat-message__typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9ca3af;
    animation: typing-bounce 1.4s ease-in-out infinite;
    flex-shrink: 0;
}

.chat-message__typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-message__typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40%            { transform: translateY(-4px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .chat-message__typing-dots span { animation: none; opacity: 0.7; }
}

/* Spinner inline no botão Salvar (edit) */
.btn-spinner {
    display: inline-block;
    width: 13px;
    height: 13px;
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    flex-shrink: 0;
}

.chat-message__edit-save.edit-save--loading {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: not-allowed;
}

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

/* ========================================== */
/* SYNC BANNER — Session desync recovery      */
/* ========================================== */

.section-sync-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.4;
    border-top: 1px solid transparent;
    animation: sync-banner-in 0.25s ease-out both;
}

.section-sync-banner--syncing {
    background-color: #fef3c7;
    color: #92400e;
    border-top-color: #fde68a;
}

.section-sync-banner--failed {
    background-color: #fee2e2;
    color: #991b1b;
    border-top-color: #fecaca;
}

.section-sync-banner--success {
    background-color: #d1fae5;
    color: #065f46;
    border-top-color: #a7f3d0;
}

.section-sync-banner__spinner {
    display: inline-block;
    width: 13px;
    height: 13px;
    border: 2px solid rgba(146, 64, 14, 0.3);
    border-top-color: #92400e;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}

@keyframes sync-banner-in {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    .section-sync-banner { animation: none; }
    .section-sync-banner__spinner { animation: none; opacity: 0.7; }
}