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

body {
  font-family: "Open Sans", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
}

/* Apple-style Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
  background: transparent;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 100px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

::-webkit-scrollbar-corner {
  background: transparent;
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
  padding-top: 0;
}

header {
  text-align: center;
  padding: 3rem 0;
}

h1 {
  font-weight: 800;
  font-size: 3rem;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 400;
}

/* Filter */
.filter-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.crime-type-select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 0.6rem 2.5rem 0.6rem 1rem;
  font-size: 0.85rem;
  font-family: inherit;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b8b9e' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  min-width: 200px;
}

.crime-type-select:hover {
  border-color: rgba(167, 139, 250, 0.4);
  background-color: var(--bg-tertiary);
}

.crime-type-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(167, 139, 250, 0.2);
}

.crime-type-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 0.5rem;
}

/* Tier List */
.tier-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tier-row {
  display: flex;
  background: var(--bg-secondary);
  border-radius: 12px;
  overflow: hidden;
  min-height: 80px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.tier-label {
  width: 80px;
  min-width: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 2rem;
  color: var(--bg-primary);
  position: relative;
  overflow: hidden;
}

.tier-row:hover .tier-label::before {
  opacity: 1;
}

.tier-label span {
  position: relative;
  z-index: 1;
  font-weight: 400;
  font-size: 1.2rem;
}

.tier-label small {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.8;
  position: relative;
  z-index: 1;
}

/* Tier Colors */
.tier-s .tier-label {
  background: var(--tier-s);
}
.tier-a .tier-label {
  background: var(--tier-a);
}
.tier-b .tier-label {
  background: var(--tier-b);
}
.tier-c .tier-label {
  background: var(--tier-c);
}
.tier-d .tier-label {
  background: var(--tier-d);
}
.tier-f .tier-label {
  background: var(--tier-f);
}

.tier-regions {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  padding: 0.75rem;
  gap: 0.5rem;
}

/* Region Cards */
.region-card {
  background: var(--bg-tertiary);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid rgba(255, 255, 255, 0.05);
  position: relative;
  overflow: hidden;
}

.region-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
  opacity: 0.7;
}

.tier-s .region-card::before {
  background: var(--tier-s);
}
.tier-a .region-card::before {
  background: var(--tier-a);
}
.tier-b .region-card::before {
  background: var(--tier-b);
}
.tier-c .region-card::before {
  background: var(--tier-c);
}
.tier-d .region-card::before {
  background: var(--tier-d);
}
.tier-f .region-card::before {
  background: var(--tier-f);
}

.region-card:hover {
  background: rgba(167, 139, 250, 0.1);
  border-color: rgba(167, 139, 250, 0.35);
  transform: translateY(-2px);
}

.region-name {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.region-stats {
  font-size: 0.7rem;
  color: var(--text-secondary);
  display: flex;
  gap: 0.75rem;
}

.stat {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.stat-icon {
  opacity: 0.6;
}

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

.commercial-badge {
  font-size: 0.7rem;
  opacity: 0.7;
}

.population-disclaimer {
  background: rgba(167, 139, 250, 0.1);
  border: 1px solid rgba(167, 139, 250, 0.25);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-top: 0.75rem;
  font-size: 0.8rem;
}

.population-disclaimer p {
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.population-disclaimer p:last-child {
  margin-bottom: 0;
}

.population-disclaimer .disclaimer-text {
  color: var(--text-secondary);
  font-size: 0.75rem;
  line-height: 1.4;
}

/* Footer */
footer {
  text-align: center;
  margin-top: 3rem;
  padding: 2rem 0;
  color: var(--text-secondary);
  font-size: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

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

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

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.active {
  display: flex;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal {
  background: var(--bg-secondary);
  border-radius: 16px;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, 0.1);
  animation: slideUp 0.3s ease;
}

.modal::-webkit-scrollbar {
  width: 6px;
}

.modal::-webkit-scrollbar-track {
  background: transparent;
  margin: 8px 0;
}

.modal::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 100px;
}

.modal::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

.modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  z-index: 1;
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 700;
}

.modal-tier-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.75rem;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--bg-primary);
  margin-top: 0.5rem;
}

.modal-close {
  background: var(--bg-tertiary);
  border: none;
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.modal-close:hover {
  background: var(--accent);
  color: var(--bg-primary);
}

.modal-body {
  padding: 1.5rem;
}

.modal-section {
  margin-bottom: 1.5rem;
}

.modal-section:last-child {
  margin-bottom: 0;
}

.modal-section-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  font-weight: 600;
}

/* Summary Stats - New Layout */
.summary-stats {
  display: flex;
  align-items: stretch;
  gap: 1.25rem;
  background: var(--bg-tertiary);
  border-radius: 12px;
  padding: 1.25rem;
}

.summary-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.5rem;
  background: linear-gradient(
    135deg,
    rgba(167, 139, 250, 0.15),
    rgba(167, 139, 250, 0.05)
  );
  border: 1px solid rgba(167, 139, 250, 0.25);
  border-radius: 10px;
  min-width: 120px;
}

.summary-main-value {
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

.summary-main-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  font-weight: 600;
}

.summary-secondary {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.6rem;
  flex: 1;
}

.summary-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.summary-item:last-child {
  border-bottom: none;
}

.summary-item-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.summary-item-value {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* Breakdown Table */
.breakdown-table {
  width: 100%;
  border-collapse: collapse;
}

.breakdown-table th,
.breakdown-table td {
  padding: 0.75rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.breakdown-table th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  font-weight: 600;
}

.breakdown-table td {
  font-size: 0.85rem;
}

.breakdown-table tr:last-child td {
  border-bottom: none;
}

.breakdown-table .crime-name {
  font-weight: 600;
}

.breakdown-table .weight-badge {
  display: inline-block;
  background: var(--bg-primary);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.7rem;
  color: var(--text-secondary);
}

/* Position Badge - colors set dynamically via JS using tier colors */
.position-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* Formula Box */
.formula-box {
  background: var(--bg-tertiary);
  border-radius: 10px;
  padding: 1rem;
  font-size: 0.8rem;
}

.formula-box code {
  background: var(--bg-primary);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-family: "SF Mono", "Monaco", monospace;
  font-size: 0.75rem;
}

.formula-box p {
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

.formula-box p:last-child {
  margin-bottom: 0;
}

/* Navbar */
.navbar {
  background: var(--bg-secondary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

.navbar-brand {
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--text-primary);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.navbar-brand:hover {
  color: var(--accent);
}

.navbar-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
}

.hamburger {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--text-primary);
  position: relative;
  transition: all 0.3s ease;
}

.hamburger::before,
.hamburger::after {
  content: "";
  position: absolute;
  width: 24px;
  height: 2px;
  background: var(--text-primary);
  left: 0;
  transition: all 0.3s ease;
}

.hamburger::before {
  top: -7px;
}

.hamburger::after {
  top: 7px;
}

.navbar-toggle[aria-expanded="true"] .hamburger {
  background: transparent;
}

.navbar-toggle[aria-expanded="true"] .hamburger::before {
  transform: rotate(45deg);
  top: 0;
}

.navbar-toggle[aria-expanded="true"] .hamburger::after {
  transform: rotate(-45deg);
  top: 0;
}

.navbar-menu {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.navbar-dropdown {
  position: relative;
}

.navbar-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.navbar-link:hover {
  background: var(--bg-tertiary);
  color: var(--accent);
}

.dropdown-arrow {
  transition: transform 0.2s ease;
}

.navbar-dropdown.open .dropdown-arrow {
  transform: rotate(180deg);
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  min-width: 220px;
  max-height: 70vh;
  overflow-y: auto;
  padding: 0.5rem;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s ease;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.dropdown-menu::-webkit-scrollbar {
  width: 6px;
}

.dropdown-menu::-webkit-scrollbar-track {
  background: transparent;
  margin: 6px 0;
}

.dropdown-menu::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 100px;
}

.dropdown-menu::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

.navbar-dropdown.open .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-item {
  display: block;
  padding: 0.6rem 1rem;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.85rem;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.dropdown-item:hover {
  background: var(--bg-tertiary);
  color: var(--accent);
}

.dropdown-item.active {
  background: rgba(167, 139, 250, 0.15);
  color: var(--accent);
}

.dropdown-header {
  display: block;
  padding: 0.5rem 1rem 0.25rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.dropdown-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 0.5rem 0;
}

/* Rate cell styling (dynamically colored via JS) */
.rate-cell {
  font-weight: 600;
}

/* Empty breakdown message */
.empty-breakdown {
  text-align: center;
  color: var(--tier-s);
}

/* Footer and formula box text utilities */
.footer-note {
  margin-top: 0.5rem;
}

.formula-section-title {
  margin-top: 0.75rem;
}

.formula-small-text {
  margin-top: 0.25rem;
  font-size: 0.75rem;
}

.formula-conclusion {
  margin-top: 0.75rem;
  color: var(--tier-s);
}

/* Responsive */
@media (max-width: 640px) {
  .navbar-container {
    padding: 0 1rem;
  }

  .navbar-toggle {
    display: block;
  }

  .navbar-menu {
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1rem;
    display: none;
    flex-direction: column;
    align-items: stretch;
  }

  .navbar-menu.open {
    display: flex;
  }

  .navbar-dropdown {
    width: 100%;
  }

  .navbar-link {
    width: 100%;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
  }

  .dropdown-menu {
    position: static;
    opacity: 1;
    visibility: visible;
    transform: none;
    margin-top: 0.5rem;
    max-height: 0;
    overflow: hidden;
    padding: 0;
    border: none;
    box-shadow: none;
    transition: max-height 0.3s ease;
  }

  .navbar-dropdown.open .dropdown-menu {
    max-height: 60vh;
    overflow-y: auto;
    padding: 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
  }

  .container {
    padding: 1rem;
  }

  h1 {
    font-size: 2rem;
  }

  .tier-label {
    width: 60px;
    min-width: 60px;
    font-size: 1.5rem;
  }

  .region-card {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
  }

  .modal {
    max-height: 95vh;
  }

  .modal-header {
    padding: 1rem;
  }

  .modal-body {
    padding: 1rem;
  }

  .summary-stats {
    flex-direction: column;
    gap: 1rem;
  }

  .summary-main {
    padding: 1rem;
  }

  .breakdown-table {
    font-size: 0.8rem;
  }

  .breakdown-table th,
  .breakdown-table td {
    padding: 0.5rem 0.25rem;
  }

  .breakdown-table th:nth-child(3),
  .breakdown-table td:nth-child(3) {
    display: none;
  }

  .filter-container {
    flex-direction: column;
    gap: 0.5rem;
  }

  .crime-type-select {
    min-width: 100%;
  }
}
