/*  Reset & base  */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --header-h: 56px;
  --sidebar-w: 300px;
  --color-primary: #374151;
  --color-accent: #6b7280;
  --color-bg: #f9fafb;
  --color-surface: #ffffff;
  --color-border: #d1d5db;
  --color-text: #111827;
  --color-muted: #6b7280;
  --color-hover: #f3f4f6;
  --color-active: #e5e7eb;
  --radius: 6px;
  --shadow: 0 1px 4px rgba(0,0,0,.12);
}

html, body { height: 100%; font-family: 'Segoe UI', system-ui, sans-serif; color: var(--color-text); background: var(--color-bg); }

/*  Header  */
header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  z-index: 1000;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}

header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: .02em;
  display: flex;
  align-items: center;
  gap: .55rem;
}


/*  App layout  */
#app {
  display: flex;
  position: fixed;
  top: var(--header-h);
  left: 0; right: 0; bottom: 0;
}

/*  Sidebar  */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 2px 0 6px rgba(0,0,0,.06);
  z-index: 500;
}

#sidebar-header {
  padding: .85rem .9rem .75rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}

#sidebar-header span {
  display: block;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-muted);
  margin-bottom: .55rem;
}

#search {
  width: 100%;
  padding: .45rem .65rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: .85rem;
  outline: none;
  transition: border-color .15s;
  background: var(--color-bg);
  color: var(--color-text);
}

#search:focus { border-color: var(--color-primary); }

/*  Colony list  */
#colony-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: .5rem 0;
}

#colony-list::-webkit-scrollbar { width: 5px; }
#colony-list::-webkit-scrollbar-track { background: transparent; }
#colony-list::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 99px; }

.colony-item {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  padding: .6rem .9rem;
  cursor: pointer;
  transition: background .12s;
  border-left: 3px solid transparent;
}

.colony-item:hover { background: var(--color-hover); }
.colony-item.active {
  background: var(--color-active);
  border-left-color: var(--color-primary);
}

.colony-rank {
  min-width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: .05rem;
}

.colony-rank.no-rank {
  background: var(--color-border);
  color: var(--color-muted);
}

.colony-info { flex: 1; min-width: 0; }

.colony-name {
  font-size: .88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.colony-meta {
  font-size: .75rem;
  color: var(--color-muted);
  margin-top: .15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/*  Botón scroll-top  */
#scroll-top {
  display: none;
  width: calc(100% - 1.8rem);
  margin: .6rem .9rem;
  padding: .45rem .7rem;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  flex-shrink: 0;
}

#scroll-top:hover { background: #1f2937; }
#scroll-top.visible { display: block; }

/*  Map */
#map { flex: 1; }

/*  Popup personalizado  */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: .85rem;
  padding: 0;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.leaflet-popup-tip { background: var(--color-surface); }

.leaflet-popup-content { margin: 0; min-width: 200px; }

.popup-title {
  background: var(--color-primary);
  color: #fff;
  padding: .55rem .8rem;
  font-weight: 700;
  font-size: .92rem;
  border-radius: var(--radius) var(--radius) 0 0;
}

.popup-body { padding: .65rem .8rem; background: var(--color-surface); }

.popup-row {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  padding: .2rem 0;
  border-bottom: 1px solid var(--color-border);
  font-size: .8rem;
}

.popup-row:last-child { border-bottom: none; }

.popup-row .label { color: var(--color-muted); }
.popup-row .value { font-weight: 600; text-align: right; }

/*  Leyenda */
.map-legend {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .6rem .8rem;
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: .8rem;
  color: var(--color-text);
  min-width: 200px;
}

.legend-title {
  font-weight: 700;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--color-muted);
  margin-bottom: .45rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .18rem 0;
}

.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
  opacity: .85;
  border: 1px solid rgba(0,0,0,.1);
}

/*  Panel de información  */
#info-panel {
  width: 400px;
  flex-shrink: 0;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: -2px 0 6px rgba(0,0,0,.06);
  z-index: 500;
}

#info-panel-header {
  padding: .85rem .9rem .75rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}

#info-panel-header span {
  display: block;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-muted);
}

#info-panel-body {
  overflow-y: auto;
  flex: 1;
  padding: .9rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#info-panel-body::-webkit-scrollbar { width: 5px; }
#info-panel-body::-webkit-scrollbar-track { background: transparent; }
#info-panel-body::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 99px; }

.info-intro {
  font-size: .78rem;
  color: var(--color-muted);
  line-height: 1.55;
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--color-border);
}

.info-cluster {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.info-cluster-header {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.info-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,.1);
}

.info-cluster strong {
  font-size: .82rem;
  color: var(--color-text);
}

.info-cluster p {
  font-size: .78rem;
  color: var(--color-muted);
  line-height: 1.55;
  padding-left: 1.1rem;
}

/*  Pantallas pequeñas */
@media (max-width: 640px) {
  :root { --sidebar-w: 100%; }

  #app { flex-direction: column; }

  #sidebar {
    height: 240px;
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }

  #map { flex: 1; }

  #info-panel { display: none; }
}
