/* ==========================================================================
   Sistema visual do painel — claro, vibrante, muito arredondado e plano.
   Ritmo de 4px, sem sombras, azul-marinho como cor primária.
   ========================================================================== */

:root {
  /* Paleta */
  --bg: #FFFFFF;
  --surface: #FFFFFF;
  --surface-2: #EDEDED;
  --border: #E2E2E2;
  --border-strong: #BEBEBE;
  --text: #333333;
  /* #BEBEBE é o cinza do sistema, mas como texto sobre branco não alcança
     contraste legível. Fica reservado para bordas; texto secundário usa um
     cinza mais fechado. */
  --muted: #6E6E6E;
  --accent: #142E66;
  --accent-hover: #0E2149;
  --accent-soft: rgba(20, 46, 102, .08);
  --danger: #CC3366;
  --warning: #E07A00;

  /* Escala de espaçamento, múltiplos de 4 */
  --sp-1: 4px;
  --sp-2: 12px;
  --sp-3: 16px;
  --sp-4: 20px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 52px;
  --sp-8: 76px;

  /* Cantos */
  --r-pill: 50px;
  --r-card: 12px;
  --r-input: 6px;

  /* Movimento */
  --t-fast: .3s;
  --t-slow: .4s;
}

* { box-sizing: border-box; }

html, body, #react-entry-point {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
}

body {
  color: var(--text);
  font-family: Graphik, Inter, "Helvetica Neue", Arial, ui-sans-serif, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button, input { font: inherit; }

/* O sistema pede anel de foco 0. Mantido para o mouse, mas quem navega por
   teclado precisa enxergar onde está — daí o :focus-visible. */
:focus { outline: 0; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-input);
}

.app-shell {
  min-height: 100vh;
  padding: var(--sp-3) var(--sp-4) var(--sp-4);
  background: var(--bg);
}

/* --------------------------------------------------------------- faixa topo */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
  padding: var(--sp-1) var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: var(--surface);
}

.brand { display: flex; flex: 0 0 auto; align-items: center; gap: var(--sp-2); }

/* Sobre fundo branco a logo azul-marinho se resolve sozinha: sem chip, sem
   moldura. */
.brand-logo {
  display: block;
  height: 34px;
  width: auto;
}

.brand h1 {
  margin: 0;
  color: var(--accent);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -.01em;
  white-space: nowrap;
}

.project-select { flex: 0 1 200px; min-width: 150px; }
.estaca-select { flex: 0 1 210px; min-width: 150px; }

.topbar .metrics { flex: 1 1 auto; justify-content: flex-end; gap: var(--sp-3); }
.topbar .metric span { font-size: 11px; }
.topbar .metric strong { font-size: 14px; }

/* ----------------------------------------------------------------- botões */

.btn {
  cursor: pointer;
  border: 1px solid var(--accent);
  border-radius: var(--r-pill);
  padding: 9px var(--sp-5);
  background: var(--surface);
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
  transition: background-color var(--t-fast) ease, color var(--t-fast) ease,
              border-color var(--t-fast) ease;
}

.btn:hover { background: var(--accent-soft); }

.btn-primary { border-color: var(--accent); background: var(--accent); color: #FFFFFF; }
.btn-primary:hover { border-color: var(--accent-hover); background: var(--accent-hover); }

.btn-ghost { border-color: var(--border-strong); background: transparent; color: var(--muted); }
.btn-ghost:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.btn-config { flex: 0 0 auto; padding: 9px var(--sp-3); font-size: 15px; line-height: 1; }

.jump-status {
  flex: 0 1 auto;
  max-width: 190px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ------------------------------------------------------------- dropdowns */

/* O Dash 4 tem os próprios tokens de tema. Remapeá-los alcança todos os
   componentes de uma vez e evita brigar por especificidade com !important.
   O padrão de fábrica traz um roxo (#7f4bc4) que não pertence a esta paleta. */
:root {
  --Dash-Fill-Interactive-Strong: var(--accent);
  --Dash-Fill-Interactive-Weak: var(--accent-soft);
  --Dash-Fill-Primary-Hover: var(--accent-soft);
  --Dash-Fill-Primary-Active: var(--accent-soft);
  --Dash-Fill-Inverse-Strong: var(--surface);
  --Dash-Stroke-Strong: var(--border-strong);
  --Dash-Stroke-Weak: var(--border);
  --Dash-Text-Primary: var(--text);
  --Dash-Text-Strong: var(--text);
  --Dash-Text-Weak: var(--muted);
  --Dash-Text-Disabled: var(--border-strong);
}

.dash-dropdown,
.dash-dropdown-content {
  border-radius: var(--r-input);
}

.dash-dropdown { transition: border-color var(--t-fast) ease; }

/* Na faixa do topo todos os controles compartilham a mesma altura; no modal
   os seletores seguem compactos, porque lá as linhas de cor são estreitas. */
.topbar .dash-dropdown,
.topbar .btn { min-height: 41px; }
.dash-dropdown-option { border-radius: var(--r-input); }

/* ------------------------------------------------------------- área útil */

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: var(--sp-2);
}

.panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: var(--surface);
}

/* O vídeo se apoia no cinza claro do sistema: dá moldura à imagem sem furar
   o tema claro nem competir com ela. */
.video-wrap {
  display: grid;
  height: clamp(520px, calc(100vh - 126px), 900px);
  place-items: center;
  background: var(--surface-2);
}

#video-player { display: block; width: 100%; height: 100%; object-fit: contain; }

.map-profile-stack {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: clamp(520px, calc(100vh - 126px), 900px);
  background: var(--surface);
}

.map-wrap {
  position: relative;
  width: 100%;
  min-height: 0;
  overflow: hidden;
}

#mapa {
  width: 100%;
  height: 100%;
  border: 0 !important;
  border-radius: 0 !important;
}

.perfil-container {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* Marcador da posição do vídeo. Como a janela do perfil mantém o ponto sempre
   centralizado, ele fica parado no centro da área de plotagem e só precisa ser
   reposicionado quando o gráfico muda de tamanho. */
.perfil-marcador-video {
  position: absolute;
  display: none;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  margin-top: -7px;
  box-sizing: border-box;
  border: 3px solid var(--accent);
  border-radius: 50%;
  background: #FFFFFF;
  z-index: 5;
}

#perfil-longitudinal,
#perfil-longitudinal .js-plotly-plot,
#perfil-longitudinal .plot-container,
#perfil-longitudinal .svg-container {
  width: 100% !important;
  height: 100% !important;
}

/* ------------------------------------------------------------- leituras */

.metrics {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}

.metric { display: flex; align-items: baseline; gap: 5px; white-space: nowrap; }
.metric strong { color: var(--accent); font-size: 16px; font-weight: 600; }
.metric span {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .07em;
}

/* ------------------------------------------------------ tela de carga */

/* z-index abaixo do modal: se a carga falhar, o aviso aparece por cima. */
.tela-carga {
  position: fixed;
  z-index: 9998;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, .74);
  backdrop-filter: blur(3px);
}

.tela-carga-caixa {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
}

.tela-carga-anel {
  width: 56px;
  height: 56px;
  border: 5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: girar .9s linear infinite;
}

.tela-carga-texto {
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .02em;
}

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

/* Quem pede menos movimento continua vendo que algo acontece, mais devagar. */
@media (prefers-reduced-motion: reduce) {
  .tela-carga-anel { animation-duration: 2.4s; }
}

/* --------------------------------------------------------------- modal */

.modal-backdrop {
  position: fixed;
  z-index: 9999;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
  background: rgba(51, 51, 51, .38);
  backdrop-filter: blur(6px);
}

.modal-card {
  width: min(620px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-card);
  background: var(--surface);
}

.modal-header, .modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: var(--sp-4);
}

.modal-header { border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 0; color: var(--accent); font-size: 24px; font-weight: 600; line-height: 1.15; }
.modal-header p { margin: var(--sp-1) 0 0; color: var(--muted); font-size: 13px; }
.modal-body { display: grid; gap: var(--sp-2); padding: var(--sp-4); }
.modal-footer { border-top: 1px solid var(--border); }

.file-row {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: var(--surface-2);
}

.file-path { overflow: hidden; color: var(--muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.file-help { margin: -2px 2px 2px; color: var(--muted); font-size: 13px; }

.project-select { margin: 0; }

.file-warning {
  margin: -2px 2px var(--sp-1);
  padding: var(--sp-2) var(--sp-3);
  border-left: 3px solid var(--warning);
  border-radius: var(--r-input);
  background: rgba(224, 122, 0, .08);
  color: #8A4B00;
  font-size: 13px;
  line-height: 1.5;
}

.color-editor:empty { display: none; }

.color-editor {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: var(--surface);
}

.color-editor-title {
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.color-editor-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: 44px;
  padding: 6px var(--sp-3);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.color-editor-row:last-child { border-bottom: 0; }

.color-select { width: 155px; flex: 0 0 155px; }

.profile-scale-select { width: 180px; flex: 0 0 180px; }

.color-editor-error { padding: var(--sp-2) var(--sp-3); color: var(--danger); font-size: 13px; }

.field-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); padding: var(--sp-1) 2px; }
.field-row label { font-size: 14px; font-weight: 600; }
.field-row small { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; font-weight: 400; }

.number-input {
  width: 110px;
  padding: var(--sp-1) var(--sp-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-input);
  outline: 0;
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--t-fast) ease;
}
.number-input:focus { border-color: var(--accent); }

.modal-status { min-height: 16px; color: var(--muted); font-size: 13px; }

/* Falha de carga precisa se distinguir da mensagem de status normal. */
.modal-erro {
  padding: var(--sp-2) var(--sp-3);
  border-left: 3px solid var(--danger);
  border-radius: var(--r-input);
  background: rgba(204, 51, 102, .08);
  color: #8A1F45;
  font-size: 13px;
  line-height: 1.5;
}


/* -------------------------------------------------------------- legenda */

.map-legend {
  position: absolute;
  z-index: 1000;
  bottom: var(--sp-5);
  left: var(--sp-2);
  min-width: 170px;
  max-width: 260px;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-card);
  background: rgba(255, 255, 255, .94);
  color: var(--text);
  font-size: 13px;
  pointer-events: none;
}

.map-legend-title {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.map-legend-item {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  margin-top: 5px;
  line-height: 1.25;
}

.map-legend-swatch {
  display: inline-block;
  flex: 0 0 22px;
  width: 22px;
  height: 4px;
  border-radius: var(--r-pill);
}

/* controle de camadas do Leaflet acompanhando o tema */
.leaflet-control-layers {
  border: 1px solid var(--border-strong) !important;
  border-radius: var(--r-card) !important;
  background: var(--surface) !important;
  box-shadow: none !important;
  color: var(--text);
  font-size: 13px;
}

.leaflet-bar a {
  border-radius: var(--r-input) !important;
  color: var(--accent) !important;
}

/* ---------------------------------------------------------- responsivo */

@media (max-width: 1400px) {
  /* A logo já identifica a marca; o título pode sair para a faixa caber
     em uma linha só. */
  .brand h1 { display: none; }
}

@media (max-width: 1050px) {
  .workspace-grid { grid-template-columns: 1fr; }
  .video-wrap, .map-profile-stack { height: min(66vh, 620px); }
}

@media (max-width: 680px) {
  .app-shell { padding: var(--sp-2); }
  .brand h1 { display: none; }
  .topbar .metrics { justify-content: flex-start; }
  .metrics { gap: var(--sp-2); flex-wrap: wrap; }
  .file-row { grid-template-columns: 1fr; }
  .modal-footer { align-items: stretch; flex-direction: column-reverse; }
  .modal-footer .btn { width: 100%; }
}
