:root {
  color-scheme: dark;
  --bg: #10131a;
  --surface: #1b2029;
  --surface-2: #232a35;
  --border: #2c3440;
  --text: #e8edf5;
  --muted: #9aa6b8;
  --accent: #f0b90b;
  --accent-text: #16181d;
  --danger: #e85d5d;
  --danger-bg: #2a1719;
  --success-bg: #1c2418;
  --success-border: #3d4a22;
  --track: #2a3140;
  --fill: #f0b90b;
  --hero: url("assets/hero-conversao.png");
  --radius: 12px;
  --fab-size: 64px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Liberation Sans", sans-serif;
  line-height: 1.5;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 40;
  padding: 8px 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 650;
  text-decoration: none;
}

.skip-link:focus {
  top: 12px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.landing {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  padding: clamp(32px, 8vh, 80px) clamp(24px, 8vw, 96px) 140px;
  background-color: var(--bg);
  background-image:
    linear-gradient(
      90deg,
      rgba(16, 19, 26, 0.94) 0%,
      rgba(16, 19, 26, 0.78) 38%,
      rgba(16, 19, 26, 0.32) 100%
    ),
    var(--hero);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

body.is-empty .landing {
  display: flex;
  align-items: center;
}

body.is-empty .page {
  display: none;
}

.landing-copy {
  max-width: 38rem;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.landing-copy h1 {
  margin: 0 0 16px;
  font-size: clamp(2rem, 4.5vw, 3.25rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  text-shadow: 0 2px 24px rgba(16, 19, 26, 0.55);
}

.lead {
  margin: 0 0 28px;
  max-width: 34rem;
  color: #c5cedb;
  font-size: 1.08rem;
}

.steps {
  counter-reset: step;
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.steps li {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  color: var(--muted);
}

.steps li::before {
  counter-increment: step;
  content: counter(step);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(240, 185, 11, 0.16);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 28px;
  text-align: center;
}

.steps strong {
  color: var(--text);
}

.page {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0 120px;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: 1.75rem;
  font-weight: 650;
}

.hero p {
  margin: 0;
  max-width: 42rem;
  color: var(--muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 28px 0 12px;
}

button {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 16px;
  font: inherit;
  cursor: pointer;
}

#print-button {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 650;
}

#print-button:hover {
  filter: brightness(1.06);
}

#clear-button {
  margin-left: auto;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

#clear-button:hover,
#clear-button:focus-visible {
  color: var(--danger);
  border-color: var(--danger);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.status-info {
  margin: 0 0 8px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--text);
}

.status-info.is-error {
  background: var(--danger-bg);
  border-color: var(--danger);
}

.fab-hint {
  display: none;
  position: fixed;
  right: calc(max(24px, env(safe-area-inset-right)) + var(--fab-size) + 12px);
  bottom: calc(max(24px, env(safe-area-inset-bottom)) + 18px);
  z-index: 15;
  margin: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(27, 32, 41, 0.92);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
  pointer-events: none;
}

body.is-empty .fab-hint {
  display: block;
}

.fab {
  position: fixed;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 16;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--fab-size);
  height: var(--fab-size);
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

.fab:hover {
  filter: brightness(1.06);
}

.fab:active {
  transform: scale(0.97);
}

body.is-empty .fab::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 0 0 0 rgba(240, 185, 11, 0.5);
  animation: fab-pulse 2.4s ease-out infinite;
}

@keyframes fab-pulse {
  70% {
    box-shadow: 0 0 0 18px rgba(240, 185, 11, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(240, 185, 11, 0);
  }
}

.fab-icon {
  width: 28px;
  height: 28px;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  fill: none;
}

body.is-loading .fab,
body.is-loading .fab-hint,
body.is-table-fullscreen .fab,
body.is-table-fullscreen .fab-hint {
  visibility: hidden;
}

.progress-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(16, 19, 26, 0.94);
  padding: 24px 6vw;
}

.progress-overlay[hidden] {
  display: none;
}

.progress-panel {
  width: min(720px, 100%);
}

#progress-label,
#progress-percent {
  margin: 0;
}

#progress-label {
  margin-bottom: 16px;
  font-size: 1.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#progress-percent {
  margin-top: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.progress {
  width: 100%;
  height: 10px;
  background: var(--track);
  overflow: hidden;
  border-radius: 999px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--fill);
  transition: width 160ms linear;
}

.errors,
#stats-section,
#result-section {
  margin-top: 28px;
}

h2 {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 12px;
}

.errors {
  padding: 16px 18px;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: var(--danger-bg);
}

.errors h2 {
  color: var(--danger);
  letter-spacing: 0;
  text-transform: none;
  font-size: 1.05rem;
}

.errors p {
  margin: 0 0 10px;
}

.errors ul {
  margin: 0;
  padding-left: 18px;
}

.errors .file-name {
  font-weight: 650;
}

.errors .file-reason {
  color: var(--muted);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

@media (min-width: 900px) {
  .stats-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .stat-card.is-featured {
    grid-column: span 2;
  }

  .stat-card:not(.is-featured) {
    grid-column: span 3;
  }
}

.stat-card {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.stat-card.is-featured {
  border-color: var(--success-border);
  background: var(--success-bg);
}

.stat-card h3 {
  margin: 0 0 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.stat-card p {
  margin: 0;
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
}

.stat-card.is-featured p:not(.hint) {
  font-size: 1.35rem;
  font-weight: 650;
}

.stat-card .hint {
  margin-top: 8px;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--muted);
  line-height: 1.4;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-head h2 {
  margin: 0;
}

#fullscreen-table-button {
  flex: 0 0 auto;
  padding: 8px 12px;
  font-size: 0.88rem;
}

.table-hint {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.88rem;
}

.table-stage-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.table-stage-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
}

.table-frame {
  position: relative;
}

.table-frame::before,
.table-frame::after {
  content: "";
  position: absolute;
  pointer-events: none;
  opacity: 0;
  transition: opacity 160ms ease;
  top: 0;
  bottom: 0;
  width: 28px;
  z-index: 3;
}

.table-frame::before {
  left: 0;
  border-radius: var(--radius) 0 0 var(--radius);
  background: linear-gradient(90deg, var(--bg), transparent);
}

.table-frame::after {
  right: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: linear-gradient(270deg, var(--bg), transparent);
}

.table-frame.has-more-left::before,
.table-frame.has-more-right::after {
  opacity: 1;
}

.table-frame.has-more-bottom .table-wrap {
  box-shadow: inset 0 -18px 18px -16px rgba(0, 0, 0, 0.45);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: min(52vh, 560px);
  background: var(--bg);
  overscroll-behavior: contain;
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--bg);
}

th {
  background: var(--surface);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 2;
}

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

.sticky-col {
  position: sticky;
  left: 0;
  z-index: 1;
  box-shadow: 8px 0 12px -10px rgba(0, 0, 0, 0.7);
}

th.sticky-col {
  z-index: 3;
  background: var(--surface);
}

td.sticky-col {
  background: var(--bg);
}

tbody tr:hover td {
  background: var(--surface-2);
}

tbody tr:hover td.sticky-col {
  background: var(--surface-2);
}

tbody tr:last-child td {
  border-bottom: 0;
}

table.is-dense th,
table.is-dense td {
  padding: 6px 10px;
  font-size: 0.92rem;
}

.record-cards {
  display: none;
  gap: 10px;
}

.record-card {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.record-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.record-card header span {
  color: var(--muted);
  font-size: 0.88rem;
}

.record-card dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 16px;
  margin: 0;
}

.record-card dt {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.record-card dd {
  margin: 0;
  font-weight: 650;
}

.table-stage:fullscreen,
body.is-table-fullscreen .table-stage {
  background: var(--bg);
  padding: 20px 24px 28px;
}

.table-stage:fullscreen .table-stage-bar,
body.is-table-fullscreen .table-stage-bar {
  display: flex;
}

.table-stage:fullscreen .table-wrap,
body.is-table-fullscreen .table-wrap {
  max-height: calc(100vh - 120px);
}

.table-stage:fullscreen .record-cards,
body.is-table-fullscreen .record-cards {
  display: none;
}

.table-stage:fullscreen .table-frame,
body.is-table-fullscreen .table-frame {
  display: block;
}

body.is-table-fullscreen .table-stage {
  position: fixed;
  inset: 0;
  z-index: 30;
  overflow: auto;
}

body.is-table-fullscreen .page > :not(#result-section),
body.is-table-fullscreen #result-section > :not(.table-stage):not(.section-head):not(.table-hint) {
  visibility: hidden;
}

@media (max-width: 820px) {
  body:not(.is-table-fullscreen):not(.is-native-fullscreen) .table-frame {
    display: none;
  }

  body:not(.is-table-fullscreen):not(.is-native-fullscreen) .record-cards {
    display: grid;
  }

  body:not(.is-table-fullscreen):not(.is-native-fullscreen) .table-hint {
    display: none;
  }
}

.dialog {
  width: min(420px, calc(100% - 32px));
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
}

.dialog::backdrop {
  background: rgba(10, 12, 16, 0.72);
}

.dialog h2 {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 1.15rem;
  letter-spacing: 0;
  text-transform: none;
}

.dialog p {
  margin: 0 0 22px;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.dialog .danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  font-weight: 650;
}

@media (max-width: 720px) {
  .fab-hint,
  body.is-empty .fab-hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fab:active,
  .progress-fill,
  body.is-empty .fab::after,
  .table-frame::before,
  .table-frame::after {
    animation: none;
    transition: none;
    transform: none;
    box-shadow: none;
  }
}

@media print {
  .skip-link,
  .landing,
  .fab,
  .fab-hint,
  .toolbar,
  .progress-overlay,
  .dialog,
  .table-hint,
  .table-stage-bar,
  .record-cards,
  #fullscreen-table-button,
  #clear-button,
  #print-button {
    display: none !important;
  }

  body,
  .page,
  body.is-empty .page {
    display: block !important;
    width: 100%;
    background: #fff;
    color: #111;
    padding: 0;
  }

  .table-wrap {
    max-height: none;
    overflow: visible;
    border: 0;
  }

  .sticky-col {
    position: static;
    box-shadow: none;
  }

  th,
  td {
    background: #fff;
    color: #111;
  }

  .stat-card,
  .record-card {
    break-inside: avoid;
  }
}
