/**
 * FOOTNOTE-MODAL.CSS
 * Estilos para modais de notas de rodapé
 * 
 * Modal de visualização: discreto e delicado (estilo Kindle)
 * Modal de edição: com formulário e botões
 */

/* ============================================
   MODAL BASE
   ============================================ */

.footnote-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Follow theme backgrounds (author box is the closest visual sibling) */
    --footnote-modal-bg: var(--author-box-bg, var(--surface));
    --footnote-modal-border-base: var(--author-box-border-base, var(--surface));
    --footnote-modal-border: color-mix(in srgb, var(--footnote-modal-border-base) 88%, var(--border-ink) 12%);
    --footnote-modal-hairline: color-mix(in srgb, var(--footnote-modal-border-base) 92%, var(--border-ink) 8%);
    --footnote-modal-header-bg: color-mix(in srgb, var(--footnote-modal-bg) 88%, var(--bg) 12%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.footnote-modal--visible {
    opacity: 1;
    pointer-events: all;
}

.footnote-modal--closing {
    opacity: 0;
}

.footnote-modal__backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
}

/* ============================================
   MODAL DE VISUALIZAÇÃO (Estilo Kindle)
   ============================================ */

.footnote-modal--view .footnote-modal__content {
    position: relative;
    max-width: 450px;
    width: 90%;
    max-height: 70vh;
    background: var(--footnote-modal-bg);
    border: 1px solid var(--footnote-modal-border);
    border-radius: 16px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.footnote-modal--view.footnote-modal--visible .footnote-modal__content {
    transform: translateY(0) scale(1);
}

.footnote-modal--view .footnote-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--footnote-modal-hairline);
    background: var(--footnote-modal-header-bg);
}

.footnote-modal__number {
    font-family: var(--font-display);
    font-size: 0.875rem;
    font-weight: var(--weight-bold);
    background: var(--accent);
    color: var(--surface);
    padding: 0.375rem 0.75rem;
    border-radius: 6px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.footnote-modal__close {
    background: transparent;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s ease;
    opacity: 0.7;
}

.footnote-modal__close:hover {
    background: var(--footnote-modal-header-bg);
    opacity: 1;
    transform: scale(1.1);
}

.footnote-modal__close:active {
    transform: scale(0.95);
}

.footnote-modal__close i {
    width: 1.125rem;
    height: 1.125rem;
}

.footnote-modal--view .footnote-modal__body {
    padding: 1.5rem 1.25rem;
    max-height: calc(70vh - 80px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--footnote-modal-border) transparent;
}

.footnote-modal--view .footnote-modal__body::-webkit-scrollbar {
    width: 6px;
}

.footnote-modal--view .footnote-modal__body::-webkit-scrollbar-track {
    background: transparent;
}

.footnote-modal--view .footnote-modal__body::-webkit-scrollbar-thumb {
    background: var(--footnote-modal-border);
    border-radius: 3px;
}

.footnote-modal--view .footnote-modal__body::-webkit-scrollbar-thumb:hover {
    background: var(--hairline);
}

.footnote-modal__text {
    font-size: 0.9375rem;
    line-height: 1.7;
    color: var(--text);
    text-align: left;
}

/* Forçar cores do tema, sobrescrevendo cores inline do Summernote */
.footnote-modal__text * {
    color: inherit;
}

.footnote-modal__text p {
    margin: 0 0 1rem 0;
    color: var(--text);
}

.footnote-modal__text p:last-child {
    margin-bottom: 0;
}

.footnote-modal__text ul,
.footnote-modal__text ol {
    margin: 0.75rem 0;
    padding-left: 1.5rem;
    color: var(--text) !important;
}

.footnote-modal__text li {
    margin: 0.5rem 0;
    color: var(--text) !important;
}

.footnote-modal__text strong {
    font-weight: var(--weight-bold);
    color: var(--heading) !important;
}

.footnote-modal__text em {
    font-style: italic;
    color: var(--text) !important;
    opacity: 0.9;
}

/* Sobrescrever cores inline de elementos específicos */
.footnote-modal__text span,
.footnote-modal__text div,
.footnote-modal__text a {
    color: var(--text) !important;
}

.footnote-modal__text a {
    color: var(--accent) !important;
    text-decoration: underline;
}

.footnote-modal__text a:hover {
    color: var(--accent-hover, var(--accent)) !important;
    opacity: 0.8;
}

/* ============================================
   MODAL DE EDIÇÃO
   ============================================ */

.footnote-modal--edit .footnote-modal__content {
    position: relative;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    background: var(--footnote-modal-bg);
    border: 1px solid var(--footnote-modal-border);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: translateY(20px) scale(0.95);
    transition: transform 0.2s ease;
}

.footnote-modal--edit.footnote-modal--visible .footnote-modal__content {
    transform: translateY(0) scale(1);
}

.footnote-modal--edit .footnote-modal__header {
    padding: 1rem;
}

.footnote-modal__title {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: var(--weight-bold);
    color: var(--heading);
}

.footnote-modal--edit .footnote-modal__body {
    padding: 1rem;
    flex: 1;
    overflow-y: auto;
}

/* Ajustes para Summernote dentro do modal */
.footnote-modal--edit .note-editor {
    border: 1px solid var(--footnote-modal-border);
    border-radius: 6px;
}

.footnote-modal--edit .note-editor .note-editable {
    min-height: 150px;
    max-height: 300px;
    overflow-y: auto;
}

.footnote-modal--edit .note-toolbar {
    background: var(--footnote-modal-header-bg);
    border-bottom: 1px solid var(--footnote-modal-hairline);
}

.footnote-modal__form {
    margin: 0;
}

.footnote-modal__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-top: 1px solid var(--footnote-modal-hairline);
    background: var(--footnote-modal-header-bg);
    gap: 0.5rem;
}

.footnote-modal__footer-actions {
    display: flex;
    gap: 0.5rem;
    margin-left: auto;
}

/* Dark theme adjustments */
[data-theme="dark"] .footnote-modal__backdrop {
    background-color: rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .footnote-modal--view .footnote-modal__content,
[data-theme="dark"] .footnote-modal--edit .footnote-modal__content {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

/* Responsive */
@media (max-width: 768px) {
    .footnote-modal--view .footnote-modal__content,
    .footnote-modal--edit .footnote-modal__content {
        width: 95%;
        max-height: 85vh;
    }
    
    .footnote-modal__footer {
        flex-direction: column;
    }
    
    .footnote-modal__footer-actions {
        width: 100%;
        margin-left: 0;
    }
    
    .footnote-modal__footer-actions .btn {
        flex: 1;
    }
}
