:root {
  --azul: #1f4e79;
  --azul-claro: #2e6da4;
  --navy1: #0c1c3a;
  --navy2: #11264a;
  --cinza-bg: #f4f6f9;
  --borda: #d9dee5;
  --verde: #1a7f37;
  --vermelho: #c0392b;
  --texto: #2b333b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, Arial, sans-serif;
  background: var(--cinza-bg);
  color: var(--texto);
}
.oculto { display: none !important; }

/* ===================== LOGIN (padrao CCS DataVision) ===================== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: linear-gradient(135deg, #0c1c3a 0%, #11264a 50%, #0a1733 100%);
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 40px 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.55);
}
.login-logo { display: flex; justify-content: center; margin-bottom: 20px; }
.login-logo img { height: 80px; width: auto; object-fit: contain; }
.login-title { font-size: 26px; font-weight: 700; color: #1e293b; text-align: center; margin: 0; letter-spacing: -0.5px; }
.login-subtitle { font-size: 14px; color: #64748b; text-align: center; margin: 6px 0 26px; }
.login-field { display: block; margin-bottom: 16px; }
.login-field span { display: block; font-size: 13px; font-weight: 600; color: #334155; margin-bottom: 6px; }
.login-field input {
  width: 100%;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  color: #1e293b;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.login-field input:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,.2); }
.login-field input::placeholder { color: #94a3b8; }
.login-msg { font-size: 13px; border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; text-align: center; }
.login-msg-error { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }
.login-btn {
  width: 100%;
  padding: 12px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, transform .1s, opacity .15s;
}
.login-btn:hover { background: #1d4ed8; }
.login-btn:active { transform: scale(.99); }
.login-btn:disabled { opacity: .6; cursor: not-allowed; }

/* ===================== APP SHELL ===================== */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--navy1) 0%, var(--navy2) 100%);
  color: #cfd8e8;
  display: flex;
  flex-direction: column;
  transition: width .18s ease;
  overflow: hidden;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand img { height: 38px; width: auto; }
.sidebar-brand span { font-size: 13px; font-weight: 700; color: #fff; line-height: 1.2; }

.menu { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 8px;
  border: none;
  background: none;
  color: #cfd8e8;
  font-size: 14px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  width: 100%;
  transition: background .15s, color .15s;
}
.menu-item svg { width: 20px; height: 20px; flex-shrink: 0; stroke: currentColor; }
.menu-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.menu-item.ativo { background: var(--azul-claro); color: #fff; font-weight: 600; }
.menu-item.breve { opacity: .5; cursor: default; }
.menu-item.breve:hover { background: none; color: #cfd8e8; }
.menu-item .tag-breve { margin-left: auto; font-size: 9px; background: rgba(255,255,255,.15); padding: 2px 6px; border-radius: 10px; text-transform: uppercase; letter-spacing: .04em; }
.sidebar-foot { padding: 14px 18px; font-size: 11px; color: #6b7a93; border-top: 1px solid rgba(255,255,255,.08); }

/* ----- Sidebar recolhida (trilho de icones) ----- */
.app.sidebar-collapsed .sidebar { width: 60px; }
.app.sidebar-collapsed .sidebar-brand span,
.app.sidebar-collapsed .menu-item span,
.app.sidebar-collapsed .sidebar-foot { display: none; }
.app.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 16px 0; }
.app.sidebar-collapsed .menu-item { justify-content: center; padding: 11px 0; gap: 0; }

.topbar-left { display: flex; align-items: center; gap: 14px; }
.btn-toggle {
  background: #fff; border: 1px solid var(--borda); border-radius: 6px;
  width: 34px; height: 34px; cursor: pointer; color: var(--azul);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.btn-toggle svg { width: 20px; height: 20px; }
.btn-toggle:hover { background: #eef2f7; }

.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--borda);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar h2 { margin: 0; font-size: 18px; font-weight: 600; color: var(--azul); }
.user-box { display: flex; align-items: center; gap: 14px; }
.user-name { font-size: 13px; color: #66707a; font-weight: 600; }
#btnSair {
  background: #fff; border: 1px solid var(--borda); color: #66707a;
  padding: 6px 14px; border-radius: 6px; font-size: 13px; cursor: pointer; font-family: inherit;
}
#btnSair:hover { background: #fef2f2; border-color: #fecaca; color: var(--vermelho); }

#conteudo { padding: 20px 24px; overflow: auto; }
.tela { max-width: 1180px; margin: 0 auto; }
.em-breve { background: #fff; border: 1px dashed var(--borda); border-radius: 10px; padding: 60px 24px; text-align: center; color: #8a949e; }
.em-breve h3 { color: var(--azul); margin: 0 0 8px; }

/* ===================== ABAS (Kardex Mega / CCS) ===================== */
.abas { display: flex; gap: 4px; border-bottom: 2px solid var(--borda); margin-bottom: 16px; }
.aba {
  background: none; border: none; padding: 10px 22px; font-size: 14px; font-weight: 600;
  color: #66707a; cursor: pointer; font-family: inherit;
  border-bottom: 3px solid transparent; margin-bottom: -2px;
}
.aba:hover { color: var(--azul); }
.aba.ativa { color: var(--azul); border-bottom-color: var(--azul-claro); }

/* ===================== FILTROS / KARDEX ===================== */
.filtros {
  display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap;
  background: #fff; padding: 16px 18px; border: 1px solid var(--borda); border-radius: 8px;
}
.campo { display: flex; flex-direction: column; }
.campo label { font-size: 12px; color: #66707a; margin-bottom: 4px; text-transform: uppercase; letter-spacing: .03em; }
.campo input, .campo select { padding: 8px 10px; border: 1px solid var(--borda); border-radius: 6px; font-size: 14px; min-width: 150px; }
.item-input { display: flex; gap: 6px; }
.item-input input { min-width: 120px; }
#btnBuscarItem {
  background: #fff; border: 1px solid var(--borda); border-radius: 6px;
  width: 38px; flex-shrink: 0; cursor: pointer; color: var(--azul-claro);
  display: flex; align-items: center; justify-content: center;
}
#btnBuscarItem svg { width: 18px; height: 18px; }
#btnBuscarItem:hover { background: #eef2f7; }

/* ----- Modal de busca de item ----- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(12, 28, 58, .5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 8vh 16px 16px; z-index: 100;
}
.modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 720px;
  max-height: 78vh; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,.5);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--borda);
  font-size: 16px; font-weight: 700; color: var(--azul);
}
.modal-close { background: none; border: none; font-size: 24px; line-height: 1; color: #8a949e; cursor: pointer; }
.modal-close:hover { color: var(--vermelho); }
#itemBusca { margin: 14px 18px 8px; padding: 11px 14px; border: 1px solid var(--borda); border-radius: 8px; font-size: 15px; outline: none; }
#itemBusca:focus { border-color: var(--azul-claro); box-shadow: 0 0 0 3px rgba(46,109,164,.15); }
.modal-body { overflow-y: auto; margin: 4px 0 8px; }
.modal-body table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.modal-body thead th { position: sticky; top: 0; background: #eef2f7; text-align: left; padding: 8px 18px; border-bottom: 1px solid var(--borda); }
.modal-body tbody td { padding: 8px 18px; border-bottom: 1px solid #eef1f4; }
.modal-body tbody tr.clicavel { cursor: pointer; }
.modal-body tbody tr.clicavel:hover { background: #e3edf7; }
.modal-body tbody tr.vazio td { text-align: center; color: #8a949e; padding: 22px; }

#btnBuscar {
  background: var(--azul-claro); color: #fff; border: 0; padding: 10px 22px;
  border-radius: 6px; font-size: 14px; font-weight: 600; cursor: pointer; height: 38px;
}
#btnBuscar:hover { background: var(--azul); }
#btnBuscar:disabled { opacity: .6; cursor: progress; }

.cabecalho {
  margin-top: 18px; background: #fff; border: 1px solid var(--borda); border-radius: 8px;
  padding: 16px 18px; display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap;
}
.prod strong { display: block; font-size: 17px; }
.prod .meta { color: #66707a; font-size: 13px; }
.saldos { display: flex; gap: 12px; flex-wrap: wrap; }
.saldo-box { background: var(--cinza-bg); border: 1px solid var(--borda); border-radius: 6px; padding: 8px 14px; text-align: right; min-width: 130px; }
.saldo-box span { display: block; font-size: 11px; color: #66707a; text-transform: uppercase; }
.saldo-box b { font-size: 18px; }
.saldo-box .ent { color: var(--verde); }
.saldo-box .sai { color: var(--vermelho); }
.saldo-box.final { background: var(--azul); }
.saldo-box.final span, .saldo-box.final b { color: #fff; }

.aviso { margin-top: 14px; padding: 10px 14px; border-radius: 6px; font-size: 14px; }
.aviso.erro { background: #fdecea; color: var(--vermelho); border: 1px solid #f5c6cb; }
.aviso.info { background: #fff8e1; color: #8a6d00; border: 1px solid #ffe08a; }

.tabela-wrap { margin-top: 16px; background: #fff; border: 1px solid var(--borda); border-radius: 8px; overflow: hidden; }

/* Grid do Kardex com rolagem propria, mantendo a Caracteristica visivel abaixo */
#kardexGrid { max-height: 46vh; overflow-y: auto; }
#kardexGrid thead th { z-index: 2; }
#saldoGrid { max-height: 62vh; overflow-y: auto; }
.caract-wrap .tabela-wrap { max-height: 30vh; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
thead th { background: #eef2f7; text-align: left; padding: 6px 8px; border-bottom: 2px solid var(--borda); position: sticky; top: 0; white-space: nowrap; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody td { padding: 3px 8px; border-bottom: 1px solid #eef1f4; line-height: 1.3; }
tbody tr.linha-ent { background: #f0faf3; box-shadow: inset 3px 0 0 #9fd8b4; }
tbody tr.linha-sai { background: #fdf1f0; box-shadow: inset 3px 0 0 #e2a8a1; }
tbody tr:hover { background: #f7fafc; }
tbody tr.linha-ent:hover { background: #e6f5ec; }
tbody tr.linha-sai:hover { background: #fbe7e5; }
td.ent { color: var(--verde); }
td.sai { color: var(--vermelho); }
td.saldo { font-weight: 600; }
tr.saldo-ant td { background: #f0f4f8; font-style: italic; color: #555; }
tr.vazio td { text-align: center; color: #8a949e; padding: 28px; }

tbody tr.clicavel { cursor: pointer; }
tbody tr.sel { outline: 2px solid var(--azul-claro); outline-offset: -2px; background: #e3edf7 !important; }

/* ===================== CARACTERÍSTICA DE ESTOQUE ===================== */
.caract-wrap { margin-top: 18px; }
.caract-head {
  font-size: 14px; font-weight: 700; color: var(--azul);
  padding: 4px 2px 10px; display: flex; align-items: baseline; gap: 8px;
}
.caract-ctx { font-weight: 400; font-size: 12px; color: #8a949e; }
.caract-wrap table { font-size: 13px; }
.caract-wrap thead th { background: #e9f0f7; }
