/* MMD NFS-e 2.0 — estilo base (sem dependências externas) */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-600: #1d4ed8;
  --primary-50: #eff6ff;
  --green: #15803d;   --green-bg: #dcfce7;
  --yellow: #a16207;  --yellow-bg: #fef9c3;
  --red: #b91c1c;     --red-bg: #fee2e2;
  --blue: #1d4ed8;    --blue-bg: #dbeafe;
  --gray: #475569;    --gray-bg: #e2e8f0;
  --sidebar: #0f172a;
  --sidebar-text: #cbd5e1;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.08);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 18px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-family: Consolas, "Courier New", monospace; }

/* ---------- Estrutura ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 4px 8px 18px; color: #fff; font-weight: 600; }
.brand img { max-height: 40px; max-width: 170px; background: #fff; border-radius: 6px; padding: 3px; }
.brand img.claro { background: transparent; padding: 0; max-height: 46px; } /* logo claro: direto sobre o menu escuro */
.logo-preview.claro { background: #0f172a; }
.sidebar a { color: var(--sidebar-text); padding: 9px 12px; border-radius: 8px; display: flex; gap: 10px; align-items: center; }
.sidebar a:hover { background: rgba(255,255,255,.07); text-decoration: none; color: #fff; }
.sidebar a.ativo { background: var(--primary); color: #fff; }
.sidebar .sep { height: 1px; background: rgba(255,255,255,.1); margin: 10px 4px; }
.sidebar .rodape { margin-top: auto; font-size: .8rem; padding: 8px; }
.main { min-width: 0; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 24px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar .quem { display: flex; flex-direction: column; }
.topbar form { margin: 0; }
.conteudo { padding: 24px; max-width: 1200px; }
.cabecalho { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.btn.menu-toggle { display: none; }

/* ---------- Cards / grid ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
.kpi .valor { font-size: 1.6rem; font-weight: 700; }
.kpi .rotulo { color: var(--muted); font-size: .85rem; }

/* ---------- Barra de quota ---------- */
.quota { margin-top: 8px; }
.barra { height: 12px; background: var(--gray-bg); border-radius: 99px; overflow: hidden; }
.barra > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.barra.alerta > span { background: #eab308; }
.barra.critico > span { background: #dc2626; }
.quota .legenda { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); margin-top: 6px; }

/* ---------- Tabelas ---------- */
.tabela-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--surface-2); }
tr:hover td { background: var(--surface-2); }
td.acoes { white-space: nowrap; text-align: right; }
td.acoes form { display: inline; }
.vazio { text-align: center; color: var(--muted); padding: 30px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge.verde { background: var(--green-bg); color: var(--green); }
.badge.amarelo { background: var(--yellow-bg); color: var(--yellow); }
.badge.vermelho { background: var(--red-bg); color: var(--red); }
.badge.azul { background: var(--blue-bg); color: var(--blue); }
.badge.cinza { background: var(--gray-bg); color: var(--gray); }

/* ---------- Botões ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primario { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primario:hover { background: var(--primary-600); }
.btn-perigo { color: var(--red); border-color: #fecaca; }
.btn-perigo:hover { background: var(--red-bg); }
.btn-sm { padding: 4px 10px; font-size: .85rem; }
.btn-link { border: 0; background: none; color: var(--primary); padding: 0; cursor: pointer; font: inherit; }
.desabilitado { opacity: .45; pointer-events: none; }
.botoes { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }

/* ---------- Formulários ---------- */
.form-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 12px 14px; }
.c2 { grid-column: span 2; } .c3 { grid-column: span 3; } .c4 { grid-column: span 4; }
.c5 { grid-column: span 5; } .c6 { grid-column: span 6; } .c7 { grid-column: span 7; } .c8 { grid-column: span 8; } .c12 { grid-column: span 12; }
label { display: block; font-size: .83rem; font-weight: 600; color: #334155; margin-bottom: 4px; }
label .req { color: var(--red); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=month], input[type=search], input[type=file], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 8px; font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-50); border-color: var(--primary); }
input[readonly] { background: var(--surface-2); color: var(--muted); }
textarea { min-height: 90px; resize: vertical; }
.dica { font-size: .78rem; color: var(--muted); margin-top: 3px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 18px; height: 18px; }
.com-botao { display: flex; gap: 6px; }
.com-botao input { flex: 1; }
.filtros { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.filtros > div { min-width: 160px; }

/* Chave (switch) IBS/CBS */
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.switch input { appearance: none; width: 42px; height: 24px; background: #cbd5e1; border-radius: 99px; position: relative; cursor: pointer; transition: .2s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { left: 21px; }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px 14px; }
.bloco-ibscbs { border: 1px dashed #93c5fd; background: var(--primary-50); border-radius: var(--radius); padding: 16px; margin-top: 12px; }
.oculto { display: none !important; }

/* Resumo de valores */
.resumo { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.resumo div { display: flex; justify-content: space-between; padding: 4px 0; }
.resumo .total { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; font-weight: 700; font-size: 1.1rem; }

/* ---------- Alertas ---------- */
.alerta { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.alerta.ok { background: var(--green-bg); color: var(--green); border-color: #bbf7d0; }
.alerta.erro { background: var(--red-bg); color: var(--red); border-color: #fecaca; }
.alerta.aviso { background: var(--yellow-bg); color: var(--yellow); border-color: #fde68a; }
.alerta.info { background: var(--blue-bg); color: var(--blue); border-color: #bfdbfe; }

/* ---------- Autocomplete ---------- */
.ac { position: relative; }
.ac-lista { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(15,23,42,.12); max-height: 300px; overflow-y: auto; margin-top: 4px; }
.ac-item { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.ac-item:last-child { border-bottom: 0; }
.ac-item:hover, .ac-item.ativo { background: var(--primary-50); }
.ac-item small { color: var(--muted); display: block; }
.selecionado { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; background: var(--primary-50); border: 1px solid #bfdbfe; border-radius: 8px; }

/* ---------- Modal ---------- */
.modal-fundo { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 820px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal header, .modal footer { padding: 14px 20px; display: flex; justify-content: space-between; align-items: center; }
.modal header { border-bottom: 1px solid var(--border); }
.modal footer { border-top: 1px solid var(--border); justify-content: flex-end; gap: 8px; }
.modal .corpo { padding: 20px; }

/* ---------- Login ---------- */
.tela-simples { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(135deg, #0f172a, #1e3a8a); }
.caixa { background: #fff; border-radius: 14px; padding: 32px; width: 100%; max-width: 400px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.caixa h1 { text-align: center; }
.caixa .sub { text-align: center; color: var(--muted); margin-bottom: 22px; }
.caixa .campo { margin-bottom: 14px; }
.caixa .btn { width: 100%; justify-content: center; padding: 10px; }

/* ---------- Detalhe ---------- */
dl.dados { display: grid; grid-template-columns: 190px 1fr; gap: 6px 14px; margin: 0; }
dl.dados dt { color: var(--muted); font-size: .88rem; }
dl.dados dd { margin: 0; }
.paginacao { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.logo-preview { max-height: 90px; max-width: 260px; border: 1px solid var(--border); border-radius: 8px; padding: 6px; background: #fff; }

/* ---------- Responsivo ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 250px; transform: translateX(-100%); transition: transform .2s; z-index: 40; }
  .sidebar.aberta { transform: none; }
  .btn.menu-toggle { display: inline-flex; }
  .g2, .g3, .g4 { grid-template-columns: 1fr 1fr; }
  .form-grid > * { grid-column: span 12; }
  .grid-5 { grid-template-columns: 1fr 1fr; }
  .sidebar.aberta { box-shadow: 0 0 0 100vmax rgba(15,23,42,.45); }
  .conteudo { padding: 16px; }
  dl.dados { grid-template-columns: 1fr; }
  dl.dados dt { margin-top: 6px; }
}
@media (max-width: 560px) {
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .topbar { padding: 10px 16px; }
}
