* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f0f2f5;
    color: #333;
}

/* ============ LAYOUT ============ */
.layout {
    display: flex;
    min-height: 100vh;
}

/* ============ SIDEBAR ============ */
.sidebar {
    width: 250px;
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 100;
}

.logo {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
}

.logo h1 {
    font-size: 32px;
    background: linear-gradient(135deg, #38bdf8, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 2px;
}

.logo span {
    font-size: 12px;
    color: #94a3b8;
    display: block;
    margin-top: 4px;
}

.menu {
    padding: 16px 0;
    flex: 1;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 20px;
    background: transparent;
    border: none;
    color: #cbd5e1;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.3s;
    text-align: left;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.menu-item.active {
    background: linear-gradient(90deg, rgba(56, 189, 248, 0.2), transparent);
    color: #38bdf8;
    border-left: 3px solid #38bdf8;
}

.menu-icon {
    font-size: 20px;
    width: 24px;
    text-align: center;
}

/* ============ CONTENT ============ */
.content {
    margin-left: 250px;
    flex: 1;
    padding: 24px;
}

.page {
    display: none;
}

.page.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============ HEADER ============ */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.page-header h2 {
    font-size: 24px;
    color: #0f172a;
}

/* ============ CARDS ============ */
.card {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 24px;
}

.card h3 {
    color: #0f172a;
    margin-bottom: 16px;
    font-size: 18px;
}

/* ============ TABLES ============ */
.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: #f8fafc;
}

th {
    text-align: left;
    padding: 12px 14px;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    color: #64748b;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
}

td {
    padding: 12px 14px;
    border-bottom: 1px solid #f1f5f9;
    font-size: 14px;
}

tbody tr {
    transition: background 0.2s;
}

tbody tr:hover {
    background: #f8fafc;
}

.empty {
    text-align: center;
    color: #94a3b8;
    padding: 32px !important;
}

/* ============ BADGES / STATUS ============ */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-orcamento {
    background: #fef3c7;
    color: #92400e;
}

.badge-em_aberto {
    background: #dbeafe;
    color: #1e40af;
}

.badge-concluido {
    background: #d1fae5;
    color: #065f46;
}

.badge-pago {
    background: #d1fae5;
    color: #065f46;
}

.badge-a_vencer {
    background: #dbeafe;
    color: #1e40af;
}

.badge-vencido {
    background: #fee2e2;
    color: #991b1b;
}

.badge-fechado {
    background: #fef3c7;
    color: #92400e;
}

.badge-finalizado {
    background: #d1fae5;
    color: #065f46;
}

.badge-blue {
    background: #dbeafe;
    color: #1e40af;
}

.valor-pendente {
    color: #dc2626;
    font-weight: 700;
}

.status-alerta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    margin-left: 6px;
    border-radius: 50%;
    background: #facc15;
    color: #78350f;
    font-weight: 800;
    font-size: 13px;
    line-height: 1;
    cursor: help;
    animation: piscaAlerta 1s ease-in-out infinite;
}
@keyframes piscaAlerta {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.2; }
}

/* ============ BOTÕES ============ */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-primary {
    background: #2563eb;
    color: #fff;
}

.btn-primary:hover {
    background: #1d4ed8;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
    background: #e2e8f0;
    color: #475569;
}

.btn-secondary:hover {
    background: #cbd5e1;
}

.btn-danger {
    background: #dc2626;
    color: #fff;
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
    margin: 0 2px;
}

.btn-edit {
    background: #f59e0b;
    color: #fff;
}

.btn-edit:hover {
    background: #d97706;
}

/* ============ FILTROS ============ */
.filtros {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 20px;
    align-items: flex-end;
}

.filtro-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filtro-group label {
    font-size: 13px;
    font-weight: 600;
    color: #64748b;
}

.filtro-actions {
    flex-direction: row;
    gap: 8px;
}

input, select {
    padding: 10px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s;
    outline: none;
    background: #fff;
}

input:focus, select:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ============ PARCELAS (condições de pagamento) ============ */
.parcela-row {
    display: grid;
    grid-template-columns: 90px 1fr 1fr;
    gap: 8px;
    align-items: end;
    background: #f8fafc;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 8px;
}

.parcela-label {
    font-weight: 700;
    color: #0f172a;
    padding: 8px 0;
    font-size: 13px;
}

#parcelas-total {
    font-size: 13px;
    color: #475569;
    margin-top: 4px;
    margin-bottom: 8px;
}

#parcelas-total.diferente {
    color: #dc2626;
    font-weight: 600;
}

/* ============ TABS ============ */
.cadastros-tabs,
.faturamento-tabs, .servicos-tabs, .faturamento-situacao-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.tab-btn {
    padding: 10px 20px;
    border: 2px solid #e2e8f0;
    background: #fff;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: #64748b;
    transition: all 0.2s;
}

.tab-btn:hover {
    border-color: #2563eb;
    color: #2563eb;
}

.tab-btn.active {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

/* ============ TOTAL BOX ============ */
.total-box {
    background: linear-gradient(135deg, #2563eb, #1e40af);
    color: #fff;
    padding: 16px 24px;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 700;
    margin-top: 16px;
    display: none;
}

.total-box.show {
    display: block;
}

.detalhe-box {
    margin-top: 16px;
    background: #f8fafc;
    border-radius: 8px;
    padding: 16px;
}

.detalhe-box h4 {
    color: #0f172a;
    margin-bottom: 12px;
}

.detalhe-box table {
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
}

/* ============ MODAL ============ */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.show {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background: #fff;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.modal-cliente-content {
    max-width: 800px;
}

.cliente-balancas-section {
    border-top: 2px solid #e2e8f0;
    margin-top: 20px;
    padding: 20px 24px;
}

.cliente-balancas-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.cliente-balancas-header h4 {
    color: #0f172a;
    font-size: 16px;
}

.submodal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1100;
    justify-content: center;
    align-items: center;
}

.submodal.show {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.submodal-content {
    background: #fff;
    border-radius: 12px;
    width: 90%;
    max-width: 450px;
    padding: 20px 0 0;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.submodal-content h4 {
    color: #0f172a;
    margin-bottom: 16px;
    padding: 0 24px;
}

.tipo-balanca-row {
    display: flex;
    gap: 8px;
}

.tipo-balanca-row select {
    flex: 1;
}

.novo-tipo-box {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    align-items: center;
}

.novo-tipo-box input {
    flex: 1;
}

.modal-detalhes-content {
    max-width: 900px;
}

.detalhes-cliente-body {
    padding: 20px 24px;
}

.detalhes-cliente-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 10px;
    background: #f8fafc;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}

.detalhes-cliente-body h4 {
    color: #0f172a;
    margin: 16px 0 10px;
}

.info-item {
    font-size: 14px;
}

.modal-small {
    max-width: 400px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid #e2e8f0;
}

.modal-header h3 {
    color: #0f172a;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #64748b;
    line-height: 1;
}

.modal-close:hover {
    color: #0f172a;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 24px;
    border-top: 1px solid #e2e8f0;
}

.form-group {
    margin-bottom: 16px;
    padding: 0 24px;
}

.form-group:first-of-type {
    margin-top: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #475569;
    margin-bottom: 6px;
}

.form-group input,
.form-group select {
    width: 100%;
}

.form-row {
    display: flex;
    gap: 16px;
    padding: 0 24px;
    margin-bottom: 16px;
    align-items: flex-start;
}

.form-row .form-group {
    flex: 1;
    padding: 0;
}

/* Corrige o margin-top global (20px) que desalinhava o 1º campo de cada linha */
.form-row .form-group:first-of-type {
    margin-top: 0;
}

/* Rótulos com a mesma altura (1 linha) mantêm os campos no mesmo eixo vertical */
.form-row .form-group label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Caixa pequena do CEP (ao lado do endereço) */
.form-row .form-group.cep-group {
    flex: 0 0 150px;
}

/* ============ TOAST ============ */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #2563eb;
    color: #fff;
    padding: 14px 24px;
    border-radius: 8px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transform: translateX(120%);
    transition: transform 0.3s ease;
    z-index: 2000;
}

.toast.show {
    transform: translateX(0);
}

.toast.success {
    background: #059669;
}

.toast.error {
    background: #dc2626;
}

/* ============ RESPONSIVO ============ */
@media (max-width: 768px) {
    .sidebar {
        width: 70px;
    }

    .logo span {
        display: none;
    }

    .logo h1 {
        font-size: 20px;
    }

    .menu-item span.menu-icon {
        margin: 0 auto;
    }

    .menu-item {
        justify-content: center;
        padding: 14px 8px;
        font-size: 0;
    }

    .menu-item::after {
        content: attr(data-tooltip);
        font-size: 10px;
    }

    .content {
        margin-left: 70px;
        padding: 16px;
    }

    .filtros {
        flex-direction: column;
    }

    .filtro-group {
        width: 100%;
    }

    .form-row {
        flex-direction: column;
        padding: 0 24px;
    }
}

/* ============ ORÇAMENTOS ============ */
.modal-orcamento-content {
    max-width: 1100px;
}
.modal-orcamento-body {
    padding: 16px 24px;
}
.orc-cabecalho {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #1e3a8a;
    padding-bottom: 10px;
    margin-bottom: 12px;
}
.orc-logo strong {
    font-size: 22px;
    color: #1e3a8a;
    display: block;
}
.orc-logo span {
    font-size: 12px;
    color: #475569;
}
.orc-numero {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.orc-campo {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
}
.orc-campo label {
    font-weight: 600;
    color: #475569;
}
.orc-campo input, .orc-campo select {
    padding: 6px 8px;
    width: auto;
}
.orc-dados {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 12px;
}
.orc-linha {
    display: grid;
    grid-template-columns: 130px 1fr;
    gap: 6px;
    align-items: center;
    margin-bottom: 4px;
    font-size: 13px;
}
.orc-linha label {
    font-weight: 600;
    color: #334155;
}
.orc-linha input, .orc-linha select {
    padding: 6px 8px;
}
.orc-tabela {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 10px;
    table-layout: fixed;
}
.orc-tabela th {
    background: #1e3a8a;
    color: #fff;
    padding: 6px 6px;
    font-size: 12px;
    text-align: left;
}
/* Colunas menores; descricao ocupa o espaco restante */
.orc-tabela th:nth-child(1), .orc-tabela td:nth-child(1) { width: 55px; }
.orc-tabela th:nth-child(2), .orc-tabela td:nth-child(2) { width: 85px; }
.orc-tabela th:nth-child(3), .orc-tabela td:nth-child(3) { width: auto; }
.orc-tabela th:nth-child(4), .orc-tabela td:nth-child(4) { width: 95px; }
.orc-tabela th:nth-child(5), .orc-tabela td:nth-child(5) { width: 95px; }
.orc-tabela th:nth-child(6), .orc-tabela td:nth-child(6) { width: 90px; }
.orc-tabela th:nth-child(7), .orc-tabela td:nth-child(7) { width: 100px; }
.orc-tabela th:nth-child(8), .orc-tabela td:nth-child(8) { width: 40px; }
.orc-tabela td {
    border: 1px solid #cbd5e1;
    padding: 2px 4px;
}
.orc-tabela input {
    border: none;
    padding: 4px 6px;
    width: 100%;
}
.orc-rodape {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 12px;
}
.orc-obs textarea {
    width: 100%;
    resize: vertical;
}
.orc-totais {
    align-self: end;
}
.orc-total-linha {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    margin-bottom: 6px;
    font-size: 14px;
}
.orc-total-linha strong {
    font-size: 16px;
    color: #1e3a8a;
}
.print-area {
    display: none;
}

/* Documento de orçamento (impressão) */
.doc-orcamento {
    font-family: Arial, sans-serif;
    color: #000;
    font-size: 12px;
    max-width: 900px;
    margin: 0 auto;
    padding: 12px;
}
.doc-cabecalho {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 3px solid #1e3a8a;
    padding-bottom: 8px;
    margin-bottom: 12px;
}
.doc-logo strong {
    font-size: 24px;
    color: #1e3a8a;
    display: block;
}
.doc-logo span {
    display: block;
    font-size: 12px;
}
.doc-infos-topo {
    text-align: right;
    font-size: 12px;
    line-height: 1.6;
}
.doc-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 12px;
}
.doc-grid p {
    margin: 3px 0;
    font-size: 12px;
}
.doc-tabela {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 12px;
    table-layout: fixed;
}
.doc-tabela th {
    background: #1e3a8a;
    color: #fff;
    border: 1px solid #1e3a8a;
    padding: 6px;
    font-size: 12px;
    text-align: left;
}
/* Colunas menores; descricao ocupa o espaco restante */
.doc-tabela th:nth-child(1), .doc-tabela td:nth-child(1) { width: 6%; }
.doc-tabela th:nth-child(2), .doc-tabela td:nth-child(2) { width: 10%; }
.doc-tabela th:nth-child(3), .doc-tabela td:nth-child(3) { width: auto; }
.doc-tabela th:nth-child(4), .doc-tabela td:nth-child(4) { width: 12%; }
.doc-tabela th:nth-child(5), .doc-tabela td:nth-child(5) { width: 13%; }
.doc-tabela th:nth-child(6), .doc-tabela td:nth-child(6) { width: 11%; }
.doc-tabela th:nth-child(7), .doc-tabela td:nth-child(7) { width: 14%; }
.doc-tabela td {
    border: 1px solid #94a3b8;
    padding: 5px;
    font-size: 12px;
}
.doc-rodape {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 16px;
}
.doc-rodape p {
    margin: 3px 0;
    font-size: 12px;
}
.doc-totais {
    text-align: right;
}
.doc-totais b {
    font-size: 14px;
}
.doc-assinatura {
    text-align: center;
    margin: 8px 0;
}
.doc-local-data {
    text-align: center;
    font-size: 12px;
    margin: 4px 0;
    font-weight: 600;
}
.doc-texto {
    font-size: 11px;
    text-align: justify;
    margin: 4px 0;
}
.doc-rodape-logo {
    text-align: center;
    font-weight: 700;
    margin-top: 12px;
    color: #1e3a8a;
}

/* Impressão: mostra apenas o documento do orçamento */
@page {
    size: A4 landscape;
    margin: 10mm;
}
@media print {
    body * {
        visibility: hidden;
    }
    #orcamento-documento,
    #orcamento-documento * {
        visibility: visible;
    }
    #orcamento-documento {
        display: block;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
    }
}

/* ============ LOGIN ============ */
#login-screen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, #1e3a8a, #0f172a);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 3000;
}
#login-screen.show { display: flex; }
.login-box {
    background: #fff;
    border-radius: 12px;
    padding: 32px;
    width: 340px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
}
.login-box h2 { color: #1e3a8a; margin: 0 0 4px; }
.login-box p { color: #64748b; margin: 0 0 16px; font-size: 13px; }
.login-box input {
    width: 100%;
    box-sizing: border-box;
    margin: 8px 0;
}
.login-box .btn { width: 100%; margin-top: 8px; }
.login-erro { color: #dc2626; font-size: 13px; margin: 8px 0 0; }
.login-contato { color: #1e3a8a; font-size: 13px; margin: 14px 0 0; padding-top: 10px; border-top: 1px solid #e2e8f0; font-weight: 600; }
.btn-sair { margin: 16px 12px; width: calc(100% - 24px); }
