/* Geral */
body {
    font-family: 'Poppins', sans-serif; /* Fonte atualizada */
    margin: 0;
    padding: 20px;
    background-color: #f4f7f6;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 900px;
    margin: 20px auto;
    background-color: #ffffff;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 20px;
    margin-bottom: 30px;
}

.header-left .os-main-title {
    font-size: 2.2em;
    color: #2b2d42; /* Cor atualizada */
    margin: 0;
}

/* ATUALIZADO: Estilo para a exibição da data da O.S. */
.os-date-display {
    font-size: 1.1em; /* Fonte maior para a data */
    color: #666; /* Cor cinza para a data */
    margin-top: 5px; /* Espaço acima da data */
    margin-bottom: 0; /* Remove margem inferior padrão de parágrafo */
}

.header-center {
    flex-grow: 1;
    text-align: center;
}

.logo-main-header {
    max-width: 250px; /* Tamanho do logo aumentado */
    height: auto;
}

.header-right .company-details-header {
    font-size: 0.85em;
    text-align: right;
    line-height: 1.4;
}

.header-right .company-details-header p {
    margin: 0;
}

.header-right .company-details-header a {
    color: #2b2d42; /* Cor atualizada */
    text-decoration: none;
}

.header-right .company-details-header a:hover {
    text-decoration: underline;
}

/* Seções (Quadro) */
.section {
    background-color: #fcfcfc;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 25px;
    margin-bottom: 25px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.section h2 {
    color: #2b2d42; /* Cor atualizada */
    border-bottom: 1px dashed #d0d0d0;
    padding-bottom: 10px;
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 1.6em;
}

.section-header-with-button {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.section-header-with-button h2 {
    margin: 0;
    border-bottom: none;
    padding-bottom: 0;
    flex-grow: 1; /* Permite que o título ocupe o espaço restante */
}

/* Estilos de input e textarea */
.input-group {
    margin-bottom: 15px;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #555;
    font-size: 0.95em;
}

.input-group input[type="text"],
.input-group input[type="email"],
.input-group input[type="password"],
.input-group textarea,
.input-group select {
    width: calc(100% - 24px); /* Full width less padding */
    padding: 12px;
    border: 1px solid #ced4da;
    border-radius: 5px;
    font-size: 1em;
    color: #495057;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-group input[type="text"]:focus,
.input-group input[type="email"]:focus,
.input-group input[type="password"]:focus,
.input-group textarea:focus,
.input-group select:focus {
    border-color: #4a4e69; /* Cor atualizada para focus */
    box-shadow: 0 0 0 0.2rem rgba(74, 78, 105, 0.25); /* Cor atualizada para sombra do focus */
    outline: none;
}

.input-group textarea {
    resize: vertical; /* Permite redimensionamento vertical */
    min-height: 80px;
}

/* Botões de Ação */
.section-action-btn,
.action-btn {
    background-color: #2b2d42; /* Cor atualizada */
    color: white;
    padding: 10px 18px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 500;
    transition: background-color 0.2s ease, transform 0.1s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px; /* Espaçamento entre texto e ícone */
}

.section-action-btn:hover,
.action-btn:hover {
    background-color: #4a4e69; /* Cor atualizada para hover */
    transform: translateY(-1px);
}

.section-action-btn:active,
.action-btn:active {
    background-color: #1e202e; /* Cor atualizada para active */
    transform: translateY(0);
}

.section-action-btn.cancel-btn { /* Estilo para o novo botão 'Cancelar' */
    background-color: #6c757d; /* Cinza */
}

.section-action-btn.cancel-btn:hover {
    background-color: #5a6268;
}


.button-icon {
    width: 20px;
    height: 20px;
}

/* Rodapé */
.action-buttons-footer {
    display: flex;
    justify-content: center;
    padding-top: 25px;
    border-top: 1px solid #e0e0e0;
    margin-top: 25px;
}

/* Autenticação Status */
#auth-status {
    text-align: center;
    font-weight: bold;
    color: #4CAF50; /* Verde para status positivo - Mantido */
    margin-top: 15px;
    font-size: 1.1em;
}

/* Aviso de Garantia */
.warranty-note {
    font-style: italic;
    color: #666;
    margin-top: 15px;
    border-top: 1px dashed #e0e0e0;
    padding-top: 10px;
    font-size: 0.9em;
}

/* Sugestões de Pesquisa (Campo Cliente Nome) */
.suggestions-container {
    position: relative; /* Para posicionar a lista de sugestões */
    width: 100%;
    margin-top: -10px; /* Ajuste para sobrepor um pouco o input */
    z-index: 500; /* Garante que fique acima de outros elementos na seção */
}

.suggestions-list {
    list-style: none;
    padding: 0;
    margin: 0;
    border: 1px solid #ced4da;
    border-top: none;
    border-radius: 0 0 5px 5px;
    background-color: #fff;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    max-height: 200px;
    overflow-y: auto;
}

.suggestions-list li {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    transition: background-color 0.2s ease;
}

.suggestions-list li:last-child {
    border-bottom: none;
}

.suggestions-list li:hover {
    background-color: #f0f0f0;
}

/* Modais (Popups) */
.modal {
    display: none; /* Oculto por padrão */
    position: fixed; /* Fixado na tela */
    z-index: 1000; /* Fica acima de tudo */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto; /* Habilita scroll se o conteúdo for maior que a tela */
    background-color: rgba(0, 0, 0, 0.6); /* Fundo escurecido */
    align-items: center; /* Centraliza verticalmente o modal-content */
    justify-content: center; /* Centraliza horizontalmente o modal-content */
}

.modal.active {
    display: flex; /* Exibe o modal usando flexbox para centralização */
}

.modal-content {
    background-color: #ffffff;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 600px; /* Tamanho máximo do conteúdo do modal */
    position: relative;
    animation: fadeIn 0.3s ease-out; /* Animação simples de entrada */
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.close-button {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s ease;
}

.close-button:hover,
.close-button:focus {
    color: #333;
    text-decoration: none;
    outline: none;
}

.modal h3, .modal h4 {
    color: #2b2d42; /* Cor atualizada */
    margin-top: 0;
    margin-bottom: 20px;
    border-bottom: 1px dashed #d0d0d0;
    padding-bottom: 10px;
    font-size: 1.4em;
}

/* Estilos específicos para o Modal de Autenticação */
.auth-modal-buttons {
    display: flex;
    justify-content: space-around;
    gap: 15px; /* Espaçamento entre botões */
    margin-top: 25px;
}

/* Estilos para a lista de clientes no modal de gerenciar clientes */
#clients-table {
    list-style: none;
    padding: 0;
    margin: 0;
    border: 1px solid #e0e0e0;
    border-radius: 5px;
    max-height: 350px; /* Altura máxima para a área de scroll */
    overflow-y: auto;
    background-color: #fff;
    margin-top: 15px; /* Espaço para o campo de busca */
}

.clients-table-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #eee;
    background-color: #f9f9f9;
}

.clients-table-row:last-child {
    border-bottom: none;
}

.clients-table-row:hover {
    background-color: #f0f8ff; /* Um leve destaque ao passar o mouse */
}

.client-name-display {
    font-weight: bold;
    color: #333;
    flex-grow: 1; /* Permite que o nome do cliente ocupe o máximo de espaço */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; /* Adiciona "..." se o texto for muito longo */
    padding-right: 10px;
}

.client-actions {
    display: flex;
    gap: 8px; /* Espaço entre os botões de ação */
}

.client-actions button {
    padding: 6px 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    transition: background-color 0.2s ease;
}

.client-actions .select-btn {
    background-color: #28a745; /* Verde para selecionar - Mantido */
    color: white;
}

.client-actions .select-btn:hover {
    background-color: #218838;
}

.client-actions .edit-btn {
    background-color: #ffc107; /* Amarelo para editar - Mantido */
    color: #333;
}

.client-actions .edit-btn:hover {
    background-color: #e0a800;
}

.client-actions .delete-btn {
    background-color: #dc3545; /* Vermelho para excluir - Mantido */
    color: white;
}

.client-actions .delete-btn:hover {
    background-color: #c82333;
}

/* Campo de pesquisa dentro do modal de lista de clientes */
#client-list-search {
    margin-bottom: 0; /* Ajuste, pois a lista agora tem margin-top */
}

/* Estilos para as áreas de Adicionar/Editar cliente dentro do modal */
#client-add-area, #client-edit-area {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

/* Responsividade Básica */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        text-align: center;
    }
    .header-left, .header-right {
        margin-bottom: 15px;
        text-align: center;
    }
    .header-right .company-details-header {
        text-align: center;
    }
    .section-header-with-button {
        flex-direction: column;
        align-items: flex-start;
    }
    .section-action-btn {
        width: 100%;
        margin-top: 10px;
    }
    .modal-content {
        width: 95%;
        padding: 20px;
    }
    .auth-modal-buttons {
        flex-direction: column;
    }
    .auth-modal-buttons button {
        width: 100%;
    }
    .clients-table-row {
        flex-direction: column;
        align-items: flex-start;
    }
    .client-actions {
        margin-top: 10px;
        width: 100%;
        justify-content: space-around;
    }
    .client-actions button {
        flex: 1; /* Faz os botões ocuparem o espaço igualmente */
    }
}

/* Otimização para Impressão */
@media print {
    /* CRITICAL: PAGE MARGINS CONTROL */
    @page {
        margin: 2mm !important; /* Forces minimal 2mm margins on all sides of the page */
        size: A4 portrait; /* Explicitly set to A4 and portrait orientation */
    }

    /* AGGRESSIVE GLOBAL RESET FOR PRINT */
    * {
        margin: 0 !important;
        padding: 0 !important;
        box-sizing: border-box !important;
        -webkit-print-color-adjust: exact !important; /* Ensures colors are printed as seen */
        print-color-adjust: exact !important;
    }

    html, body {
        width: 100% !important; /* Takes full available width within @page margins */
        height: auto !important; /* Allows content to define height naturally */
        margin: 0 !important; /* Ensures no body margins */
        padding: 0 !important;
        font-family: 'Poppins', sans-serif !important;
        font-size: 8.5pt !important; /* Requested font size for readability */
        line-height: 1.2 !important; /* Optimized line spacing */
        color: #000 !important;
        background-color: #fff !important;
    }

    .container {
        width: 100% !important; /* Fills 100% of the body's width */
        min-height: calc(297mm - 4mm) !important; /* A4 height (297mm) minus top/bottom @page margins (2mm each) */
        margin: 0 auto !important; /* Center container */
        padding: 2mm !important; /* Minimal internal padding for the container */
        box-shadow: none !important;
        border: none !important;
    }

    /* Header adjustments */
    .header {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: flex-start !important;
        margin-bottom: 3mm !important; /* Reduced margin */
        padding-bottom: 3mm !important; /* Reduced padding */
        border-bottom: 0.5px solid #ccc !important;
    }
    .header-left, .header-center, .header-right {
        width: 33.33% !important; /* Precise one-third distribution */
        flex: 1 !important;
        text-align: center !important;
    }
    .header-left { text-align: left !important; }
    .header-right { text-align: right !important; }

    .os-main-title {
        font-size: 1.1em !important;
        line-height: 1.1 !important;
    }

    /* ATUALIZADO: Ajustes para o novo elemento de data na impressão */
    .os-date-display {
        font-size: 1em !important; /* Tamanho maior para impressão */
        margin-top: 1mm !important; /* Ajuste a margem para impressão */
    }

    .logo-main-header {
        max-width: 95% !important; /* Scale down logo to fit more */
        height: auto !important;
    }
    .company-details-header {
        font-size: 0.7em !important;
        line-height: 1.1 !important;
    }
    .company-details-header p {
        margin: 0 !important;
    }
    .company-details-header a {
        font-size: 1em !important;
        color: #000 !important;
    }

    /* Sections */
    .section {
        padding: 3mm !important; /* Minimal padding for sections */
        margin-bottom: 3mm !important; /* Minimal margin between sections */
        border: 1px solid #ddd !important; /* Light border for clarity */
        border-radius: 3px !important;
        box-shadow: none !important;
        background-color: #fcfcfc !important;
        page-break-inside: avoid !important; /* CRITICAL: Prevents content breaking across pages */
    }
    .section h2 {
        font-size: 1.25em !important; /* Section titles size */
        padding-bottom: 2px !important;
        margin-bottom: 2px !important;
        border-bottom: 0.5px dashed #ccc !important;
        color: #000 !important;
    }

    /* Input groups and elements */
    .input-group {
        margin-bottom: 2mm !important; /* Very small margin between input groups */
    }
    .input-group label {
        font-size: 0.85em !important; /* Label font size */
        margin-bottom: 0px !important;
        color: #000 !important;
        font-weight: normal !important;
    }
    input[type="text"],
    input[type="email"],
    input[type="password"],
    textarea,
    select {
        width: 100% !important; /* Ensures inputs fill their available width */
        padding: 1px 2px !important; /* Minimal padding */
        font-size: 0.9em !important; /* Input text size */
        height: auto !important;
        min-height: 15px !important; /* Allows aggressive vertical compression if needed */
        border: none !important;
        box-shadow: none !important;
        background-color: transparent !important;
        color: #000 !important;
        line-height: 1.1 !important;
    }
    textarea {
        min-height: 20px !important; /* Slightly increased for readability of multi-line text */
    }

    /* Specific section element overrides */
    .warranty-note {
        font-size: 0.85em !important;
        line-height: 1.1 !important;
        margin-top: 2mm !important;
        padding-top: 2mm !important;
        border-top: 0.5px dashed #ccc !important;
    }

    p {
        font-size: 0.85em !important;
        line-height: 1.1 !important;
    }

    /* Hide unnecessary elements for print */
    .section-action-btn,
    .action-btn,
    .auth-access-buttons,
    .modal,
    #footer-buttons,
    .suggestions-container,
    #client-list-search,
    .section-header-with-button .section-action-btn,
    .close-button {
        display: none !important;
    }

    /* Ensure specific sections are visible (even if hidden by JS) */
    #client-data-section,
    #aparelho-problema-section,
    #total-value-section,
    #garantia-section,
    #observacoes-section {
        display: block !important;
        visibility: visible !important;
    }

    /* Ensure no extra space at the end of the container */
    .container > *:last-child {
        margin-bottom: 0 !important;
    }
}
