:root {
    --bg: #f4f7fb;
    --card: #ffffff;
    --text: #1c2733;
    --muted: #667085;
    --primary: #1746a2;
    --primary-dark: #0f347c;
    --success: #148a4a;
    --warning: #b7791f;
    --danger: #b42318;
    --border: #d9e2ec;
    --soft: #eef4ff;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar {
    background: linear-gradient(135deg, #0f347c, #1746a2);
    color: #fff;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    box-shadow: 0 8px 24px rgba(15,52,124,.16);
}
.brand { font-weight: 800; font-size: 20px; letter-spacing: .2px; }
.nav { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.nav a { color: #fff; opacity: .92; font-weight: 600; font-size: 14px; }
.nav a:hover { opacity: 1; }
.container { width: min(1180px, calc(100% - 32px)); margin: 28px auto; }
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 22px;
    box-shadow: 0 8px 30px rgba(28,39,51,.06);
    margin-bottom: 20px;
}
.auth-wrap { min-height: calc(100vh - 70px); display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(460px, 100%); }
h1,h2,h3 { margin: 0 0 14px; line-height: 1.2; }
p { line-height: 1.55; }
.muted { color: var(--muted); }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 850px) { .grid-2,.grid-3,.grid-4 { grid-template-columns: 1fr; } .topbar { align-items: flex-start; flex-direction: column; } }
label { display: block; font-weight: 700; margin-bottom: 7px; font-size: 14px; }
input, select, textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    font-size: 15px;
}
textarea { min-height: 95px; }
.form-row { margin-bottom: 14px; }
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 12px;
    padding: 10px 14px;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
    cursor: pointer;
    min-height: 42px;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn-secondary { background: #eef4ff; color: var(--primary); }
.btn-secondary:hover { background: #dbe8ff; }
.btn-danger { background: var(--danger); }
.btn-success { background: var(--success); }
.btn-small { padding: 7px 10px; min-height: 34px; font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.alert { border-radius: 14px; padding: 12px 14px; margin-bottom: 16px; border: 1px solid; }
.alert-success { background: #ecfdf3; color: #027a48; border-color: #abefc6; }
.alert-error { background: #fef3f2; color: #b42318; border-color: #fecdca; }
.alert-warning { background: #fffaeb; color: #b54708; border-color: #fedf89; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.badge { display: inline-flex; border-radius: 999px; padding: 4px 9px; font-size: 12px; font-weight: 800; background: #eef4ff; color: var(--primary); }
.badge-success { background: #ecfdf3; color: var(--success); }
.badge-warning { background: #fffaeb; color: var(--warning); }
.badge-danger { background: #fef3f2; color: var(--danger); }
.badge-muted { background: #f2f4f7; color: var(--muted); }
.stat { padding: 18px; border-radius: 16px; border: 1px solid var(--border); background: #fff; }
.stat .num { font-size: 26px; font-weight: 900; margin-top: 8px; }
.stat .label { color: var(--muted); font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.footer { text-align: center; color: var(--muted); padding: 24px; font-size: 13px; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; word-break: break-all; }
hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.checkbox-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.checkbox-item { border: 1px solid var(--border); border-radius: 12px; padding: 10px; display: flex; gap: 8px; align-items: center; }
.checkbox-item input { width: auto; }

.modal.hidden { display: none; }
.modal { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 22px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(16, 24, 40, .55); }
.modal-panel { position: relative; z-index: 1; width: min(1180px, 100%); max-height: min(86vh, 860px); overflow: auto; background: var(--card); border-radius: 18px; padding: 22px; border: 1px solid var(--border); box-shadow: 0 24px 80px rgba(16,24,40,.25); }
.modal-content { margin-top: 14px; }
.modal-open { overflow: hidden; }
.modal-summary { margin-bottom: 18px; }

/* V4 - Barra horizontal flutuante para tabelas largas */
.table-wrap { overflow-x: auto; position: relative; }
.floating-scrollbar {
    position: fixed;
    bottom: 0;
    height: 18px;
    overflow-x: auto;
    overflow-y: hidden;
    background: rgba(255,255,255,.96);
    border-top: 1px solid var(--border);
    box-shadow: 0 -6px 18px rgba(16,24,40,.10);
    z-index: 999;
    display: none;
}
.floating-scrollbar-inner { height: 1px; }

/* V5 - Cadastro de empresas em lista única com modal e consulta por CNPJ */
.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}
.page-head h1 { margin-bottom: 6px; }
.toolbar-form {
    display: flex;
    gap: 12px;
    align-items: end;
    margin-bottom: 16px;
}
.toolbar-search { flex: 1; margin-bottom: 0; }
.toolbar-actions { padding-bottom: 0; }
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 14px;
}
.modal-header p { margin: 0; }
.modal-company-panel { width: min(920px, 100%); }
.cnpj-lookup-row {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) auto;
    gap: 12px;
    align-items: end;
}
.hidden { display: none !important; }
@media (max-width: 760px) {
    .page-head,
    .toolbar-form,
    .modal-header { flex-direction: column; align-items: stretch; }
    .cnpj-lookup-row { grid-template-columns: 1fr; }
}
