:root {
  --bg: #0b1020;
  --surface: #121933;
  --surface-2: #1a2444;
  --border: rgba(255, 255, 255, 0.08);
  --text: #eef2ff;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --success: #22c55e;
  --error: #ef4444;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "DM Sans", system-ui, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(99, 102, 241, 0.18), transparent 30%),
    radial-gradient(circle at bottom right, rgba(34, 197, 94, 0.12), transparent 25%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

.app {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 20px 24px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #22c55e);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.header h1 {
  margin: 0;
  font-size: 1.6rem;
}

.header p {
  margin: 4px 0 0;
  color: var(--muted);
}

.status-badge {
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  background: var(--surface);
  white-space: nowrap;
}

.status-badge--ok {
  color: var(--success);
  border-color: rgba(34, 197, 94, 0.35);
}

.status-badge--error {
  color: var(--error);
  border-color: rgba(239, 68, 68, 0.35);
}

.layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  background: rgba(18, 25, 51, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  min-width: 0;
}

.filters {
  padding: 16px 20px;
}

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

.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.filters-row--options {
  align-items: center;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

.results h2 {
  margin: 0 0 16px;
  font-size: 1.1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 0;
}

.field span,
fieldset.field > span {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.field--cnae {
  flex: 1.4;
  min-width: 160px;
}

.field--uf {
  flex: 0.8;
  min-width: 100px;
}

.field--capital,
.field--idade {
  flex: 0.7;
  min-width: 110px;
}

.field--porte {
  border: none;
  padding: 0;
  margin: 0;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

input:focus {
  outline: 2px solid rgba(99, 102, 241, 0.45);
  border-color: transparent;
}

.checkbox-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
}

.checkbox-inline label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}

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

.btn:not(:disabled):hover {
  transform: translateY(-1px);
}

.btn--primary {
  background: linear-gradient(135deg, var(--primary), #4f46e5);
  color: white;
  align-self: flex-end;
  min-height: 42px;
}

.btn--secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn--ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.results {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.results__toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.results__toolbar h2 {
  margin: 0;
}

.results__toolbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

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

.loading {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-radius: 12px;
  background: var(--surface-2);
  margin-bottom: 16px;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

.alert {
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 16px;
}

.alert--error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fecaca;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  max-height: calc(100vh - 300px);
}

table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  table-layout: fixed;
}

thead {
  position: sticky;
  top: 0;
  background: #151d3a;
  z-index: 1;
}

th, td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  max-width: 0;
}

th {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color 0.15s ease, background 0.15s ease;
}

th.sortable:hover {
  color: var(--text);
  background: rgba(99, 102, 241, 0.12);
}

th.sortable--active {
  color: var(--primary-hover);
}

.sort-icon {
  display: inline-block;
  min-width: 1em;
  color: var(--primary);
  font-size: 0.7rem;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 16px;
}

.hidden {
  display: none !important;
}

@media (max-width: 768px) {
  .app {
    padding: 16px;
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
  }

  .filters-row {
    flex-direction: column;
    align-items: stretch;
  }

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

  .results__toolbar {
    flex-direction: column;
  }

  .table-wrap {
    max-height: calc(100vh - 420px);
  }
}
