/* =============================================================
   app.css — Application component styles
   Design tokens (variables, font-faces, base reset, utilities)
   live in tokens.css — do not duplicate them here.
   ============================================================= */


/* -------------------------------------------------------------
   1. APP LAYOUT
   ------------------------------------------------------------- */

html, body {
  margin: 0;
  padding: 0;
}

.app-container {
  width: 100%;
  min-height: 100vh;
  position: relative;
  background-color: var(--bg-primary);
}

.map-container {
  width: calc(100% - 300px);
  height: 70vh;
  min-height: 500px;
  position: relative;
  z-index: 1;
}

.world-map {
  height: 100% !important;
  width: 100% !important;
}


/* -------------------------------------------------------------
   2. SIDE PANEL
   ------------------------------------------------------------- */

.side-panel {
  position: fixed;
  top: 0;
  right: 20px;
  background: rgba(255, 255, 255, 0.80);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.10);
  border: 1px solid rgba(200, 200, 200, 0.6);
  width: 320px;
  height: 70vh;
  max-height: 70vh;
  padding: 8px;
  z-index: 100;
  border-radius: var(--radius-xs);
  overflow: hidden;
  user-select: none;
  display: flex;
  flex-direction: column;
}

.side-panel.has-selection {
  height: auto;
}


/* -------------------------------------------------------------
   3. INFO BUTTON
   ------------------------------------------------------------- */

.info-button-container {
  position: fixed;
  top: auto;
  bottom: calc(40vh + 80px);
  left: 50px;
  z-index: 200;
}

.info-button {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  border-radius: 50%;
  z-index: 110;
  width: 25px;
  height: 25px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.info-icon {
  width: 25px;
  height: 25px;
}


/* -------------------------------------------------------------
   4. DROPDOWN
   ------------------------------------------------------------- */

.dropdown-container {
  margin-bottom: 4px;
  margin-top: 3px;
}

.native-dropdown {
  font-family: var(--font-brand);
  font-size: var(--text-xs);
  width: 100%;
}


/* -------------------------------------------------------------
   5. BUTTONS
   ------------------------------------------------------------- */

.button {
  text-align: center;
  background-color: var(--brand-mid);
  border-radius: var(--radius-pill);
  width: auto;
  padding: .5em 1.5em;
  font-family: var(--font-brand);
  font-size: 1.5em;
  font-weight: var(--weight-bold);
  line-height: 1.26;
  color: var(--text-on-dark);
  border: none;
  cursor: pointer;
}

.reset-button-container {
  margin-top: 8px;
  text-align: center;
}

.reset-button-container.hidden {
  display: none;
}

.reset-button-container.visible {
  display: block;
}

.reset-button {
  font-size: 11px !important;
  font-family: var(--font-brand) !important;
  font-weight: 300 !important;
  padding: 5px 18px !important;
  width: fit-content !important;
  border-radius: var(--radius-pill) !important;
  line-height: 1 !important;
}


/* -------------------------------------------------------------
   6. CHART CONTAINERS
   ------------------------------------------------------------- */

.line-chart-container {
  margin-top: 10px;
  margin-bottom: 10px;
  max-height: 250px;
}

.line-chart-container.hidden {
  display: none;
}

.line-chart-container.visible {
  display: block;
}

.line-chart {
  width: 100%;
  height: 220px;
}

.d3-chart {
  height: 400px;
  max-height: 600px;
}


/* -------------------------------------------------------------
   7. TABLE
   ------------------------------------------------------------- */

.table-container {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  font-size: var(--text-xs);
  margin-bottom: 4px;
}

#table {
  font-family: var(--font-ui) !important;
  font-size: var(--text-xs) !important;
}

#table .dash-cell {
  font-family: var(--font-ui) !important;
  font-size: var(--text-xs) !important;
}

#table .dash-header {
  font-family: var(--font-ui) !important;
  font-size: var(--text-xs) !important;
}

.table-container .dash-table-container {
  font-family: var(--font-ui) !important;
  font-size: var(--text-xs) !important;
}

.table-container .dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner table {
  font-family: var(--font-ui) !important;
  font-size: var(--text-xs) !important;
}

.table-container .dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner .dash-cell {
  font-family: var(--font-ui) !important;
  font-size: var(--text-xs) !important;
}

.table-container .dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner .dash-header {
  font-family: var(--font-ui) !important;
  font-size: var(--text-xs) !important;
  font-weight: 600 !important;
  background-color: #bababa !important;
  color: #ffffff !important;
}

.table-container .dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner th {
  background-color: #bababa !important;
  color: #ffffff !important;
}


/* -------------------------------------------------------------
   8. MAP CONTROLS PANEL
   ------------------------------------------------------------- */

.map-controls-panel {
  margin-top: 10px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  padding-top: 6px;
}

.map-controls-summary {
  font-size: 10px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  letter-spacing: 0.5px;
}

.map-ctrl-body {
  padding: 6px 0 2px 0;
}

.map-ctrl-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
  flex-wrap: wrap;
}

.map-ctrl-label {
  font-family: var(--font-brand);
  font-size: 9px;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 52px;
}

.map-ctrl-input {
  font-family: var(--font-brand);
  font-size: 11px;
  width: 60px;
  padding: 2px 4px;
  border: 1px solid var(--border-default);
  border-radius: 2px;
  color: var(--text-secondary);
}


/* -------------------------------------------------------------
   9. MAP HOVER TOOLTIPS
   ------------------------------------------------------------- */

.hover-content {
  font-family: var(--font-ui);
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  padding: 8px;
  border-radius: var(--radius-xs);
}

.hover-ranking,
.hover-score,
.hover-divider,
.hover-population,
.hover-spacer {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--text-primary);
}

.hover-spacer {
  font-size: 9px;
  color: transparent;
}

.hover-category {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  /* color set dynamically via inline style */
}

.hover-country {
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: bold;
  /* color set dynamically via inline style */
}


/* -------------------------------------------------------------
   10. HELP OVERLAY SYSTEM
   ------------------------------------------------------------- */

.help-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.3);
  z-index: 1000;
  cursor: pointer;
}

.help-overlay .help-box,
.help-overlay {
  cursor: default;
}

.help-overlay.hidden {
  display: none;
}

.help-overlay.visible {
  display: block;
}

.help-box {
  position: absolute;
  background: rgba(255, 255, 255, 0.9);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  white-space: nowrap;
  z-index: 1001;
  border: 1px solid rgba(0, 0, 0, 0.1);
  max-width: 200px;
}

.help-box-map {
  top: 30%;
  left: 30%;
  transform: translateX(-50%);
}

.help-box-legend {
  position: fixed;
  top: 480px;
  left: 150px;
  transform: translateX(-50%);
}

.help-box-dropdown {
  top: 60px;
  right: 80px;
}

.help-box-table {
  top: 50%;
  right: 50px;
  transform: translateY(-50%);
}

.help-icon {
  width: 30px;
  height: 30px;
  margin-right: 8px;
}

.help-text {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}


/* Help overlay interaction */
#info-button:hover {
  background-color: rgba(0, 0, 0, 0.1) !important;
  transform: scale(1.1);
  transition: all 0.2s ease;
}


#help-overlay {
  animation: fadeIn 0.3s ease-in-out;
}

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

.help-content h4 {
  margin-bottom: 10px;
  font-weight: 600;
}

.help-content ul {
  margin-bottom: 15px;
  padding-left: 20px;
}

.help-content li {
  margin-bottom: 5px;
}

/* Override text-medium color inside help overlay */
.help-overlay .text-medium {
  color: var(--text-primary) !important;
  font-family: var(--font-ui) !important;
  font-size: var(--text-xs) !important;
  font-weight: var(--weight-regular) !important;
  line-height: 1.2 !important;
}


/* -------------------------------------------------------------
   11. TYPOGRAPHY CLASSES (legacy — use .t-* tokens for new code)
   ------------------------------------------------------------- */

.heading {
  color: var(--text-primary);
  text-transform: none;
  margin-top: 0;
  margin-bottom: 0;
  padding-left: 0;
  font-family: var(--font-ui);
  font-size: 3em;
  line-height: 1.26;
}

.heading.center {
  text-align: center;
  margin-bottom: 25px;
}

.text-light {
  color: var(--text-primary);
  text-align: left;
  margin-bottom: 10px;
  padding-top: 20px;
  font-family: var(--font-ui);
  font-size: 1.21em;
  font-weight: var(--weight-light);
  line-height: 1.26;
  display: block;
}

.text-medium {
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 1.21em;
  font-weight: var(--weight-regular);
  line-height: 1.26;
}

.text-bold {
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 1.7em;
  font-weight: var(--weight-bold);
  line-height: 1.17;
}


/* -------------------------------------------------------------
   12. COLOR UTILITIES
   ------------------------------------------------------------- */

.color-primary   { color: var(--brand-mid); }
.color-secondary { color: var(--brand-alt); }
.color-tertiary  { color: var(--brand-dark); }

.bg-primary   { background-color: var(--brand-mid); }
.bg-secondary { background-color: var(--brand-alt); }
.bg-light     { background-color: var(--bg-subtle); }


/* -------------------------------------------------------------
   13. VISIBILITY UTILITIES
   ------------------------------------------------------------- */

.hidden  { display: none !important; }
.visible { display: block !important; }


/* -------------------------------------------------------------
   14. D1 DASHBOARD LAYOUT
   ------------------------------------------------------------- */

.d1-main-row {
  display: flex;
  flex-direction: row;
  align-items: stretch;
}

.d1-chart-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
}

.d1-sidebar {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-start;
  padding-left: 20px;
  min-width: 160px;
  flex-shrink: 0;
}

.d1-legend {
  margin-bottom: 16px;
}

.d1-info-btn {
  background-color: var(--bg-subtle);
  border: none;
  padding: var(--pad-btn-sm);
  cursor: pointer;
  font-family: var(--font-brand);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  white-space: nowrap;
  transition: background-color 0.15s ease;
}

.d1-info-btn:hover {
  background-color: #ede8ce;
}

.d1-info-btn--active {
  background-color: var(--status-danger-bg);
}

.d1-info-btn--active:hover {
  background-color: #ffc5c5;
}

/* D1 explanation overlay — covers chart-wrap only */
.d1-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.80);
  padding: 40px 52px;
  z-index: 10;
  overflow-y: auto;
  border: 1px dashed var(--border-subtle);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  line-height: 1.6;
  animation: fadeIn 0.2s ease;
}

.d1-overlay.hidden  { display: none; }
.d1-overlay.visible { display: block; }


/* -------------------------------------------------------------
   15. MOBILE LAYOUT  (max-width: 768px)
   ------------------------------------------------------------- */

@media screen and (max-width: 768px) {
  body, html {
    margin: 0 !important;
    padding: 0 !important;
    overflow-x: hidden !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .app-container {
    flex-direction: column;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }

  .map-container {
    width: 100%;
    max-width: 100vw;
    height: 30vh;
    min-height: 250px;
    margin: 0 auto 2px auto;
    overflow: hidden;
    box-sizing: border-box;
    position: relative;
  }

  .world-map {
    height: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
    position: relative !important;
  }

  .map-container #world-map {
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .map-container .js-plotly-plot,
  .map-container .plotly,
  .map-container svg {
    transform: translateX(0%) !important;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .map-container .js-plotly-plot .plotly .main-svg {
    width: 100% !important;
    height: 100% !important;
  }

  .map-container .js-plotly-plot .plotly .subplot {
    margin: 0 !important;
    padding: 0 !important;
  }

  .info-button-container  { display: none !important; }
  .reset-button-container { display: none !important; }
  .table-container        { display: none !important; }

  .line-chart-container {
    max-height: 200px;
  }

  .d3-chart {
    height: 550px;
    max-height: 550px;
  }

  .dropdown-container {
    position: fixed !important;
    top: calc(30vh + 10px) !important;
    left: 10px !important;
    right: 10px !important;
    width: calc(100vw - 20px) !important;
    margin: 0 !important;
    z-index: 2000 !important;
    background: transparent !important;
    border-radius: 0 !important;
    padding: 10px !important;
    box-shadow: none !important;
    border: none !important;
  }

  .native-dropdown {
    font-size: 16px !important;
    padding: 12px !important;
    min-height: 44px !important;
    width: 100% !important;
    border: 1px solid var(--border-subtle) !important;
    border-radius: var(--radius-xs) !important;
  }

  .side-panel {
    position: relative;
    top: 80px !important;
    right: 0;
    left: 0;
    width: calc(100% - 20px);
    max-width: none;
    margin: 10px;
    padding: 15px;
    border-radius: var(--radius-sm);
    border: none !important;
    box-shadow: none !important;
  }

  /* Map legend — horizontal layout on mobile */
  .plotly .legend {
    font-size: 8px !important;
    color: var(--text-primary) !important;
    padding: 6px !important;
    position: relative !important;
    bottom: auto !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    margin: 2px auto !important;
    background: rgba(255, 255, 255, 0.95) !important;
    border: 1px solid var(--border-subtle) !important;
    border-radius: var(--radius-xs) !important;
    width: auto !important;
    max-width: calc(100vw - 20px) !important;
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 4px !important;
    overflow-x: auto !important;
  }

  .plotly .legend .legendtrace {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    margin: 0 !important;
    padding: 2px 4px !important;
    font-size: 10px !important;
    flex-shrink: 0 !important;
    white-space: nowrap !important;
  }

  .plotly .legend .legendtitletext {
    font-size: 11px !important;
    color: var(--text-primary) !important;
    font-weight: var(--weight-bold) !important;
    margin-bottom: 2px !important;
    text-align: left !important;
  }

  .plotly .legend .legendtext {
    font-size: 10px !important;
    letter-spacing: -0.2 px !important;
    color: var(--text-primary) !important;
    font-weight: var(--weight-regular) !important;
    white-space: nowrap !important;
  }

  /* Typography */
  body    { font-size: 12px; }
  .heading { font-size: 24px; }
  .text-light, .text-medium { font-size: 12px; }
  .text-bold { font-size: 18px; }
  .native-dropdown { font-size: 12px; }
  .button { font-size: 11px; padding: 8px 12px; }
  .reset-button { font-size: 11px; padding: 6px; }

  /* Help overlay */
  .help-box {
    padding: 6px 10px;
    font-size: 11px;
    max-width: 180px;
  }
  .help-box-map      { top: 25%; left: 50%; transform: translateX(-50%); }
  .help-box-legend   { bottom: 15%; left: 10%; }
  .help-box-dropdown { top: 15px; right: 15px; }
  .help-box-table    { top: 60%; right: 15px; }

  .help-icon { width: 25px; height: 25px; margin-right: 6px; }
  .help-text { font-size: 10px; }

  /* D1 — stack sidebar below chart on mobile */
  .d1-main-row {
    flex-direction: column;
  }

  .d1-sidebar {
    flex-direction: row;
    justify-content: center;
    align-items: center;
    padding-left: 0;
    padding-top: 10px;
    gap: 20px;
    min-width: unset;
    width: 100%;
  }

  .d1-legend {
    display: flex;
    flex-direction: row;
    gap: 20px;
    margin-bottom: 0;
  }

  .d1-legend > div { margin-bottom: 0; }

  .d1-info-btn { display: none; }
}
