/* AFDES Election Engine — final responsive integrity layer.
   Presentation only. Keeps the approved wide-desktop composition, then
   deliberately reflows at laptop/tablet/phone widths instead of clipping. */

html,body{max-width:100%;overflow-x:hidden}
.engine-shell,.workspace,.map-card,.map-toolbar,.map-toolbar-main,.map-controls-inline,.election-view-bar,.afdes-rb,.map-stage,.map-legend,.results-card{min-width:0;max-width:100%}

/* Election View: cycle selector occupies exactly one election-button share. */
@media(min-width:761px){
  .election-view-bar{
    display:grid!important;
    grid-template-columns:auto minmax(92px,1fr) minmax(0,5fr)!important;
    align-items:center!important;
    gap:7px!important;
  }
  .election-cycle-select{
    width:100%!important;
    min-width:0!important;
    max-width:none!important;
    height:32px!important;
    min-height:32px!important;
    box-sizing:border-box!important;
    border:1px solid #cfd9e1!important;
    border-radius:6px!important;
    background:#fff!important;
    color:#526273!important;
    font-size:.64rem!important;
    font-weight:800!important;
    cursor:pointer!important;
    transition:border-color .16s ease,background .16s ease!important;
  }
  .election-cycle-select:hover,
  .election-cycle-select:focus-visible{
    border-color:#9fb4c2!important;
    background:#f8fafb!important;
    outline:none!important;
  }
  .election-type-buttons{
    display:grid!important;
    grid-template-columns:repeat(5,minmax(0,1fr))!important;
    gap:5px!important;
    min-width:0!important;
  }
  .election-type-button{
    width:100%!important;
    min-width:0!important;
    height:29px!important;
    padding-inline:7px!important;
    white-space:nowrap!important;
    overflow:hidden!important;
    text-overflow:ellipsis!important;
  }
}

/* Cleaner state-selector chevron — no text glyph. */
.state-select-trigger{padding-right:34px!important}
.state-select-trigger::after{
  content:''!important;
  position:absolute!important;
  right:13px!important;
  top:50%!important;
  width:7px!important;
  height:7px!important;
  border-right:1.5px solid #536273!important;
  border-bottom:1.5px solid #536273!important;
  transform:translateY(-68%) rotate(45deg)!important;
  transform-origin:center!important;
  font-size:0!important;
}
.state-select-trigger[aria-expanded="true"]::after{transform:translateY(-25%) rotate(225deg)!important}

/* Desktop/laptop: preserve one horizontal Census Geography composition. */
@media(min-width:961px){
  .map-toolbar-main{
    display:flex!important;
    flex-direction:row!important;
    flex-wrap:nowrap!important;
    align-items:flex-end!important;
    gap:18px!important;
    width:100%!important;
  }
  .map-back-button{flex:0 0 auto!important}
  .map-title-wrap{
    flex:0 1 430px!important;
    width:auto!important;
    min-width:280px!important;
    max-width:430px!important;
    margin:0!important;
    padding:0!important;
  }
  .map-back-button:not([hidden]) + .map-title-wrap{
    margin-left:18px!important;
  }
  .map-controls-inline{
    display:flex!important;
    flex:0 0 auto!important;
    flex-direction:row!important;
    flex-wrap:nowrap!important;
    align-items:flex-end!important;
    justify-content:flex-end!important;
    gap:8px!important;
    width:auto!important;
    min-width:0!important;
    margin-left:auto!important;
  }
  .geography-layer-switch{
    display:grid!important;
    grid-template-columns:155px 165px!important;
    gap:8px!important;
    flex:0 0 auto!important;
  }
  .toolbar-state-jump{
    flex:0 0 250px!important;
    width:250px!important;
    min-width:250px!important;
  }
  .map-layer-hint{
    width:max-content!important;
    max-width:min(590px,100%)!important;
    margin:3px 0 0 auto!important;
    padding-left:0!important;
    text-align:right!important;
  }
}

/* Narrow tablet only: controlled two-row fallback instead of clipping. */
@media(min-width:761px) and (max-width:960px){
  .map-toolbar{padding:8px 0 7px!important}
  .map-toolbar-main{
    display:grid!important;
    grid-template-columns:minmax(0,1fr) auto!important;
    align-items:end!important;
    gap:10px 18px!important;
  }
  .map-back-button{grid-column:1;grid-row:1;justify-self:start!important}
  .map-title-wrap{
    grid-column:1 / -1!important;
    grid-row:1!important;
    width:100%!important;
    min-width:0!important;
    max-width:none!important;
    padding-right:110px!important;
  }
  .map-back-button:not([hidden]) + .map-title-wrap{padding-left:166px!important}
  .map-controls-inline{
    grid-column:1 / -1!important;
    grid-row:2!important;
    width:100%!important;
    display:flex!important;
    justify-content:flex-end!important;
    align-items:flex-end!important;
    flex-wrap:nowrap!important;
    margin-left:0!important;
  }
  .map-layer-hint{margin:3px 0 0 auto!important;text-align:right!important;max-width:620px!important}
  .toolbar-state-jump{flex:0 1 235px!important;min-width:205px!important;width:auto!important}
  .geography-layer-switch{flex:0 1 auto!important;grid-template-columns:minmax(140px,1fr) minmax(150px,1fr)!important}
}

/* Tablet / phone composition: no sticky overlays, no clipping, touch-safe controls. */
@media(max-width:760px){
  body{padding:0!important;background:#fff!important}
  .engine-shell{width:100%!important}
  .system-strip,.stats{margin-left:0!important;margin-right:0!important}
  .workspace{padding:0!important;gap:10px!important}
  .map-toolbar{position:relative!important;top:auto!important;box-shadow:none!important;padding:10px 0 8px!important}
  .map-toolbar-main{display:grid!important;grid-template-columns:1fr!important;gap:9px!important}
  .map-back-button{justify-self:start!important;min-height:40px!important}
  .map-title-wrap{width:100%!important;min-width:0!important;max-width:none!important;padding:0!important}
  .map-title-line{display:flex!important;flex-wrap:wrap!important;align-items:center!important;gap:6px!important}
  .map-title-wrap>#map-subtitle{white-space:normal!important;overflow:visible!important;text-overflow:clip!important;line-height:1.35!important}
  .map-controls-inline{display:grid!important;grid-template-columns:1fr!important;width:100%!important;gap:8px!important}
  .geography-layer-switch{display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr))!important;width:100%!important;gap:6px!important}
  .result-geography-indicator.geography-choice{width:100%!important;min-width:0!important;min-height:44px!important}
  .toolbar-state-jump{width:100%!important;min-width:0!important;flex-basis:auto!important}
  .state-select-trigger{min-height:44px!important;font-size:.72rem!important}
  .state-select-menu{left:0!important;right:auto!important;width:min(100%,320px)!important;max-width:100%!important;max-height:230px!important}
  .map-layer-hint{display:block!important;padding:0!important;margin:3px 0 0!important;text-align:left!important;line-height:1.25!important}

  .election-view-bar{
    display:grid!important;
    grid-template-columns:minmax(88px,108px) minmax(0,1fr)!important;
    gap:6px!important;
    align-items:center!important;
  }
  .election-view-heading{min-width:0!important}
  .election-cycle-select{width:100%!important;min-width:0!important;height:36px!important}
  .election-type-buttons{display:none!important}
  .election-type-mobile{display:block!important;width:100%!important;min-width:0!important;height:36px!important;grid-column:2!important}

  .afdes-rb{width:calc(100% - 8px)!important;max-width:100%!important;margin:10px auto 14px!important}
  .map-stage{width:100%!important;min-height:0!important;height:clamp(300px,72vw,440px)!important;margin:18px 0 24px!important;overflow:hidden!important}
  .map-card:has(#back-us[hidden]) .map-stage{min-height:0!important;height:clamp(300px,72vw,440px)!important}
  #map-svg{max-width:100%!important}

  .map-legend{display:flex!important;flex-wrap:wrap!important;align-items:center!important;gap:8px 11px!important;padding:10px 0!important}
  .map-legend>span,.map-legend>.map-share{min-width:0!important}
  .results-source-status{max-width:100%!important;white-space:normal!important}

  .results-card{grid-template-columns:1fr!important;padding-top:15px!important}
  .results-card>*{grid-column:1!important;grid-row:auto!important;min-width:0!important}
  .results-card>.results-meta{grid-template-columns:repeat(2,minmax(0,1fr))!important}
  .results-unit-control select{width:100%!important;min-width:0!important}
}

@media(max-width:520px){
  .system-strip,.stats{grid-template-columns:1fr 1fr!important}
  .system-strip>div,.stats article{min-width:0!important}
  .system-strip strong,.stats span{overflow-wrap:anywhere!important}
  .map-title-wrap .map-title-line strong{font-size:1.08rem!important}
  .map-level-badge{font-size:.49rem!important}
  .result-geography-indicator.geography-choice>span:last-child{display:none!important}
  .election-view-bar{grid-template-columns:1fr 1fr!important}
  .election-view-heading{grid-column:1 / -1!important}
  .election-cycle-select,.election-type-mobile{height:40px!important}
  .afdes-rb{grid-template-columns:42px minmax(0,1fr) 42px!important;gap:6px!important}
  .map-stage,.map-card:has(#back-us[hidden]) .map-stage{height:clamp(275px,78vw,370px)!important;margin:16px 0 22px!important}
  .results-card>.results-meta{grid-template-columns:1fr 1fr!important}
  .engine-footer{display:grid!important;grid-template-columns:1fr!important;gap:4px!important}
}

@media(max-width:390px){
  .system-strip,.stats{grid-template-columns:1fr!important}
  .geography-layer-switch{grid-template-columns:1fr!important}
  .map-stage,.map-card:has(#back-us[hidden]) .map-stage{height:clamp(250px,84vw,330px)!important}
  .map-legend{gap:7px 9px!important;font-size:.61rem!important}
  .results-card>.results-meta{grid-template-columns:1fr!important}
  .result-candidate{grid-template-columns:1fr!important}
}

/* Secondary sharing utility: intentionally visually quiet. */
.map-share{position:relative;margin-left:auto;display:inline-flex;align-items:center;flex:0 0 auto}
.map-share-trigger{display:inline-flex;align-items:center;gap:6px;min-height:32px;padding:0 10px;border:1px solid #cfd9e1;border-radius:6px;background:#fff;color:#526273;font-size:.64rem;font-weight:800;cursor:pointer}
.map-share-trigger:hover,.map-share-trigger:focus-visible{border-color:#9fb4c2;background:#f8fafb;outline:none}
.map-share-trigger svg{width:13px;height:13px;display:block;fill:none;stroke:currentColor;stroke-width:1.8}
.map-share-menu{position:absolute;right:0;bottom:calc(100% + 7px);z-index:50;width:210px;padding:6px;background:#fff;border:1px solid #d5dde5;border-radius:8px;box-shadow:0 12px 28px rgba(7,24,39,.14)}
.map-share-menu[hidden]{display:none!important}
.map-share-menu button,.map-share-menu a{display:flex;width:100%;align-items:center;min-height:36px;padding:0 9px;border:0;border-radius:5px;background:transparent;color:#1d3042;text-decoration:none;font-size:.7rem;font-weight:700;text-align:left;cursor:pointer}
.map-share-menu button:hover,.map-share-menu button:focus-visible,.map-share-menu a:hover,.map-share-menu a:focus-visible{background:#eef5f9;outline:none}
.map-share-feedback{display:block;padding:4px 9px 2px;color:#667786;font-size:.58rem;font-weight:700}
@media(max-width:760px){.map-share{margin-left:0}.map-share-trigger{min-height:36px}.map-share-menu{left:0;right:auto;bottom:calc(100% + 6px);width:min(230px,88vw)}}
