/* ==========================================================================
   1. VARIÁVEIS E CONFIGURAÇÕES GLOBAIS
   ========================================================================== */
:root {
    --primary: #1a2a3a;      
    --accent: #4a6fa5;       
    --success: #2d6a4f;      
    --danger: #a4161a;       
    --bg: #2d3436;           
    --surface: #ffffff;      
    --text: #2d3436;         
    --text-light: #636e72;   
    --border: #e2e8f0;       
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.25); 
}

* { box-sizing: border-box; }

body { 
    font-family: 'Inter', system-ui, -apple-system, sans-serif; 
    background-color: var(--bg); 
    color: var(--text); 
    margin: 0; 
    line-height: 1.7; 
}

.container { 
    max-width: 1200px; 
    margin: 50px auto; 
    background: var(--surface); 
    padding: 50px; 
    border-radius: 12px; 
    box-shadow: var(--shadow);
}

/* ==========================================================================
   2. HEADER E LOGO
   ========================================================================== */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

header > div:first-child {
    direction: ltr !important; 
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 250px;
}

header h1 {
    margin: 0;
    font-size: 1.8rem;
    color: var(--primary);
}

header svg { 
    overflow: visible; 
    flex-shrink: 0;
    max-width: 100%;
    height: auto;
}

/* ==========================================================================
   3. FORMULÁRIOS E INPUTS
   ========================================================================== */
.form-card, .card-edit { 
    background: #fcfcfc; 
    border: 1px solid var(--border); 
    padding: 30px; 
    border-radius: 8px;
    margin-bottom: 20px;
}

.form-grid { 
    display: flex; 
    flex-direction: column; 
    gap: 30px; 
}

.form-row { 
    display: flex; 
    gap: 20px; 
    margin-bottom: 20px; 
    flex-wrap: wrap;
}

.form-group { 
    display: flex; 
    flex-direction: column; 
    gap: 6px; 
    flex: 1; 
    min-width: 150px; 
}

.form-group label { 
    font-size: 0.85rem; 
    font-weight: 700; 
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input[type="text"], 
input[type="color"], 
input[type="email"],
input[type="url"],
input[type="number"],
textarea, 
select {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 1rem;
    width: 100%;
    font-family: inherit;
    transition: all 0.2s ease;
}

input:focus, 
textarea:focus, 
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(74, 111, 165, 0.1);
}

input[type="color"] { 
    height: 50px; 
    cursor: pointer;
    padding: 5px;
}

textarea {
    resize: vertical;
    min-height: 120px;
}

/* Seção de Upload Drag & Drop */
.upload-section {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 40px;
    text-align: center;
    background: #f9fafb;
    cursor: pointer;
    transition: all 0.3s ease;
}

.upload-section:hover { 
    border-color: var(--accent); 
    background: #f0f4f8; 
}

.upload-section.dragover {
    border-color: var(--accent);
    background: #e8f0f7;
}

.upload-section input[type="file"] {
    display: none;
}

.upload-section label {
    display: block;
    cursor: pointer;
    color: var(--primary);
    font-weight: 600;
    font-size: 1rem;
    margin: 0;
}

.upload-section label::before {
    content: "📄 ";
    font-size: 1.5rem;
    display: block;
    margin-bottom: 10px;
}

/* ==========================================================================
   4. BOTÕES E INTERAÇÕES
   ========================================================================== */
.btn-primary { 
    background: var(--primary); 
    color: white; 
    padding: 12px 24px; 
    border-radius: 6px; 
    text-decoration: none; 
    font-weight: bold; 
    border: none; 
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.btn-primary:hover {
    background: #0f1a2a;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(26, 42, 58, 0.3);
}

.btn-outline { 
    border: 1px solid var(--border); 
    color: var(--primary); 
    padding: 10px 16px; 
    border-radius: 6px; 
    text-decoration: none; 
    background: white;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-outline:hover {
    border-color: var(--primary);
    background: #f9fafb;
}

/* Container da célula de ações */
.actions-cell {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 0;
    width: 100%;
}

/* Base Comum para os botões de ação */
.btn-action {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    text-decoration: none;
    transition: all 0.2s ease;
    border: 1px solid;
    background: white;
    cursor: pointer;
    min-height: 32px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Cores específicas */
.btn-analyze { 
    border-color: var(--success); 
    color: var(--success);
}

.btn-analyze:hover { 
    background: var(--success); 
    color: white;
}

.btn-edit-outline { 
    border-color: var(--accent); 
    color: var(--accent);
}

.btn-edit-outline:hover { 
    background: var(--accent); 
    color: white;
}

.btn-delete-outline { 
    border-color: var(--danger); 
    color: var(--danger);
}

.btn-delete-outline:hover { 
    background: var(--danger); 
    color: white;
}

/* Ícone dos botões */
.btn-action .icon {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
}

.btn-action .btn-text {
    display: none;
}

/* Mostrar texto em telas maiores */
@media (min-width: 768px) {
    .btn-action {
        padding: 8px 14px;
        font-size: 0.8rem;
        min-height: 36px;
    }

    .btn-action .btn-text {
        display: inline;
    }

    .btn-action .icon {
        font-size: 1rem;
    }

    .actions-cell {
        flex-direction: row;
        justify-content: flex-end;
        gap: 8px;
        padding: 10px;
    }
}

.btn-edit-tag { 
    text-decoration: none;
    font-size: 0.75rem;
    background: #f1f5f9;
    color: #475569;
    padding: 8px 12px;
    border-radius: 4px;
    border: 1px solid var(--border);
    transition: all 0.2s ease;
    font-weight: 700;
    cursor: pointer;
}

.btn-edit-tag:hover {
    background: var(--border);
    color: var(--primary);
}

.delete-btn { 
    color: var(--danger); 
    text-decoration: none; 
    font-size: 0.8rem; 
    font-weight: 600; 
    padding: 6px 12px;
    cursor: pointer;
}

/* ==========================================================================
   5. RELATÓRIO: CATEGORIAS E CITAÇÕES
   ========================================================================== */
.category-header { 
    background: white;
    padding: 25px;
    border-radius: 12px;
    border-left: 10px solid;
    margin-bottom: 25px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.category-header h2 {
    margin: 0;
    text-transform: uppercase;
    font-size: 1.5rem;
}

.tag-grid { 
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.tag-card {
    background: white;
    border: 1px solid var(--border);
    border-top: 4px solid;
    padding: 20px;
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    cursor: pointer;
    display: flex;
    flex-direction: column;
}

.tag-card h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--primary);
    margin-bottom: 10px;
}

.tag-card-info {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: auto;
}

.tag-card:hover { 
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.filter-bar { 
    display: flex;
    align-items: flex-end;
    gap: 15px;
    background: #f9fafb;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 25px;
    border: 1px solid var(--border);
    flex-wrap: wrap;
}

.filter-bar > div {
    flex: 1;
    min-width: 200px;
}

.filter-bar label {
    font-size: 0.7rem;
    font-weight: 700;
    display: block;
    margin-bottom: 6px;
    color: var(--primary);
    text-transform: uppercase;
}

.filter-bar select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 5px;
    background-color: white;
    font-size: 0.95rem;
    box-sizing: border-box;
    transition: border-color 0.2s ease;
}

.filter-bar select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(74, 111, 165, 0.1);
}

/* Citacao Card */
.citacao-card {
    background: white;
    border: 1px solid var(--border);
    border-left: 5px solid;
    padding: 20px;
    margin-bottom: 20px;
    border-radius: 8px;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.2s ease;
}

.citacao-card:hover {
    box-shadow: var(--shadow);
}

.citacao-text { 
    font-style: italic;
    font-size: 1rem;
    color: #333;
    line-height: 1.6;
    margin-bottom: 15px;
    text-align: justify;
}

.memo-box { 
    margin: 15px 0 0 0;
    padding: 15px;
    background: #fffde7;
    border-radius: 8px;
    border-left: 5px solid #fadb14;
}

.memo-box strong { 
    display: block;
    font-size: 0.7rem;
    color: #bc5100;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.memo-box p {
    margin: 0;
    color: #5d4037;
    line-height: 1.5;
}

.apa-ref { 
    font-size: 0.85rem;
    color: var(--text-light);
    border-top: 1px solid #eee;
    padding-top: 12px;
    line-height: 1.5;
    word-break: break-word;
}

/* ==========================================================================
   6. SISTEMA DE CÓPIA E IDIOMAS
   ========================================================================== */
.copy-controls {
    position: absolute;
    top: 15px;
    right: 15px;
    display: flex;
    gap: 10px;
    align-items: center;
}

.copy-menu-trigger { 
    position: relative;
    display: inline-block;
}

.copy-menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.copy-menu-toggle:hover {
    background: #3a5a8f;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(74, 111, 165, 0.3);
}

.copy-menu-toggle::after {
    content: ' ▼';
    font-size: 0.6rem;
}

.copy-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: var(--shadow);
    z-index: 100;
    min-width: 160px;
    margin-top: 5px;
}

.copy-menu.active { 
    display: block;
}

.copy-menu-item { 
    display: block;
    width: 100%;
    padding: 10px 15px;
    border: none;
    background: transparent;
    text-align: left;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    border-bottom: 1px solid #f0f0f0;
    color: var(--primary);
    transition: all 0.2s ease;
}

.copy-menu-item:last-child {
    border-bottom: none;
}

.copy-menu-item:hover {
    background: #f9fafb;
    padding-left: 20px;
}

.copy-menu-item.bibtex::before {
    content: '{ } ';
    margin-right: 4px;
    color: var(--accent);
    font-weight: bold;
}

.copy-menu-item.apa::before {
    content: '🔤 ';
}

.copy-menu-item.plain::before {
    content: '📄 ';
}

.language-switcher { 
    display: flex;
    gap: 6px;
    margin-bottom: 20px;
    padding: 0;
    border-bottom: none;
}

.lang-btn {
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-light);
    background: transparent;
    padding: 6px 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.lang-btn:hover {
    background: #f0f4f8;
    color: var(--primary);
}

.lang-btn.active { 
    background: #e8f0f7;
    color: var(--primary);
    font-weight: bold;
}

.copy-tooltip {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--success);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    z-index: 9999;
    font-weight: bold;
    box-shadow: var(--shadow);
    animation: slideUp 0.3s ease;
}

.copy-tooltip.exit {
    animation: slideDown 0.3s ease forwards;
}

@keyframes slideUp {
    from {
        transform: translateY(100px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideDown {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(100px);
        opacity: 0;
    }
}

/* ==========================================================================
   7. TABELAS E IMPRESSÃO
   ========================================================================== */
table { 
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 30px 0;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

thead {
    background: #f8fafc;
    border-bottom: 2px solid var(--primary);
}

th { 
    padding: 18px 15px;
    text-align: left;
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--primary);
    letter-spacing: 0.5px;
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background-color 0.2s ease;
}

tbody tr:hover {
    background-color: #f9fafb;
}

tbody tr:last-child {
    border-bottom: none;
}

td { 
    padding: 18px 15px;
    vertical-align: middle;
}

/* Tag Badge */
.tag-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    color: white;
    margin: 2px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 50px 20px;
    background: white;
    border-radius: 8px;
    border: 1px dashed var(--border);
    color: var(--text-light);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 10px;
}

/* ==========================================================================
   8. RESPONSIVIDADE
   ========================================================================== */
@media (max-width: 1024px) {
    .container {
        padding: 30px;
        margin: 30px auto;
    }

    header {
        padding-bottom: 15px;
    }

    .tag-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

@media (max-width: 768px) {
    .container {
        padding: 20px;
        margin: 20px;
    }

    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    header > div:first-child {
        width: 100%;
        justify-content: center;
    }

    header > div:last-child {
        width: 100%;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .form-row {
        flex-direction: column;
    }

    .filter-bar {
        flex-direction: column;
        gap: 12px;
    }

    .filter-bar > div {
        width: 100%;
        min-width: unset;
    }

    .filter-bar button {
        width: 100%;
    }

    .tag-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

    .category-header {
        flex-direction: column;
        align-items: flex-start;
    }

    td {
        padding: 12px 10px;
        font-size: 0.9rem;
    }

    th {
        padding: 12px 10px;
        font-size: 0.65rem;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 15px;
        margin: 10px;
    }

    header {
        margin-bottom: 20px;
    }

    header h1 {
        font-size: 1.2rem;
    }

    .tag-grid {
        grid-template-columns: 1fr;
    }

    table {
        font-size: 0.85rem;
    }

    td {
        padding: 10px 8px;
    }

    th {
        padding: 10px 8px;
    }

    .btn-action {
        padding: 6px 10px;
        font-size: 0.65rem;
    }

    .copy-tooltip {
        left: 10px;
        right: 10px;
        max-width: unset;
    }

    .citacao-card {
        padding: 15px;
    }

    .citacao-text {
        font-size: 0.9rem;
    }

    .apa-ref {
        font-size: 0.75rem;
    }
}

/* ==========================================================================
   9. SUPORTE RTL (ÁRABE)
   ========================================================================== */
html[dir="rtl"] header {
    flex-direction: row-reverse;
}

html[dir="rtl"] .category-header {
    border-left: none;
    border-right: 10px solid;
    flex-direction: row-reverse;
}

html[dir="rtl"] .citacao-card {
    border-left: none;
    border-right: 5px solid;
}

html[dir="rtl"] .citacao-text {
    text-align: right;
}

html[dir="rtl"] .memo-box {
    border-left: none;
    border-right: 5px solid #fadb14;
    text-align: right;
}

html[dir="rtl"] th,
html[dir="rtl"] td {
    text-align: right;
}

html[dir="rtl"] .actions-cell {
    justify-content: flex-start;
}

html[dir="rtl"] .copy-menu {
    right: auto;
    left: 0;
}

html[dir="rtl"] .copy-menu-item:hover {
    padding-left: auto;
    padding-right: 20px;
}

html[dir="rtl"] .tag-card {
    border-top: none;
    border-bottom: 4px solid;
}

html[dir="rtl"] .language-switcher {
    flex-direction: row-reverse;
}

html[dir="rtl"] .upload-section label::before {
    content: " 📄";
    margin-left: 10px;
    margin-bottom: 0;
}

html[dir="rtl"] header svg {
    margin-left: auto;
    margin-right: 0;
}

/* ==========================================================================
   10. PRINT STYLES
   ========================================================================== */
@media print {
    .language-switcher,
    header,
    .filter-bar,
    .copy-controls,
    .delete-btn,
    .btn-edit-tag,
    .btn-outline,
    .btn-action {
        display: none !important;
    }

    .container {
        box-shadow: none;
        padding: 0;
    }

    .citacao-card {
        page-break-inside: avoid;
        border: 1px solid #ddd;
        box-shadow: none;
    }

    body {
        background: white;
    }

    table {
        box-shadow: none;
    }

    tbody tr:hover {
        background-color: transparent;
    }
}

/* Tags de Estado do PDF */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: bold;
    margin-bottom: 5px;
}
.status-pdf { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.status-no-pdf { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }

/* Alerta de topo */
.alert-box {
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 8px;
    text-align: center;
    font-weight: 600;
    animation: fadeIn 0.5s ease-in;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

.badge-pdf-sim {
    background-color: #d1fae5;
    color: #065f46;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.badge-pdf-nao {
    background-color: #f3f4f6;
    color: #6b7280;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: bold;
}

.result-abstract {
    font-size: 0.85rem;
    color: #6b7280; /* Um cinza suave */
    margin-top: 8px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-style: italic;
}

/* No teu style dentro do analisar.php */

.pdf-page { 
    position: relative; 
    margin-bottom: 25px; 
    box-shadow: 0 8px 20px rgba(0,0,0,0.3); 
    background: white; 
}

/* Esta é a parte que resolve o texto visível */
.textLayer {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    opacity: 0.2; /* Podes colocar 0 para ficar totalmente invisível */
    line-height: 1.0;
}

.textLayer span {
    color: transparent; /* Torna o texto invisível mas selecionável */
    position: absolute;
    white-space: pre;
    cursor: text;
    transform-origin: 0% 0%;
}

/* Melhora a cor de quando selecionas o texto */
.textLayer ::selection {
    background: rgba(0, 102, 255, 0.3);
}