/* The analytical workspace shares one ink, surface and separator palette.
   The login, administration dialogs and client data retain their own styling. */
#app {
  --atlas-ink: #143649;
  --atlas-secondary: #466170;
  --atlas-teal: #007c84;
  --atlas-line: #d3e0e4;
  --atlas-paper: #f3f6f7;
  background: var(--atlas-paper);
  min-height: 100vh;
}
#app > .app-header {
  height: 66px;
  gap: 20px;
  padding-inline: clamp(16px,2.4vw,48px);
  background: #fff;
  border-top: 0;
  border-bottom: 1px solid var(--atlas-line);
}
.app-header .brand-logo { width: 169px; height: 48px; }
.app-header .brand-logo img { width: 169px; transform: translateY(-39px); }
.app-header .header-section {
  padding-left: 20px; border-left: 1px solid var(--atlas-line);
  color: var(--atlas-secondary); font-size: .88rem; font-weight: 550;
}
.app-header .demo-label { color: #356372; border: 0; background: #edf4f5; border-radius: 12px; }
.app-header #user-role { color: var(--atlas-secondary); font-size: .84rem; }
#app > main { padding: clamp(17px,2vw,30px) clamp(16px,2.4vw,48px) 18px; max-width: 1960px; }
#analysis-panel { color: var(--atlas-ink); }
.territory-heading { align-items: center; gap: 16px; }
.territory-heading .eyebrow {
  display: inline-flex; align-items: center; gap: 8px; color: #20717b;
  font-size: .68rem; font-weight: 750; letter-spacing: .13em; margin: 0 0 6px;
}
.territory-heading .eyebrow::before { content: ''; width: 20px; height: 2px; background: #16828a; }
.territory-heading #page-title {
  margin: 0; color: var(--atlas-ink); letter-spacing: -.04em; font-weight: 700;
  line-height: 1.07; font-size: clamp(1.72rem,2.3vw,2.55rem);
}
.territory-context { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-top: 8px; }
.territory-context #zone-name,.territory-context #client-sector { margin: 0; }
.territory-context #zone-name { color: #335768; font-weight: 650; font-size: .89rem; gap: 0; }
.territory-context #zone-name::before { display: none; }
.territory-context #client-sector { color: #536978; font-size: .8rem; }
.territory-context #client-sector:not(:empty) { padding-left: 12px; border-left: 1px solid #adbec6; }
.territory-heading .source-actions { align-items: flex-end; justify-content: center; flex-direction: column; gap: 5px; }
.territory-heading #source-date { color: #516a79; font-size: .8rem; font-variant-numeric: tabular-nums; }
#analysis-panel .admin-client-context { margin-top: 12px; padding: 9px 14px; background: #eaf0f2; border: 0; border-radius: 7px; }
#analysis-panel .admin-client-context label { font-size: .78rem; }
#analysis-panel .admin-client-context .admin-note { margin: 0; align-self: center; }
#analysis-panel .data-message:not([hidden]) { margin-block: 10px; }

.territory-indicators.kpi-strip {
  display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: clamp(8px,1vw,17px);
  border: 0; margin: 18px 0 13px; padding: 0;
}
.territory-indicators .kpi {
  --visual-width: min(29%,104px);
  display: grid; grid-template-rows: auto 1fr auto; align-items: center;
  gap: 5px; position: relative; min-width: 0; min-height: 111px; margin: 0; overflow: hidden;
  padding: 13px clamp(13px,1.2vw,22px) 12px;
  border: 1px solid var(--atlas-line); border-radius: 10px;
  color: var(--atlas-ink); background: #fff; box-shadow: 0 2px 6px #173a4a05;
}
.territory-indicators .kpi > span {
  color: #344f60; font-weight: 650; font-size: clamp(.81rem,.93vw,.96rem); line-height: 1.22;
  padding-right: calc(var(--visual-width) + 2px); z-index: 1;
}
.territory-indicators .kpi strong {
  align-self: center; font-size: clamp(1.8rem,2.45vw,2.65rem); line-height: 1;
  letter-spacing: -.055em; font-variant-numeric: tabular-nums; font-weight: 685;
  color: var(--atlas-ink); padding-right: var(--visual-width); z-index: 1;
}
.territory-indicators .kpi small {
  font-size: clamp(.71rem,.78vw,.81rem); line-height: 1.3;
  color: #506675; z-index: 1; align-self: end;
}
.territory-indicators .kpi-geography {
  background: linear-gradient(110deg,#133747 25%,#164d59);
  border-color: #174755; color: #fff;
}
.territory-indicators .kpi-geography > span { color: #d4efeb; }
.territory-indicators .kpi-geography strong { color: white; }
.territory-indicators .kpi-geography small { color: #bfdddf; }
.territory-indicators .kpi-highlight { border-color: #bad6d3; background: #f9fcfb; }
.territory-indicators .kpi-highlight strong { color: #096f72; }
.kpi-visual { position: absolute; width: var(--visual-width); top: 45%; right: 12px; transform: translateY(-50%); }
.kpi-visual svg { display: block; width: 100%; max-height: 64px; }
.kpi-geography .kpi-visual { width: min(34%,135px); }
.kpi-chart-text { fill: #20515a; font-size: 13px; font-weight: 700; }
.kpi-axis { fill: #526977; font-size: 9px; font-weight: 600; }

.territory-filters {
  background: #fff; border: 1px solid var(--atlas-line); border-radius: 10px;
  margin-bottom: 16px;
}
.territory-filters > summary {
  display: flex; align-items: center; gap: 8px; padding: 11px 15px;
  list-style: none; cursor: pointer; font-size: .85rem;
}
.territory-filters > summary::-webkit-details-marker { display:none; }
.territory-filters > summary::after {
  content: ''; margin-left: auto; width: 7px; height: 7px; border: solid #47616b; border-width: 0 1.7px 1.7px 0;
  transform: rotate(45deg);
}
.territory-filters[open] > summary::after { transform: rotate(225deg); }
.territory-filters > summary svg { width: 17px; height: 17px; stroke: var(--atlas-teal); stroke-width: 1.7; fill: none; }
.territory-filters #active-filter-count { font-size: .77rem; color: var(--atlas-teal); font-weight: 600; }
.territory-filters .filters { padding: 0 14px 12px; margin: 0; gap: 12px; }
.territory-filters .filters label { gap: 4px; }
.territory-filters .filters label > span { color: #415e6c; font-size: .76rem; font-weight: 650; }
.territory-filters .filters :is(select,input) {
  min-height: 38px; height: 38px; border: 1px solid #cbd9df; border-radius: 6px;
  color: #173c4d; background-color: #f9fbfc; font-size: .88rem; padding-block: 5px;
}
.territory-filters .filters input[type=search] {
  padding-left: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%23516d7a' stroke-width='1.7'%3E%3Ccircle cx='8' cy='8' r='5'/%3E%3Cpath d='m12 12 5 5'/%3E%3C/svg%3E");
  background-repeat:no-repeat; background-size: 15px; background-position: 11px center;
}
.territory-filters .filters select {
  appearance: none; padding-right: 27px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%234B6572' stroke-width='1.6'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat:no-repeat; background-size: 15px; background-position: right 8px center;
}
.territory-filters .filters > .text-button { color: #156e77; min-height: 38px; font-size: .83rem; }
#map-workspace > :is(.map-panel,.list-panel,.map-tool-panel) { border-color: var(--atlas-line); border-radius: 11px; box-shadow: 0 3px 12px #163c4a09; }
#map-workspace .panel-heading { background: #fff; min-height: 49px; padding: 9px 16px; }
#map-workspace .panel-heading h2 { color: var(--atlas-ink); font-size: 1.04rem; letter-spacing: -.018em; font-weight: 670; }
#map-workspace #fit-map { min-height: 30px; border: 1px solid var(--atlas-line); border-radius: 6px; padding: 4px 10px; font-size: .8rem; color: #205967; }
#map-workspace .map-footer { padding: 10px 15px; min-height: 0; gap: 5px; }
#map-workspace .list-columns { background: #eff4f5; color: #506775; }
#map-workspace .location-name { color: #163849; }
#map-workspace .location-entry:hover { background:#f6fafb; }
#map-workspace .location-row.selected { box-shadow: inset 3px 0 #087e83; }
#map-workspace .location-score .band-label { background: #f4f7f8; }
#map-workspace .leaflet-control-zoom a,#detail-environment-map .leaflet-control-zoom a { color: #254c59; }
/* Only the tiles take a neutral tint. Symbols, data layers, attribution and
   municipal-layer contrast rules stay independent of the basemap. */
:root:not([data-basemap=original]) :is(#map,#detail-environment-map):not(.madrid-context-active):not(.footfall-map-active) .leaflet-tile-pane {
  filter: saturate(.24) contrast(.85) brightness(1.1);
}
.basemap-style { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; padding: 0; border: 0; }
.basemap-style legend { font-weight: 650; color: #3a5666; font-size: .82rem; padding: 0 0 7px; }
.basemap-style label { display: flex; align-items: center; gap: 6px; border-radius: 6px; border: 1px solid #cad7db; padding: 5px 8px; cursor: pointer; font-size: .81rem; }
.basemap-style label:has(input:checked) { color: #006973; background: #e8f4f3; border-color: #4a9d9f; }
.basemap-style input { width: 14px; height: 14px; margin: 0; accent-color: #0c7980; }
.basemap-style :is(.swatch-atlas,.swatch-original) { display:none; }
@media(min-width: 851px) {
  #map-workspace { grid-template-columns: minmax(0,1.95fr) minmax(310px,.95fr); gap: 16px; }
  #map-workspace.has-tool { grid-template-columns: minmax(0,1.6fr) minmax(350px,1fr); }
  #map-workspace #map { height: clamp(450px,58vh,690px); }
  #map-workspace .location-list { height: clamp(413px,calc(58vh - 37px),653px); }
}
@media(min-width: 1120px) {
  .territory-filters { position: relative; }
  .territory-filters[open] > summary { position: absolute; top: 0; bottom: 0; left: 0; width: 46px; justify-content: center; padding: 0; border-right: 1px solid #e4ebed; }
  .territory-filters[open] > summary::after { display:none; }
  .territory-filters[open] > summary strong, .territory-filters[open] > summary span { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; }
  .territory-filters[open] .filters { padding: 10px 14px 11px 60px; }
}
@media(max-width: 1100px) {
  .territory-indicators .kpi { --visual-width: 27%; min-height: 112px; }
  .kpi-visual { right: 8px; }
}
@media(max-width: 850px) {
  .territory-indicators.kpi-strip { grid-template-columns: 1fr 1fr; gap: 8px; }
  .territory-indicators .kpi { --visual-width: min(29%,75px); min-height: 91px; }
}
@media(max-width: 760px) {
  #app > .app-header { height: 52px; gap: 8px; }
  #app > main { padding: 16px 12px 12px; }
  .app-header .brand-logo { width: 137px; height: 40px; }
  .app-header .brand-logo img { width: 137px; transform: translateY(-31px); }
  .app-header .header-section { display: none; }
  .app-header .header-user { min-width: 0; gap: 5px; }
  .app-header #user-role { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; max-width:26vw; }
  .territory-heading { gap: 6px; flex-direction: column; align-items: flex-start; }
  .territory-heading .source-actions { align-items: center; flex-direction: row; width: auto; gap: 8px; }
  .territory-heading .source-actions:has(#source-date:empty):has(#change-file[hidden]) { display: none; }
  .territory-context { margin-top: 5px; gap: 4px 8px; }
  .territory-context #client-sector:not(:empty) { padding-left: 8px; }
  .territory-indicators.kpi-strip { margin: 11px 0 8px; }
  .territory-indicators .kpi { padding: 9px 10px 8px; min-height: 89px; gap: 3px; }
  .territory-indicators .kpi > span { font-size: .78rem; }
  .territory-indicators .kpi strong { font-size: 1.75rem; }
  .territory-indicators .kpi small { font-size: .7rem; }
  .territory-filters { margin-bottom: 10px; }
  .territory-filters .filters { gap: 9px; }
  #map-workspace .panel-heading { min-height: 45px; padding: 7px 10px; }
}
@media(max-width: 410px) {
  .kpi-visual { width: 38px; right: 7px; }
  .kpi-geography .kpi-visual { width: 43px; }
  .territory-indicators .kpi > span { padding-right: 29px; }
}
#outlet-picker {
  box-sizing: border-box; width: min(410px, calc(100vw - 28px)); max-width: none;
  padding: 20px; border: 1px solid #c5d8db; border-radius: 10px; color: #173c4b;
}
#outlet-picker::backdrop { background: rgb(17 48 61 / .30); }
#outlet-picker header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#outlet-picker h2 { margin: 0; font-size: 1.16rem; }
#outlet-picker p { margin: 8px 0 15px; color: #46616c; }
.outlet-choices { display: grid; gap: 8px; min-width: 0; }
.outlet-choices select { width: 100%; min-width: 0; text-overflow: ellipsis; }
.outlet-choices .popup-button { white-space: normal; overflow-wrap: anywhere; min-height: 36px; }
.poi-info .outlet-choices { margin-top: 8px; padding-top: 8px; border-top: 1px solid #cfdddf; }
#map .selection-popup .leaflet-popup-content { max-height: var(--popup-content-height); max-width: var(--popup-content-width); overflow-y: auto; overscroll-behavior: contain; }
#map .selection-popup-shifted .leaflet-popup-tip-container { visibility: hidden; }
