:root {
  color-scheme: light;
  --panel-bg: #f7f8f5;
  --panel-line: #c9d1c7;
  --ink: #17211c;
  --muted: #5b665f;
  --accent: #0f766e;
  --accent-2: #b45309;
  --danger: #b91c1c;
  --water: #2563eb;
  --surface: #ffffff;
  --shadow: 0 18px 50px rgba(16, 24, 40, 0.18);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
.app-shell,
#viewDiv {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  color: var(--ink);
  background: #dfe7e1;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
}

.side-panel {
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  padding: 22px;
  overflow: auto;
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-line);
  box-shadow: var(--shadow);
}

.panel-header {
  display: grid;
  gap: 8px;
}

.eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.presupuesto-licitacion {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  margin: 14px 0 0;
  padding: 10px 12px;
  border-left: 3px solid #f0c84b;
  background: rgba(5, 18, 24, 0.72);
  color: #fff;
}

.presupuesto-licitacion span,
.presupuesto-licitacion small {
  font-size: 10px;
  color: #b8c9ce;
}

.presupuesto-licitacion strong {
  grid-row: 1 / span 2;
  grid-column: 2;
  align-self: center;
  font-size: 15px;
  color: #fff !important;
}

.censored-client {
  display: inline-block;
  margin-top: 8px;
  padding: 3px 8px;
  background: repeating-linear-gradient(90deg, #020304 0 5px, #343b3e 5px 8px);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .12em;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 31px;
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: 13px;
  letter-spacing: 0;
  text-transform: uppercase;
}

p,
dd,
dt,
.selection-panel,
.layer-row {
  font-size: 13px;
  line-height: 1.45;
}

.panel-header p,
.selection-panel,
dd {
  color: var(--muted);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric-grid div {
  min-width: 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--panel-line);
  border-radius: 6px;
}

.metric-grid span,
.facts dt {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.metric-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
  line-height: 1.1;
}

.panel-section {
  display: grid;
  gap: 10px;
}

.layer-controls {
  display: grid;
  gap: 8px;
}

.layer-row {
  display: grid;
  grid-template-columns: 18px 12px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  background: var(--surface);
  border: 1px solid var(--panel-line);
  border-radius: 6px;
}

.layer-row input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.calibration-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.calibration-grid label {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.calibration-grid span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.calibration-grid input {
  width: 100%;
  min-width: 0;
  height: 32px;
  padding: 0 8px;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--panel-line);
  border-radius: 6px;
}

.calibration-nudges {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.calibration-nudges button {
  min-width: 0;
  height: 30px;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  background: var(--surface);
  border: 1px solid var(--panel-line);
  border-radius: 6px;
  cursor: pointer;
}

.calibration-nudges button:hover,
.calibration-nudges button:focus-visible {
  color: #fff;
  background: var(--accent);
  outline: none;
}

.calibration-summary {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.facts {
  display: grid;
  gap: 8px;
  margin: 0;
}

.facts div {
  display: grid;
  gap: 2px;
  padding: 10px 0;
  border-bottom: 1px solid var(--panel-line);
}

.facts div:last-child {
  border-bottom: 0;
}

.facts dd {
  margin: 0;
}

.export-links {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.export-links a {
  min-width: 0;
  padding: 9px 10px;
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--surface);
  border: 1px solid var(--panel-line);
  border-radius: 6px;
}

.export-links a:hover,
.export-links a:focus-visible {
  color: #fff;
  background: var(--accent);
  outline: none;
}

.selection-panel {
  min-height: 96px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--panel-line);
  border-radius: 6px;
}

.selection-panel strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 15px;
}

.selection-panel dl {
  display: grid;
  grid-template-columns: 95px minmax(0, 1fr);
  gap: 4px 10px;
  margin: 0;
}

.selection-panel dt {
  color: var(--muted);
  font-weight: 700;
}

.selection-panel dd {
  margin: 0;
}

.map-stage {
  position: relative;
  min-width: 0;
  height: 100%;
}

.topbar {
  position: absolute;
  z-index: 2;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.status-pill,
.toolbar {
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(23, 33, 28, 0.14);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.16);
}

.status-pill {
  max-width: min(560px, 60vw);
  padding: 9px 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.toolbar {
  display: inline-flex;
  padding: 4px;
}

.toolbar button {
  min-width: 42px;
  height: 32px;
  padding: 0 10px;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}

.toolbar button:hover,
.toolbar button:focus-visible {
  color: #fff;
  background: var(--accent);
  outline: none;
}

.esri-ui-top-left {
  top: 68px;
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(260px, 38vh) minmax(0, 1fr);
  }

  .side-panel {
    order: 2;
    max-height: 62vh;
    border-top: 1px solid var(--panel-line);
    border-right: 0;
  }

  .map-stage {
    order: 1;
  }

  .topbar {
    flex-wrap: wrap;
  }
}

/* ---- Planificacion 4D ---- */
.timeline4d {
  position: fixed;
  left: 405px;
  right: 20px;
  bottom: 14px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 14px;
  padding: 10px 16px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
  flex-wrap: wrap;
}
.timeline4d button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: #0f766e;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  flex: 0 0 auto;
}
.timeline4d input[type="range"] {
  flex: 1 1 220px;
  accent-color: #0f766e;
  min-width: 160px;
}
.t4d-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}
.t4d-info strong { font-size: 0.85rem; white-space: nowrap; }
.t4d-bar {
  width: 130px;
  height: 8px;
  border-radius: 5px;
  background: #e2e8f0;
  overflow: hidden;
}
.t4d-bar-fill { height: 100%; background: linear-gradient(90deg, #0f766e, #16a34a); }
#t4dPct { font-size: 0.82rem; font-weight: 600; color: #0f766e; white-space: nowrap; }
.t4d-tasks { display: flex; gap: 6px; flex-wrap: wrap; flex: 1 1 100%; }
.t4d-chip {
  font-size: 0.7rem;
  border: 1.5px solid #94a3b8;
  border-radius: 999px;
  padding: 2px 9px;
  background: #fff;
  white-space: nowrap;
}
.t4d-chip-done { color: #0f766e; border-color: #0f766e; font-weight: 600; }

/* tooltip de fotos y velocidad 4D */
.photo-tip {
  position: absolute;
  z-index: 40;
  max-width: 230px;
  background: rgba(15, 23, 42, 0.88);
  color: #f8fafc;
  font-size: 0.72rem;
  line-height: 1.35;
  padding: 8px 10px;
  border-radius: 10px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  box-shadow: 0 6px 18px rgba(0,0,0,0.3);
}
.photo-tip.show { opacity: 1; }
.t4d-speed {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  flex: 0 0 auto;
}
.t4d-speed input[type="range"] {
  width: 90px;
  min-width: 90px;
  flex: 0 0 auto;
  accent-color: #b45309;
}

/* cabecera de proyecto y grupos de capas */
.logo-licitador {
  display: block;
  max-width: 200px;
  margin-bottom: 8px;
}
.titulo-licitacion {
  font-size: 0.72rem;
  line-height: 1.4;
  color: #475569;
}
.layer-group-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #0f766e;
  margin: 10px 0 4px;
  padding-bottom: 2px;
  border-bottom: 1px solid #e2e8f0;
}

/* panel oferta vigente */
.oferta-panel { font-size: 0.74rem; line-height: 1.4; }
.oferta-meta { color: #475569; margin-bottom: 4px; }
.oferta-panel a { color: #0f766e; font-weight: 600; }
.oferta-claves { margin: 6px 0 0 14px; padding: 0; }
.oferta-claves li { margin-bottom: 4px; }
.oferta-panel details summary { cursor: pointer; color: #0f766e; margin-top: 4px; }

/* paquete BIM 4D pro: gantt, leyenda, overlay, hitos */
.t4d-gantt-btn {
  width: auto !important;
  border-radius: 10px !important;
  padding: 0 12px;
  font-size: 0.78rem;
  height: 32px !important;
  background: #334155 !important;
}
.t4d-legend {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.68rem;
  color: #475569;
  flex: 0 0 auto;
}
.t4d-legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-left: 7px;
}
.t4d-gantt {
  flex: 1 1 100%;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 6px;
  overflow-x: auto;
}
.t4d-gantt canvas { width: 100%; height: auto; display: block; }
.t4d-overlay {
  position: fixed;
  top: 66px;
  left: 50%;
  transform: translateX(calc(-50% + 190px));
  z-index: 30;
  background: rgba(15, 23, 42, 0.82);
  color: #fff;
  border-radius: 12px;
  padding: 8px 18px;
  text-align: center;
  pointer-events: none;
}
.t4d-overlay b { font-size: 1.15rem; letter-spacing: 0.04em; display: block; }
.t4d-overlay span { font-size: 0.72rem; color: #cbd5e1; }
.t4d-hito {
  position: fixed;
  top: 130px;
  left: 50%;
  transform: translateX(calc(-50% + 190px));
  z-index: 31;
  background: #dc2626;
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  border-radius: 999px;
  padding: 7px 18px;
  box-shadow: 0 6px 18px rgba(220, 38, 38, 0.4);
  pointer-events: none;
}

/* version final: paneles minimizables/acoplables y transparencia */
.panel-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  z-index: 5;
}
.side-panel { position: relative; }
.panel-controls button {
  width: 26px; height: 26px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: #334155;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
}
body.side-collapsed .app-shell { grid-template-columns: 54px minmax(0, 1fr); }
body.side-collapsed .side-panel > *:not(.panel-controls) { display: none; }
body.panel-right .app-shell { grid-template-columns: minmax(0, 1fr) minmax(320px, 390px); }
body.panel-right.side-collapsed .app-shell { grid-template-columns: minmax(0, 1fr) 54px; }
body.panel-right .side-panel { order: 2; border-right: 0; border-left: 1px solid var(--panel-line); }
body.panel-right .map-stage { order: 1; }
body.panel-right .panel-controls { right: auto; left: 8px; }
.layer-row { display: flex; align-items: center; gap: 8px; }
.layer-row .layer-title { flex: 1 1 auto; min-width: 0; }
.layer-row .layer-opacity {
  width: 54px;
  flex: 0 0 auto;
  accent-color: #94a3b8;
  height: 4px;
  opacity: 0.55;
}
.layer-row .layer-opacity:hover { opacity: 1; }
.t4d-dock { display: flex; gap: 3px; flex: 0 0 auto; }
.t4d-dock button {
  width: 26px !important; height: 26px !important;
  border-radius: 6px !important;
  background: #e2e8f0 !important;
  color: #334155 !important;
  font-size: 0.8rem;
  border: none;
  cursor: pointer;
}
.timeline4d.t4d-vertical { flex-direction: column; align-items: stretch; overflow-y: auto; }
.timeline4d.t4d-vertical .t4d-info { flex-wrap: wrap; }
.timeline4d.t4d-vertical .t4d-gantt canvas { width: 100%; }
.timeline4d.t4d-min .t4d-info,
.timeline4d.t4d-min .t4d-tasks,
.timeline4d.t4d-min .t4d-legend,
.timeline4d.t4d-min .t4d-gantt,
.timeline4d.t4d-min .t4d-gantt-btn,
.timeline4d.t4d-min .t4d-speed { display: none; }

/* garantizar que lo interno queda oculto aunque haya reglas display */
[hidden] { display: none !important; }

/* panel de actividades fijo + transparencia del 4D */
.t4d-actpanel {
  position: fixed;
  width: 280px;
  z-index: 22;
  background: rgba(255, 255, 255, 0.68);
  backdrop-filter: blur(6px);
  border-radius: 14px;
  padding: 10px 12px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
}
.t4d-actpanel h3 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #0f766e;
  margin: 0 0 8px;
}
.t4d-actpanel .t4d-chip {
  display: block;
  white-space: normal;
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.85);
  line-height: 1.3;
  padding: 5px 10px;
}
.timeline4d {
  background: rgba(255, 255, 255, 0.72) !important;
  backdrop-filter: blur(7px);
}
.t4d-gantt {
  background: rgba(255, 255, 255, 0.55) !important;
  backdrop-filter: blur(4px);
}
.t4d-chip-crit { border-color: #dc2626 !important; color: #b91c1c !important; font-weight: 600; }

/* la barra 4D siempre clicable por encima del panel de actividades */
.timeline4d { z-index: 32 !important; }
.t4d-actpanel { z-index: 22; }

/* credito CIVILTEK */
.panel-footer {
  font-size: 0.68rem;
  color: #64748b;
  border-top: 1px solid var(--panel-line);
  padding-top: 10px;
  line-height: 1.4;
}

@media (max-width: 820px) {
  .timeline4d,
  .timeline4d.t4d-vertical {
    position: absolute;
    left: 8px !important;
    right: 8px !important;
    bottom: 8px !important;
    top: auto !important;
    width: auto !important;
    max-height: calc(100% - 16px) !important;
    overflow: auto;
    transform: none !important;
    padding: 8px;
  }

  .t4d-gantt {
    max-height: 150px;
    overflow: auto;
  }

  .t4d-gantt canvas {
    width: 900px;
    max-width: none;
  }

  .t4d-actpanel,
  .t4d-overlay {
    display: none !important;
  }
}
