/* Style.css - Design Corporativo Moderno para Faturação Multi-Documento (AGT / Angola) */

/* Importar fontes modernas e legíveis */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
    --primary-color: #0f172a; /* Slate 900 - Azul Escuro Corporativo */
    --primary-hover: #1e293b;
    --accent-color: #2563eb;  /* Azul Destaque */
    --bg-dark: #0f172a;
    --sidebar-bg: #1e293b;
    --text-primary: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --bg-light: #f8fafc;
    --font-heading: 'Plus Jakarta Sans', sans-serif;
    --font-body: 'Inter', sans-serif;
}

body {
    background-color: #f1f5f9;
    font-family: var(--font-body);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

/* Layout Split-Screen */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Painel de Controle (Sidebar) */
.sidebar {
    width: 390px;
    background-color: var(--sidebar-bg);
    color: #f8fafc;
    padding: 2rem 1.5rem;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    overflow-y: auto;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    z-index: 100;
    transition: all 0.3s ease;
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}
.sidebar::-webkit-scrollbar-thumb {
    background-color: #475569;
    border-radius: 3px;
}

.sidebar h3 {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.2rem;
    margin-bottom: 1.25rem;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 1px solid #334155;
    padding-bottom: 0.75rem;
}

.sidebar h3 i {
    color: var(--accent-color);
}

.sidebar-section {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 1.1rem;
    margin-bottom: 1.1rem;
}

.sidebar-section-title {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    margin-bottom: 0.85rem;
    font-weight: 600;
}

.form-label-custom {
    font-size: 0.8rem;
    font-weight: 500;
    color: #cbd5e1;
    margin-bottom: 0.35rem;
}

.form-control-custom {
    background: rgba(15, 23, 42, 0.6) !important;
    border: 1px solid #334155 !important;
    color: #f8fafc !important;
    border-radius: 8px !important;
    font-size: 0.85rem !important;
    padding: 0.45rem 0.65rem !important;
    transition: all 0.2s ease !important;
}

.form-control-custom:focus {
    border-color: var(--accent-color) !important;
    box-shadow: 0 0 0 2px rgba(37, 99, 211, 0.25) !important;
}

.card-item-sidebar {
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid #334155;
    border-radius: 8px;
}

/* Área do Visualizador A4 */
.preview-area {
    margin-left: 390px;
    flex: 1;
    padding: 2.5rem;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    min-height: 100vh;
}

/* A4 Sheet Container */
.invoice-page {
    width: 210mm;
    min-height: 297mm;
    background-color: #ffffff;
    padding: 12mm;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    box-sizing: border-box;
    position: relative;
    font-size: 8.5pt;
    line-height: 1.4;
    color: #1e293b;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
}

/* Carimbo D'água (Watermark) */
.invoice-watermark {
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-30deg);
    font-family: var(--font-heading);
    font-weight: 900;
    font-size: 5.5rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    pointer-events: none;
    user-select: none;
    z-index: 1;
    opacity: 0.06;
    white-space: nowrap;
}

.watermark-pago {
    color: #16a34a;
    border: 8px solid #16a34a;
    padding: 0.5rem 2rem;
    border-radius: 16px;
    opacity: 0.08;
}

.watermark-anulado {
    color: #dc2626;
    border: 8px solid #dc2626;
    padding: 0.5rem 2rem;
    border-radius: 16px;
    opacity: 0.08;
}

.watermark-proforma {
    color: #0f172a;
    opacity: 0.05;
}

/* Badges de Estado */
.document-status-badge {
    font-size: 7.5pt;
    font-weight: 800;
    padding: 0.2rem 0.55rem;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.status-emitido {
    background-color: #e2e8f0;
    color: #334155;
}

.status-pago {
    background-color: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.status-pendente {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

.status-anulado {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* Estrutura Interna da Fatura */
.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 0.6rem;
    margin-bottom: 0.6rem;
    position: relative;
    z-index: 2;
}

.company-brand-box {
    max-width: 55%;
}

.logo-display-container {
    height: 45px;
    margin-bottom: 0.4rem;
    display: flex;
    align-items: center;
}

.logo-display-container img {
    max-height: 100%;
    max-width: 180px;
    object-fit: contain;
}

.logo-placeholder-svg {
    height: 38px;
    color: var(--primary-color);
}

.company-title {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.15rem;
    margin: 0 0 0.15rem 0;
    color: var(--primary-color);
    letter-spacing: -0.02em;
}

.company-details-text {
    font-size: 8pt;
    color: var(--text-muted);
    line-height: 1.3;
}

.document-meta-box {
    text-align: right;
    max-width: 45%;
}

.document-title {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--primary-color);
    margin: 0;
    letter-spacing: -0.01em;
}

.document-number-badge {
    background-color: var(--primary-color);
    color: #ffffff;
    display: inline-block;
    padding: 0.15rem 0.55rem;
    font-weight: 700;
    font-size: 8.5pt;
    border-radius: 4px;
    margin-bottom: 0.4rem;
}

.document-meta-text {
    font-size: 8pt;
    line-height: 1.35;
}

.document-meta-label {
    color: var(--text-muted);
    font-weight: 500;
}

.document-meta-value {
    font-weight: 600;
}

/* Transport Info Section */
.transport-info-section {
    background-color: #f1f5f9;
    border-radius: 6px;
    padding: 0.45rem 0.65rem;
    margin-bottom: 0.6rem;
    border: 1px solid #cbd5e1;
    position: relative;
    z-index: 2;
}

/* Dados de Clientes */
.client-info-section {
    background-color: var(--bg-light);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.6rem;
    border-left: 4px solid var(--primary-color);
    position: relative;
    z-index: 2;
}

.client-section-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 8pt;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--primary-color);
    margin-bottom: 0.15rem;
}

.client-name {
    font-weight: 700;
    font-size: 9pt;
    margin-bottom: 0.1rem;
}

.client-details {
    font-size: 8pt;
    color: var(--text-muted);
    line-height: 1.3;
}

/* Tabelas */
.table-invoice {
    width: 100%;
    margin-bottom: 0.6rem;
    border-collapse: collapse;
    position: relative;
    z-index: 2;
}

.table-invoice th {
    background-color: var(--primary-color);
    color: #ffffff;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 8pt;
    padding: 0.35rem 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border: none;
}

.table-invoice td {
    padding: 0.35rem 0.5rem;
    font-size: 8pt;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.table-invoice tr:last-child td {
    border-bottom: 2px solid var(--primary-color);
}

.table-invoice th.text-end,
.table-invoice td.text-end {
    text-align: right;
}

.item-ref {
    font-family: monospace;
    font-size: 7.5pt;
    color: var(--text-muted);
    background-color: var(--bg-light);
    padding: 0.05rem 0.2rem;
    border-radius: 3px;
}

/* Totais e Resumos */
.summary-container {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 1.25rem;
    margin-bottom: 0.6rem;
    position: relative;
    z-index: 2;
}

.taxes-summary-box h4,
.financial-summary-box h4 {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 8pt;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--primary-color);
    margin-bottom: 0.35rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.15rem;
}

.table-taxes {
    width: 100%;
    font-size: 7.5pt;
}

.table-taxes th {
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.2rem;
}

.table-taxes td {
    padding: 0.2rem 0;
    border-bottom: 1px dashed var(--border-color);
}

.financial-values {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.financial-row {
    display: flex;
    justify-content: space-between;
    font-size: 8pt;
    color: var(--text-muted);
}

.financial-row.grand-total {
    background-color: var(--primary-color);
    color: #ffffff;
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
    font-size: 9.5pt;
    font-weight: 800;
    margin-top: 0.15rem;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.15);
}

.financial-row.grand-total span:last-child {
    color: #ffffff;
}

/* Observações */
.notes-section {
    background-color: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
    margin-bottom: 0.6rem;
    font-size: 7pt;
    color: var(--text-muted);
    line-height: 1.35;
    position: relative;
    z-index: 2;
}

.notes-section h5 {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 7.5pt;
    text-transform: uppercase;
    color: var(--primary-color);
    margin-top: 0;
    margin-bottom: 0.2rem;
}

/* Dados Bancários */
.bank-details-section {
    background-color: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
    margin-bottom: 0.6rem;
    font-size: 8pt;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 2;
}

.bank-title {
    font-family: var(--font-heading);
    font-weight: 700;
    color: var(--primary-color);
}

/* Assinaturas */
.signatures-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 0.6rem;
    text-align: center;
    padding-top: 0.15rem;
    position: relative;
    z-index: 2;
}

.signature-box {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.signature-line {
    width: 80%;
    border-bottom: 1px solid var(--text-muted);
    margin-bottom: 0.15rem;
    height: 22px;
}

.signature-label {
    font-size: 7.5pt;
    font-weight: 500;
    color: var(--text-muted);
}

/* Rodapé Final */
.invoice-footer {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    border-top: 1px solid var(--border-color);
    padding-top: 0.4rem;
    margin-top: auto;
    position: relative;
    z-index: 2;
}

.legal-footer-text {
    font-size: 7pt;
    color: var(--text-muted);
    max-width: 78%;
    line-height: 1.3;
}

.qr-code-box {
    width: 48px;
    height: 48px;
    background-color: #f1f5f9;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2px;
}

.qr-code-box svg {
    width: 100%;
    height: 100%;
}

/* Botões do Painel Lateral */
.btn-primary-custom {
    background-color: var(--accent-color);
    border: none;
    color: #ffffff;
    font-weight: 600;
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    width: 100%;
    transition: all 0.2s ease;
    font-family: var(--font-heading);
}

.btn-primary-custom:hover {
    background-color: #1d4ed8;
    box-shadow: 0 4px 12px rgba(37, 99, 211, 0.3);
}

.btn-secondary-custom {
    background-color: #334155;
    border: 1px solid #475569;
    color: #f8fafc;
    font-weight: 600;
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    width: 100%;
    transition: all 0.2s ease;
    font-family: var(--font-heading);
    margin-top: 0.5rem;
}

.btn-secondary-custom:hover {
    background-color: #475569;
    color: #ffffff;
}

/* Seletor de Cores da Marca */
.color-picker-container {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.color-option {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s ease;
}

.color-option.active {
    border-color: #ffffff;
    transform: scale(1.1);
}

/* Ajustes de Layout para Ecrãs Pequenos */
@media (max-width: 1200px) {
    .app-container {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    }
    .preview-area {
        margin-left: 0;
        padding: 1.5rem 0.5rem;
    }
    .invoice-page {
        width: 100%;
        max-width: 210mm;
        min-height: auto;
        padding: 8mm;
    }
    .summary-container {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }
}

/* User Profile Card na Sidebar */
.user-profile-card {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(56, 189, 248, 0.25);
    border-radius: 8px;
    padding: 0.75rem;
    margin-bottom: 1.25rem;
}

.user-badge-title {
    font-size: 7.5pt;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Ecrã de Login Overlay */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.login-card {
    background: #1e293b;
    border: 1px solid rgba(56, 189, 248, 0.3);
    border-radius: 16px;
    padding: 2.25rem 2rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5), 0 0 20px rgba(56, 189, 248, 0.15);
}

.login-icon-box {
    width: 64px;
    height: 64px;
    background: rgba(56, 189, 248, 0.1);
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(56, 189, 248, 0.2);
}

/* ESTILOS DE IMPRESSÃO (CRÍTICO) */
@media print {
    body {
        background-color: #ffffff !important;
        color: #000000 !important;
        font-size: 8pt !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    .sidebar, .modal, .modal-backdrop {
        display: none !important;
    }
    .preview-area {
        margin-left: 0 !important;
        padding: 0 !important;
        display: block !important;
        background-color: #ffffff !important;
    }
    .invoice-page {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        box-shadow: none !important;
        padding: 0 !important;
        border: none !important;
        margin: 0 !important;
        page-break-after: avoid !important;
        page-break-before: avoid !important;
    }
    
    @page {
        size: A4 portrait;
        margin: 12mm 10mm;
    }

    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .table-invoice th {
        background-color: var(--primary-color) !important;
        color: #ffffff !important;
    }
    .financial-row.grand-total {
        background-color: var(--primary-color) !important;
        color: #ffffff !important;
    }
}
