* {
  box-sizing: border-box;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

body {
  margin: 0;
  padding: 0;
  background: linear-gradient(135deg, #10b981 0%, #0d9488 50%, #1e3a8a 100%);
  min-height: 100vh;
  color: #111827;
  display: flex;
}

/* ===========================
   SIDE NAVIGATION PANEL
   =========================== */
.sidenav {
  width: 280px;
  min-width: 280px;
  background: linear-gradient(180deg, #1e3a8a 0%, #1e40af 50%, #0d9488 100%);
  color: white;
  height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  overflow-y: auto;
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
  transition: transform 0.3s ease;
  z-index: 1000;
}

.sidenav.collapsed {
  transform: translateX(-280px);
}

.sidenav-header {
  padding: 25px 20px;
  border-bottom: 2px solid rgba(255, 255, 255, 0.2);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidenav-header h2 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
}

.toggle-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 1.5rem;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  display: none;
}

.toggle-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.sidenav-content {
  padding: 20px;
}

.nav-section {
  margin-bottom: 30px;
}

.nav-section h3 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.7;
  margin: 0 0 15px 0;
  font-weight: 600;
}

.nav-btn {
  width: 100%;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid transparent;
  color: white;
  padding: 14px 18px;
  margin-bottom: 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  text-align: left;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateX(5px);
}

.nav-btn.active {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.info-box {
  background: rgba(255, 255, 255, 0.1);
  padding: 15px;
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.6;
}

.info-box p {
  margin: 8px 0;
}

.info-box strong {
  color: #10b981;
}

/* ===========================
   MAIN CONTENT AREA
   =========================== */
.main-content {
  flex: 1;
  margin-left: 280px;
  padding: 20px;
  transition: margin-left 0.3s ease;
  min-height: 100vh;
}

.main-content.expanded {
  margin-left: 0;
}

header {
  text-align: center;
  margin-bottom: 30px;
  color: white;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

h1 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  font-weight: 700;
}

.subtitle {
  margin: 0;
  font-size: 1rem;
  opacity: 0.95;
}

main {
  max-width: 1400px;
  margin: 0 auto;
}

/* ===========================
   VIEW CONTAINERS
   =========================== */
.view-container {
  display: none;
  animation: fadeIn 0.4s ease-in;
}

.view-container.active {
  display: block;
}

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

/* ===========================
   CONTROLS SECTION
   =========================== */
.controls {
  background-color: #ffffff;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 15px;
}

.control-group {
  display: flex;
  gap: 15px;
  align-items: center;
}

.controls label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: #374151;
}

.controls select {
  padding: 8px 12px;
  border: 2px solid #e5e7eb;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.2s;
  background-color: white;
}

.controls select:hover {
  border-color: #0d9488;
}

.controls select:focus {
  outline: none;
  border-color: #0d9488;
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.2);
}

.customize-btn {
  background: linear-gradient(135deg, #10b981 0%, #0d9488 100%);
  color: white;
  border: none;
  padding: 12px 28px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: all 0.3s;
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.3);
}

.customize-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(13, 148, 136, 0.4);
}

/* ===========================
   RISK CUSTOMIZATION PANEL
   =========================== */
.risk-panel {
  background-color: #ffffff;
  border: 3px solid #0d9488;
  border-radius: 12px;
  padding: 0;
  margin-bottom: 20px;
  box-shadow: 0 10px 40px rgba(13, 148, 136, 0.2);
  animation: slideDown 0.3s ease-out;
  overflow: hidden;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.panel-header {
  background: linear-gradient(135deg, #10b981 0%, #0d9488 100%);
  color: white;
  padding: 20px 25px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-header h3 {
  margin: 0 0 5px 0;
  font-size: 1.3rem;
  font-weight: 700;
}

.panel-subtitle {
  margin: 0;
  font-size: 0.9rem;
  opacity: 0.9;
}

.close-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: white;
  padding: 5px;
  width: 35px;
  height: 35px;
  border-radius: 50%;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: rotate(90deg);
}

.panel-content {
  padding: 25px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.risk-group {
  background: linear-gradient(135deg, #ecfdf5 0%, #e0f7f5 100%);
  padding: 20px;
  border-radius: 8px;
  border: 2px solid #ccecea;
  transition: all 0.3s;
}

.risk-group:hover {
  border-color: #99d9d4;
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.15);
}

.risk-group h4 {
  margin: 0 0 15px 0;
  color: #0d9488;
  font-size: 1.1rem;
  font-weight: 700;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 6px;
  background-color: white;
  border: 2px solid transparent;
}

.checkbox-label:hover {
  background-color: #f8fafc;
  border-color: #0d9488;
  transform: translateX(5px);
}

.risk-checkbox {
  cursor: pointer;
  width: 18px;
  height: 18px;
  accent-color: #0d9488;
}

.checkbox-label span {
  font-size: 0.9rem;
  color: #374151;
  font-weight: 500;
}

.panel-actions {
  display: flex;
  gap: 12px;
  margin-top: 10px;
}

.apply-btn {
  background: linear-gradient(135deg, #10b981 0%, #0d9488 100%);
  color: white;
  border: none;
  padding: 14px 28px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: all 0.3s;
  flex: 1;
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.3);
}

.apply-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(13, 148, 136, 0.4);
}

.reset-btn {
  background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
  color: white;
  border: none;
  padding: 14px 28px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: all 0.3s;
  flex: 1;
  box-shadow: 0 4px 12px rgba(107, 114, 128, 0.3);
}

.reset-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(107, 114, 128, 0.4);
}

.selection-info {
  background: linear-gradient(135deg, #d1fae5 0%, #defcf9 100%);
  padding: 15px 20px;
  border-radius: 8px;
  border-left: 4px solid #0d9488;
  font-size: 0.95rem;
  color: #0d9488;
}

/* ===========================
   CHART CONTAINERS
   =========================== */
#chart-container,
.chart-container {
  background-color: #ffffff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  min-height: 600px;
  margin-bottom: 20px;
}

/* ===========================
   TOOLTIP
   =========================== */
.tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(17, 24, 39, 0.95);
  color: #f9fafb;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  border: 2px solid #0d9488;
  z-index: 1000;
}

.tooltip-enhanced {
  white-space: normal;
  max-width: 350px;
  background: rgba(255, 255, 255, 0.98);
  color: #1f2937;
  padding: 10px 14px;
  border: 2px solid #0d9488;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  line-height: 1.6;
  font-size: 0.85rem;
}

/* ===========================
   NOTES
   =========================== */
.notes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 15px;
  margin-top: 20px;
}

.note-card {
  background-color: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border-left: 4px solid #0d9488;
}

.note-card h4 {
  margin: 0 0 10px 0;
  color: #0d9488;
  font-size: 1rem;
  font-weight: 700;
}

.note-card ul {
  margin: 10px 0;
  padding-left: 20px;
}

.note-card li {
  margin: 5px 0;
}

/* ===========================
   FOOTER
   =========================== */
.footer-note {
  text-align: center;
  font-size: 0.85rem;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  margin-top: 30px;
}

/* ===========================
   D3 VISUALIZATIONS
   =========================== */
.axis path,
.axis line {
  stroke: #9ca3af;
}

.axis text {
  fill: #374151;
  font-size: 0.8rem;
}

.axis-title {
  font-size: 0.95rem;
  fill: #111827;
  font-weight: 700;
}

.bar {
  stroke: #111827;
  stroke-width: 0.8px;
  cursor: pointer;
  transition: all 0.2s;
}

.bar:hover {
  stroke-width: 2px;
  filter: brightness(1.1);
}

/* Map styles */
.state {
  stroke: #ffffff;
  stroke-width: 1px;
  cursor: pointer;
  transition: all 0.2s;
}

.state:hover {
  stroke: #0d9488;
  stroke-width: 2px;
  filter: brightness(1.1);
}

/* Legend */
.legend {
  font-size: 0.85rem;
}

.legend-title {
  font-weight: 700;
  font-size: 0.9rem;
}

/* ===========================
   RESPONSIVE DESIGN
   =========================== */
@media (max-width: 1024px) {
  .sidenav {
    transform: translateX(-280px);
  }

  .sidenav.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .toggle-btn {
    display: block;
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1001;
    background: linear-gradient(135deg, #10b981 0%, #0d9488 100%);
  }
}

@media (max-width: 768px) {
  body {
    padding: 0;
  }

  .main-content {
    padding: 10px;
  }

  h1 {
    font-size: 1.5rem;
  }

  .controls {
    flex-direction: column;
  }

  .control-group {
    flex-direction: column;
    width: 100%;
  }

  .controls select {
    width: 100%;
  }

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

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

@media (max-width: 480px) {
  h1 {
    font-size: 1.2rem;
  }

  .panel-header {
    padding: 15px;
  }

  .panel-content {
    padding: 15px;
  }

  .risk-group {
    padding: 15px;
  }

  .sidenav {
    width: 240px;
    min-width: 240px;
  }

  .sidenav-header h2 {
    font-size: 1.2rem;
  }
}

/* ===========================
   LOADING ANIMATION
   =========================== */
.loading {
  text-align: center;
  padding: 40px;
  color: #6b7280;
}

.loading::after {
  content: "⏳ Loading visualization...";
  font-size: 1.1rem;
  font-weight: 500;
}

/* ===========================
   GLOBAL LOADING OVERLAY
   =========================== */
.loader-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: linear-gradient(135deg, #10b981 0%, #0d9488 50%, #1e3a8a 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  opacity: 1;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loader-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-container {
  text-align: center;
  padding: 40px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  max-width: 400px;
  animation: fadeInScale 0.5s ease;
}

@keyframes fadeInScale {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.loader-spinner {
  width: 80px;
  height: 80px;
  margin: 0 auto 30px;
  border: 6px solid #e5e7eb;
  border-top: 6px solid #10b981;
  border-right: 6px solid #0d9488;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.loader-text {
  font-size: 1.5rem;
  font-weight: 700;
  color: #111827;
  margin-bottom: 10px;
  background: linear-gradient(135deg, #10b981 0%, #0d9488 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.loader-subtext {
  font-size: 0.95rem;
  color: #6b7280;
  font-weight: 500;
}

/* Loading dots animation */
.loader-text::after {
  content: '';
  animation: loadingDots 1.5s infinite;
}

@keyframes loadingDots {
  0%, 20% {
    content: '';
  }
  40% {
    content: '.';
  }
  60% {
    content: '..';
  }
  80%, 100% {
    content: '...';
  }
}

/* Disable interactions during loading */
body.loading-data .sidenav,
body.loading-data .main-content {
  pointer-events: none;
  user-select: none;
}

body.loading-data .nav-btn {
  opacity: 0.5;
  cursor: not-allowed;
}