/* Reset & base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #f8f9fa;
  --color-surface: #ffffff;
  --color-text: #1d2d35;
  --color-text-muted: #5a6872;
  --color-primary: #1d70b8;
  --color-primary-hover: #144e81;
  --color-border: #d3dce0;
  --color-bar: #1d70b8;
  --color-bar-bg: #e8eef1;
  --color-stripe: #f4f6f7;
  --color-link: #1d70b8;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

html {
  font-size: 16px;
  line-height: 1.5;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
}

a {
  color: var(--color-link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Header */
header {
  background: var(--color-text);
  color: #fff;
  padding: 2rem 1.5rem 1.5rem;
  text-align: center;
}

header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

header .subtitle {
  color: #b0bec5;
  font-size: 0.95rem;
}

/* Main */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Loading */
.loading {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--color-text-muted);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  margin: 0 auto 1rem;
  animation: spin 0.8s linear infinite;
}

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

.error {
  text-align: center;
  padding: 2rem;
  color: #d32f2f;
  background: #fdecea;
  border-radius: var(--radius);
}

/* Static SEO content */
.static-content {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow);
}

.static-content h2 {
  font-size: 1.25rem;
  margin-bottom: 0.75rem;
}

.static-content h3 {
  font-size: 1rem;
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
}

.static-content p {
  margin-bottom: 0.75rem;
  color: var(--color-text);
  line-height: 1.6;
}

.static-content ul {
  margin: 0 0 0.75rem 1.5rem;
  color: var(--color-text);
}

.static-content li {
  margin-bottom: 0.25rem;
}

/* Stats section */
.stats-section {
  margin-bottom: 2rem;
}

.stats-section h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-value {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: 0.25rem;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Bar chart */
.chart-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.chart-section h3 {
  font-size: 1rem;
  margin-bottom: 1rem;
}

.bar-chart .bar-row {
  display: flex;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.bar-chart .bar-label {
  width: 280px;
  flex-shrink: 0;
  text-align: right;
  padding-right: 0.75rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-chart .bar-track {
  flex: 1;
  background: var(--color-bar-bg);
  border-radius: 3px;
  height: 22px;
  position: relative;
  overflow: hidden;
}

.bar-chart .bar-fill {
  height: 100%;
  background: var(--color-bar);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.bar-chart .bar-count {
  width: 60px;
  flex-shrink: 0;
  padding-left: 0.5rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Search section */
.search-section {
  margin-bottom: 2rem;
}

.search-section h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.search-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.search-bar input {
  flex: 1;
  padding: 0.6rem 0.85rem;
  font-size: 0.95rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s;
}

.search-bar input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(29, 112, 184, 0.15);
}

.search-bar button,
.filter-actions button {
  padding: 0.6rem 1.25rem;
  font-size: 0.95rem;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s;
}

.search-bar button:hover,
.filter-actions button:hover {
  background: var(--color-primary-hover);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.filter-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.filter-group select {
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  min-width: 160px;
  max-width: 260px;
  outline: none;
}

.filter-group select:focus {
  border-color: var(--color-primary);
}

.filter-actions {
  justify-content: flex-end;
}

.filter-actions button {
  background: #6c757d;
}

.filter-actions button:hover {
  background: #545b62;
}

/* Results */
.results-section {
  margin-bottom: 2rem;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.results-header h2 {
  font-size: 1.25rem;
}

#results-count {
  font-weight: 400;
  font-size: 0.95rem;
  color: var(--color-text-muted);
}

.sort-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.sort-controls label {
  color: var(--color-text-muted);
}

.sort-controls select {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  background: var(--color-surface);
}

/* Table */
.table-wrapper {
  overflow-x: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead {
  background: var(--color-stripe);
}

th {
  text-align: left;
  padding: 0.7rem 0.75rem;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}

th.sortable {
  cursor: pointer;
  user-select: none;
}

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

td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

tbody tr:nth-child(even) {
  background: var(--color-stripe);
}

tbody tr:hover {
  background: #e8f0fe;
}

.col-date {
  width: 95px;
}

.col-ref {
  width: 200px;
}

.col-address {
  min-width: 250px;
}

.col-category {
  width: 180px;
}

.col-region {
  width: 70px;
  text-align: center;
}

.col-link {
  width: 60px;
  text-align: center;
}

td.col-region {
  text-align: center;
}

td.col-link {
  text-align: center;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
  padding: 0.75rem;
}

.pagination button {
  padding: 0.45rem 1rem;
  font-size: 0.9rem;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}

.pagination button:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.pagination button:disabled {
  background: var(--color-border);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

#page-info {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

/* Footer */
footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
  margin-top: 1rem;
}

footer p {
  margin-bottom: 0.25rem;
}

footer a {
  color: var(--color-primary);
}

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

  .stats-cards {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat-value {
    font-size: 1.4rem;
  }

  .bar-chart .bar-label {
    width: 140px;
    font-size: 0.75rem;
  }

  .search-bar {
    flex-direction: column;
  }

  .filters {
    flex-direction: column;
  }

  .filter-group select {
    max-width: 100%;
    width: 100%;
  }

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

  .col-category,
  .col-ref {
    display: none;
  }

  th, td {
    padding: 0.5rem;
    font-size: 0.8rem;
  }
}

@media (max-width: 480px) {
  main {
    padding: 1rem 0.75rem;
  }

  .stats-cards {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .stat-card {
    padding: 0.75rem;
  }

  .stat-value {
    font-size: 1.2rem;
  }

  .bar-chart .bar-label {
    width: 100px;
    font-size: 0.7rem;
  }
}
