/* Reset e variáveis */
:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary-color: #64748b;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --error-color: #ef4444;
  --info-color: #3b82f6;
  --bg-color: #f8fafc;
  --card-bg: #ffffff;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  color: var(--text-primary);
  line-height: 1.6;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 3rem;
  color: white;
}

header h1 {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.subtitle {
  font-size: 1.1rem;
  opacity: 0.9;
}

/* Main */
main {
  flex: 1;
}

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  margin-bottom: 2rem;
}

.card h2 {
  color: var(--text-primary);
  margin-bottom: 1.5rem;
  font-size: 1.75rem;
}

/* Form */
.search-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
}

.form-group label {
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.form-group input {
  padding: 0.75rem;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 1rem;
  transition: all 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group small {
  margin-top: 0.25rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* Toggle */
.toggle-group {
  display: flex;
  gap: 0.5rem;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.35rem;
}

.toggle-option {
  flex: 1;
}

.toggle-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-option label {
  display: block;
  text-align: center;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-option input:checked + label {
  background: var(--primary-color);
  color: #fff;
  box-shadow: var(--shadow);
}

/* Buttons */
.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-secondary {
  background: var(--secondary-color);
  color: white;
}

.btn-secondary:hover {
  background: #475569;
  transform: translateY(-2px);
}

/* Alerts */
.alert {
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
  border-left: 4px solid var(--error-color);
}

.alert-error p {
  margin: 0.5rem 0;
}

.alert-error small {
  display: block;
  margin-top: 0.5rem;
  opacity: 0.8;
}

.alert-info {
  background: #dbeafe;
  color: #1e40af;
  border-left: 4px solid var(--info-color);
}

/* Info Card */
.info-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.info-card h3 {
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.info-card ul {
  list-style: none;
  padding-left: 0;
}

.info-card li {
  padding: 0.5rem 0;
  padding-left: 1.5rem;
  position: relative;
}

.info-card li:before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--success-color);
  font-weight: bold;
}

/* Results */
.results-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.results-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.results-header h2 {
  color: white;
  flex: 1;
}

.origin-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
}

.origin-card h3 {
  margin-bottom: 1rem;
  color: var(--text-primary);
}

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

.info-item {
  padding: 0.75rem;
  background: var(--bg-color);
  border-radius: 8px;
}

.meta-info {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  background: var(--card-bg);
  padding: 1rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.meta-item {
  padding: 0.5rem 1rem;
  background: var(--bg-color);
  border-radius: 6px;
  font-size: 0.9rem;
}

/* Badges */
.badge {
  padding: 0.25rem 0.75rem;
  border-radius: 12px;
  font-size: 0.875rem;
  font-weight: 600;
  display: inline-block;
}

.badge-success {
  background: #d1fae5;
  color: #065f46;
}

.badge-warning {
  background: #fef3c7;
  color: #92400e;
}

.badge-info {
  background: #dbeafe;
  color: #1e40af;
}

/* Table */
.results-list {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
}

.results-list h3 {
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.table-container {
  overflow-x: auto;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
}

.results-table thead {
  background: var(--bg-color);
}

.results-table th {
  padding: 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 2px solid var(--border-color);
}

.results-table td {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.results-table tbody tr:hover {
  background: var(--bg-color);
}

.cep-cell {
  font-family: 'Courier New', monospace;
  font-size: 1.1rem;
}

.address-cell {
  min-width: 200px;
}

.address-cell strong {
  color: var(--text-primary);
  display: block;
  margin-bottom: 0.25rem;
}

.address-secondary {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

.address-placeholder {
  color: var(--text-secondary);
  font-style: italic;
  font-size: 0.9rem;
}

.distance-cell {
  color: var(--primary-color);
  font-weight: 600;
  white-space: nowrap;
}

/* Actions */
.actions {
  text-align: center;
  margin-top: 2rem;
}

/* Footer */
footer {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  text-align: center;
  color: white;
}

footer p {
  margin: 0.5rem 0;
  opacity: 0.9;
}

footer a {
  color: white;
  text-decoration: none;
  margin: 0 0.5rem;
}

footer a:hover {
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 768px) {
  header h1 {
    font-size: 2rem;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

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

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

  .table-container {
    font-size: 0.9rem;
  }

  .results-table th,
  .results-table td {
    padding: 0.75rem 0.5rem;
  }
}

/* Loading state */
.loading {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 1s ease-in-out infinite;
}

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

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.pagination-info {
  background: var(--bg-color);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.pagination-current {
  font-weight: 600;
  color: var(--text-primary);
}

.btn-disabled {
  background: var(--border-color);
  color: var(--text-secondary);
  cursor: not-allowed;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
}

@media (max-width: 768px) {
  .pagination {
    flex-direction: column;
    gap: 0.5rem;
  }
}

/* Download Actions */
.download-actions {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-color);
}

.download-actions h3 {
  margin-bottom: 1rem;
  color: var(--text-primary);
  font-size: 1.1rem;
}

.download-buttons {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.btn-download {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.95rem;
  transition: all 0.2s ease;
  box-shadow: var(--shadow);
}

.btn-download:hover {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-download:active {
  transform: translateY(0);
}

.download-empty {
  color: var(--text-secondary);
  font-style: italic;
  padding: 0.5rem;
}

@media (max-width: 768px) {
  .download-buttons {
    flex-direction: column;
  }

  .btn-download {
    width: 100%;
    justify-content: center;
  }
}
