
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    :root {
      --red:   #cc0000;
      --green: #1a5c2a;
      --black: #111;
      --white: #fff;
      --gray1: #444;
      --gray2: #888;
      --gray3: #ccc;
      --gray4: #f2f2f2;
      --border:#ddd;
      --shadow: 0 2px 12px rgba(0,0,0,.13);
    }

    #grafico-principal {
      font-family: 'Heebo', sans-serif;
      height: 100vh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }

    /* ── Header ── */
    #grafico-principal .topbar {
      background: var(--white);
      border-bottom: 3px solid var(--green);
      padding: 8px 14px;
      display: flex;
      align-items: center;
      gap: 12px;
      flex-shrink: 0;
      z-index: 10;
      min-height: 54px;
    }
    #grafico-principal .topbar-logo { height: 58px; width: auto; flex-shrink: 0; margin-right: 15px;}
    #grafico-principal .topbar-texts { display: flex; flex-direction: column; gap: 1px; min-width: 0; margin-top:20px; margin-bottom: 10px; }
    #grafico-principal .topbar-title {
      font-size: 25px; font-weight: 800; color: var(--black);
      text-transform: uppercase; letter-spacing: .04em; line-height: 1.2;
    }
    .topbar-year { color: var(--green); }
    .topbar-sub  { font-size: 22px; color: var(--gray2); font-weight: 400; line-height: 1.1;}

    /* ── Map wrapper ── */
    #map-wrap { flex: 1; position: relative; overflow: hidden; }
    #map      { position: absolute; inset: 0; visibility: hidden; }

    /* ── Floating controls ── */
    #controls {
      position: absolute;
      top: 12px; left: 12px;
      z-index: 20;
      display: flex;
      flex-direction: column;
      gap: 8px;
      width: 190px;
    }

    /* pos-row hidden when party mode */
    .pos-row.hidden { display: none; }

    @media (max-width: 320px) {
      #controls { width: 160px; }
      .var-item { font-size: 25px; padding: 5px 6px; }
      .topbar-sub { font-size: 23px; }
      .pos-pill { font-size: 12px; padding: 4px 2px; }
      .prov-select { font-size: 13px; padding: 7px 8px; }
      #legend { padding: 7px 9px; min-width: 120px; }
      .lg-title { font-size: 14px; }
      .lg-item  { font-size: 15px; }
      .topbar-title { font-size: 23px; line-height: 1.1; margin-bottom: 10px; }
      .topbar-logo  { opacity: 0; width: 5px }
      #footer { font-size: 13px;}
    }

    .ctrl-card {
      background: var(--white);
      border: 1px solid var(--border);
      box-shadow: var(--shadow);
    }
    .ctrl-card-clip { overflow: hidden; }

    /* Variable selector */
    .var-list { padding: 8px; display: flex; flex-direction: column; gap: 4px; }
    .var-toggle {
      display: flex; align-items: center; justify-content: space-between;
      padding: 8px 10px; cursor: pointer; font-weight: 700;
      border-top: 1px solid var(--border); background: var(--white);
      font-size: 14px; color: var(--gray1);
      margin-top: 10px;
    }
    .var-toggle:focus { outline: 2px solid rgba(0,0,0,0.08); }
    .var-toggle .var-toggle-caret { margin-left: 8px; }
    .var-list.collapsed { display: none; }
    .var-item {
      display: flex; align-items: center; gap: 8px;
      padding: 6px 8px; 
      cursor: pointer; font-size: 15px; font-weight: 500;
      transition: background .15s;
      border: none; background: none; text-align: left; width: 100%;
    }
    .var-item:hover   { background: var(--gray4); }
    .var-item.active  { background: var(--gray4); font-weight: 700; }
    .var-dot {
      width: 10px; height: 10px; flex-shrink: 0;
      border: 1px solid rgba(0,0,0,.12);
    }
    .var-sep {
      height: 1px; background: var(--border); margin: 2px 8px;
    }

    /* Province selector */
    .prov-select {
      width: 100%; border: none; padding: 9px 10px;
      font-family: 'Heebo', sans-serif; font-size: 15px;
      font-weight: 600; color: var(--black);
      background: var(--white); cursor: pointer; outline: none;
      appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
      background-repeat: no-repeat; background-position: right 10px center;
      padding-right: 28px;
    }

    /* ── Legend ── */
    #legend {
      position: absolute;
      bottom: 28px; left: 12px;
      z-index: 20;
      background: var(--white);
      border: 1px solid var(--border);
      box-shadow: var(--shadow);
      padding: 10px 12px;
      min-width: 140px;
    }
    .lg-title {
      font-size: 13px; font-weight: 700; text-transform: uppercase;
      letter-spacing: .08em; color: var(--gray2); margin-bottom: 8px;
    }
    .lg-item {
      display: flex; align-items: center; gap: 7px;
      font-size: 14px; font-weight: 500; margin-bottom: 5px;
      color: var(--black);
    }
    .lg-item:last-child { margin-bottom: 0; }
    .lg-dot {
      width: 10px; height: 10px; flex-shrink: 0;
      border: 1px solid rgba(0,0,0,.1);
    }
    /* gradient legend for % mode */
    .lg-grad { height: 8px; margin-bottom: 4px; }
    .lg-scale { display: flex; justify-content: space-between; font-size: 14px; color: var(--gray2); }

    /* ── Tooltip ── */
    #tooltip {
      position: absolute; z-index: 50; pointer-events: none;
      background: var(--white); border: 1px solid var(--border);
       box-shadow: var(--shadow);
      padding: 10px 13px; min-width: 180px; max-width: 220px;
      opacity: 0; transition: opacity .12s, transform .12s;
      transform: translateY(4px);
    }
    #tooltip.vis { opacity: 1; transform: translateY(0); }
    .tt-name   { font-size: 16px; font-weight: 700; margin-bottom: 1px; }
    .tt-sub    { font-size: 13px; color: var(--gray2); margin-bottom: 7px; }
    .tt-sep    { height: 1px; background: var(--border); margin: 6px 0; }
    .tt-row    { display: flex; align-items: center; gap: 6px; font-size: 14px; margin-bottom: 4px; }
    .tt-row:last-child { margin-bottom: 0; }
    .tt-dot    { width: 8px; height: 8px; flex-shrink: 0; border: 1px solid rgba(0,0,0,.1); }
    .tt-party  { flex: 1; color: var(--gray1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .tt-pct    { font-weight: 700; white-space: nowrap; }

    /* ── Loading ── */
    #loader {
      position: absolute; inset: 0; z-index: 100;
      background: rgba(242,242,242,.92);
      display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
    }
    #loader.hidden { display: none; }
    .spinner {
      width: 32px; height: 32px; border: 3px solid var(--border);
      border-top-color: var(--red);
      animation: spin .7s linear infinite;
    }
    @keyframes spin { to { transform: rotate(360deg); } }
    #loader p { font-size: 15px; color: var(--gray2); font-weight: 500; }

    /* Position pills */
    .pos-row { display: flex; gap: 4px; padding: 8px 8px 2px; }
    .pos-pill {
      flex: 1; padding: 5px 2px;
      border: 1px solid var(--border); background: var(--white);
      font-family: 'Heebo', sans-serif; font-size: 13px; font-weight: 600;
      color: var(--gray1); cursor: pointer; text-align: center; transition: all .15s;
    }
    .pos-pill:hover  { border-color: var(--gray2); }
    .pos-pill.active { background: var(--black); color: var(--white); border-color: var(--black); }

    /* ── Buscador de municipios ── */
    .search-wrap { position: relative; }
    .search-input {
      width: 100%; border: none; padding: 9px 30px 9px 10px;
      font-family: 'Heebo', sans-serif; font-size: 14px;
      color: var(--black); background: var(--white); outline: none;
    }
    .search-input::placeholder { color: var(--gray3); }
    .search-clear {
      position: absolute; right: 8px; top: 50%;
      transform: translateY(-50%);
      background: none; border: none; color: var(--gray2);
      cursor: pointer; font-size: 13px; display: none; line-height: 1;
    }
    .search-dropdown {
      position: absolute; top: 100%; left: 0; right: 0;
      background: var(--white); border: 1px solid var(--border);
      border-top: none; box-shadow: var(--shadow);
      max-height: 220px; overflow-y: auto; z-index: 30; display: none;
    }
    .search-dropdown.open { display: block; }
    .search-suggestion {
      padding: 9px 12px; cursor: pointer; font-size: 13px; font-weight: 500;
      color: var(--black); border-bottom: 1px solid var(--gray4);
    }
    .search-suggestion:last-child { border-bottom: none; }
    .search-suggestion:hover, .search-suggestion.focused { background: var(--gray4); }

    /* MapLibre controls */
    .maplibregl-ctrl-group { box-shadow: var(--shadow) !important; }

#footer{
    text-align:center;font: size 15px;color:var(--gray2);padding-top:20px; margin-bottom: 20px; border-top: 1px solid var(--green); background-color: white;
}
