:root {
  --bg: #f4f7fa;
  --surface: #ffffff;
  --border: #dce5ed;
  --text: #172b3b;
  --muted: #5b6f7f;
  --primary: #145073;
  --primary-hover: #0d3e5a;
  --ok-bg: #ecfdf3;
  --ok-border: #abefc6;
  --ok-text: #067647;
  --warn-bg: #fffaeb;
  --warn-border: #fedf89;
  --warn-text: #b54708;
  --err-bg: #fef3f2;
  --err-border: #fecdca;
  --err-text: #b42318;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

button, input, select { font: inherit; }
:focus-visible { outline: 3px solid #6bc0cf; outline-offset: 2px; }

.hidden {
  display: none !important;
}

/* Login */
.login-wrapper {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: radial-gradient(circle at 12% 10%, #dceff1 0, transparent 34%),
    radial-gradient(circle at 92% 88%, #e3ebf6 0, transparent 36%), var(--bg);
}

.login-shell {
  width: 100%;
  max-width: 1020px;
  min-height: 600px;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 34px 80px rgba(15, 63, 91, 0.18);
}

.login-brand {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 2rem;
  padding: 2.4rem;
  color: #fff;
  background: radial-gradient(520px 360px at 88% -6%, rgba(127, 176, 200, 0.38), transparent 62%),
    linear-gradient(155deg, #2b4a63 0, #16293a 52%, #0d1822 100%);
}

.lb-logo { display: flex; align-items: center; gap: 0.8rem; }
.lb-logo img { width: 46px; height: 46px; border-radius: 12px; box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35); }
.lb-wordmark { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.04em; line-height: 1; }
.lb-wordmark b { color: #7fb0c8; font-weight: 800; }

.lb-eyebrow {
  display: block;
  color: #7fb0c8;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.login-brand h2 {
  margin: 0.55rem 0 0.8rem;
  font-size: clamp(1.6rem, 2.6vw, 2.15rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
}
.login-brand p { color: #c6d4e0; font-size: 0.95rem; max-width: 38ch; }

.lb-lista { list-style: none; display: grid; gap: 1rem; margin-top: 1.7rem; }
.lb-lista li { display: flex; gap: 0.85rem; align-items: flex-start; }
.lb-ico {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: #7fb0c8;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.14);
}
.lb-ico svg { width: 21px; height: 21px; }
.lb-lista b { display: block; font-size: 0.95rem; }
.lb-lista div span { display: block; font-size: 0.84rem; color: #b7c8d6; }

.lb-rodape {
  font-size: 0.82rem;
  color: #b7c8d6;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}
.lb-rodape strong { display: block; color: #fff; font-size: 0.97rem; margin-bottom: 0.1rem; }

.login-card.login-form {
  max-width: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 2.6rem clamp(1.6rem, 4vw, 3rem);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: var(--surface);
}
.lf-mobile-logo { display: none; width: 40px; height: 40px; border-radius: 11px; margin-bottom: 1rem; }

.eyebrow {
  display: block;
  color: #177c87;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 0.3rem;
}
.login-card h1 {
  font-size: clamp(1.55rem, 3vw, 1.95rem);
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 0.5rem;
}
.login-card p { font-size: 0.92rem; color: var(--muted); margin-bottom: 1.4rem; }

.login-form input[type="text"],
.login-form input[type="password"] { padding: 0.8rem 0.9rem; border-radius: 11px; }
.lf-campo { position: relative; }
.lf-campo input { width: 100%; padding-right: 2.9rem; }
.lf-olho {
  position: absolute;
  top: 50%;
  right: 0.45rem;
  width: 36px;
  height: 36px;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #6c8191;
  cursor: pointer;
}
.lf-olho:hover { background: #eef3f7; color: var(--primary); }
.lf-olho svg { width: 20px; height: 20px; }
.lf-olho[aria-pressed="true"] { color: var(--primary); }

.login-form .lf-entrar {
  padding: 0.85rem 1rem;
  border-radius: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
  background: linear-gradient(135deg, #1a2c3d, #145073);
  box-shadow: 0 10px 24px rgba(20, 80, 115, 0.28);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}
.login-form .lf-entrar:hover { transform: translateY(-1px); filter: brightness(1.08); box-shadow: 0 14px 30px rgba(20, 80, 115, 0.34); }

.login-card .lf-seguro {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 1.2rem 0 0.35rem;
  font-size: 0.8rem;
  color: #6c8191;
}
.lf-seguro svg { flex: none; width: 15px; height: 15px; }
.login-card .lf-ajuda { margin: 0; font-size: 0.84rem; }
.lf-ajuda a { color: var(--primary); font-weight: 700; text-decoration: none; }
.lf-ajuda a:hover { text-decoration: underline; }

@media (max-width: 860px) {
  .login-wrapper { padding: 0; align-items: start; background: var(--surface); }
  .login-shell { grid-template-columns: 1fr; min-height: 100vh; border: 0; border-radius: 0; box-shadow: none; }
  .login-brand { gap: 0.9rem; padding: 1.4rem 1.4rem 1.6rem; }
  .login-brand h2 { font-size: 1.35rem; margin: 0.35rem 0 0; }
  .login-brand p, .lb-lista, .lb-rodape { display: none; }
  .login-card.login-form { justify-content: flex-start; padding: 1.8rem 1.4rem 2rem; }
}

/* Topbar */
.topbar {
  background: linear-gradient(110deg, #103f60, #145b76);
  color: #fff;
  padding: 1rem max(1.5rem, calc((100vw - 1320px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.topbar-brand h1 {
  font-size: 1.22rem;
  font-weight: 700;
}

.topbar-brand span {
  font-size: 0.82rem;
  opacity: 0.85;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.88rem;
}

.badge-role {
  background: rgba(255, 255, 255, 0.18);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.76rem;
  text-transform: uppercase;
}

/* Layout */
.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 1.25rem 2.5rem;
}

/* Alert Banners */
.banner {
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 1rem;
  font-size: 0.92rem;
  font-weight: 500;
}

.banner-ok {
  background: var(--ok-bg);
  border-color: var(--ok-border);
  color: var(--ok-text);
}

.banner-err {
  background: var(--err-bg);
  border-color: var(--err-border);
  color: var(--err-text);
}

.banner-warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn-text);
}

/* Tabs */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1.8rem;
  padding-top: 0.7rem;
  white-space: normal;
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(244, 247, 250, 0.97);
}

.tab-btn {
  background: none;
  border: none;
  padding: 0.85rem 1rem;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-btn:hover { color: var(--primary); background: #eaf1f5; }
.inline-link { border: 0; background: none; color: var(--primary); text-decoration: underline; cursor: pointer; font-weight: 700; }

.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.4rem;
}
.page-heading h2 { font-size: clamp(1.6rem, 3vw, 2rem); line-height: 1.15; }
.page-heading p { color: var(--muted); max-width: 720px; margin-top: 0.4rem; }
.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.85rem; margin-bottom: 1.25rem; }
.quick-action {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  min-height: 130px;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(21, 70, 99, 0.04);
}
.quick-action:hover { border-color: #70acba; box-shadow: 0 8px 22px rgba(21, 70, 99, 0.09); transform: translateY(-1px); }
.quick-action span { color: #177c87; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.quick-action strong { color: var(--primary); font-size: 1rem; }
.quick-action small { color: var(--muted); font-size: 0.81rem; }
.data-note { color: var(--muted); font-size: 0.82rem; margin: 0 0 1rem; }

/* Metrics */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.25rem;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: 0 3px 14px rgba(21, 70, 99, 0.035);
}

.metric-card .label {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.metric-card .value {
  font-size: 1.55rem;
  font-weight: 700;
  margin-top: 0.25rem;
}

/* Cards & Forms */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 4px 18px rgba(21, 70, 99, 0.045);
}

.card h2 {
  font-size: 1.1rem;
  margin-bottom: 0.85rem;
  color: var(--primary);
}

.section-lead { color: var(--muted); font-size: 0.9rem; margin-bottom: 0.85rem; }
.help-details { margin: 0 0 1.2rem; color: var(--muted); font-size: 0.85rem; }
.help-details summary { width: fit-content; color: var(--primary); cursor: pointer; font-weight: 600; }
.help-details p { padding: 0.65rem 0 0; max-width: 880px; }
.selection-count { color: var(--muted); font-weight: 500; white-space: nowrap; }
.progress-summary { background: #eaf4f6; border-left: 4px solid #178b98; border-radius: 6px; padding: 0.75rem 0.9rem; margin-bottom: 0.9rem; font-weight: 600; }
#card-progresso-lote, #card-progresso-sped { scroll-margin-top: 5rem; }
.lote-filter { width: min(100%, 320px); min-width: 0; }
.lote-filter select { width: 100%; min-width: 0; }
.result-actions { display: flex; align-items: end; flex-wrap: wrap; gap: 0.65rem; min-width: 0; }
.segment-switch { display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0.35rem; width: fit-content; max-width: 100%; margin: 0 0 1.2rem; background: #e9f0f4; border-radius: 10px; }
.segment-btn { border: 0; border-radius: 7px; padding: 0.55rem 0.9rem; background: transparent; color: var(--muted); font: inherit; font-size: 0.86rem; font-weight: 650; cursor: pointer; }
.segment-btn:hover { color: var(--primary); }
.segment-btn.active { background: var(--surface); color: var(--primary); box-shadow: 0 1px 5px rgba(21, 70, 99, 0.12); }
.segment-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.9rem;
  margin-bottom: 0.9rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.32rem;
}

.form-group label {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="file"],
select {
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  background: #fff;
  min-height: 42px;
}

input:disabled { opacity: 0.65; cursor: not-allowed; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  min-height: 38px;
}
.btn:disabled { opacity: 0.62; cursor: wait; }

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}

.btn-danger {
  background: var(--err-bg);
  border-color: var(--err-border);
  color: var(--err-text);
}

.btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: 0.8rem;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th,
td {
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:hover { background: #f7fafc; }
tbody tr.row-alert:hover { background: #ffeded; }

th {
  background: #f8fafc;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  white-space: nowrap;
}

tr.row-alert {
  background: #fff5f5;
}

.pill {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  white-space: nowrap;
}

.pill-ok {
  background: var(--ok-bg);
  color: var(--ok-text);
  border: 1px solid var(--ok-border);
}

.pill-err {
  background: var(--err-bg);
  color: var(--err-text);
  border: 1px solid var(--err-border);
}

.pill-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid var(--warn-border);
}

/* SPED: informações relacionadas na mesma célula, sem colunas extensas. */
.compact-table { table-layout: fixed; width: 100%; }
.compact-table th { white-space: normal; }
.compact-table td { overflow-wrap: anywhere; vertical-align: top; }
.compact-table .pill { white-space: normal; max-width: 100%; }
.compact-table .cell-sub { display: block; color: var(--muted); font-size: 0.76rem; line-height: 1.35; margin-top: 0.25rem; }
.compact-table .cell-badges { margin-top: 0.4rem; }
.compact-table .download-links { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.55rem; }
.compact-table .download-links:empty { display: none; }
.compact-table .btn { max-width: 100%; text-align: center; white-space: normal; }
.compact-table .row-details { margin-top: 0.45rem; font-size: 0.76rem; color: var(--muted); }
.compact-table .row-details summary { color: var(--primary); cursor: pointer; font-weight: 600; }
.compact-table .row-details span,
.compact-table .row-details code { display: block; margin-top: 0.25rem; overflow-wrap: anywhere; }
.compact-table .icms-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.55rem 0.7rem; font-size: 0.8rem; }
.compact-table .icms-grid small { display: block; color: var(--muted); font-size: 0.72rem; }
.compact-table .icms-grid strong { display: block; font-weight: 650; }

.sped-cross-table th:nth-child(1) { width: 17%; }
.sped-cross-table th:nth-child(2) { width: 19%; }
.sped-cross-table th:nth-child(3) { width: 18%; }
.sped-cross-table th:nth-child(4) { width: 25%; }
.sped-cross-table th:nth-child(5) { width: 21%; }
.sped-files-table th:nth-child(1) { width: 24%; }
.sped-files-table th:nth-child(2) { width: 16%; }
.sped-files-table th:nth-child(3) { width: 25%; }
.sped-files-table th:nth-child(4) { width: 25%; }
.sped-files-table th:nth-child(5) { width: 10%; }
.sped-progress-table th:nth-child(1) { width: 22%; }
.sped-progress-table th:nth-child(2) { width: 23%; }
.sped-progress-table th:nth-child(3) { width: 18%; }
.sped-progress-table th:nth-child(4) { width: 37%; }
.siare-progress-table th:nth-child(1) { width: 20%; }
.siare-progress-table th:nth-child(2) { width: 28%; }
.siare-progress-table th:nth-child(3) { width: 18%; }
.siare-progress-table th:nth-child(4) { width: 34%; }
.siare-current-table th:nth-child(1), .siare-result-table th:nth-child(2) { width: 25%; }
.siare-current-table th:nth-child(2), .siare-result-table th:nth-child(1) { width: 17%; }
.siare-current-table th:nth-child(3), .siare-result-table th:nth-child(3) { width: 22%; }
.siare-current-table th:nth-child(4), .siare-result-table th:nth-child(4) { width: 24%; }
.siare-current-table th:nth-child(5), .siare-result-table th:nth-child(5) { width: 12%; }
.siare-history-table th:nth-child(1) { width: 15%; }
.siare-history-table th:nth-child(2) { width: 27%; }
.siare-history-table th:nth-child(3) { width: 16%; }
.siare-history-table th:nth-child(4) { width: 30%; }
.siare-history-table th:nth-child(5) { width: 12%; }

.empresas-selector {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 0.65rem;
  margin: 0.75rem 0;
}

.empresa-check-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.8rem;
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  background: #fbfcfe;
}
.empresa-check-item:has(input:checked) { border-color: #6cb1bd; background: #f0fafb; }
.empresa-check-item:has(input:disabled) { opacity: 0.6; }

@media (max-width: 850px) {
  .quick-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .compact-table,
  .compact-table tbody,
  .compact-table tr,
  .compact-table td { display: block; width: 100%; }
  .compact-table thead { display: none; }
  .compact-table tr { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); }
  .compact-table td { position: relative; border: 0; padding: 0.45rem 0 0.45rem 112px; min-height: 2rem; }
  .compact-table td::before { content: attr(data-label); position: absolute; left: 0; top: 0.5rem; width: 105px; color: var(--muted); font-size: 0.72rem; font-weight: 700; text-transform: uppercase; }
  .compact-table td[colspan] { padding-left: 0; }
  .compact-table td[colspan]::before { display: none; }
  .compact-table .icms-grid { max-width: 410px; }
}

@media (max-width: 600px) {
  .topbar { padding: 0.9rem 1rem; }
  .topbar-brand span { display: none; }
  .topbar-user { width: 100%; justify-content: space-between; }
  .container { padding: 0 0.85rem 2rem; }
  .tabs { margin-bottom: 1.25rem; }
  .tab-btn { padding: 0.75rem 0.8rem; font-size: 0.84rem; }
  .quick-actions, .metrics-grid { grid-template-columns: 1fr; }
  .quick-action { min-height: 0; }
  .card { padding: 1rem; }
  .toolbar { align-items: flex-start; }
  .toolbar > select { width: 100%; }
  .toolbar .lote-filter, .result-actions { width: 100%; }
  .segment-switch { width: 100%; }
  .segment-btn { flex: 1 1 auto; }
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

