:root {
  --ink: #0b0d0c;
  --ink-soft: #515854;
  --paper: #f5f7f5;
  --surface: #ffffff;
  --line: #dde3df;
  --green: #25d366;
  --green-dark: #16813d;
  --green-soft: #e7f9ed;
  --amber: #b76b00;
  --amber-soft: #fff3d9;
  --red: #b42318;
  --red-soft: #feeceb;
  --blue: #175cd3;
  --blue-soft: #e9f1ff;
  --radius: 16px;
  --shadow: 0 14px 35px rgba(11, 13, 12, 0.08);
}

* { box-sizing: border-box; }
html { font-family: "Poppins", sans-serif; color: var(--ink); background: var(--paper); }
body { margin: 0; min-width: 320px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }

.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 0.85fr) minmax(460px, 1.15fr);
  background: var(--surface);
}
.login-brand {
  background: var(--ink);
  color: white;
  padding: clamp(34px, 7vw, 90px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 100vh;
}
.brand-lockup { display: inline-flex; align-items: center; gap: 13px; text-decoration: none; }
.brand-mark { width: 46px; height: 46px; border: 2px solid var(--green); border-radius: 14px; display: grid; place-items: center; color: var(--green); font-weight: 700; }
.brand-name { font-size: 1.45rem; font-weight: 700; letter-spacing: -.04em; }
.brand-sub { color: var(--green); font-size: .75rem; display: block; margin-top: -2px; }
.login-brand h1 { font-size: clamp(2.2rem, 5vw, 4.8rem); line-height: 1; letter-spacing: -.065em; margin: 60px 0 22px; max-width: 720px; }
.login-brand p { color: #b9c0bc; max-width: 560px; line-height: 1.7; }
.login-foot { color: #7f8983; font-size: .78rem; }
.login-panel { display: grid; place-items: center; padding: 34px; }
.login-card { width: min(430px, 100%); }
.eyebrow { color: var(--green-dark); font-size: .74rem; text-transform: uppercase; letter-spacing: .12em; font-weight: 700; }
h2 { font-size: clamp(1.8rem, 3vw, 2.5rem); letter-spacing: -.05em; margin: 8px 0; }
.muted { color: var(--ink-soft); }
.field { display: grid; gap: 7px; margin-top: 18px; }
.field label { font-size: .82rem; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 11px; background: white;
  padding: 12px 13px; color: var(--ink); outline: none; transition: .18s;
}
.field textarea { min-height: 100px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green-dark); box-shadow: 0 0 0 3px rgba(37, 211, 102, .16); }
.field small { color: var(--ink-soft); }
.cnpj-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: stretch; }
.cnpj-row .btn { white-space: nowrap; }
.btn { border: 0; border-radius: 11px; min-height: 42px; padding: 10px 16px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn-primary { color: #07130b; background: var(--green); }
.btn-primary:hover { background: #1fc55d; }
.btn-dark { color: white; background: var(--ink); }
.btn-light { background: white; border: 1px solid var(--line); color: var(--ink); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-sm { min-height: 34px; padding: 7px 11px; font-size: .78rem; }
.btn-block { width: 100%; margin-top: 22px; }
.login-note { font-size: .75rem; color: var(--ink-soft); margin-top: 18px; line-height: 1.6; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 248px 1fr; }
.sidebar { background: var(--ink); color: white; padding: 26px 18px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar .brand-lockup { padding: 0 8px 22px; }
.sidebar .brand-mark { width: 38px; height: 38px; border-radius: 11px; }
.nav { display: grid; gap: 6px; margin-top: 20px; }
.nav button { border: 0; color: #aeb6b1; background: transparent; padding: 11px 12px; border-radius: 10px; text-align: left; font-weight: 500; display: flex; gap: 11px; align-items: center; }
.nav button:hover, .nav button.active { background: #1a1f1c; color: white; }
.nav button.active { box-shadow: inset 3px 0 var(--green); }
.nav-icon { width: 22px; color: var(--green); text-align: center; }
.sidebar-bottom { margin-top: auto; border-top: 1px solid #252b28; padding: 18px 8px 0; }
.user-name { font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.signout { color: #9ca5a0; border: 0; background: none; padding: 10px 0 0; font-size: .74rem; }

.main { min-width: 0; }
.topbar { height: 78px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.88); backdrop-filter: blur(12px); display: flex; align-items: center; justify-content: space-between; padding: 0 clamp(20px, 4vw, 54px); position: sticky; top: 0; z-index: 5; }
.topbar-title { font-weight: 600; letter-spacing: -.02em; }
.period-pill { background: var(--green-soft); color: var(--green-dark); border-radius: 999px; padding: 8px 13px; font-size: .78rem; font-weight: 600; }
.content { padding: 34px clamp(20px, 4vw, 54px) 70px; max-width: 1500px; margin: auto; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.page-head h1 { font-size: clamp(1.8rem, 3vw, 2.6rem); line-height: 1.05; letter-spacing: -.055em; margin: 5px 0; }
.page-head p { margin: 7px 0 0; color: var(--ink-soft); }
.actions { display: flex; gap: 9px; flex-wrap: wrap; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 1px 0 rgba(11,13,12,.02); }
.stat { padding: 21px; }
.stat-label { font-size: .77rem; color: var(--ink-soft); }
.stat-value { font-size: 1.9rem; letter-spacing: -.055em; font-weight: 700; margin-top: 6px; }
.stat-hint { font-size: .7rem; color: var(--ink-soft); margin-top: 2px; }
.grid-2 { display: grid; grid-template-columns: 1.2fr .8fr; gap: 16px; margin-top: 16px; }
.section-card { padding: 22px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 15px; margin-bottom: 16px; }
.section-head h3 { margin: 0; letter-spacing: -.03em; }
.section-head a { color: var(--green-dark); font-size: .78rem; font-weight: 600; }
.progress { height: 9px; background: #e9eeeb; border-radius: 99px; overflow: hidden; margin: 15px 0 8px; }
.progress > span { display: block; height: 100%; background: var(--green); border-radius: inherit; }
.checklist { list-style: none; margin: 8px 0 0; padding: 0; }
.checklist li { display: flex; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); padding: 12px 0; font-size: .8rem; }
.ok { color: var(--green-dark); font-weight: 600; }
.pending { color: var(--amber); font-weight: 600; }
.table-card { overflow: hidden; }
.table-tools { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; justify-content: space-between; }
.search { max-width: 320px; width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; outline: none; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; min-width: 720px; }
th, td { text-align: left; padding: 14px 18px; border-bottom: 1px solid var(--line); font-size: .79rem; vertical-align: middle; }
th { color: var(--ink-soft); font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; background: #fbfcfb; }
tbody tr:hover { background: #fbfdfb; }
.cell-main { font-weight: 600; }
.cell-sub { color: var(--ink-soft); font-size: .7rem; margin-top: 3px; }
.badge { display: inline-flex; border-radius: 999px; padding: 5px 9px; font-size: .68rem; font-weight: 600; white-space: nowrap; }
.badge-draft { background: #eef1ef; color: #4c5750; }
.badge-ready_for_review { background: var(--amber-soft); color: var(--amber); }
.badge-approved, .badge-issued { background: var(--green-soft); color: var(--green-dark); }
.badge-issuing { background: var(--blue-soft); color: var(--blue); }
.badge-failed, .badge-rejected, .badge-cancelled { background: var(--red-soft); color: var(--red); }
.empty { padding: 60px 24px; text-align: center; color: var(--ink-soft); }
.empty strong { display: block; color: var(--ink); font-size: 1rem; margin-bottom: 6px; }
.empty .btn { margin-top: 18px; }
.row-actions { display: flex; gap: 6px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(2,7,4,.62); z-index: 20; display: grid; place-items: center; padding: 20px; }
.modal { background: white; border-radius: 19px; width: min(690px, 100%); max-height: calc(100vh - 40px); overflow: auto; box-shadow: var(--shadow); }
.modal-head { padding: 21px 24px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; letter-spacing: -.03em; }
.modal-close { border: 0; background: #f0f3f1; border-radius: 50%; width: 34px; height: 34px; }
.modal-body { padding: 4px 24px 24px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.span-2 { grid-column: span 2; }
.modal-foot { padding: 16px 24px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 9px; }
.toast-root { position: fixed; right: 20px; bottom: 20px; z-index: 50; display: grid; gap: 9px; }
.toast { background: var(--ink); color: white; border-radius: 11px; padding: 12px 16px; box-shadow: var(--shadow); max-width: 380px; font-size: .8rem; }
.toast.error { background: #8d1a12; }
.access-state { min-height: 70vh; display: grid; place-items: center; text-align: center; }
.access-state .card { max-width: 560px; padding: 36px; }
.access-state h2 { font-size: 2rem; }

@media (max-width: 1050px) { .stats { grid-template-columns: repeat(2, 1fr); } .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .login-page { grid-template-columns: 1fr; }
  .login-brand { min-height: auto; padding: 28px; }
  .login-brand h1 { font-size: 2.4rem; margin-top: 50px; }
  .login-brand p, .login-foot { display: none; }
  .login-panel { padding: 36px 22px; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; top: auto; height: 67px; padding: 7px; }
  .sidebar .brand-lockup, .sidebar-bottom { display: none; }
  .nav { display: flex; margin: 0; justify-content: space-around; }
  .nav button { flex-direction: column; gap: 1px; font-size: .58rem; padding: 5px 7px; }
  .nav button.active { box-shadow: inset 0 -3px var(--green); }
  .topbar { height: 64px; }
  .content { padding-bottom: 100px; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 16px; }
  .stat-value { font-size: 1.55rem; }
  .form-grid { grid-template-columns: 1fr; }
  .cnpj-row { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
}
