/* ===== GESTÃO SJAX — ESTILOS GLOBAIS ===== */

:root {
  --gold: #4A90D9;
  --gold-dark: #004A80;
  --gold-light: #6FB1E3;
  --dark: #1a1a1a;
  --dark2: #2d2d2d;
  --gray1: #374151;
  --gray2: #4b5563;
  --gray3: #6b7280;
  --gray4: #9ca3af;
  --gray5: #d1d5db;
  --gray6: #e5e7eb;
  --gray7: #f3f4f6;
  --gray8: #f9fafb;
  --white: #ffffff;
  --green: #059669;
  --green-bg: #d1fae5;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --blue: #2563eb;
  --blue-bg: #dbeafe;
  --orange: #d97706;
  --orange-bg: #fef3c7;
  --sidebar-w: 240px;
  --header-h: 56px;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--gray1);
  background: var(--gray7);
  line-height: 1.5;
}

a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-dark); }

/* ===== LAYOUT COM SIDEBAR ===== */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--dark);
  color: var(--white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid #333;
}
.sidebar-logo .marca {
  font-size: 15px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.sidebar-logo .submarca {
  font-size: 11px;
  color: var(--gray4);
  margin-top: 2px;
}

.sidebar-nav {
  padding: 12px 0;
  flex: 1;
}

.nav-section-title {
  font-size: 10px;
  font-weight: 600;
  color: var(--gray3);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 12px 20px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--gray5);
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, color .15s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: #333; color: var(--white); }
.nav-item.active { background: var(--gold); color: var(--dark); }
.nav-item.active svg { opacity: 1; }
.nav-item svg { opacity: .7; flex-shrink: 0; }
.nav-item.active:hover { background: var(--gold-dark); }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid #333;
}
.sidebar-user {
  font-size: 12px;
  color: var(--gray4);
  margin-bottom: 8px;
}
.sidebar-user strong { color: var(--white); display: block; font-size: 13px; }

/* ===== CONTEÚDO PRINCIPAL ===== */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--header-h);
  background: var(--white);
  border-bottom: 1px solid var(--gray6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--dark);
}

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.page-content {
  padding: 24px;
  flex: 1;
}

/* ===== CARDS ===== */
.card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--gray6);
  box-shadow: var(--shadow);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray6);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--dark);
}
.card-body { padding: 20px; }

/* ===== STATS CARDS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--gray6);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}
.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--gray3);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 8px;
}
.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--dark);
  line-height: 1;
}
.stat-value.gold { color: var(--gold); }
.stat-value.green { color: var(--green); }
.stat-value.red { color: var(--red); }
.stat-value.blue { color: var(--blue); }

/* ===== BOTÕES ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--gold); color: var(--dark); border-color: var(--gold); }
.btn-primary:hover:not(:disabled) { background: var(--gold-dark); border-color: var(--gold-dark); }

.btn-secondary { background: var(--white); color: var(--gray1); border-color: var(--gray5); }
.btn-secondary:hover:not(:disabled) { background: var(--gray7); }

.btn-danger { background: var(--red); color: var(--white); border-color: var(--red); }
.btn-danger:hover:not(:disabled) { background: #b91c1c; border-color: #b91c1c; }

.btn-success { background: var(--green); color: var(--white); border-color: var(--green); }
.btn-success:hover:not(:disabled) { background: #047857; }

.btn-ghost { background: transparent; color: var(--gray2); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--gray7); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 24px; font-size: 15px; }

/* ===== TABELA ===== */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
}
th {
  background: var(--gray8);
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--gray3);
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--gray6);
  white-space: nowrap;
}
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--gray6);
  color: var(--gray1);
  font-size: 13px;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray8); }

/* ===== BADGES DE STATUS ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-rascunho    { background: var(--gray6); color: var(--gray2); }
.badge-aberto      { background: var(--blue-bg); color: var(--blue); }
.badge-em_cotacao  { background: var(--orange-bg); color: var(--orange); }
.badge-aguardando_aprovacao { background: #fde68a; color: #92400e; }
.badge-aprovado    { background: #d1fae5; color: #065f46; }
.badge-em_finalizacao { background: #dbeafe; color: #1e40af; }
.badge-finalizado  { background: #d1fae5; color: var(--green); }
.badge-rejeitado   { background: var(--red-bg); color: var(--red); }
.badge-cancelado   { background: var(--gray6); color: var(--gray3); }

.badge-prioridade-baixa   { background: var(--gray7); color: var(--gray3); }
.badge-prioridade-media   { background: var(--blue-bg); color: var(--blue); }
.badge-prioridade-alta    { background: var(--orange-bg); color: var(--orange); }
.badge-prioridade-urgente { background: var(--red-bg); color: var(--red); }

/* ===== FORMULÁRIOS ===== */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray1);
  margin-bottom: 5px;
}
.form-label .required { color: var(--red); margin-left: 2px; }
.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--gray5);
  border-radius: 6px;
  font-size: 13px;
  color: var(--gray1);
  background: var(--white);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.form-control:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(74,144,217,.15);
}
.form-control:disabled { background: var(--gray7); color: var(--gray4); cursor: not-allowed; }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }

.form-hint { font-size: 12px; color: var(--gray4); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row.cols3 { grid-template-columns: 1fr 1fr 1fr; }

/* ===== ALERTAS ===== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  border: 1px solid transparent;
  margin-bottom: 16px;
}
.alert-warning { background: var(--orange-bg); border-color: #f59e0b; color: #92400e; }
.alert-danger   { background: var(--red-bg); border-color: #fca5a5; color: #991b1b; }
.alert-success  { background: var(--green-bg); border-color: #6ee7b7; color: #065f46; }
.alert-info     { background: var(--blue-bg); border-color: #93c5fd; color: #1e40af; }

/* ===== FILTROS ===== */
.filters-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-bottom: 1px solid var(--gray6);
  background: var(--gray8);
}
.filters-bar .form-control {
  width: auto;
  padding: 6px 10px;
  font-size: 13px;
}

/* ===== LOADING ===== */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--gray5);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.loading-box {
  background: var(--white);
  border-radius: var(--radius);
  padding: 24px 32px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 14px;
  font-weight: 500;
}

/* ===== MODAL ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--gray6);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-size: 15px; font-weight: 600; color: var(--dark); }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--gray6);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

/* ===== ITENS DO PEDIDO ===== */
.item-row {
  display: grid;
  grid-template-columns: 1fr 100px 80px 36px;
  gap: 10px;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray6);
}
.item-row:last-child { border-bottom: none; }
.item-row .btn-ghost { padding: 7px; }

/* ===== TIMELINE DE STATUS ===== */
.timeline { list-style: none; position: relative; }
.timeline::before {
  content: '';
  position: absolute;
  left: 15px; top: 0; bottom: 0;
  width: 2px;
  background: var(--gray6);
}
.timeline-item {
  position: relative;
  padding: 0 0 20px 42px;
}
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot {
  position: absolute;
  left: 8px; top: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--gray5);
  border: 2px solid var(--white);
  box-shadow: 0 0 0 2px var(--gray5);
}
.timeline-dot.active { background: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.timeline-dot.done   { background: var(--green); box-shadow: 0 0 0 2px var(--green); }
.timeline-dot.reject { background: var(--red); box-shadow: 0 0 0 2px var(--red); }
.timeline-label { font-size: 13px; font-weight: 600; color: var(--dark); }
.timeline-sub   { font-size: 12px; color: var(--gray4); margin-top: 2px; }

/* ===== COTAÇÕES ===== */
.cotacao-card {
  border: 1px solid var(--gray6);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  position: relative;
}
.cotacao-card.selecionada {
  border-color: var(--green);
  background: #f0fdf4;
}
.cotacao-card .cotacao-fornecedor { font-weight: 600; font-size: 13px; }
.cotacao-card .cotacao-valor { font-size: 20px; font-weight: 700; color: var(--dark); }
.cotacao-card .cotacao-meta { font-size: 12px; color: var(--gray4); }

/* ===== SEÇÃO DE AÇÕES DO PEDIDO ===== */
.acoes-pedido {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 16px 20px;
  border-top: 1px solid var(--gray6);
  background: var(--gray8);
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--gray4);
}
.empty-state svg { opacity: .4; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ===== LOGIN ===== */
.login-page {
  min-height: 100vh;
  background: var(--dark);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--white);
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo .marca {
  font-size: 22px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 1px;
  text-transform: uppercase;
}
.login-logo .submarca {
  font-size: 13px;
  color: var(--gray3);
  margin-top: 4px;
}
.login-error {
  background: var(--red-bg);
  border: 1px solid #fca5a5;
  color: #991b1b;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}

/* ===== PAGINAÇÃO ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-top: 1px solid var(--gray6);
  font-size: 13px;
  color: var(--gray3);
}
.pagination-btns { display: flex; gap: 6px; }

/* ===== TOAST ===== */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--dark);
  color: var(--white);
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: slideIn .2s ease;
  max-width: 340px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.toast.success { border-left: 4px solid var(--green); }
.toast.error   { border-left: 4px solid var(--red); }
.toast.info    { border-left: 4px solid var(--gold); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===== UTILIDADES ===== */
.d-none { display: none !important; }
.d-flex { display: flex; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-0 { margin-bottom: 0; }
.text-muted { color: var(--gray4); }
.text-danger { color: var(--red); }
.text-success { color: var(--green); }
.fw-600 { font-weight: 600; }
.fs-12 { font-size: 12px; }

/* ===== BADGES MÓDULO MEDIÇÃO ===== */
.badge-med-rascunho      { background: var(--gray6); color: var(--gray2); }
.badge-med-emitida       { background: var(--blue-bg); color: var(--blue); }
.badge-med-aguardando_n1 { background: #fff3cd; color: #856404; }
.badge-med-aguardando_n2 { background: #ffeeba; color: #856404; }
.badge-med-aguardando_resposta_n1         { background: #fde68a; color: #78350f; }
.badge-med-aguardando_resposta_n2         { background: #fde68a; color: #78350f; }
.badge-med-aguardando_resposta_financeiro { background: #fde68a; color: #78350f; }
.badge-med-aprovada      { background: #d4edda; color: #155724; }
.badge-med-financeiro    { background: #cce5ff; color: #004085; }
.badge-med-concluida     { background: var(--green-bg); color: var(--green); }
.badge-med-paga          { background: var(--green-bg); color: var(--green); }
.badge-med-cancelada     { background: var(--red-bg); color: var(--red); }
.badge-med-reprovada_financeiro { background: #f8d7da; color: #721c24; }

.badge-ct-ativo      { background: var(--green-bg); color: var(--green); }
.badge-ct-encerrado  { background: var(--gray6); color: var(--gray2); }
.badge-ct-cancelado  { background: var(--red-bg); color: var(--red); }

.badge-tipo-medicao  { background: var(--blue-bg); color: var(--blue); }
.badge-tipo-sinal    { background: var(--orange-bg); color: var(--orange); }

/* ===== SIDEBAR MÓDULO REEMBOLSO ===== */
.sidebar-reemb { background: #0f1117; }
.sidebar-reemb .sidebar-nav { padding: 4px 8px; }
.sidebar-reemb .nav-item-reemb {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 2px;
  font-size: 13px;
  font-weight: 400;
  color: #9ca3af;
  gap: 12px;
}
.sidebar-reemb .nav-item-reemb:hover {
  background: #1a1d27;
  color: #e5e7eb;
}
.sidebar-reemb .nav-item-reemb.active {
  background: #1a1d27;
  color: #fff;
  font-weight: 500;
}
.sidebar-reemb .nav-item-reemb.active::after {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  margin-left: auto;
  flex-shrink: 0;
}
.sidebar-reemb .nav-item-reemb svg { opacity: .6; }
.sidebar-reemb .nav-item-reemb:hover svg,
.sidebar-reemb .nav-item-reemb.active svg { opacity: 1; }

/* ===== BADGES MÓDULO REEMBOLSO ===== */
.badge-reemb-ativa       { background: var(--blue-bg); color: var(--blue); }
.badge-reemb-substituta  { background: var(--orange-bg); color: var(--orange); }
.badge-reemb-fechada     { background: var(--gray6); color: var(--gray2); }
.badge-reemb-enviada     { background: #cce5ff; color: #004085; }
.badge-reemb-rejeitada   { background: var(--red-bg); color: var(--red); }
.badge-reemb-devolvida   { background: #fef3c7; color: #92400e; }

.badge-rel-gerado    { background: var(--orange-bg); color: var(--orange); }
.badge-rel-enviado   { background: var(--blue-bg); color: var(--blue); }
.badge-rel-pago      { background: var(--green-bg); color: var(--green); }
.badge-rel-cancelado { background: var(--red-bg); color: var(--red); }

/* ===== BADGES MÓDULO REEMBOLSO V2 ===== */
.badge-v2rel-rascunho     { background: var(--gray6); color: var(--gray2); }
.badge-v2rel-enviado      { background: var(--blue-bg); color: var(--blue); }
.badge-v2rel-em_auditoria { background: var(--orange-bg); color: var(--orange); }
.badge-v2rel-devolvido    { background: #fee2e2; color: #dc2626; }
.badge-v2rel-finalizado   { background: var(--green-bg); color: var(--green); }
.badge-v2rel-aprovado     { background: var(--green-bg); color: var(--green); }
.badge-v2rel-pgto_agendado { background: #dbeafe; color: #1d4ed8; }
.badge-v2rel-pgto_efetuado { background: #d1fae5; color: #047857; }

.badge-v2aud-pendente  { background: var(--gray6); color: var(--gray2); }
.badge-v2aud-aprovada  { background: var(--green-bg); color: var(--green); }
.badge-v2aud-rejeitada { background: var(--red-bg); color: var(--red); }

/* ===== ITENS DINÂMICOS (CONTRATOS/MEDIÇÕES) ===== */
.itens-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.itens-table th { background: var(--gray8); padding: 8px 10px; text-align: left; font-size: 11px; font-weight: 600; color: var(--gray3); text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--gray6); }
.itens-table td { padding: 8px 10px; border-bottom: 1px solid var(--gray6); font-size: 13px; }
.itens-table .form-control { padding: 6px 8px; font-size: 13px; }
.itens-table input[type="number"] { width: 100%; text-align: right; }
.itens-table .btn-remove { color: var(--red); cursor: pointer; background: none; border: none; font-size: 18px; padding: 4px 8px; }
.itens-table .btn-remove:hover { background: var(--red-bg); border-radius: 4px; }

.item-total { text-align: right; font-weight: 600; font-size: 13px; color: var(--dark); }

/* ===== RESUMO VALORES ===== */
.resumo-valores {
  background: var(--gray8);
  border: 1px solid var(--gray6);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-top: 16px;
}
.resumo-linha {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--gray6);
}
.resumo-linha:last-child { border-bottom: none; }
.resumo-linha.total { font-weight: 700; font-size: 16px; color: var(--dark); border-top: 2px solid var(--gray5); padding-top: 10px; }
.resumo-linha .label { color: var(--gray2); }
.resumo-linha .valor { color: var(--dark); font-weight: 600; }
.resumo-linha .valor.desconto { color: var(--red); }

/* ===== PRINT STYLES ===== */
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main { margin-left: 0 !important; }
  .page-content { padding: 0 !important; }
  body { background: white; font-size: 12px; }
  .card { border: none; box-shadow: none; }
  .assinatura-bloco {
    display: inline-block;
    width: 45%;
    text-align: center;
    margin-top: 60px;
    border-top: 1px solid #333;
    padding-top: 8px;
    font-size: 12px;
  }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .form-row { grid-template-columns: 1fr; }
}
