*{box-sizing:border-box}

html,body{
  margin:0;
  width:100%;
  height:100%;
  min-height:100%;
  font-family:system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;
}

body{
  display:grid;
  grid-template-rows:auto minmax(0,1fr);
  overflow:hidden;
}

.map-topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:20px;
  padding:12px 18px;
  position:relative;
  z-index:1100;
}

.brand-stack{min-width:0}

.eyebrow{
  display:inline-block;
  margin-bottom:3px;
  padding:3px 9px;
  border-radius:999px;
  font-size:10px;
  font-weight:900;
  letter-spacing:.12em;
  text-transform:uppercase;
  background:rgba(255,255,255,.14);
}

.topbar h1{
  margin:0;
  font-size:25px;
  line-height:1.08;
}

.topbar p{
  margin:4px 0 0;
  font-size:13px;
}

.header-actions{min-width:max-content}

.top-control-row,
.lang-switch{
  display:flex;
  align-items:center;
  gap:6px;
  flex-wrap:nowrap;
}

.lang-switch a{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:34px;
  height:32px;
  padding:0 8px;
  border:1px solid var(--theme-line,#aa6c16);
  border-radius:999px;
  color:var(--theme-text,#10213d);
  background:linear-gradient(180deg,var(--theme-control,#f2dfad),var(--theme-control-2,#dfbd72));
  text-decoration:none;
  font-size:11px;
  font-weight:900;
  line-height:1;
  box-shadow:0 4px 10px rgba(0,0,0,.10);
}

.lang-switch a:hover{filter:brightness(1.05)}

.lang-switch a.active{
  color:var(--theme-button-text,#fff);
  background:linear-gradient(180deg,var(--theme-button,#075fbf),var(--theme-button-hover,#084f9c));
  border-color:var(--theme-accent-2,#084f9c);
}

.header-link{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:36px;
  padding:8px 14px;
  border-radius:999px;
  text-decoration:none;
  font-weight:800;
}

.map-layout{
  min-height:0;
  display:grid;
  grid-template-columns:320px minmax(0,1fr);
  gap:14px;
  padding:0 18px 18px;
}

.map-sidebar{
  position:relative;
  min-width:0;
  min-height:0;
  overflow:hidden;
  padding:0!important;
  border-radius:22px!important;
}

.sidebar-scroll{
  height:100%;
  min-height:0;
  overflow:auto;
  padding:14px;
  scrollbar-width:thin;
}

.sidebar-section + .sidebar-section{margin-top:12px}

.sidebar-section h2{
  margin:0 0 8px;
  font-size:15px;
}

.sidebar-title-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  margin-bottom:8px;
}

.sidebar-title-row h2{margin:0}

.sidebar-close{
  display:none;
  width:34px;
  height:34px;
  border:1px solid var(--theme-line,#aa6c16);
  border-radius:10px;
  font-size:16px;
  cursor:pointer;
  color:var(--theme-text,#10213d);
  background:linear-gradient(180deg,var(--theme-control,#f2dfad),var(--theme-control-2,#dfbd72));
}

.stats-stack{
  display:grid;
  grid-template-columns:repeat(3,minmax(0,1fr));
  gap:8px;
}

.control-stack{display:grid;gap:8px}

.mini-stat,
.selectbox,
.action-btn,
.hint-card{width:100%}

.mini-stat{
  display:grid;
  grid-template-columns:1fr;
  justify-items:center;
  align-content:center;
  gap:3px;
  min-height:78px;
  padding:8px 5px;
  border-radius:15px;
  text-align:center;
}

.mini-stat span{font-size:18px;line-height:1}
.mini-stat strong{font-size:22px;line-height:1;min-width:0}
.mini-stat em{font-style:normal;font-size:10px;line-height:1.15;margin:0}


.sidebar-select{
  display:grid;
  grid-template-columns:88px minmax(0,1fr);
  align-items:center;
  gap:8px;
  min-height:54px;
  padding:8px 10px;
  border-radius:14px;
}

.sidebar-select span{font-size:12px;font-weight:800}

.sidebar-select select,
.sidebar-select input[type="search"]{
  width:100%;
  min-width:0;
  min-height:36px;
  padding:5px 30px 5px 10px!important;
  border:1px solid var(--theme-line,#aa6c16);
  border-radius:10px!important;
  color:var(--theme-text,#10213d);
  background:var(--theme-control-2,#dfbd72);
  font:700 12px/1.2 system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;
  outline:none;
}
.sidebar-select input[type="search"]{padding-right:10px!important;text-transform:uppercase}
.sidebar-select input[type="search"]::placeholder{color:var(--theme-muted,#65513a);opacity:.72;text-transform:none}
.sidebar-select input[type="search"]:focus,
.sidebar-select select:focus{box-shadow:0 0 0 3px color-mix(in srgb,var(--theme-accent,#075fbf) 22%,transparent);border-color:var(--theme-accent,#075fbf)}

.action-buttons{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:8px;
}
.action-buttons-simple{grid-template-columns:1fr 1fr}
.action-buttons .full-span{grid-column:1 / -1}

.action-btn{
  min-height:42px;
  border:1px solid var(--theme-accent-2,#0d4b8e);
  border-radius:13px;
  cursor:pointer;
  color:var(--theme-button-text,#fff);
  background:linear-gradient(180deg,var(--theme-button,#175fab),var(--theme-button-hover,#0d4b8e));
  box-shadow:0 8px 18px rgba(0,0,0,.14);
  font:800 12px/1.15 system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;
  transition:transform .15s ease,filter .15s ease;
}

.action-btn:hover,.sidebar-close:hover,.floating-btn:hover{
  transform:translateY(-1px);
  filter:brightness(1.05);
}

.action-btn.secondary{
  color:var(--theme-text,#10213d);
  background:linear-gradient(180deg,var(--theme-control,#f2dfad),var(--theme-control-2,#dfbd72));
  border-color:var(--theme-line,#aa6c16);
}
.action-btn:disabled{opacity:.58;cursor:default;box-shadow:none;transform:none!important;filter:none!important}

.hint-card{
  margin-top:8px;
  padding:9px 10px;
  border-radius:14px;
  border:1px dashed rgba(255,255,255,.18);
  background:rgba(255,255,255,.06);
}

.hint-card strong{display:block;margin-bottom:3px;font-size:12px}
.hint-card p{margin:0;font-size:11px;line-height:1.35}


.sidebar-backdrop{
  display:none;
}

.map-stage{
  position:relative;
  min-width:0;
  min-height:0;
  overflow:hidden;
  border-radius:24px;
  box-shadow:0 18px 46px rgba(0,0,0,.22);
}

#map{height:100%;min-height:0;width:100%}

.map-overlay{
  position:absolute;
  z-index:800;
  padding:10px 12px!important;
  border-radius:15px!important;
  backdrop-filter:blur(8px);
}

.map-overlay-top{top:14px;left:58px;min-width:170px;max-width:min(520px,calc(100% - 140px));display:none}
.map-overlay-top.is-visible{display:block}
.map-overlay-top .overlay-value{overflow-wrap:anywhere}
.map-overlay-bottom{left:14px;bottom:14px}

.overlay-caption{
  font-size:10px;
  font-weight:800;
  text-transform:uppercase;
  letter-spacing:.1em;
  opacity:.8;
}

.overlay-row + .overlay-row{margin-top:8px;padding-top:8px;border-top:1px solid rgba(255,255,255,.22)}
.overlay-value{margin-top:4px;font-size:14px;font-weight:900}
.overlay-value-small{font-size:13px}

.legend-row{display:flex;align-items:center;gap:12px;flex-wrap:wrap}
.band-legend-items{display:inline-flex;align-items:center;gap:8px;flex-wrap:wrap}
.legend-item{display:inline-flex;align-items:center;gap:7px;font-size:12px;font-weight:700}
.legend-btn{appearance:none;border:1px solid transparent;background:transparent;border-radius:999px;padding:4px 8px;cursor:pointer;color:inherit;font:inherit;display:inline-flex;align-items:center;gap:7px;line-height:1}
.legend-btn:hover{background:rgba(255,255,255,.18)}
.legend-btn.is-active{background:rgba(255,255,255,.26);border-color:rgba(0,0,0,.16);box-shadow:inset 0 0 0 1px rgba(255,255,255,.12)}
.legend-dot,.legend-line{display:inline-block;flex:0 0 auto}
.legend-dot{width:11px;height:11px;border-radius:50%;background:#36a9ff;border:2px solid #0b74d1}
.legend-line{width:20px;height:0;border-top:3px solid #3fa9ff;border-radius:99px}

.floating-tools{
  position:absolute;
  right:14px;
  top:14px;
  z-index:850;
  display:grid;
  gap:8px;
}

.map-inline-btn{
  position:absolute;
  top:14px;
  right:70px;
  z-index:845;
  min-height:36px;
  padding:8px 12px;
  border:1px solid var(--theme-line,#aa6c16);
  border-radius:999px;
  color:var(--theme-text,#10213d);
  background:linear-gradient(180deg,var(--theme-control,#f2dfad),var(--theme-control-2,#dfbd72));
  box-shadow:0 10px 22px rgba(0,0,0,.18);
  font:800 12px/1 system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;
  cursor:pointer;
}
.map-inline-btn:hover{filter:brightness(1.04)}
.map-inline-btn[hidden]{display:none!important}

.floating-btn{
  width:44px;
  height:44px;
  border:1px solid var(--theme-accent-2,#0d4b8e);
  border-radius:13px;
  cursor:pointer;
  color:var(--theme-button-text,#fff);
  background:linear-gradient(180deg,var(--theme-button,#175fab),var(--theme-button-hover,#0d4b8e));
  font-size:19px;
  font-weight:900;
  box-shadow:0 10px 22px rgba(0,0,0,.20);
}

#sidebarToggle{display:none}

.notice{
  position:fixed;
  right:18px;
  bottom:18px;
  max-width:min(520px,calc(100vw - 36px));
  z-index:1200;
}

.leaflet-control-attribution{font-size:10px}
.leaflet-popup-content{font-size:14px;line-height:1.4}
.popup-title{margin-bottom:7px;font-size:15px;font-weight:900}
.popup-grid{display:grid;grid-template-columns:auto minmax(160px,1fr);gap:4px 9px}
.popup-grid b{white-space:nowrap}


.filter-input-wrap output{display:none}
.map-stage.line-focus .map-overlay-bottom{max-width:calc(100% - 160px)}

@media (max-width:1100px){
  .map-layout{grid-template-columns:290px minmax(0,1fr)}
  .topbar h1{font-size:23px}
  .lang-switch a{min-width:31px;padding:0 6px}
}

@media (max-width:920px){
  .sidebar-backdrop{
    display:block;
    position:fixed;
    inset:0;
    z-index:1150;
    border:0;
    padding:0;
    background:rgba(8,20,38,.38);
    opacity:0;
    pointer-events:none;
    transition:opacity .2s ease;
  }

  body.sidebar-open .sidebar-backdrop{
    opacity:1;
    pointer-events:auto;
  }
  .map-layout{grid-template-columns:1fr;padding:0 14px 14px}

  .map-sidebar{
    position:fixed;
    top:92px;
    left:14px;
    bottom:14px;
    width:min(330px,calc(100vw - 28px));
    z-index:1200;
    transform:translateX(calc(-100% - 20px));
    transition:transform .22s ease;
  }

  body.sidebar-open .map-sidebar{transform:translateX(0)}
  .sidebar-close{display:inline-flex;align-items:center;justify-content:center}
  #sidebarToggle{display:block}

  .map-overlay-top{top:14px;left:58px;right:70px;min-width:0}
  .map-overlay-bottom{left:14px;bottom:14px;right:14px;width:max-content;max-width:calc(100% - 28px)}
  .map-inline-btn{right:70px;left:14px;top:14px;min-height:34px;padding:7px 10px;max-width:calc(100% - 84px);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
}

@media (max-width:700px){
  body{grid-template-rows:auto minmax(0,1fr)}
  .map-topbar{align-items:flex-start;flex-direction:column;gap:10px;padding:10px 14px}
  .topbar h1{font-size:21px}
  .topbar p{font-size:12px}
  .header-actions,.top-control-row{width:100%}
  .top-control-row{justify-content:flex-start;flex-wrap:wrap}
  .lang-switch{flex-wrap:wrap}
  .lang-switch a{height:30px}
  .map-sidebar{top:126px}
  .stats-stack{grid-template-columns:repeat(3,minmax(0,1fr))}
  .sidebar-select{grid-template-columns:1fr;gap:5px}
  .action-buttons{grid-template-columns:1fr}
}

.point-selected{
  filter:drop-shadow(0 0 6px rgba(255,214,102,.9));
}

/* Selected-line detail: hover keeps the Leaflet popup, click opens this stable card. */
.line-detail-card{
  position:absolute;
  z-index:840;
  top:66px;
  right:14px;
  width:min(380px,calc(100% - 110px));
  max-height:calc(100% - 150px);
  overflow:auto;
  padding:16px 18px!important;
  border-radius:18px!important;
  box-shadow:0 18px 40px rgba(0,0,0,.24)!important;
}
.line-detail-card[hidden]{display:none!important}
.line-detail-close{
  position:absolute;
  top:9px;
  right:10px;
  width:32px;
  height:32px;
  border:0;
  border-radius:10px;
  color:var(--theme-text,#10213d);
  background:transparent;
  font-size:17px;
  font-weight:900;
  cursor:pointer;
}
.line-detail-close:hover{background:rgba(0,0,0,.07)}
.line-detail-title{
  margin:0 34px 12px 0;
  font-size:19px;
  line-height:1.2;
  font-weight:900;
}
.line-detail-grid{
  display:grid;
  grid-template-columns:max-content minmax(0,1fr);
  gap:8px 14px;
  align-items:start;
  font-size:14px;
  line-height:1.35;
}
.line-detail-grid b{white-space:nowrap}
.line-detail-grid span{min-width:0;overflow-wrap:anywhere}
.line-detail-band{
  display:inline-flex;
  align-items:center;
  gap:8px;
  font-weight:900;
}
.line-detail-band::before{
  content:"";
  width:26px;
  border-top:4px solid var(--line-detail-color,#64748b);
  border-radius:99px;
}

@media (max-height:760px) and (min-width:921px){
  .line-detail-card{
    top:58px;
    width:min(350px,calc(100% - 100px));
    max-height:calc(100% - 124px);
    padding:13px 15px!important;
  }
  .line-detail-title{font-size:17px;margin-bottom:9px}
  .line-detail-grid{font-size:13px;gap:6px 11px}
}

@media (max-width:920px){
  .line-detail-card{
    top:auto;
    left:14px;
    right:14px;
    bottom:66px;
    width:auto;
    max-height:45%;
  }
  .map-inline-btn{top:14px}
}

.r2r-ref-label.leaflet-tooltip{
  background:rgba(242,223,173,.96);
  border:1px solid var(--theme-line,#aa6c16);
  color:var(--theme-text,#10213d);
  border-radius:10px;
  box-shadow:0 6px 14px rgba(0,0,0,.16);
  padding:4px 8px;
  font:800 12px/1.2 system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;
}
.r2r-ref-label.leaflet-tooltip-top:before{
  border-top-color:var(--theme-line,#aa6c16);
}

.line-detail-distance{font-weight:900}
.r2r-distance-marker{
  background:transparent!important;
  border:0!important;
}
.r2r-distance-marker span{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:92px;
  min-height:28px;
  padding:5px 10px;
  border:1px solid var(--theme-line,#aa6c16);
  border-radius:999px;
  color:var(--theme-text,#10213d);
  background:rgba(242,223,173,.96);
  box-shadow:0 7px 18px rgba(0,0,0,.2);
  white-space:nowrap;
  font:900 12px/1 system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;
}
