/* GLOBAL & RESET */
* {
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: #f0f2f5;
  margin: 0;
  padding: 0;
  color: #333;
  padding-bottom: 40px; /* Espaço para o rodapé/toast */
}

/* HEADER */
header {
  background-color: #0056b3;
  color: white;
  padding: 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

header h1 {
  margin: 0;
  font-size: 1.8rem;
}

.btn-logout {
  color: white;
  text-decoration: none;
  padding: 0.5rem 1rem;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 20px;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.9rem;
}

.btn-logout:hover {
  background: rgba(255,255,255,0.1);
}

/* NAV */
nav {
  display: flex;
  justify-content: center;
  gap: 20px;
}

nav a {
  color: #e0e0e0;
  text-decoration: none;
  font-weight: bold;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  transition: background 0.2s, color 0.2s;
}

nav a:hover {
  background-color: rgba(255,255,255,0.1);
  color: white;
}

nav a.active {
  background-color: #004494;
  color: white;
  border-bottom: 3px solid #ffc107; /* Destaque */
}

/* MAIN CONTAINER */
main {
  padding: 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

/* SECTIONS (TABS) */
.tab {
  display: none; /* Esconde todas por padrão */
  animation: fadeIn 0.4s ease-in-out;
}

.tab.active {
  display: block; /* Exibe a ativa */
}

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

/* FORMS & INPUTS */
form {
  background: white;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
}

label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: #555;
}

input, select, textarea {
  width: 100%;
  padding: 0.7rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
}

textarea {
  resize: vertical;
}

button {
  background-color: #007bff;
  color: white;
  border: none;
  padding: 0.8rem 1.2rem;
  font-size: 1rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
}

button:hover {
  background-color: #0056b3;
}

button.secondary {
  background-color: #6c757d;
}

button.secondary:hover {
  background-color: #5a6268;
}

/* TABLE */
table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  margin-top: 1rem;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

th, td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid #eee;
}

th {
  background-color: #0056b3;
  color: white;
}

tr:hover {
  background-color: #f9f9f9;
}

/* ACTIONS (Table buttons) */
td button {
  padding: 0.4rem 0.8rem;
  font-size: 0.9rem;
  margin-right: 5px;
  background-color: #e2e6ea;
  color: #333;
  border: 1px solid #ccc;
}

td button:hover {
  background-color: #dbe2ef;
}

/* DASHBOARD CARDS */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.card {
  background: white;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  text-align: center;
  transition: transform 0.2s;
}

.card:hover {
  transform: translateY(-5px);
}

.card .icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  display: block;
}

.card .value {
  font-size: 1.8rem;
  font-weight: bold;
  color: #333;
  margin: 0.5rem 0;
}

.card .label {
  color: #666;
  font-size: 0.9rem;
}

/* Cores específicas para cards */
.card-total .value { color: #007bff; }
.card-economia .value { color: #28a745; }
.card-itens .value { color: #17a2b8; }
.card-media .value { color: #6f42c1; }

/* GRAFICOS */
.graficos {
  display: grid;
  gap: 2rem;
}

.grafico-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 1.5rem;
}

.grafico-card {
  background: white;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.grafico-titulo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 1rem;
  border-bottom: 1px solid #eee;
  padding-bottom: 0.5rem;
}

.canvas-container {
  position: relative;
  height: 300px;
  width: 100%;
}

/* MODAL CATEGORIA E GERAL */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: white;
  padding: 2rem;
  border-radius: 8px;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.categoria-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem;
  border-bottom: 1px solid #eee;
}

.categoria-item:last-child {
  border-bottom: none;
}

/* TABS DE ITENS (CADASTRO) */
.itens-tabs-container {
  border: 1px solid #ddd;
  border-radius: 4px;
  overflow: hidden;
  background: white;
  margin-top: 1rem;
}

.itens-tabs-header {
  display: flex;
  background: #f1f1f1;
  border-bottom: 1px solid #ddd;
}

.itens-tabs-list {
  display: flex;
  overflow-x: auto;
  flex-grow: 1;
}

.item-tab {
  padding: 10px 20px;
  cursor: pointer;
  border-right: 1px solid #ddd;
  background: #f1f1f1;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.item-tab:hover {
  background: #e9e9e9;
}

.item-tab.active {
  background: white;
  border-bottom: 2px solid #007bff;
  font-weight: bold;
  color: #007bff;
}

.add-tab-btn {
  padding: 10px 15px;
  background: #28a745;
  color: white;
  border: none;
  cursor: pointer;
  font-weight: bold;
}

.add-tab-btn:hover {
  background: #218838;
}

.itens-tabs-content {
  padding: 20px;
}

.item-tab-content {
  display: none;
}

.item-tab-content.active {
  display: block;
  animation: fadeIn 0.3s;
}

/* ESTILOS INTERNOS DO ITEM (CADASTRO) */
.item-block {
  background: #fff;
  /* border removido pois está dentro da tab */
}

.fornecedores {
  margin-top: 1rem;
  background: #f8f9fa;
  padding: 1rem;
  border-radius: 4px;
}

.fornecedor-block {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
  border-bottom: 1px dashed #ccc;
  padding-bottom: 10px;
}

.fornecedor-block:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.item-actions {
  margin-top: 1rem;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.remover-item {
  background-color: #dc3545;
}

.remover-item:hover {
  background-color: #c82333;
}

.remover-fornecedor {
  background-color: #dc3545;
  padding: 0.5rem;
  font-size: 0.8rem;
}

.remove-tab-x {
  margin-left: 5px;
  font-size: 0.8em;
  color: #666;
  cursor: pointer;
}

.remove-tab-x:hover {
  color: red;
}

.item-resumo {
  margin-top: 10px;
  padding: 10px;
  background: #f9f9f9;
  border: 1px solid #eee;
  border-radius: 5px;
}

/* ESTILO MODAL CATEGORIA */
.modal-overlay, .modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.modal-content {
  background: white;
  padding: 2rem;
  border-radius: 10px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.modal-footer, .modal-buttons {
  margin-top: 1rem;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ESTILO TOAST NOTIFICAÇÃO */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #333;
  color: white;
  padding: 12px 24px;
  border-radius: 4px;
  z-index: 10000;
  animation: slideIn 0.3s, fadeOut 0.3s 2.7s;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.toast.sucesso { background: #28a745; }
.toast.erro { background: #dc3545; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* Dashboard Filter */
.dashboard-filter, .filters-compact {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  align-items: center;
  background: white;
  padding: 15px;
  border-radius: 10px;
  box-shadow: 0 0 12px rgba(0,0,0,0.06);
  flex-wrap: wrap;
}

.dashboard-filter select, .dashboard-filter input, .filters-compact select, .filters-compact input {
  margin: 0;
}

/* === ESTILOS MODERNOS DO MODAL DE DETALHES === */

/* Estilo base do body para previnir scroll quando modal aberto */
body.modal-open {
    overflow: hidden;
}

/* Modal Backdrop com efeito Glassmorphism */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(20, 20, 25, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none; /* Controlado via JS */
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* Ao abrir (classe controlada via JS ou estilo inline de display) */
.modal-backdrop[style*="display: flex"] {
    opacity: 1;
}

/* Container Moderno do Modal */
.modal-modern {
    background: #ffffff;
    width: 90%;
    max-width: 900px;
    border-radius: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15), 0 10px 20px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    max-height: 85vh;
    transform: translateY(20px);
    animation: modalSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    overflow: hidden;
    position: relative;
}

@keyframes modalSlideUp {
    to { transform: translateY(0); }
}

/* Header do Modal */
.modal-modern-header {
    padding: 24px 32px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.95);
    position: sticky;
    top: 0;
    z-index: 10;
}

.modal-modern-header h3 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #1a73e8 0%, #0d47a1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

/* Botão de Fechar (X) */
.btn-close-modern {
    background: #f1f3f4;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: #5f6368;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-close-modern:hover {
    background: #fee2e2;
    color: #ef4444;
    transform: rotate(90deg);
}

/* Corpo do Modal */
.modal-modern-body {
    padding: 32px;
    overflow-y: auto;
    /* Scrollbar estilizada */
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f1f5f9;
}

.modal-modern-body::-webkit-scrollbar {
    width: 8px;
}

.modal-modern-body::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.modal-modern-body::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 4px;
}

/* Footer do Modal */
.modal-modern-footer {
    padding: 20px 32px;
    border-top: 1px solid #f0f0f0;
    background: #f8fafc;
    display: flex;
    justify-content: flex-end;
}

.btn-action-close {
    background: #334155;
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px rgba(51, 65, 85, 0.2);
}

.btn-action-close:hover {
    background: #1e293b;
    transform: translateY(-1px);
    box-shadow: 0 6px 12px rgba(51, 65, 85, 0.25);
}

/* === CONTEÚDO INTERNO DO MODAL === */

/* Detalhes do orçamento */
.detalhes-orcamento {
    font-family: 'Inter', 'Segoe UI', sans-serif;
    background: transparent;
    padding: 0;
    border: none;
    margin: 0;
}

.detalhes-header {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 24px;
    background: #f8fafc;
    padding: 24px;
    border-radius: 20px;
    margin-bottom: 32px;
    border: 1px solid #e2e8f0;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

.detalhe-campo {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.detalhe-campo strong {
    color: #64748b;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
}

.detalhe-campo-valor {
    color: #1e293b;
    font-size: 1rem;
    font-weight: 500;
    line-height: 1.5;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-badge.pendente { background: #fff7ed; color: #c2410c; border: 1px solid #ffedd5; }
.status-badge.aprovado { background: #f0fdf4; color: #15803d; border: 1px solid #dcfce7; }
.status-badge.recebido { background: #f0fdf4; color: #15803d; border: 1px solid #dcfce7; }
.status-badge.cancelado { background: #fef2f2; color: #b91c1c; border: 1px solid #fee2e2; }

.detalhes-orcamento h3 {
    font-size: 1.2rem;
    color: #334155;
    margin-bottom: 20px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
    border: none;
}

.detalhes-orcamento h3::before {
    content: '';
    display: block;
    width: 4px;
    height: 24px;
    background: #3b82f6;
    border-radius: 2px;
}

/* Card de Item Moderno */
.item-detalhe {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    margin-bottom: 24px;
    overflow: hidden;
    transition: all 0.3s ease;
    position: relative;
    padding: 0;
}

.item-detalhe:hover {
    border-color: #cbd5e1;
    box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.05);
    transform: translateY(-2px);
}

.item-header {
    background: #f8fafc;
    padding: 16px 24px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.item-header h4 {
    margin: 0;
    color: #1e293b;
    font-size: 1.1rem;
    font-weight: 600;
    border: none;
}

.item-meta {
    background: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    color: #475569;
    font-weight: 500;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}

/* Tabela de Fornecedores */
.fornecedores-lista {
    padding: 0;
    margin: 0;
}

.tabela-fornecedores {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
}

.tabela-fornecedores th {
    text-align: left;
    padding: 12px 24px;
    font-size: 0.8rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #f1f5f9;
    background: white;
}

.tabela-fornecedores td {
    padding: 16px 24px;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
    font-size: 0.95rem;
    vertical-align: middle;
}

.tabela-fornecedores tr:last-child td {
    border-bottom: none;
}

/* Linha de Melhor Preço */
.tabela-fornecedores tr.melhor-preco-row {
    background: #f0fdf4;
    position: relative;
}

.tabela-fornecedores tr.melhor-preco-row td:first-child {
    position: relative;
}

.tabela-fornecedores tr.melhor-preco-row td:first-child::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: #22c55e;
}

.tabela-fornecedores tr.melhor-preco-row td {
    color: #166534;
    font-weight: 500;
}

.tabela-fornecedores .col-nome {
    font-weight: 600;
    color: #0f172a;
    min-width: 150px;
}

.tabela-fornecedores .col-total {
    font-weight: 700;
    font-size: 1rem;
    text-align: right;
}

.sem-fornecedores {
    padding: 20px;
    text-align: center;
    color: #94a3b8;
    font-style: italic;
}

/* Total Geral */
.total-orcamento-container {
    margin-top: 32px;
    background: linear-gradient(135deg, #0f172a 0%, #334155 100%);
    color: white;
    padding: 24px 32px;
    border-radius: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 20px 25px -5px rgba(15, 23, 42, 0.3), 0 8px 10px -6px rgba(15, 23, 42, 0.3);
    position: relative;
    overflow: hidden;
}

.total-orcamento-container::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0IiBoZWlnaHQ9IjQiPgo8cmVjdCB3aWR0aD0iNCIgaGVpZ2h0PSI0IiBmaWxsPSIjZmZmIiBmaWxsLW9wYWNpdHk9IjAuMDUiLz4KPC9zdmc+');
    opacity: 0.3;
}

.total-label {
    font-size: 1.1rem;
    font-weight: 500;
    color: #94a3b8;
    z-index: 1;
}

.total-valor {
    font-size: 2rem;
    font-weight: 800;
    color: #4ade80;
    text-shadow: 0 2px 10px rgba(74, 222, 128, 0.2);
    z-index: 1;
}

/* Responsividade */
@media (max-width: 640px) {
    .modal-modern {
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
    
    .detalhes-header {
        grid-template-columns: 1fr;
    }
    
    .total-orcamento-container {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
}
