:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-sub: #f8fafc;
  --border: #e3e8ef;
  --ink: #171b21;
  --muted: #5b6574;
  --brand: #1c477a;
  --brand-hover: #153760;
  --brand-tint: #eef3f9;
  --blue-ink: #1d4ed8;
  --blue-bg: #eff6ff;
  --blue-border: #bfdbfe;
  --red-ink: #b91c1c;
  --red-bg: #fef2f2;
  --red-border: #fecaca;
  --green-ink: #047857;
  --green-bg: #ecfdf5;
  --green-border: #a7f3d0;
  --amber-ink: #b45309;
  --amber-bg: #fffbeb;
  --amber-border: #fde68a;
  --radius-sm: 8px;
  --radius-md: 14px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background-color: var(--bg);
  background-image: radial-gradient(1200px 420px at 50% -260px, #e8eef6 0%, rgba(232, 238, 246, 0) 70%);
  background-repeat: no-repeat;
  color: var(--ink);
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--muted);
}

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-shell[hidden],
#appShell[hidden] {
  display: none !important;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 12px 32px rgba(28, 71, 122, 0.06);
}

.login-head {
  display: flex;
  align-items: center;
  gap: 14px;
}

.login-head h1 {
  margin: 2px 0 0;
  font-size: 20px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.login-sub {
  margin: 0;
  font-size: 13px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-erro {
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  color: var(--red-ink);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12.5px;
  font-weight: 600;
}

.login-foot {
  margin: 2px 0 0;
  font-size: 12px;
  text-align: center;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  height: 36px;
  width: auto;
  display: block;
}

.brand-kicker {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--brand);
}

.brand-text h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.topbar-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-group label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.month-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-pills {
  display: flex;
  align-items: center;
  gap: 8px;
}

.container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px 20px 36px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.kpis-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.kpi-value {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.15;
  color: var(--ink);
}

.kpi-sub {
  font-size: 12px;
  color: var(--muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.lote-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 8px 2px 2px;
}

.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}

.lote-progress {
  background: var(--surface);
  border: 1px solid #cbd9ea;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lote-progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.lote-progress-head > div {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.progress-track {
  width: 100%;
  height: 8px;
  background: var(--surface-sub);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--brand);
  transition: width 220ms var(--ease);
}

.lote-progress-sub {
  font-size: 12px;
}

.banner-info {
  background: var(--brand-tint);
  border: 1px solid #cbd9ea;
  color: var(--brand);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.32fr) minmax(390px, 1fr);
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.panel-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.panel-header p {
  margin: 2px 0 0;
  font-size: 12px;
}

.input {
  height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  transition: border-color 120ms var(--ease);
}

.input:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.input-sm {
  height: 30px;
  font-size: 12px;
}

.input-search {
  width: 240px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 120ms var(--ease), border-color 120ms var(--ease);
}

.btn-sm {
  height: 31px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-primary {
  background: var(--brand);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--brand-hover);
}

.btn-success {
  background: var(--green-ink);
  color: #ffffff;
}

.btn-success:hover {
  background: #065f46;
}

.btn-outline {
  background: var(--surface);
  border-color: var(--border);
  color: var(--ink);
}

.btn-outline:hover {
  background: var(--surface-sub);
  border-color: #c8d2df;
}

.btn-danger-outline {
  background: var(--surface);
  border-color: var(--red-border);
  color: var(--red-ink);
}

.btn-danger-outline:hover {
  background: var(--red-bg);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}

.btn-ghost:hover {
  color: var(--ink);
  background: var(--surface-sub);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-sub);
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 120ms var(--ease);
}

.chip:hover {
  color: var(--ink);
  border-color: #c8d2df;
}

.chip.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #ffffff;
}

.table-wrap {
  max-height: 680px;
  overflow: auto;
}

.fila-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.fila-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-sub);
  border-bottom: 1px solid var(--border);
  text-align: left;
  padding: 8px 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  z-index: 1;
}

.fila-table th.num,
.fila-table td.num {
  text-align: right;
}

.fila-table tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background-color 120ms var(--ease);
}

.fila-table tbody tr:hover {
  background: #f3f6fb;
}

.fila-table tbody tr.selected {
  background: var(--brand-tint);
}

.fila-table td {
  padding: 8px 8px;
  vertical-align: middle;
}

.emp-nome {
  font-weight: 600;
  color: var(--ink);
  display: block;
  max-width: 230px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.emp-cnpj {
  font-size: 11px;
  color: var(--muted);
}

.emp-sub {
  display: block;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.badge,
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-brand {
  background: var(--brand-tint);
  border-color: #cbd9ea;
  color: var(--brand);
}

.badge-neutral,
.pill-neutral {
  background: var(--surface-sub);
  color: var(--muted);
}

.badge-azul {
  background: var(--blue-bg);
  border-color: var(--blue-border);
  color: var(--blue-ink);
}

.badge-vermelho {
  background: var(--red-bg);
  border-color: var(--red-border);
  color: var(--red-ink);
}

.badge-ok,
.pill-ok {
  background: var(--green-bg);
  border-color: var(--green-border);
  color: var(--green-ink);
}

.badge-aviso {
  background: var(--amber-bg);
  border-color: var(--amber-border);
  color: var(--amber-ink);
}

.tabs-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--surface-sub);
}

.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 12px 10px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 120ms var(--ease);
}

.tab-btn.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
  background: var(--surface);
}

.tab-pane {
  display: none;
  padding: 16px;
}

.tab-pane.active {
  display: block;
}

.empty-state,
.empty-cell {
  text-align: center;
  padding: 36px 20px;
  color: var(--muted);
}

.company-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.company-head h3 {
  margin: 6px 0 4px;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.25;
}

.company-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.company-total-box {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}

.company-total-box strong {
  font-size: 20px;
  color: var(--brand);
}

.step-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 12px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.step-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.step-head > div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.step-num {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--brand);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.step-head h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.step-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1.6fr;
  gap: 10px;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 1fr;
  gap: 10px;
}

.venc-tag {
  display: block;
  margin-top: 3px;
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
}

.venc-tag.ok {
  color: var(--green-ink);
}

.venc-tag.pendente {
  color: var(--amber-ink);
}

.venc-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.venc-lote-box {
  background: var(--surface-sub);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.venc-lote-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.venc-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 500px;
  overflow-y: auto;
}

.venc-row {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.venc-row-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.venc-row-title {
  font-weight: 700;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.venc-row-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.jev-box {
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12.5px;
  border: 1px solid var(--border);
}

.jev-box.azul {
  background: var(--blue-bg);
  border-color: var(--blue-border);
  color: var(--blue-ink);
}

.jev-box.vermelho {
  background: var(--red-bg);
  border-color: var(--red-border);
  color: var(--red-ink);
}

.jev-box.ok {
  background: var(--green-bg);
  border-color: var(--green-border);
  color: var(--green-ink);
}

.analitico-resumo {
  background: var(--surface-sub);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12px;
}

.code-out {
  margin: 0;
  background: var(--surface-sub);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11.5px;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.ia-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.chat-log {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-sub);
  padding: 12px;
  height: 410px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}

.chat-msg {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  white-space: pre-wrap;
}

.chat-msg.user {
  background: var(--brand-tint);
  border-color: #cbd9ea;
  align-self: flex-end;
  max-width: 88%;
}

.chat-msg.assistant strong {
  display: block;
  font-size: 11px;
  color: var(--brand);
  margin-bottom: 4px;
}

.chat-msg p {
  margin: 0;
}

.chat-form {
  display: flex;
  gap: 8px;
}

.chat-form .input {
  flex: 1;
}

.cr-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 520px;
  overflow: auto;
}

.cr-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--ink);
  color: #ffffff;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 32px rgba(23, 27, 33, 0.16);
  font-size: 13px;
  font-weight: 600;
  z-index: 50;
  max-width: 420px;
}

@media (max-width: 920px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .kpis-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .kpis-grid,
  .form-grid,
  .form-grid-3 {
    grid-template-columns: 1fr;
  }
  .input-search {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
