/* ============================================================
   ESTILO.CSS — DESIGN SYSTEM ÚNICO DO SISTEMA KIPORTAS
   Todas as páginas herdam via cabecalho.php
   ------------------------------------------------------------
   1. VARIÁVEIS          5. CONTEÚDO (.main)
   2. BASE               6. BOXES (.dash-box, .card)
   3. TOPBAR             7. FORMULÁRIOS (.form-center, .det-field)
   4. SIDEBAR            8. BOTÕES (.btn) / 9. TABELAS
                         10. RESPONSIVIDADE + CENTRALIZAÇÃO
   ============================================================ */

/* ---------- 1. VARIÁVEIS GLOBAIS ---------- */
:root {
  --navy: #0d2035;
  --navy-claro: #1e3a5f;
  --sage: #c9d3d0;
  --texto: #3f4a52;
  --texto-suave: #7a858d;
  --borda: #e2e8ea;
  --cinza-fundo: #dfe4e6;
  --preenchido: #eef1f2;
  --placeholder: #c9d0d4;
  --azul: #2f5d8a;
  --vermelho: #dc2626;
  --campo-borda: #b7bec1;
  --fundo-box: #eef1f2;
  --btn-texto: #2b343b;
  --altura-controle: 30px;
  --largura-botao: 45px;    /* mínimo — cresce sozinho se o texto for maior */
  --altura-botao: 29px;
  --topbar-alt: 100px;
  --sidebar-larg: 350px;
  --sidebar-colapsada: 44px;
}

/* ---------- 2. BASE ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', Helvetica, Arial, sans-serif; }
html, body { max-width: 100% !important; overflow-x: hidden !important; }
body { min-height: 100vh; background: linear-gradient(180deg, #f2f5f5 0%, #6c6e6e 100%); color: var(--texto); }
button, input, select, textarea { font-family: inherit; }

/* ---------- 3. TOPBAR ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; width: 100%;
  height: var(--topbar-alt); z-index: 60; background: #2a2a2a;
  padding: 0 36px; display: flex; justify-content: space-between;
  align-items: center; flex-wrap: wrap; gap: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.topbar-marca { display: flex; flex-direction: column; justify-content: center; }
.topbar-marca .marca { font-size: clamp(18px, 1.8vw, 24px); font-weight: 800; color: #FFFFFF; line-height: 1.1; letter-spacing: 0.02em; white-space: nowrap; }
.topbar-marca .marca span { color: var(--sage); }
.topbar-marca .empresa { font-size: clamp(11px, 1.1vw, 13px); color: #B0B0B0; margin-top: 3px; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-left: auto; }
.notif-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; font-size: 14px; font-weight: 800; color: #FFFFFF;
  background: linear-gradient(180deg, #1e3a5f 0%, #0d2035 100%);
  padding: 0 16px; border-radius: 0; border: 2px solid #2f5d8a;
  cursor: pointer; min-height: 44px; min-width: 150px;
  transition: filter 0.2s; white-space: nowrap; text-transform: uppercase;
  letter-spacing: 0.03em; box-shadow: 0 2px 6px rgba(13,32,53,0.3);
}
.notif-btn:hover { filter: brightness(1.15); }
.notif-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 0; background: #dc2626; color: #fff; font-size: 11px; font-weight: 800; }
@keyframes piscarVermelho { 0%, 100% { border-color: #ff4d4d; box-shadow: 0 0 14px rgba(220,38,38,0.6); } 50% { border-color: rgba(255,77,77,0.4); box-shadow: 0 0 6px rgba(220,38,38,0.3); } }
.notif-btn.tem-msg { animation: piscarVermelho 1s infinite; }

/* ---------- 4. SIDEBAR (fonte única — veio do sidebar.php) ---------- */
.sidebar {
  position: fixed; top: var(--topbar-alt); left: 0; bottom: 0;
  width: var(--sidebar-larg); background: #2a2a2a; color: #F0F0F0;
  display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden;
  flex-shrink: 0; z-index: 50; transition: width 0.3s ease;
}
.sidebar-toggle {
  display: flex; align-items: center; justify-content: center; align-self: flex-end;
  width: 30px; height: 30px; margin: 8px 10px 0 0;
  background: rgba(255,255,255,0.10); border: 1px solid rgba(255,255,255,0.18);
  color: #fff; font-size: 13px; cursor: pointer; transition: background 0.2s; flex-shrink: 0;
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.22); }
.sidebar nav { flex: 1; padding: 8px 0; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 14px;
  padding: 11px 26px; color: #E0E0E0; text-decoration: none; font-size: 14px; font-weight: 500;
  border-left: 3px solid transparent; border-top: none; border-right: none; border-bottom: none;
  background: none; width: 100%; text-align: left; cursor: pointer;
  transition: all 0.2s; white-space: nowrap;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #FFFFFF; }
.nav-item.active { background: rgba(255,255,255,0.12); border-left-color: var(--sage); color: #FFFFFF; }
.nav-item .ico { font-size: 15px; width: 22px; text-align: center; flex-shrink: 0; }
.nav-flutua { display: none; }
.nav-sair {
  width: auto; margin: 10px 16px 16px; padding: 11px 0; text-align: center;
  background: linear-gradient(to bottom, #E42323, #B30707);
  border: 1px solid #B30707; color: #ffffff; justify-content: center;
  font-weight: 700; box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.nav-sair:hover { filter: brightness(1.1); background: linear-gradient(to bottom, #E42323, #B30707); color: #ffffff; }
.nav-sair.active { border-left-color: transparent; }

/* ---------- 4.1 SIDEBAR RECOLHIDA (44px — UNIFICADO) ---------- */
@media (min-width: 769px) {
  body.colapsada .sidebar { width: var(--sidebar-colapsada) !important; overflow: visible; }
  body.colapsada .sidebar-toggle { align-self: center; margin: 10px auto 4px; width: 26px; height: 26px; font-size: 12px; }
  body.colapsada .nav-item { justify-content: center; gap: 0; padding: 10px 0; margin: 0; }
  body.colapsada .nav-item .ico { font-size: 14px; }
  body.colapsada .nav-item .txt { display: none; }
  body.colapsada .nav-item .nav-flutua {
    display: none; align-items: center; gap: 10px;
    position: absolute; left: calc(100% + 8px); top: 50%; transform: translateY(-50%);
    min-width: 210px; background: #2f2f2f; border: 1px solid rgba(255,255,255,0.18);
    box-shadow: 8px 8px 0 rgba(0,0,0,0.25), 0 10px 30px rgba(0,0,0,0.5);
    padding: 9px 14px; z-index: 999; font-size: 13px; font-weight: 600; color: #ffffff; white-space: nowrap;
  }
  body.colapsada .nav-item:hover .nav-flutua { display: flex; }
  body.colapsada .nav-item .nav-flutua .ico { font-size: 14px; width: auto; }
  body.colapsada .nav-sair { width: 30px; height: 30px; margin: 8px auto 10px; padding: 0; display: flex; align-items: center; justify-content: center; }
  body.colapsada .nav-sair .txt { display: none; }
  body.colapsada .nav-sair .ico { font-size: 15px; }
  body.colapsada .nav-sair:hover .nav-flutua { display: flex; }
  /* CONTEÚDO acompanha a sidebar de 44px (corrige o desalinhamento) */
  body.colapsada .main { margin-left: var(--sidebar-colapsada) !important; }
}
@media (max-width: 768px) { .sidebar-toggle { display: none; } }

/* ---------- 5. CONTEÚDO PRINCIPAL (centraliza e nunca passa da tela) ---------- */
.main {
  margin-left: var(--sidebar-larg);
  margin-top: var(--topbar-alt);
  padding: 28px 36px;
  min-height: calc(100vh - var(--topbar-alt));
  width: auto !important;
  max-width: 100% !important;
  overflow-x: hidden !important;
  box-sizing: border-box !important;
  transition: margin-left 0.3s ease;
}
.pagina-cabecalho { margin-bottom: 18px; }
.pagina-cabecalho h1 { font-size: clamp(20px, 2.2vw, 28px); color: var(--navy); font-weight: 800; }

/* ---------- 6. BOXES / CARDS ---------- */
.dash-box {
  background: #2a2a2a; border: 1px solid #2a2a2a; border-radius: 0;
  padding: 10px; margin-bottom: 30px;
  box-shadow: 10px 10px 0 #d9dfe3, 0 8px 18px rgba(13,32,53,0.35);
  width: 100% !important; max-width: 100% !important;
  margin-left: auto !important; margin-right: auto !important;
  box-sizing: border-box !important;
}
.card {
  background: #ffffff; border: 1px solid var(--borda); border-radius: 0;
  box-shadow: 0 2px 8px rgba(13,32,53,0.05); padding: 12px 18px; margin-bottom: 12px;
  width: 100% !important; max-width: 100% !important; box-sizing: border-box !important;
}

/* ---------- 7. FORMULÁRIOS ---------- */
.form-center {
  display: grid;
  grid-template-columns: minmax(0,1fr) minmax(0,2fr) minmax(0,1fr);
  gap: 10px; max-width: 1200px; margin: 0 auto;
  width: 100% !important; box-sizing: border-box !important;
}
.form-center > * { grid-column: 2; min-width: 0 !important; max-width: 100% !important; }
.field label { display: block; font-size: clamp(11px, 1.1vw, 12px); font-weight: 600; color: var(--navy); margin-bottom: 3px; text-align: left; }
.det-field {
  display: flex; align-items: center;
  height: var(--altura-controle); min-height: var(--altura-controle);
  border: 1px solid var(--campo-borda); background: #ffffff;
  box-shadow: inset 1px 1px 0 #ffffff, inset -1px -1px 0 #aeb6ba;
  font-size: clamp(12px, 1.1vw, 13px);
  min-width: 0 !important; max-width: 100% !important; box-sizing: border-box !important;
}
.det-field .det-label { flex-shrink: 0; font-weight: 600; color: var(--navy); letter-spacing: 0.02em; padding: 0 8px; white-space: nowrap; text-transform: uppercase; }
.det-field .det-label::after { content: ':'; }
.det-field input, .det-field select {
  flex: 1; min-width: 0; border: none; outline: none; font-size: inherit;
  font-weight: 600; text-transform: uppercase; background: transparent; color: #0b0f14;
  padding: 0 8px 0 0; box-sizing: border-box; height: 100%;
}
.det-field input::placeholder { color: var(--placeholder); opacity: 1; font-weight: 500; }
.det-field input.lowercase { text-transform: lowercase; }
.det-field:focus-within { border-color: var(--azul); box-shadow: inset 1px 1px 0 #ffffff, inset -1px -1px 0 #2f5d8a; }
.det-field.preenchido { background: var(--preenchido); }
.det-field.preenchido .det-label { color: var(--azul); }
.input-group {
  display: flex; gap: 8px; align-items: stretch;
  flex-wrap: wrap !important; min-width: 0 !important; max-width: 100% !important;
}
.input-group .det-field { flex: 1 1 180px; min-width: 0 !important; }
.input-group .btn { flex: 0 0 auto; white-space: nowrap; }
.search-bar { display: flex; gap: 10px; margin: 8px 0 16px; flex-wrap: wrap; align-items: stretch; width: 100% !important; }
.search-bar input {
  flex: 1 1 200px; min-width: 0; padding: 0 8px; height: var(--altura-controle);
  border: 1px solid var(--campo-borda); font-size: 13px;
  background: #f7f9fa; box-shadow: inset 1px 1px 0 #ffffff, inset -1px -1px 0 #aeb6ba;
  max-width: 100% !important;
}
.form-actions { display: flex; gap: 10px; margin-top: 4px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- 8. BOTÕES (mínimo 45px, alarga para caber o texto em 1 linha) ---------- */
.btn, button,
input[type="button"], input[type="submit"] {
  min-width: var(--largura-botao) !important;
  width: auto !important;
  min-height: var(--altura-botao) !important;
  height: var(--altura-botao) !important;
  padding: 0 10px !important;
  font-size: 12px !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--campo-borda);
  background: linear-gradient(135deg, #ffffff 0%, #e5e9ea 40%, #c3c9cc 100%);
  color: var(--btn-texto); font-weight: 600; cursor: pointer;
  box-shadow: inset 0 1px 0 #ffffff, inset -1px -1px 0 #aeb6ba;
  max-width: 100% !important;
}
.btn:hover { filter: brightness(1.03); }
.btn-vermelho { background: linear-gradient(135deg, #fbe6e6 0%, #f2d0d0 40%, #d9a5a5 100%) !important; color: #7a1f1f !important; border-color: #d9a5a5 !important; }
.btn-verde    { background: linear-gradient(135deg, #e2f3e6 0%, #c9e6d0 40%, #9fc9ab 100%) !important; color: #1d5c33 !important; border-color: #9fc9ab !important; }

/* ---------- 9. TABELAS (rolagem DENTRO da caixa, sem estourar a tela) ---------- */
.table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch; margin-top: 4px;
  width: 100% !important; max-width: 100% !important; box-sizing: border-box !important;
}
table { width: 100%; border-collapse: collapse; background: #f5f5f5; min-width: 900px; }
thead { background: #000000; }
thead th { color: #fff; text-align: left; padding: 4px 8px; font-size: clamp(11px, 1vw, 12px); font-weight: 700; white-space: nowrap; text-transform: uppercase; }
tbody td { padding: 4px 8px; height: var(--altura-controle); font-size: clamp(11px, 1.1vw, 13px); color: #374151; border-bottom: 1px solid #f1f5f9; white-space: nowrap; vertical-align: middle; }
tbody tr:hover td { background: #f6f9f9; }
.empty { text-align: center; color: var(--texto-suave); padding: 14px; }

/* ---------- 10. RESPONSIVIDADE + CENTRALIZAÇÃO (forçado) ---------- */
@media (max-width: 1200px) {
  .form-center { grid-template-columns: minmax(0,1fr) !important; max-width: 100% !important; }
  .form-center > * { grid-column: 1 / -1 !important; }
  .main { padding: 20px !important; }
  .topbar { padding: 0 20px !important; }
}
@media (max-width: 992px) {
  table tbody td { font-size: 11px !important; padding: 3px 6px !important; height: 28px !important; }
  thead th { font-size: 10px !important; padding: 3px 6px !important; }
  .det-field { height: 28px !important; min-height: 28px !important; }
}
@media (max-width: 768px) {
  .sidebar { position: fixed; top: auto; bottom: 0; left: 0; right: 0; width: 100% !important; height: auto; max-height: 56px; flex-direction: row !important; align-items: center; overflow-x: auto; overflow-y: hidden; z-index: 70; }
  .sidebar nav { display: flex !important; flex-direction: row !important; padding: 0 !important; }
  .sidebar nav .nav-sair { display: none !important; }
  .sidebar nav .nav-item { border-left: none !important; border-bottom: 3px solid transparent; padding: 16px 18px !important; }
  .sidebar nav .nav-item.active { border-bottom-color: var(--sage) !important; }
  .sidebar nav .nav-flutua { display: none !important; }
  .main { margin-left: 0 !important; margin-top: var(--topbar-alt) !important; margin-bottom: 56px; padding: 20px 16px !important; width: 100% !important; max-width: 100% !important; }
  .topbar { height: auto; min-height: var(--topbar-alt); padding: 10px 16px !important; }
  .topbar-actions { width: 100% !important; justify-content: space-between !important; }
  .user-info span { display: none !important; }
  .btn, button, input[type="button"], input[type="submit"] { width: 100% !important; min-width: 0 !important; height: 34px !important; font-size: 12px !important; margin: 2px 0 !important; }
  .det-field { width: 100% !important; max-width: 100% !important; }
  .input-group { flex-direction: column !important; align-items: stretch !important; }
  .input-group .det-field, .input-group .btn { width: 100% !important; flex: 1 1 100% !important; }
  .dash-box { padding: 8px !important; }
}
@media (max-width: 480px) {
  .main { padding: 14px 10px !important; }
}