/* Estilos base para o layout desktop */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: #f8f9fa;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #333;
    padding: 20px;
    box-sizing: border-box;
}

.main-container {
    width: 100%;
    max-width: 1000px;
    background-color: #ffffff;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.header {
    padding: 25px 30px;
    background-color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #f0f0f0;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.profile {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6a4b8a 0%, #89739c 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-weight: bold;
    font-size: 20px; 
    box-shadow: 0 4px 10px rgba(106, 75, 138, 0.3);
}

.greeting h1 {
    font-size: 24px;
    font-weight: 700;
    color: #2c2c2c;
    line-height: 1.2;
}

.greeting p {
    color: #888;
    font-size: 16px; 
    font-weight: 500;
}

.actions {
    display: flex;
    gap: 20px;
}

.action-btn {
    width: 45px;
    height: 45px;
    border-radius: 15px;
    background: #f5f5f7;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #6a4b8a;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn:hover {
    background: #eaeaea;
    transform: translateY(-2px);
}
.action-btn:active {
    transform: scale(0.95);
    background: #dcdcdc;
}

/* Conteúdo principal (Grid para desktop) */
.content {
    padding: 30px; 
    background-color: #ffffff;
    flex: 1;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 30px;
}

/* Seções de Estoque (Gráficos e Botões) */
.stock-section {
    background: #f8f9fa;
    border-radius: 20px;
    padding: 25px; 
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    text-align: center;
    display: flex;
    flex-direction: column;
}

.chart-section .chart-title {
    font-size: 20px; 
    font-weight: 700;
    color: #2c2c2c;
    margin-bottom: 20px; 
}

.chart-container {
    display: flex;
    justify-content: space-around;
    align-items: flex-end;
    height: 200px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e0e0e0;
    position: relative;
}

/* Gráficos Chart.js */
canvas {
    width: 100% !important;
    height: 100% !important;
    max-width: 100%;
}


/* Botões de Ação */
.action-buttons {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.action-button {
    padding: 22px 30px;
    background: linear-gradient(135deg, #89739c 0%, #6a4b8a 100%);
    border-radius: 30px;
    color: white;
    font-size: 18px; 
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 6px 15px rgba(137, 115, 156, 0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    border: none; /* Adicionado para garantir */
}

.action-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(137, 115, 156, 0.4);
}
.action-button:active {
    transform: scale(0.98);
    box-shadow: 0 4px 12px rgba(137, 115, 156, 0.5);
}
.action-button i {
    font-size: 22px;
}

/* Footer (Nav-Bar) para Desktop */
.nav-bar {
    width: 100%;
    max-width: 1000px;
    background-color: white;
    padding: 15px 25px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-around;
    box-shadow: 0 -5px 15px rgba(0,0,0,0.05);
    border: 1px solid #89739c;
    border-radius: 15px;
    margin-top: 30px;
    margin-bottom: 20px;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #999;
    font-size: 13px;
    transition: all 0.3s ease;
    cursor: pointer;
    padding: 10px 20px;
    border-radius: 18px;
}

.nav-item.active {
    color: #6a4b8a;
    background-color: rgba(106, 75, 138, 0.1);
    transform: translateY(-5px);
}
.nav-item:hover {
    color: #89739c;
    transform: translateY(-2px);
}

.nav-item i {
    font-size: 24px;
    margin-bottom: 5px;
}

.nav-item span {
    font-weight: 500;
}

/* Scroll personalizado */
.content::-webkit-scrollbar {
    width: 8px;
}

.content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.content::-webkit-scrollbar-thumb {
    background: #89739c;
    border-radius: 10px;
}

.content::-webkit-scrollbar-thumb:hover {
    background: #6a4b8a;
}

/* Scrollbar para o container da tabela */
.table-container::-webkit-scrollbar {
    width: 8px;
}

.table-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.table-container::-webkit-scrollbar-thumb {
    background: #89739c;
    border-radius: 10px;
}

.table-container::-webkit-scrollbar-thumb:hover {
    background: #6a4b8a;
}


/* --- Media Queries para Mobile (max-width: 768px) --- */
@media (max-width: 768px) {
    body {
        height: 100vh;
        overflow: hidden;
        padding: 0;
        align-items: flex-start;
    }

    .main-container {
        width: 100%;
        max-width: none;
        height: calc(100vh - 50px);
        border-radius: 0;
        box-shadow: none;
        overflow-y: auto;
        overflow-x: hidden;
    }

    /* Barra de status do dispositivo (Visível apenas em Mobile) */
    .status-bar {
        display: flex;
    }

    .header {
        padding: 16px 20px 10px;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    }
    .user-info {
        gap: 12px;
    }
    .profile {
        width: 42px;
        height: 42px;
        font-size: 18px;
    }
    .greeting h1 {
        font-size: 20px;
    }
    .greeting p {
        font-size: 14px;
    }
    .actions {
        gap: 15px;
    }
    .action-btn {
        width: 38px;
        height: 38px;
        font-size: 18px;
    }

    .content {
        padding: 0 20px;
        padding-bottom: 80px;
        grid-template-columns: 1fr;
        gap: 25px;
        overflow-y: auto;
    }
    
    .stock-section {
        padding: 20px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
    }
    .chart-section .chart-title {
        font-size: 17px;
    }
    .chart-container {
        height: 150px;
    }
    /* Removido os estilos de barra customizados, usando apenas Chart.js */

    .action-buttons {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    .action-button {
        padding: 18px 25px;
        font-size: 16px;
        gap: 10px;
    }
    .action-button i {
        font-size: 18px;
    }

    /* Nav-bar para Mobile (fixo na parte inferior) */
    .nav-bar {
        position: fixed;
        bottom: 0;
        width: 100%;
        max-width: none; 
        border: none; 
        border-top: 1px solid #f0f0f0; 
        border-radius: 0; 
        margin-top: 0; 
        margin-bottom: 0; 
        box-shadow: 0 -2px 5px rgba(0,0,0,0.05); 
        padding: 8px 12px; /* Ajustado para mobile */
    }

    .nav-item {
        padding: 8px 12px;
        font-size: 11px;
    }
    .nav-item i {
        font-size: 20px;
        margin-bottom: 3px;
    }
}

/* Estilos para a área de exibição de dados da API */
#dataDisplayArea h2 {
    font-size: 20px;
    font-weight: 700;
    color: #2c2c2c;
    margin-bottom: 15px;
    text-align: center;
}

#dataDisplayArea h3 {
    font-size: 18px;
    font-weight: 600;
    color: #6a4b8a;
    margin-bottom: 10px;
    text-align: center;
}

/* Estilos para o container da tabela (para rolagem e espaçamento) */
.table-container {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
    max-width: 100%;
}

/* Estilos para a tabela em si */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0; /* Ajustado para 0, o container já tem margin-bottom */
    background-color: #ffffff;
    -webkit-overflow-scrolling: touch; /* Melhor rolagem em iOS */
}

/* Remover border-collapse e ajustar display para mobile */
@media (max-width: 768px) {
    .data-table {
        border-collapse: separate; /* Volta ao normal para permitir o overflow-x */
        display: table; /* Volta ao display de tabela */
        white-space: normal; /* Volta ao normal para permitir que o texto quebre */
    }

    .table-container {
        overflow-x: auto; /* Mantém a rolagem horizontal para o container */
        width: 100%; /* Garante que ocupe a largura total */
        display: block;
    }

    .data-table th, .data-table td {
        padding: 10px;
        font-size: 13px;
        white-space: normal; /* Permite que o texto quebre normalmente dentro das células */
    }
}


.data-table thead tr {
    background-color: #6a4b8a; 
    color: #ffffff;
    text-align: left;
}

.data-table th,
.data-table td {
    padding: 12px 15px;
    border-bottom: 1px solid #e8e8e8;
    text-align: center;
}

.data-table th {
    font-weight: 600;
    font-size: 14px;
    text-transform: uppercase;
}

/* --- Ajustes para o Formulário de CRUD de Produto --- */

#manageProductsSection {
    padding: 30px;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    margin-top: 30px;
    text-align: center;
}

#manageProductsSection h3 {
    font-size: 22px;
    font-weight: 700;
    color: #2c2c2c;
    margin-bottom: 25px;
}

#manageProductsSection h4 {
    font-size: 18px;
    font-weight: 600;
    color: #6a4b8a;
    margin-bottom: 15px;
    text-align: center;
}

#productCrudForm {
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-width: 500px;
    margin: 0 auto 40px auto;
    padding: 25px;
    border: 1px solid #e0e0e0;
    border-radius: 15px;
    background-color: #fcfcfc;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
}

#productCrudForm div.form-group {
    display: flex;
    flex-direction: column;
    width: 100%;
}

#productCrudForm label {
    text-align: left;
    width: 100%;
    font-weight: 500;
    color: #444;
    margin-bottom: 8px;
    padding-left: 0; 
    box-sizing: border-box;
}

#productCrudForm input[type="text"],
#productCrudForm input[type="number"] {
    width: 100%;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 16px;
    color: #333;
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    margin-bottom: 0; 
}

#productCrudForm input[type="text"]:focus,
#productCrudForm input[type="number"]:focus {
    border-color: #6a4b8a;
    box-shadow: 0 0 0 3px rgba(106, 75, 138, 0.2);
    outline: none;
}

#productCrudForm div.form-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    width: 100%;
    margin-top: 20px;
}

#productCrudForm button {
    margin-top: 0;
    width: auto;
    min-width: 120px;
    padding: 12px 25px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

#saveProductButton {
    background: linear-gradient(135deg, #6a4b8a 0%, #89739c 100%);
    color: white;
}

#saveProductButton:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(106, 75, 138, 0.3);
}

#cancelProductCrudButton {
    background-color: #e0e0e0;
    color: #333;
}

#cancelProductCrudButton:hover {
    background-color: #d0d0d0;
    transform: translateY(-2px);
}

/* --- Estilos para os botões de Ações (Editar/Excluir) na Tabela de CRUD --- */

.action-button.small-button {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 5px;
    margin: 0 3px;
    transition: all 0.2s ease;
    box-shadow: none;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
    vertical-align: middle;
}

.edit-button {
    background-color: #a899b3;
    color: white;
}

.edit-button:hover {
    background-color: #89739c;
    transform: translateY(-1px);
}

.delete-button {
    background-color: #e74c3c;
    color: white;
}

.delete-button:hover {
    background-color: #c0392b;
    transform: translateY(-1px);
}

/* Ajustes para a coluna de ações da tabela de CRUD */
#crudProductsTable th:last-child,
#crudProductsTable td:last-child {
    width: 150px;
    white-space: nowrap;
    text-align: center;
}

/* Estilos para a Seção de Registro de Venda */
#registerSaleSection {
    padding: 30px;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    margin-top: 30px;
    text-align: center;
}

#registerSaleSection h3 {
    font-size: 22px;
    font-weight: 700;
    color: #2c2c2c;
    margin-bottom: 25px;
}

#saleRegistrationForm {
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-width: 600px;
    margin: 0 auto 40px auto;
    padding: 25px;
    border: 1px solid #e0e0e0;
    border-radius: 15px;
    background-color: #fcfcfc;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
}

#saleRegistrationForm .form-group {
    display: flex;
    flex-direction: column;
    width: 100%;
    text-align: left;
}

#saleRegistrationForm label {
    font-weight: 500;
    color: #444;
    margin-bottom: 8px;
}

#saleRegistrationForm select,
#saleRegistrationForm input[type="number"] {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 16px;
    color: #333;
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#saleRegistrationForm select:focus,
#saleRegistrationForm input[type="number"]:focus {
    border-color: #6a4b8a;
    box-shadow: 0 0 0 3px rgba(106, 75, 138, 0.2);
    outline: none;
}

.sale-item-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap; /* Permite que os itens quebrem para a próxima linha */
}

.sale-item-row select,
.sale-item-row input {
    flex: 1;
    min-width: 120px; /* Garante que os campos não fiquem muito pequenos */
}

.sale-item-row .delete-item-button {
    background-color: #e74c3c;
    color: white;
    padding: 8px 12px;
    font-size: 14px;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    border: none;
    box-shadow: none;
}

.sale-item-row .delete-item-button:hover {
    background-color: #c0392b;
}

#addSaleItemButton {
    background-color: #a899b3;
    color: white;
    margin-top: 10px;
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 16px;
    border: none;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

#addSaleItemButton:hover {
    background-color: #89739c;
}

#saleTotalPrice {
    color: #6a4b8a;
    font-size: 20px;
}

#submitSaleButton {
    background: linear-gradient(135deg, #6a4b8a 0%, #89739c 100%);
    color: white;
}

#cancelSaleRegistrationButton {
    background-color: #e0e0e0;
    color: white
}

/* Estilos para a nova seção de Gerenciar Estoque */
#stockManagementSection {
    padding: 30px;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    margin-top: 30px;
    text-align: center;
}

#stockManagementSection h3 {
    font-size: 22px;
    font-weight: 700;
    color: #2c2c2c;
    margin-bottom: 25px;
}

#stockManagementSection h4 {
    font-size: 18px;
    font-weight: 600;
    color: #6a4b8a;
    margin-bottom: 15px;
    text-align: center;
}

#stockManagementTable input[type="number"] {
    width: 80px;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 14px;
    text-align: center;
    box-sizing: border-box;
}

.update-stock-button {
    background-color: #6a4b8a;
    color: white;
    padding: 8px 15px;
    font-size: 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(106, 75, 138, 0.2);
    border: none;
}

.update-stock-button:hover {
    background-color: #89739c;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(106, 75, 138, 0.3);
}

.update-stock-button:active {
    transform: translateY(0);
    box-shadow: 0 1px 3px rgba(106, 75, 138, 0.4);
}

/* Media Query para telas menores que 600px */
@media (max-width: 600px) {
    #productCrudForm {
        padding: 15px;
    }

    #productCrudForm input {
        padding: 10px;
        font-size: 14px;
    }

    #productCrudForm button {
        width: 100%;
        margin-top: 5px;
    }
    
    .action-button.small-button {
        padding: 5px 8px;
        font-size: 10px;
        margin: 0 1px;
    }

    #crudProductsTable th:last-child,
    #crudProductsTable td:last-child {
        width: 100px;
        font-size: 10px;
    }

    /* Ajustes específicos para o formulário de registro de venda no mobile */
    #saleRegistrationForm {
        padding: 15px;
        gap: 10px;
    }
    #saleRegistrationForm select,
    #saleRegistrationForm input[type="number"] {
        padding: 8px;
        font-size: 14px;
    }
    .sale-item-row {
        flex-direction: column; /* Empilha os itens */
        align-items: stretch; /* Estica para ocupar a largura total */
        gap: 8px; /* Reduz o espaçamento entre os itens empilhados */
    }
    .sale-item-row select,
    .sale-item-row input {
        width: 100%; /* Ocupa a largura total quando empilhado */
        min-width: unset; /* Remove o min-width para flexibilidade */
    }
    .sale-item-row .delete-item-button {
        width: 100%; /* Botão de remover ocupa a largura total */
        margin-top: 5px; /* Espaço entre o input e o botão */
    }

    #addSaleItemButton,
    #submitSaleButton,
    #cancelSaleRegistrationButton {
        width: 100%; /* Botões de ação no formulário de venda ocupam a largura total */
        margin-left: 0;
        margin-right: 0;
        margin-top: 10px;
    }
}

