* { box-sizing: border-box; margin: 0; }
:root {
  --accent: #0a6cff;
  --bg: #f6f7f9;
  --card: #ffffff;
  --border: #e3e6ea;
  --text: #16181d;
  --muted: #6b7280;
}
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
       color: var(--text); background: var(--bg); height: 100vh; overflow: hidden; }
.hidden { display: none !important; }

/* Auth / paywall */
.auth-screen { position: fixed; inset: 0; display: flex; align-items: center;
               justify-content: center; background: var(--bg); z-index: 50; }
.auth-card { background: var(--card); border: 1px solid var(--border); border-radius: 16px;
             padding: 40px; width: 380px; text-align: center;
             box-shadow: 0 10px 40px rgba(0,0,0,.08); display: flex; flex-direction: column; gap: 12px; }
.auth-logo { font-size: 48px; }
.auth-card h1 { font-size: 28px; }
.tagline { color: var(--muted); font-size: 14px; line-height: 1.5; margin-bottom: 8px; }
.auth-card input { padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px;
                   font-size: 15px; background: var(--bg); }
.auth-error { color: #d33; font-size: 13px; }
.btn-primary { background: var(--accent); color: #fff; border: 0; padding: 12px;
               border-radius: 10px; font-size: 15px; font-weight: 600; cursor: pointer;
               text-decoration: none; display: block; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-link { background: none; border: 0; color: var(--accent); font-size: 13px; cursor: pointer; }

/* Layout */
#app { display: flex; flex-direction: column; height: 100vh; }
header { display: flex; align-items: center; gap: 12px; padding: 10px 16px;
         background: var(--card); border-bottom: 1px solid var(--border); position: relative; z-index: 20; }
.brand { font-size: 16px; white-space: nowrap; }
#search { width: 340px; padding: 9px 14px; border: 1px solid var(--border);
          border-radius: 10px; font-size: 14px; background: var(--bg); }
.search-results { position: absolute; top: 52px; left: 140px; width: 380px; background: var(--card);
                  border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
                  box-shadow: 0 8px 30px rgba(0,0,0,.12); }
.search-results .row { padding: 10px 14px; display: flex; gap: 10px; align-items: center;
                       cursor: pointer; font-size: 14px; }
.search-results .row:hover { background: var(--bg); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.row .layer { color: var(--muted); font-size: 12px; margin-left: auto; white-space: nowrap; }
.btn-chip { background: var(--bg); border: 1px solid var(--border); border-radius: 999px;
            padding: 8px 14px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.btn-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.trial-chip { font-size: 12px; color: var(--muted); background: var(--bg);
              border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; }
.spacer { flex: 1; }
.user-email { color: var(--muted); font-size: 13px; }
.header-search { position: relative; }
.header-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.brand { display: flex; align-items: center; gap: 6px; }
.brand-mark { font-size: 18px; line-height: 1; }
.account-menu { position: relative; }
.account-summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 10px; font-size: 13px; user-select: none;
}
.account-summary::-webkit-details-marker { display: none; }
.account-icon { font-size: 14px; line-height: 1; }
.account-dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 160px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.12); padding: 6px; z-index: 30;
}
.account-signout {
  width: 100%; text-align: left; border: 0; background: transparent;
  padding: 10px 12px; border-radius: 8px; font-size: 14px; cursor: pointer; color: var(--text);
}
.account-signout:hover { background: var(--bg); }

.body { display: flex; flex: 1; min-height: 0; }
#map { flex: 1; }

/* Layers panel */
.layers-toggle { display: none; }
.layers-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.layers-panel-head h3 { margin-bottom: 0; }
.layers-close {
  display: none; border: 0; background: var(--bg); color: var(--muted);
  width: 36px; height: 36px; border-radius: 10px; font-size: 20px; cursor: pointer; line-height: 1;
}
.layers-close:hover { background: var(--border); }
.layers-scrim {
  display: none; position: absolute; inset: 0; background: rgba(15,23,42,.35); z-index: 16; border: 0; padding: 0; cursor: pointer;
}
#layers-panel { width: 250px; background: var(--card); border-right: 1px solid var(--border);
                padding: 16px; overflow-y: auto; }
#layers-panel h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em;
                   color: var(--muted); margin-bottom: 10px; }
.layer-columns { display: flex; justify-content: flex-end; gap: 18px; padding: 0 4px 4px;
                 font-size: 11.5px; color: var(--muted); }
.layer-columns span { width: 44px; text-align: right; }
.layer-group { margin-bottom: 14px; }
.layer-group:not(:first-child) { padding-top: 10px; border-top: 1px solid var(--border); }
.layer-group-title-row { display: flex; justify-content: space-between; align-items: baseline;
                          padding: 6px 4px 6px; cursor: pointer; border-radius: 8px; }
.layer-group-title-row:hover { background: var(--bg); }
.layer-group-title { font-weight: 700; font-size: 14.5px; color: var(--text); }
.layer-group-caret { display: inline-block; margin-right: 5px; font-size: 11px; color: var(--muted);
                      transition: transform .15s ease; }
.layer-group-caret.collapsed { transform: rotate(-90deg); }
.layer-subtotal-nums { display: flex; gap: 18px; font-weight: 700; font-size: 14px; color: var(--text); }
.layer-subtotal-nums span { width: 44px; text-align: right; }
.layer-row { display: flex; align-items: flex-start; gap: 8px; padding: 6px 4px 6px 18px;
             font-size: 13.5px; cursor: pointer; border-radius: 8px; }
.layer-row:hover { background: var(--bg); }
.layer-row .dot { margin-top: 4px; }
.layer-row .count { margin-left: auto; color: var(--muted); font-size: 12px; }
.row-nums { margin-left: auto; display: flex; flex: none; gap: 10px; color: var(--muted); font-size: 12px; }
.row-nums span { width: 38px; text-align: right; }
.layer-coverage { padding: 0 4px 6px 36px; font-size: 11.5px; color: var(--muted); }
.layer-row.off { opacity: .38; }

/* Side panel */
#side-panel { width: 400px; background: var(--card); border-left: 1px solid var(--border);
              overflow-y: auto; position: relative; }
.panel-close { position: absolute; top: 10px; right: 12px; border: 0; background: var(--bg);
               width: 30px; height: 30px; border-radius: 50%; font-size: 16px; cursor: pointer; z-index: 2; }
#panel-content { padding: 18px; }
#panel-content h2 { font-size: 19px; margin-bottom: 4px; padding-right: 30px; }
.sub { color: var(--muted); font-size: 13px; margin-bottom: 12px; display: flex; align-items: center; gap: 7px; }
.hero { width: 100%; height: 190px; object-fit: cover; border-radius: 12px; margin-bottom: 14px;
        background: var(--bg); }
.hero.placeholder { display: flex; align-items: center; justify-content: center;
                    font-size: 40px; color: var(--border); }
.facts { border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
         margin-bottom: 14px; font-size: 14px; }
.facts .frow { display: flex; padding: 9px 13px; border-bottom: 1px solid var(--border); }
.facts .frow:last-child { border-bottom: 0; }
.facts .flabel { width: 110px; font-weight: 600; flex: none; }
.facts .fvalue { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: 1; min-width: 0; }
.facts .fvalue-text { overflow-wrap: anywhere; }
.fedit-btn { background: none; border: 0; cursor: pointer; color: var(--muted); font-size: 12px;
             padding: 0; opacity: 0; }
.frow:hover .fedit-btn { opacity: 1; }
.finput { font: inherit; font-size: 13px; padding: 4px 6px; border: 1px solid var(--border);
          border-radius: 6px; min-width: 0; flex: 1; }
.ferror { color: #c0392b; font-size: 12px; flex-basis: 100%; }
.ch-status-warn { color: #c0392b; font-weight: 600; }
.notes-box { background: var(--bg); border-radius: 12px; padding: 13px; font-size: 13.5px;
             line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.notes-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.notes-head h4 { font-size: 13px; }
.notes-box a { color: var(--accent); }
.notes-edit { width: 100%; min-height: 140px; border: 1px solid var(--border); border-radius: 10px;
              padding: 10px; font: inherit; font-size: 13.5px; margin-bottom: 8px; }
.muted { color: var(--muted); }

/* Comps table */
.comps-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.comps-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 8px;
                  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--card); }
.comps-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); }
.comps-table tr { cursor: pointer; }
.comps-table tbody tr:hover { background: var(--bg); }
.comps-note { font-size: 12px; color: var(--muted); margin: 10px 0; }
/* ==========================================================================
   Demand studio — HESA London HE analytics
   ========================================================================== */
#side-panel.demand-open {
  width: min(560px, 46vw);
  background: #f3efe7;
  border-left: 1px solid #e4ddd0;
}
#side-panel.demand-open #panel-content {
  padding: 22px 20px 28px;
  color: #141820;
}
#side-panel.demand-open .panel-close {
  background: #fffdf8;
  border: 1px solid #e4ddd0;
}

.demand-studio { display: flex; flex-direction: column; gap: 14px; }

.demand-eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #6f675c;
}
.demand-title {
  font-family: Georgia, "Times New Roman", Times, serif;
  font-size: 28px;
  font-weight: 600;
  color: #141820;
  margin: 0;
  padding-right: 30px;
  line-height: 1.15;
}
.demand-sub {
  font-size: 13px;
  color: #6f675c;
  margin: -6px 0 2px;
}

.demand-kpis {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 10px;
}
.demand-kpi {
  background: #fffdf8;
  border: 1px solid #e8e1d4;
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 1px 0 rgba(20, 24, 32, .03);
}
.demand-kpi.wide { grid-column: 1 / -1; }
.dk-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #6f675c;
  font-weight: 600;
}
.dk-value {
  font-size: 22px;
  font-weight: 650;
  margin-top: 4px;
  color: #141820;
  letter-spacing: -0.02em;
}
.demand-kpi.wide .dk-value { font-size: 28px; }
.dk-delta { font-size: 13px; font-weight: 600; margin-left: 6px; }
.dk-delta.up { color: #1f7a6c; }
.dk-delta.down { color: #c45c26; }
.dk-delta.flat { color: #6f675c; }
.dk-hint { font-size: 12px; color: #6f675c; margin-top: 2px; }

.demand-card {
  background: #fffdf8;
  border: 1px solid #e8e1d4;
  border-radius: 14px;
  padding: 14px 14px 12px;
  box-shadow: 0 1px 0 rgba(20, 24, 32, .03);
}
.demand-card h3 {
  font-size: 13px;
  font-weight: 650;
  color: #141820;
  margin: 0 0 10px;
  letter-spacing: -0.01em;
}
.demand-chart-wrap { position: relative; width: 100%; }
.demand-chart-wrap.line { height: 180px; }
.demand-chart-wrap.stack { height: 200px; }
.demand-chart-wrap.doughnut { height: 160px; max-width: 180px; margin: 0 auto; }

.demand-origin {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: 12px;
  align-items: center;
}
.demand-mix-bars { display: flex; flex-direction: column; gap: 10px; }
.demand-mix-row { display: flex; flex-direction: column; gap: 4px; }
.demand-mix-meta {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12px; color: #141820;
}
.demand-mix-meta .name { font-weight: 600; }
.demand-mix-meta .val { color: #6f675c; font-variant-numeric: tabular-nums; }
.demand-mix-track {
  height: 8px; border-radius: 999px; background: #efeae0; overflow: hidden;
}
.demand-mix-fill { height: 100%; border-radius: 999px; }
.demand-mix-fill.uk { background: #1f7a6c; }
.demand-mix-fill.eu { background: #3b6fd9; }
.demand-mix-fill.non-eu { background: #c45c26; }

.demand-legend {
  display: flex; flex-wrap: wrap; gap: 10px 14px;
  margin-top: 8px; font-size: 11.5px; color: #6f675c;
}
.demand-legend span { display: inline-flex; align-items: center; gap: 6px; }
.demand-swatch {
  width: 9px; height: 9px; border-radius: 2px; flex: none;
}
.demand-swatch.uk { background: #1f7a6c; }
.demand-swatch.eu { background: #3b6fd9; }
.demand-swatch.non-eu { background: #c45c26; }
.demand-swatch.total { background: #141820; }
.demand-swatch.non-uk { background: #8b6bb5; }

.demand-providers { display: flex; flex-direction: column; gap: 10px; }
.demand-prov {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  align-items: center;
}
.demand-prov-name {
  font-size: 12px; font-weight: 600; color: #141820;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.demand-prov-total {
  font-size: 11.5px; color: #6f675c; font-variant-numeric: tabular-nums;
}
.demand-prov-bar {
  grid-column: 1 / -1;
  display: flex; height: 10px; border-radius: 999px; overflow: hidden;
  background: #efeae0;
}
.demand-prov-seg { height: 100%; min-width: 0; }
.demand-prov-seg.uk { background: #1f7a6c; }
.demand-prov-seg.eu { background: #3b6fd9; }
.demand-prov-seg.non-eu { background: #c45c26; }

.demand-footnote {
  font-size: 11.5px;
  line-height: 1.45;
  color: #6f675c;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid #e4ddd0;
}
.demand-footnote ul {
  margin: 6px 0 0; padding-left: 16px;
}
.demand-footnote li { margin-bottom: 2px; }


.demand-pill {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  vertical-align: middle;
  color: #6f675c;
  background: #efeae0;
  border: 1px solid #e4ddd0;
}
.demand-accom-note {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: #6f675c;
}
.demand-accom-kpis { margin-top: 2px; }

.demand-spark {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 44px;
  margin-top: 12px;
  padding: 0 2px;
}
.demand-spark-bar {
  flex: 1;
  min-width: 0;
  background: #1f7a6c;
  opacity: .85;
  border-radius: 3px 3px 1px 1px;
}
.demand-spark-label {
  font-size: 11px;
  margin-top: 4px;
}



/* Map controls + dense-pin picker */
.maplibregl-ctrl-group button {
  width: 36px;
  height: 36px;
}
.pin-pick { display: flex; flex-direction: column; gap: 2px; min-width: 160px; }
.pin-pick-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); padding: 2px 4px 6px;
}
.pin-pick-row {
  display: flex; align-items: center; gap: 8px;
  border: 0; background: transparent; text-align: left;
  padding: 10px 6px; border-radius: 8px; cursor: pointer;
  font: inherit; font-size: 13px; min-height: 40px;
}
.pin-pick-row:hover, .pin-pick-row:active { background: var(--bg); }
.pin-pick-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pin-pick-popup .maplibregl-popup-content {
  padding: 10px 10px 8px; border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,.14);
}

/* ==========================================================================
   Mobile / phone web — Demand studio + chrome
   ========================================================================== */
@media (max-width: 820px) {
  .maplibregl-ctrl-bottom-right {
    margin: 0 10px 18px 0;
    margin-bottom: max(18px, env(safe-area-inset-bottom));
  }
  .maplibregl-ctrl-group button {
    width: 44px !important;
    height: 44px !important;
  }

  body { height: 100dvh; }
  #app { height: 100dvh; }

  .auth-card {
    width: min(380px, calc(100vw - 32px));
    padding: 28px 20px;
    margin: 16px;
  }

  header {
    flex-wrap: nowrap;
    gap: 8px;
    padding: 8px 10px;
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    padding-top: max(8px, env(safe-area-inset-top));
    align-items: center;
  }
  .brand-name { display: none; }
  .header-search { flex: 1 1 auto; min-width: 0; }
  #search {
    width: 100%;
    min-width: 0;
    font-size: 16px; /* avoid iOS zoom */
    padding: 10px 12px;
  }
  .search-results {
    left: 0;
    right: 0;
    width: auto;
    top: calc(100% + 6px);
    max-height: min(50vh, 320px);
    overflow-y: auto;
  }
  .header-actions { gap: 6px; }
  .btn-chip { padding: 10px 12px; font-size: 13px; min-height: 40px; }
  header .btn-chip#comps-toggle,
  header .btn-chip#operators-toggle,
  #trial-chip { display: none; }
  #demand-toggle { flex: none; font-weight: 600; }
  .account-summary {
    padding: 0;
    width: 40px; height: 40px; justify-content: center;
  }
  .account-summary .user-email { display: none; }
  .spacer { display: none; }

  .layers-toggle { display: inline-flex; align-items: center; font-weight: 600; }
  .layers-close { display: inline-flex; align-items: center; justify-content: center; }

  #layers-panel {
    display: none;
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: min(300px, 88vw);
    z-index: 17;
    border-right: 1px solid var(--border);
    box-shadow: 8px 0 28px rgba(0,0,0,.14);
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  #layers-panel.open {
    display: block;
  }
  .layers-scrim.visible {
    display: block;
  }

  .body { position: relative; }

  #side-panel:not(.hidden) {
    position: absolute;
    inset: 0;
    width: 100%;
    max-width: none;
    border-left: 0;
    z-index: 18;
    box-shadow: none;
  }

  #side-panel.demand-open {
    width: 100%;
    background: #f3efe7;
  }

  #side-panel.demand-open #panel-content {
    padding: 16px 14px 28px;
    padding-bottom: max(28px, env(safe-area-inset-bottom));
  }

  .panel-close {
    top: 8px;
    right: 8px;
    width: 36px;
    height: 36px;
    font-size: 18px;
  }

  .demand-title {
    font-size: 24px;
    padding-right: 36px;
  }

  .demand-kpis {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .demand-kpi { padding: 10px 12px; }
  .dk-value { font-size: 18px; }
  .demand-kpi.wide .dk-value { font-size: 24px; }

  .demand-origin {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .demand-chart-wrap.line { height: 160px; }
  .demand-chart-wrap.stack { height: 170px; }
  .demand-chart-wrap.doughnut {
    height: 140px;
    max-width: 150px;
  }

  .demand-card { padding: 12px; border-radius: 12px; }
  .demand-prov-name { white-space: normal; overflow: visible; text-overflow: unset; }
}

@media (max-width: 420px) {
  #demand-toggle { padding: 10px 11px; }
  .demand-kpis { grid-template-columns: 1fr; }
  .demand-kpi.wide { grid-column: auto; }
}
