:root {
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-subtle: #f8fafd;
  --surface-muted: #eef3f9;
  --ink: #0b1526;
  --ink-secondary: #334155;
  --muted: #64748b;
  --border: #dce5f0;
  --border-strong: #c5d3e3;

  --navy: #0f1b2d;
  --cobalt: #1d4ed8;
  --cobalt-dark: #1e40af;
  --ice-blue: #0284c7;
  --ice-glow: rgba(14, 165, 233, 0.14);

  --teal-ink: #0f766e;
  --teal-bg: #ecfdf8;
  --teal-bd: #a7f3d0;

  --rose-ink: #9f1239;
  --rose-bg: #fff1f2;
  --rose-bd: #fecdd3;

  --slate-ink: #1e40af;
  --slate-bg: #eff6ff;
  --slate-bd: #bfdbfe;

  --shadow-card: 0 14px 36px -16px rgba(11, 21, 38, 0.10), 0 2px 6px -1px rgba(11, 21, 38, 0.04);
  --shadow-focus: 0 0 0 3px rgba(2, 132, 199, 0.16);
  --radius-lg: 16px;
  --radius-md: 11px;
  --radius-sm: 8px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  position: relative;
}

.bg-aura {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(900px 420px at 15% -8%, rgba(2, 132, 199, 0.08), transparent 65%),
    radial-gradient(760px 380px at 88% 4%, rgba(29, 78, 216, 0.06), transparent 60%);
}

.container {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* Topbar */
.topbar {
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.topbar-inner {
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: var(--ink);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--navy), var(--cobalt-dark));
  color: #e0f2fe;
  box-shadow: 0 4px 12px rgba(15, 27, 45, 0.18);
}

.brand-name {
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.brand-name span {
  color: var(--ice-blue);
}

.topbar-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #0ea5e9;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.18);
}

.topbar-meta .sep {
  color: var(--border-strong);
}

.price-tag {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--cobalt-dark);
  background: var(--slate-bg);
  border: 1px solid var(--slate-bd);
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
}

/* Main */
.main-wrap {
  flex: 1;
  padding-top: 2.6rem;
  padding-bottom: 4rem;
}

/* Hero */
.hero {
  margin-bottom: 1.6rem;
}

.eyebrow {
  margin: 0 0 0.45rem;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ice-blue);
}

.hero h1 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.55rem, 3vw, 2.05rem);
  font-weight: 700;
  letter-spacing: -0.028em;
  color: var(--ink);
  line-height: 1.2;
}

.hero-sub {
  margin: 0;
  font-size: 0.96rem;
  color: var(--muted);
  max-width: 600px;
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.form-card {
  padding: 1.65rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1.35fr 0.8fr 1.15fr;
  gap: 1rem;
}

.field label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.45rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-secondary);
}

.field-status {
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--font-mono);
}

.field-status.ok {
  color: var(--teal-ink);
}

.field-status.err {
  color: var(--rose-ink);
}

.field input,
.field select {
  width: 100%;
  height: 46px;
  padding: 0 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 0.94rem;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.field input {
  font-family: var(--font-mono);
  letter-spacing: 0.01em;
}

.field select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.8rem center;
  padding-right: 2.2rem;
}

.field input:focus,
.field select:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--ice-blue);
  box-shadow: var(--shadow-focus);
}

.field input.is-invalid,
.field select.is-invalid {
  border-color: #f43f5e;
  background: #fff8f9;
}

.alert-box {
  margin-top: 1rem;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 500;
  border: 1px solid var(--rose-bd);
  background: var(--rose-bg);
  color: var(--rose-ink);
}

.form-actions {
  margin-top: 1.35rem;
  padding-top: 1.15rem;
  border-top: 1px solid var(--surface-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.action-hint {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.action-hint svg {
  color: var(--ice-blue);
  flex-shrink: 0;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  height: 46px;
  padding: 0 1.25rem;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--navy) 0%, var(--cobalt-dark) 100%);
  color: #ffffff;
  font-family: var(--font-sans);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 20px -8px rgba(30, 64, 175, 0.55);
  transition: transform 0.12s ease, box-shadow 0.18s ease, opacity 0.15s ease;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px -8px rgba(30, 64, 175, 0.65);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

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

.btn-price {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.14);
  color: #e0f2fe;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Pending card */
.pending-card {
  margin-top: 1rem;
  padding: 1.1rem 1.35rem;
  border-color: var(--slate-bd);
  background: var(--slate-bg);
}

.pending-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.pending-inner h3 {
  margin: 0 0 0.2rem;
  font-size: 0.94rem;
  color: var(--slate-ink);
}

.pending-inner p {
  margin: 0;
  font-size: 0.84rem;
  color: var(--ink-secondary);
}

/* Result Section */
.result-section {
  margin-top: 1.5rem;
  animation: fadeUp 0.26s ease-out;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-card {
  overflow: hidden;
}

.result-header {
  padding: 1.5rem 1.65rem;
  background: linear-gradient(135deg, #0b1526 0%, #132542 100%);
  color: #ffffff;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.result-badges {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.65rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.pill-ativa {
  background: rgba(16, 185, 129, 0.16);
  color: #6ee7b7;
  border: 1px solid rgba(110, 231, 183, 0.32);
}

.pill-inativa {
  background: rgba(244, 63, 94, 0.18);
  color: #fda4af;
  border: 1px solid rgba(253, 164, 175, 0.32);
}

.pill-uf {
  background: rgba(56, 189, 248, 0.16);
  color: #bae6fd;
  border: 1px solid rgba(186, 230, 253, 0.28);
  font-family: var(--font-mono);
}

.pill-mode {
  background: rgba(255, 255, 255, 0.1);
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.result-title {
  margin: 0;
  font-size: 1.32rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.result-subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.88rem;
  color: #cbd5e1;
}

.result-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-tool {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 34px;
  padding: 0 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #f8fafc;
  font-family: var(--font-sans);
  font-size: 0.79rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-tool:hover {
  background: rgba(255, 255, 255, 0.16);
}

/* KPI Strip */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--border);
  background: var(--surface-subtle);
}

.kpi-cell {
  padding: 1rem 1.25rem;
  border-right: 1px solid var(--border);
}

.kpi-cell:last-child {
  border-right: none;
}

.kpi-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.kpi-val {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--ink);
  word-break: break-word;
}

.kpi-val.is-sans {
  font-family: var(--font-sans);
  font-size: 0.88rem;
}

.copy-btn {
  border: none;
  background: var(--surface-muted);
  color: var(--muted);
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s ease, background 0.15s ease;
}

.copy-btn:hover {
  color: var(--cobalt-dark);
  background: var(--slate-bd);
}

/* Data Blocks */
.result-body {
  padding: 1.5rem 1.65rem;
  display: grid;
  gap: 1.6rem;
}

.block-title {
  margin: 0 0 0.85rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ice-blue);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.block-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--surface-muted);
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem 1.25rem;
}

.info-item {
  min-width: 0;
}

.info-item.span-2 {
  grid-column: span 2;
}

.info-item.span-3 {
  grid-column: span 3;
}

.info-label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.15rem;
}

.info-value {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink);
  word-break: break-word;
}

.info-value.mono {
  font-family: var(--font-mono);
  font-size: 0.86rem;
}

.info-value.empty {
  color: #94a3b8;
  font-weight: 400;
}

.sefaz-msg-box {
  padding: 0.8rem 1rem;
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 0.86rem;
  color: var(--ink-secondary);
}

/* Not Found Notice */
.not-found-body {
  padding: 1.75rem 1.65rem;
}

.not-found-box {
  padding: 1.15rem 1.25rem;
  border-radius: var(--radius-md);
  background: var(--rose-bg);
  border: 1px solid var(--rose-bd);
  color: var(--rose-ink);
  font-size: 0.92rem;
  font-weight: 500;
}

/* Receipt Footer */
.result-foot {
  padding: 0.9rem 1.65rem;
  background: var(--surface-subtle);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  font-size: 0.76rem;
  color: var(--muted);
  font-family: var(--font-mono);
}

/* Secondary / Ghost buttons */
.btn-secondary {
  height: 38px;
  padding: 0 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary:hover {
  background: var(--surface-subtle);
}

.btn-ghost-sm {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
}

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

/* History */
.history-card {
  margin-top: 1.5rem;
  padding: 1.25rem 1.5rem;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
}

.history-head h2 {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink-secondary);
}

.history-list {
  display: grid;
  gap: 0.5rem;
}

.history-item {
  width: 100%;
  text-align: left;
  padding: 0.75rem 0.95rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.history-item:hover {
  border-color: var(--ice-blue);
  background: var(--surface);
}

.history-left {
  min-width: 0;
}

.history-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-meta {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
}

.history-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  flex-shrink: 0;
}

.history-badge.ok {
  background: var(--teal-bg);
  color: var(--teal-ink);
  border: 1px solid var(--teal-bd);
}

.history-badge.warn {
  background: var(--rose-bg);
  color: var(--rose-ink);
  border: 1px solid var(--rose-bd);
}

/* Footer */
.footer {
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.6);
  padding: 1.1rem 0;
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--muted);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 90;
  background: var(--navy);
  color: #f8fafc;
  padding: 0.65rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 500;
  box-shadow: 0 12px 30px rgba(11, 21, 38, 0.25);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Responsive */
@media (max-width: 740px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .kpi-strip {
    grid-template-columns: 1fr 1fr;
  }

  .kpi-cell:nth-child(2) {
    border-right: none;
  }

  .kpi-cell:nth-child(1),
  .kpi-cell:nth-child(2) {
    border-bottom: 1px solid var(--border);
  }

  .info-grid {
    grid-template-columns: 1fr 1fr;
  }

  .info-item.span-3 {
    grid-column: span 2;
  }
}

@media (max-width: 480px) {
  .topbar-meta span:not(.price-tag):not(.status-dot) {
    display: none;
  }

  .topbar-meta .sep {
    display: none;
  }

  .kpi-strip,
  .info-grid {
    grid-template-columns: 1fr;
  }

  .kpi-cell {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .kpi-cell:last-child {
    border-bottom: none;
  }

  .info-item.span-2,
  .info-item.span-3 {
    grid-column: span 1;
  }

  .btn-primary {
    width: 100%;
  }
}

/* Print */
@media print {
  .bg-aura,
  .topbar,
  .hero,
  .form-card,
  .pending-card,
  .history-card,
  .result-toolbar,
  .copy-btn,
  .footer,
  .toast {
    display: none !important;
  }

  body {
    background: #ffffff;
  }

  .main-wrap {
    padding: 0;
    max-width: 100%;
  }

  .result-section {
    margin: 0;
  }

  .card {
    box-shadow: none;
    border: 1px solid #cbd5e1;
  }

  .result-header {
    background: #0f1b2d !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
