@import url('tokens.css');
@import url('components.css');
@import url('layout.css');
@import url('responsive.css');

/* ============================================
   DASH MAP RIO DOCE — Overrides & Extras
   (Tokens vêm de tokens.css / MIV)
   ============================================ */

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

#react-entry-point,
#_dash-app-content,
#_dash-app-content > div {
  width: 100%;
  height: 100%;
}

body {
  font-family: var(--font-family);
  background: #0d1117;
  overflow: hidden;
  overscroll-behavior: none;
}

/* ── App Shell (dark map mode) ── */
.app-shell {
  position: relative;
  width: 100%;
  /* O shell do mapa começa abaixo do cabeçalho MIV de 64 px. */
  height: calc(100vh - 64px);
  height: calc(100dvh - 64px);
  min-height: calc(100vh - 64px);
  min-height: calc(100dvh - 64px);
  color: #e6edf3;
  background: #0d1117;
  overflow: hidden;
}

/* ── App Header ── */
.app-header {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: auto;
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 24px;
  padding: 14px clamp(16px, 3vw, 28px);
  background: var(--funasa-blue-dark);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
}

.app-header__logo {
  display: block;
  flex: 0 0 auto;
  width: auto;
  height: clamp(42px, 5.2vw, 54px);
}

.app-header__copy {
  flex: 1 1 280px;
  min-width: 220px;
}

.app-header__title {
  margin: 0;
  color: var(--text-inverse);
  font-size: clamp(0.96rem, 1.7vw, 1.12rem);
  font-weight: 800;
  line-height: 1.18;
}

.app-header__subtitle {
  margin: 3px 0 0;
  color: #f3f4f6;
  font-size: clamp(0.72rem, 1.2vw, 0.8rem);
  font-weight: 700;
  line-height: 1.25;
}

/* ── Stats Row ── */
.stats-row {
  display: flex;
  flex: 0 1 auto;
  gap: 8px;
  min-width: 0;
}

.stat-card {
  min-width: 100px;
  padding: 10px 18px;
  text-align: center;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(17, 24, 39, 0.16);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.stat-card__value {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
}

.stat-card__label {
  margin-top: 4px;
  color: var(--text-secondary);
  font-size: var(--font-size-xs);
  font-weight: 700;
  line-height: 1.15;
}

/* ── Map ── */
.map-loading {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
}

.map-loading > div,
.map-loading [data-dash-is-loading] {
  width: 100% !important;
  height: 100% !important;
}

.map-graph {
  width: 100%;
}

#mapa-principal {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}

#mapa-principal .js-plotly-plot,
#mapa-principal .plot-container,
#mapa-principal .svg-container,
#mapa-principal .main-svg,
#mapa-principal .mapboxgl-map,
#mapa-principal .mapboxgl-canvas,
#mapa-principal .mapboxgl-canvas-container,
#mapa-principal .maplibregl-map,
#mapa-principal .maplibregl-canvas,
#mapa-principal .maplibregl-canvas-container {
  width: 100% !important;
  height: 100% !important;
}

/* ── Filter Bar (bottom pill) ── */
.filter-bar {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  left: max(16px, env(safe-area-inset-left));
  z-index: 1000;
  display: flex;
  justify-content: center;
  gap: 8px;
  max-width: 560px;
  margin: 0 auto;
  padding: 6px 8px;
  overflow-x: auto;
  background: rgba(22, 27, 34, 0.92);
  border: 1px solid #30363d;
  border-radius: 999px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.filter-bar::-webkit-scrollbar {
  display: none;
}

.filter-btn {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 8px 20px;
  color: #8b949e;
  font: 600 0.8rem var(--font-family);
  white-space: nowrap;
  letter-spacing: 0.01em;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.08);
  border: 0;
  border-radius: 999px;
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.filter-btn:hover {
  transform: translateY(-1px);
}

.filter-btn--all.is-active {
  color: #0d1117;
  background: #e6edf3;
}

.filter-btn--sim.is-active {
  color: var(--text-inverse);
  background: #2196f3;
}

.filter-btn--nao.is-active {
  color: var(--text-inverse);
  background: var(--status-danger);
}

/* ── Data lists and spreadsheet export ── */
.data-panel-trigger {
  position: absolute;
  top: 104px;
  right: max(16px, env(safe-area-inset-right));
  z-index: 1200;
  min-height: 40px;
  padding: 9px 16px;
  color: #ffffff;
  font: 700 0.78rem var(--font-family);
  cursor: pointer;
  background: #084b86;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  box-shadow: 0 4px 18px rgba(8, 75, 134, 0.32);
}

.data-panel-trigger:hover {
  background: #0c5ea6;
}

.data-panel {
  position: absolute;
  inset: 12px;
  z-index: 1500;
  display: none;
  flex-direction: column;
  min-width: 0;
  overflow: auto;
  color: #1d2939;
  background: #f8fafc;
  border: 1px solid #d0d5dd;
  border-radius: 18px;
  box-shadow: 0 24px 72px rgba(16, 24, 40, 0.38);
}

.data-panel--open {
  display: flex;
}

.data-panel__header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  color: #ffffff;
  background: #063d6e;
}

.data-panel__header h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
}

.data-panel__header p {
  margin: 4px 0 0;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.72rem;
}

.data-panel__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.data-panel__download,
.data-panel__close {
  min-height: 38px;
  padding: 8px 14px;
  font: 700 0.74rem var(--font-family);
  cursor: pointer;
  border-radius: 999px;
}

.data-panel__download {
  color: #063d6e;
  background: #ffffff;
  border: 1px solid #ffffff;
}

.data-panel__close {
  color: #ffffff;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.52);
}

.data-tabs {
  flex: 1;
  min-height: 0;
}

.data-tab {
  padding: 11px 14px !important;
  color: #667085 !important;
  font-size: 0.78rem !important;
  font-weight: 700 !important;
  background: #eef2f6 !important;
  border: 0 !important;
  border-bottom: 3px solid transparent !important;
}

.data-tab--selected {
  color: #084b86 !important;
  background: #ffffff !important;
  border-bottom-color: #0c5ea6 !important;
}

.data-table-wrap {
  padding: 14px;
  overflow: auto;
  background: #ffffff;
}

.data-table-hint {
  margin: 0 0 10px;
  color: #667085;
  font-size: 0.72rem;
}

/* ── Responsive ── */
@media (max-width: 1024px) {
  .app-header {
    align-items: flex-start;
    gap: 10px 16px;
  }

  .stats-row {
    flex: 1 1 100%;
  }

  .stat-card {
    flex: 1 1 0;
    min-width: 0;
    padding: 9px 12px;
  }
}

@media (max-width: 768px) {
  .app-header {
    padding: 10px 12px;
    text-align: center;
  }

  .app-header__logo {
    height: 40px;
  }

  .app-header__copy {
    flex-basis: 100%;
    min-width: 0;
    text-align: center;
  }

  .app-header__title {
    font-size: 0.95rem;
    text-align: center;
  }

  .app-header__subtitle {
    font-size: 0.7rem;
    text-align: center;
  }

  .stats-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    justify-items: center;
  }

  .stat-card {
    padding: 8px 6px;
    text-align: center;
  }

  .stat-card__value {
    font-size: 1.05rem;
  }

  .stat-card__label {
    font-size: 0.58rem;
  }

  .filter-bar {
    justify-content: center;
    max-width: none;
    padding: 6px;
    border-radius: 18px;
  }

  .filter-btn {
    min-height: 36px;
    padding: 8px 14px;
    font-size: 0.76rem;
  }
}

@media (max-width: 767px) {
  .app-shell {
    height: calc(100dvh - 64px - 52px);
    min-height: unset;
    max-height: calc(100dvh - 64px - 52px);
  }

  /* A área do mapa já termina acima da navegação móvel. */
  .filter-bar {
    bottom: max(8px, env(safe-area-inset-bottom));
  }

  .data-panel-trigger {
    top: 118px;
    right: 10px;
    min-height: 36px;
    padding: 7px 12px;
    font-size: 0.7rem;
  }

  .data-panel {
    inset: 6px;
    border-radius: 14px;
  }

  .data-panel__header {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
  }

  .data-panel__actions {
    width: 100%;
  }

  .data-panel__download {
    flex: 1;
  }

  .data-table-wrap {
    padding: 8px;
  }
}

@media (max-width: 420px) {
  .app-header {
    gap: 8px 10px;
  }

  .app-header__logo {
    height: 34px;
  }

  .app-header__copy {
    flex-basis: calc(100% - 46px);
  }

  .app-header__title {
    font-size: 0.86rem;
  }

  .app-header__subtitle {
    font-size: 0.64rem;
  }

  .stat-card {
    padding: 7px 4px;
  }

  .stat-card__value {
    font-size: 0.95rem;
  }

  .filter-btn {
    padding: 8px 12px;
    font-size: 0.72rem;
  }
}
