:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e4e8ef;
  --border-strong: #d3d9e3;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #eff4ff;
  --ok: #047857;      --ok-soft: #ecfdf5;      --ok-line: #a7f3d0;
  --warn: #b45309;    --warn-soft: #fffbeb;    --warn-line: #fde68a;
  --bad: #b91c1c;     --bad-soft: #fef2f2;     --bad-line: #fecaca;
  --neutral: #475569; --neutral-soft: #f1f5f9; --neutral-line: #e2e8f0;
  --green: #16a34a; --green-hover: #15803d; --green-soft: #f0fdf4; --green-line: #bbf7d0; --green-text: #166534;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .04);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Mono', Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #0f172a;
    --border: #1f2937;
    --border-strong: #334155;
    --text: #e5e7eb;
    --text-2: #cbd5e1;
    --muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-soft: #172554;
    --ok: #34d399;      --ok-soft: #052e22;      --ok-line: #065f46;
    --warn: #fbbf24;    --warn-soft: #2a1d05;    --warn-line: #78350f;
    --bad: #f87171;     --bad-soft: #2a0d0d;     --bad-line: #7f1d1d;
    --neutral: #cbd5e1; --neutral-soft: #1e293b; --neutral-line: #334155;
    --green: #16a34a; --green-hover: #22c55e; --green-soft: #052e16; --green-line: #14532d; --green-text: #4ade80;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 var(--font);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
main { flex: 1; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; margin: 6px 0 0; }
.mono { font-family: var(--mono); font-size: .94em; letter-spacing: .01em; }
.ico { width: 18px; height: 18px; flex: none; }
.ico--sm { width: 15px; height: 15px; }

/* ---------- topbar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar__inner { display: flex; align-items: center; justify-content: space-between; height: 64px; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 17px; }
.brand:hover { text-decoration: none; }
.brand__mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: var(--primary); color: #fff;
}
.brand__mark .ico { width: 19px; height: 19px; }
.topbar__note { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }

/* ---------- search */
.search { padding: 28px 0 8px; }
.is-home .search { max-width: 760px; margin: 0 auto; padding: 8vh 0 40px; text-align: center; }
.search__title { font-size: clamp(26px, 4.4vw, 38px); line-height: 1.15; font-weight: 700; }
.search__lead { color: var(--muted); font-size: 16.5px; margin: 12px auto 28px; max-width: 540px; }
.search__form { max-width: 680px; }
.is-home .search__form { margin: 0 auto; }
.field {
  position: relative; display: flex; align-items: center;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px;
  box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s;
}
.field:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 16%, transparent); }
.field.is-invalid { border-color: var(--bad); box-shadow: 0 0 0 4px color-mix(in srgb, var(--bad) 14%, transparent); }
.field__icon { position: absolute; left: 16px; color: var(--muted); }
.field__input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text);
  font: 500 18px var(--mono); letter-spacing: .03em; padding: 16px 12px 16px 46px;
}
.field__input::placeholder { color: var(--muted); opacity: .55; }
.field__btn { margin: 6px; }
.search__hint { color: var(--muted); font-size: 13px; margin: 10px 2px 0; min-height: 20px; }
.is-home .search__hint { text-align: center; }
.search__hint.is-error { color: var(--bad); font-weight: 500; }

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; border-radius: 10px; padding: 0 16px; height: 40px;
  font: 600 14px var(--font); cursor: pointer; white-space: nowrap; color: var(--text-2);
  background: transparent; transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { text-decoration: none; }
.btn--primary { background: var(--primary); color: #fff; height: 46px; padding: 0 24px; font-size: 15px; }
.btn--primary:hover { background: var(--primary-hover); }
.btn--ghost { border-color: var(--border); background: var(--surface); }
.btn--ghost:hover { border-color: var(--border-strong); background: var(--surface-2); color: var(--text); }
.btn--sm { height: 34px; padding: 0 12px; font-size: 13px; }
.btn .ico { width: 16px; height: 16px; }
.btn[disabled] { opacity: .75; cursor: progress; }
.spinner {
  display: none; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .4); border-top-color: #fff; animation: spin .7s linear infinite;
}
.is-loading .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--neutral-soft); color: var(--text); }
.icon-btn .ico { width: 16px; height: 16px; }
.link-btn {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 0;
  color: var(--primary); font: 500 13px var(--font); cursor: pointer;
}

/* ---------- recent */
.recent { margin-top: 36px; text-align: left; }
.recent__head { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px; }
.recent__head .link-btn { text-transform: none; letter-spacing: 0; }
.recent__list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.recent__list li + li { border-top: 1px solid var(--border); }
.recent__list a { display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: var(--text); }
.recent__list a:hover { background: var(--surface-2); text-decoration: none; }
.recent__name { flex: 1; min-width: 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent__cnpj { color: var(--muted); font-family: var(--mono); font-size: 13px; }

/* ---------- alerts */
.alert {
  display: flex; gap: 14px; align-items: flex-start; max-width: 680px; margin: 8px 0 24px;
  padding: 16px 18px; border-radius: 12px; border: 1px solid;
}
.is-home .alert { margin: 0 auto 40px; }
.alert p { margin: 2px 0 0; color: var(--text-2); }
.alert__icon { width: 22px; height: 22px; margin-top: 1px; }
.alert--bad { background: var(--bad-soft); border-color: var(--bad-line); color: var(--bad); }
.alert--warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }

/* ---------- cards */
.result { padding: 12px 0 40px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px 24px; min-width: 0;
}
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card__head .card__title { margin: 0; }
.card__title { display: flex; align-items: center; gap: 9px; font-size: 15px; font-weight: 600; margin-bottom: 14px; }
.card__title .ico { color: var(--primary); }
.card__foot { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.card--wide { grid-column: 1 / -1; }

/* summary */
.summary { position: relative; overflow: hidden; padding: 24px 28px 26px; }
.summary::before { content: ''; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--neutral-line); }
.summary--ok::before { background: var(--ok); }
.summary--warn::before { background: var(--warn); }
.summary--bad::before { background: var(--bad); }
.summary__top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.badges, .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.summary__name { font-size: clamp(21px, 3vw, 28px); line-height: 1.2; font-weight: 700; margin-top: 18px; word-break: break-word; }
.summary__alias { margin: 6px 0 0; color: var(--muted); font-size: 16px; font-weight: 500; }
.summary__cnpj { display: flex; align-items: center; gap: 4px; margin-top: 10px; color: var(--text-2); font-size: 16px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; margin: 22px 0 0; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.kpis > div { padding: 14px 18px; min-width: 0; }
.kpis > div + div { border-left: 1px solid var(--border); }
.kpis dt { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.kpis dd { margin: 4px 0 0; font-weight: 600; font-size: 15px; word-break: break-word; }
.kpis small { display: block; color: var(--muted); font-weight: 500; font-size: 12.5px; }

/* badges */
.badge {
  display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 11px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; letter-spacing: .02em; border: 1px solid;
  background: var(--neutral-soft); color: var(--neutral); border-color: var(--neutral-line);
}
.badge--sm { height: 24px; font-size: 12px; padding: 0 9px; }
.badge--ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-line); }
.badge--warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.badge--bad { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-line); }
.badge--outline { background: var(--surface); color: var(--text-2); border-color: var(--border-strong); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--primary-soft); color: var(--primary); font-size: 11.5px; font-weight: 600; }
.tag--muted { background: var(--neutral-soft); color: var(--muted); margin-left: 4px; }
.count { display: inline-grid; place-items: center; min-width: 22px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--neutral-soft); color: var(--muted); font-size: 12px; font-weight: 600; }

/* definition list */
.list { margin: 0; }
.list > div { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 12px; padding: 9px 0; border-top: 1px solid var(--border); }
.list > div:first-child { border-top: 0; padding-top: 0; }
.list dt { color: var(--muted); font-size: 13.5px; }
.list dd { margin: 0; font-weight: 500; word-break: break-word; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.list dd small { color: var(--muted); font-weight: 400; font-size: 12.5px; }

/* cnae */
.subhead { display: flex; align-items: center; gap: 8px; margin: 18px 0 8px; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.cnae { display: flex; align-items: baseline; gap: 14px; padding: 9px 0; }
.cnae--main { background: var(--primary-soft); border-radius: 10px; padding: 12px 14px; align-items: center; }
.cnae--main .cnae__desc { font-weight: 600; }
.cnae__code { flex: none; color: var(--primary); font-weight: 600; min-width: 96px; }
.cnae__desc { flex: 1; min-width: 0; }
.cnae-list { list-style: none; margin: 0; padding: 0; columns: 2; column-gap: 32px; }
.cnae-list .cnae { break-inside: avoid; border-top: 1px solid var(--border); }
.cnae-list .cnae__code { color: var(--text-2); font-weight: 500; }

/* years */
.years { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.year { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; background: var(--surface-2); }
.year span { display: block; color: var(--muted); font-size: 12px; }
.year strong { font-size: 13.5px; font-weight: 600; }

/* table */
.filter {
  height: 36px; width: 240px; max-width: 100%; padding: 0 12px; border-radius: 9px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: 14px var(--font); outline: 0;
}
.filter:focus { border-color: var(--primary); }
.table-wrap { overflow-x: auto; margin: 0 -24px; padding: 0 24px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; padding: 0 12px 10px 0; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px 12px 12px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table td strong { font-weight: 600; }
.table td small { display: block; color: var(--muted); font-size: 12.5px; }
.table tr[hidden] { display: none !important; }

/* source footer */
.source { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 18px; color: var(--muted); font-size: 13px; }
.source > span { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.source strong { color: var(--text-2); }
.site-footer { border-top: 1px solid var(--border); color: var(--muted); font-size: 12.5px; padding: 18px 0; text-align: center; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .2); transition: opacity .2s, transform .2s; z-index: 50;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Pix MEI */
.btn--green { background: var(--green); color: #fff; height: 46px; padding: 0 20px; font-size: 15px; white-space: normal; text-align: center; line-height: 1.25; }
.btn--green:hover { background: var(--green-hover); }
.btn--green[disabled] { opacity: .55; cursor: not-allowed; }
.btn--block { display: flex; width: 100%; height: 52px; font-size: 16px; }
.mei-cta {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  margin-top: 16px; padding: 16px 20px; border-radius: var(--radius);
  background: var(--green-soft); border: 1px solid var(--green-line);
}
.mei-cta__text { display: flex; flex-direction: column; min-width: 0; flex: 1 1 260px; }
.mei-cta__text strong { color: var(--green-text); }
.mei-cta__text span { color: var(--text-2); font-size: 14px; }

.mei-notice {
  display: flex; align-items: center; gap: 12px; margin: 0 auto 28px; max-width: 680px;
  padding: 14px 18px; border-radius: var(--radius); text-align: left; cursor: pointer;
  background: var(--green-soft); border: 1px solid var(--green-line); color: var(--text-2); font-size: 15px;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--green) 8%, transparent);
}
.mei-notice strong { color: var(--green-text); }
.mei-notice__icon { display: grid; place-items: center; flex: none; width: 38px; height: 38px; border-radius: 10px; background: var(--green); color: #fff; }
.mei-notice__icon .ico { width: 20px; height: 20px; }

.modal {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow-y: auto;
  border: 0; border-radius: 18px; padding: 32px 28px 24px; background: var(--surface); color: var(--text);
  box-shadow: 0 24px 64px rgba(15, 23, 42, .3);
}
.modal::backdrop { background: rgba(15, 23, 42, .55); backdrop-filter: blur(2px); }
.modal[open] { animation: modal-in .18s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal__close { position: absolute; top: 12px; right: 12px; }
.modal__icon { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 14px; background: var(--green-soft); color: var(--green); margin-bottom: 14px; }
.modal__icon .ico { width: 26px; height: 26px; }
.modal__title { font-size: 23px; font-weight: 700; margin-bottom: 10px; }
.modal p { margin: 0 0 12px; color: var(--text-2); }
.modal strong { color: var(--text); }
.modal__warn { display: flex; gap: 10px; padding: 12px 14px; margin-bottom: 12px; border-radius: 10px; background: var(--warn-soft); border: 1px solid var(--warn-line); color: var(--warn); }
.modal__warn p { margin: 0; font-size: 14px; }
.modal__warn .ico { margin-top: 2px; }
.checklist { list-style: none; margin: 0 0 20px; padding: 0; display: grid; gap: 10px; }
.checklist li { display: flex; gap: 10px; align-items: flex-start; font-size: 14.5px; }
.checklist .ico { color: var(--green); margin-top: 2px; }
.modal__note { margin: 8px 0 0 !important; text-align: center; font-size: 12.5px; color: var(--warn) !important; }
.modal__disclaimer { margin: 16px 0 0 !important; font-size: 12px; color: var(--muted) !important; line-height: 1.45; }

/* ---------- página de obrigado */
.thanks { max-width: 600px; margin: 0 auto; padding: 7vh 0 48px; text-align: center; }
.thanks__check {
  display: grid; place-items: center; width: 76px; height: 76px; margin: 0 auto 22px; border-radius: 50%;
  background: var(--green); color: #fff; box-shadow: 0 0 0 10px var(--green-soft);
  animation: pop .4s cubic-bezier(.2, 1.4, .4, 1);
}
.thanks__check .ico { width: 40px; height: 40px; stroke-width: 2.5; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
.thanks__title { font-size: clamp(26px, 4.4vw, 34px); line-height: 1.15; font-weight: 700; }
.thanks__lead { color: var(--text-2); font-size: 17px; margin: 12px auto 24px; }
.thanks__whats {
  display: flex; align-items: center; gap: 14px; text-align: left; padding: 16px 18px; margin-bottom: 16px;
  border-radius: var(--radius); background: var(--green-soft); border: 1px solid var(--green-line);
}
.thanks__whats > div { display: flex; flex-direction: column; }
.thanks__whats strong { color: var(--green-text); font-size: 16px; }
.thanks__whats span { color: var(--text-2); font-size: 14px; }
.thanks__whats-icon { display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: 12px; background: var(--green); color: #fff; }
.thanks__whats-icon .ico { width: 22px; height: 22px; }
.thanks__steps { text-align: left; margin-bottom: 16px; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.steps li { display: flex; gap: 12px; align-items: flex-start; }
.steps li > span { display: grid; place-items: center; flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-size: 13px; font-weight: 700; }
.steps p { margin: 2px 0 0; color: var(--text-2); font-size: 14.5px; }
.steps strong { color: var(--text); }
.thanks__alert { text-align: left; max-width: none; margin: 0 0 24px; }
.thanks__disclaimer { margin: 20px 0 0; color: var(--muted); font-size: 12px; }

/* ---------- responsive */
@media (max-width: 900px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis > div:nth-child(3) { border-left: 0; }
  .kpis > div:nth-child(n+3) { border-top: 1px solid var(--border); }
  .cnae-list { columns: 1; }
}
@media (max-width: 600px) {
  .wrap { padding: 0 16px; }
  .topbar__note { display: none; }
  .is-home .search { padding-top: 7vh; }
  .card { padding: 18px; }
  .summary { padding: 20px 18px 22px; }
  .table-wrap { margin: 0 -18px; padding: 0 18px; }
  .field__input { font-size: 16px; padding-left: 42px; }
  .field__icon { left: 14px; }
  .btn--primary { padding: 0 16px; }
  .actions .btn span { display: none; }
  .actions .btn { width: 40px; padding: 0; }
  .list > div { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .cnae, .cnae--main { flex-direction: column; align-items: flex-start; gap: 2px; }
  .cnae__code { min-width: 0; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 12px 0; border-bottom: 1px solid var(--border); }
  .table tr:last-child { border-bottom: 0; }
  .table td { border: 0; padding: 2px 0; display: flex; gap: 10px; }
  .table td::before { content: attr(data-label); flex: none; width: 104px; color: var(--muted); font-size: 12.5px; }
  .table td:first-child { display: block; padding-bottom: 6px; }
  .table td:first-child::before { display: none; }
}

/* ---------- print */
@media print {
  :root {
    --bg: #fff; --surface: #fff; --surface-2: #fff; --border: #d9dee6; --text: #000; --text-2: #222; --muted: #555;
    --primary: #1d4ed8; --primary-soft: #f1f5ff; --shadow: none;
  }
  body { font-size: 12px; }
  .topbar, .search, .no-print, .site-footer, .toast { display: none !important; }
  .result { padding: 0; }
  .grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { break-inside: avoid; padding: 14px 16px; }
  .card--wide { break-inside: auto; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .kpis > div:nth-child(n) { border-top: 0; border-left: 1px solid var(--border); }
  .kpis > div:first-child { border-left: 0; }
}
