/* ============================================================
   RULERS.CAT — Design System
   ============================================================ */

:root {
  --sidebar-w: 272px;
  --sidebar-bg: #12100e;
  --sidebar-border: rgba(255,255,255,0.07);

  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #f9f8f5;
  --border: #e6e3db;
  --border-strong: #ccc8bc;

  --red: #b91c1c;
  --red-light: #fef2f2;
  --gold: #b45309;
  --gold-light: #fffbeb;
  --blue: #1d4ed8;
  --blue-light: #eff6ff;

  --text: #1c1917;
  --text-2: #44403c;
  --text-3: #78716c;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow: 0 3px 10px rgba(0,0,0,.09), 0 1px 4px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 28px rgba(0,0,0,.12), 0 3px 10px rgba(0,0,0,.07);

  /* Token colors (used to avoid hardcoding in dark-mode-sensitive rules) */
  --table-head-bg: #1a1714;
  --table-head-color: #a8a29e;
  --row-hover: #eeecea;
  --era-bg-1: #faf6f0;
  --era-bg-2: #fdf9f5;
  --era-text: #92400e;
  --era-border: #f3e8d8;
  --nota-bg-1: #fefce8;
  --nota-bg-2: #fffde8;
  --nota-border: #fde68a;
  --muni-hover: #faf9f7;
  --card-hover-bg: var(--surface);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%2378716c' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
}

/* ============================================================
   DARK MODE
   ============================================================ */
[data-theme="dark"] {
  --bg: #111110;
  --surface: #1c1a17;
  --surface-2: #232120;
  --border: #2d2b27;
  --border-strong: #3c3835;

  --red-light: rgba(185,28,28,.18);
  --gold-light: rgba(180,83,9,.15);
  --blue-light: rgba(29,78,216,.15);

  --text: #f0ece6;
  --text-2: #bdb5ab;
  --text-3: #756c65;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
  --shadow: 0 3px 10px rgba(0,0,0,.4), 0 1px 4px rgba(0,0,0,.2);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.6), 0 3px 10px rgba(0,0,0,.3);

  --table-head-bg: #0e0d0b;
  --table-head-color: #5a5550;
  --row-hover: #252220;
  --era-bg-1: #1a1108;
  --era-bg-2: #1e1408;
  --era-text: #c87c20;
  --era-border: #2e1e08;
  --nota-bg-1: #1a1800;
  --nota-bg-2: #1e1a00;
  --nota-border: #2e2800;
  --muni-hover: #222120;
  --card-hover-bg: #1f1d1a;
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%23a09890' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  height: 100%;
  -webkit-font-smoothing: antialiased;
  transition: background-color .3s ease, color .3s ease;
}
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font: inherit; }

/* ============================================================
   APP SHELL
   ============================================================ */
.app {
  display: flex;
  min-height: 100vh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 200;
  overflow: hidden;
  border-right: 1px solid var(--sidebar-border);
  transition: transform .25s ease;
}

/* Brand */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s;
}
.sidebar-brand:hover { background: rgba(255,255,255,.04); }
.brand-mark {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #c41a1a, #9b1212);
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -1px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(196,26,26,.4);
}
.brand-name {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.3px;
}
.brand-name span { color: #c41a1a; }
.brand-tagline {
  font-size: 10px;
  color: #6b6560;
  letter-spacing: .3px;
  margin-top: 1px;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
  scrollbar-width: thin;
  scrollbar-color: #333 transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: #333; border-radius: 2px; }

.nav-group { margin-bottom: 24px; }
.nav-group-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #4a453f;
  padding: 0 8px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  color: #b8afa5;
  font-size: 13px;
  font-weight: 450;
  transition: background .15s, color .15s;
  margin-bottom: 1px;
  line-height: 1.4;
}
.nav-item:hover:not(.disabled) {
  background: rgba(255,255,255,.07);
  color: #e8e0d8;
}
.nav-item.active {
  background: rgba(196,26,26,.18);
  color: #fca5a5;
  font-weight: 550;
}
.nav-item.disabled {
  opacity: .45;
  cursor: default;
  pointer-events: none;
}
.nav-icon { font-size: 11px; opacity: .5; flex-shrink: 0; }
.nav-item.active .nav-icon { opacity: .8; }
.nav-badge {
  margin-left: auto;
  font-size: 9.5px;
  font-weight: 600;
  background: rgba(255,255,255,.08);
  color: #6b6560;
  padding: 2px 6px;
  border-radius: 10px;
  letter-spacing: .03em;
  flex-shrink: 0;
}

/* Sidebar footer — theme toggle */
.sidebar-footer {
  padding: 10px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  color: #7a726a;
  font-size: 12.5px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.theme-toggle:hover {
  background: rgba(255,255,255,.07);
  color: #c0b8b0;
}
.theme-toggle-icon {
  font-size: 15px;
  line-height: 1;
  flex-shrink: 0;
}

/* Sigles drawer */
.sigles-drawer {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 300;
  display: flex;
  align-items: stretch;
  border-radius: 8px 0 0 8px;
  overflow: hidden;
  box-shadow: -4px 0 20px rgba(0,0,0,.14);
}
.sigles-tab {
  writing-mode: vertical-rl;
  background: var(--sidebar-bg);
  color: rgba(255,255,255,.7);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: 20px 12px;
  cursor: pointer;
  border: none;
  user-select: none;
  transition: color .15s;
  flex-shrink: 0;
}
.sigles-tab:hover { color: #fff; }
.sigles-panel {
  width: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-right: none;
  max-height: 70vh;
  overflow-y: auto;
  padding: 12px;
  display: none;
  transition: background-color .3s, border-color .3s;
}
.sigles-drawer.open .sigles-panel { display: block; }
.sigle-row {
  display: flex;
  gap: 6px;
  padding: 3px 0;
  font-size: 11px;
  border-bottom: 1px solid rgba(128,128,128,.1);
}
.sigle-row:last-child { border-bottom: none; }
.sigle-code { font-weight: 700; color: #e8c88a; min-width: 52px; flex-shrink: 0; }
.sigle-name { color: var(--text-3); }
.sigle-desc { color: var(--text-3); font-style: italic; font-size: 9.5px; margin-left: 2px; opacity: .7; }
.sigle-grup {
  color: #7c6a50;
  font-size: 8.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  padding: 9px 0 2px;
  border-bottom: 1px solid rgba(128,128,128,.12) !important;
  display: block;
}

/* ============================================================
   MAIN
   ============================================================ */
.main-wrapper {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}
.main {
  flex: 1;
  padding: 36px 40px 48px;
  max-width: 1400px;
}


/* ============================================================
   VIEWS
   ============================================================ */
.view { display: none; }
.view.active { display: block; }

/* View header */
.view-header { margin-bottom: 28px; }
.view-breadcrumb {
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.view-breadcrumb a { color: var(--red); font-weight: 500; }
.view-breadcrumb a:hover { text-decoration: underline; }
.view-title {
  font-size: 27px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -.5px;
  line-height: 1.2;
  margin-bottom: 8px;
}
.view-desc {
  font-size: 14px;
  color: var(--text-3);
  max-width: 600px;
  line-height: 1.6;
}

/* ============================================================
   OVERVIEW CARDS
   ============================================================ */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid transparent;
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .25s ease, border-color .25s ease, transform .2s ease,
              background-color .25s ease;
  cursor: pointer;
}
.card:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--border-strong);
  border-top-color: var(--red);
  transform: translateY(-4px);
  background: var(--card-hover-bg);
}
.card--soon { opacity: .6; cursor: default; pointer-events: none; }
.card--wide { grid-column: 1 / -1; }
.card-header { display: flex; justify-content: space-between; align-items: flex-start; }
.card-icon {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
  padding: 4px 8px;
  border-radius: 5px;
}
.card-icon--red     { background: var(--red-light);  color: var(--red); }
.card-icon--gold    { background: var(--gold-light); color: var(--gold); }
.card-icon--blue    { background: var(--blue-light); color: var(--blue); }
.card-icon--muted   { background: var(--surface-2);  color: var(--text-3); }
.card-icon--green   { background: #f0fdf4; color: #15803d; }
.card-icon--orange  { background: #fff7ed; color: #c2410c; }
.card-icon--violet  { background: #faf5ff; color: #7e22ce; }
.card-icon--emerald { background: #ecfdf5; color: #059669; }
.card-icon--teal    { background: #ecfeff; color: #0891b2; }
[data-theme="dark"] .card-icon--green   { background: rgba(21,128,61,.18);  color: #4ade80; }
[data-theme="dark"] .card-icon--orange  { background: rgba(194,65,12,.18);  color: #fb923c; }
[data-theme="dark"] .card-icon--violet  { background: rgba(126,34,206,.18); color: #c084fc; }
[data-theme="dark"] .card-icon--emerald { background: rgba(5,150,105,.18);  color: #34d399; }
[data-theme="dark"] .card-icon--teal    { background: rgba(8,145,178,.18);  color: #22d3ee; }
.card-arrow {
  font-size: 16px;
  color: var(--border-strong);
  transition: color .2s, transform .2s;
}
.card:hover .card-arrow { color: var(--text-3); transform: translateX(3px); }
.card-title { font-size: 14px; font-weight: 600; color: var(--text); line-height: 1.4; }
.card-meta  { font-size: 12px; color: var(--text-3); }

/* ============================================================
   SECTION NAV — Compact territory navigation list
   ============================================================ */
.section-nav {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 28px;
  box-shadow: var(--shadow-sm);
  transition: background-color .3s, border-color .3s;
}
.section-nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
  cursor: pointer;
  color: inherit;
}
.section-nav-item:last-child { border-bottom: none; }
.section-nav-item:hover { background: var(--muni-hover); }
.section-nav-icon {
  width: 38px; height: 38px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  flex-shrink: 0;
  /* inherits background/color from card-icon--* */
}
.section-nav-body { flex: 1; min-width: 0; }
.section-nav-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}
.section-nav-meta {
  font-size: 11.5px;
  color: var(--text-3);
  margin-top: 2px;
  line-height: 1.4;
}
.section-nav-chevron {
  width: 18px; height: 18px;
  color: var(--border-strong);
  flex-shrink: 0;
  transition: transform .15s, color .15s;
}
.section-nav-item:hover .section-nav-chevron {
  transform: translateX(2px);
  color: var(--text-3);
}

/* ============================================================
   TABLE CONTROLS
   ============================================================ */
.table-controls {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.search-wrap { position: relative; flex: 1; min-width: 200px; }
.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-3);
  pointer-events: none;
}
.search-input {
  width: 100%;
  padding: 9px 12px 9px 36px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s, background-color .3s, color .3s;
  outline: none;
}
.search-input:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(185,28,28,.1);
}
.search-input::placeholder { color: var(--text-3); }

.filter-select {
  padding: 9px 32px 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13.5px;
  color: var(--text-2);
  background: var(--surface) var(--select-arrow) no-repeat right 10px center;
  appearance: none;
  cursor: pointer;
  outline: none;
  transition: border-color .15s, background-color .3s, color .3s;
}
.filter-select:focus { border-color: var(--red); }

/* ============================================================
   TABLE
   ============================================================ */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  transition: background-color .3s, border-color .3s;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.data-table thead th {
  background: var(--table-head-bg);
  color: var(--table-head-color);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 12px 16px;
  text-align: left;
  position: sticky;
  top: 0;
  z-index: 1;
  white-space: nowrap;
  border-bottom: 2px solid var(--red);
  transition: background-color .3s, color .3s;
}
.data-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background-color .12s;
}
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:nth-child(even):not(.era-row):not(.no-results):not(.nota-historica) {
  background: var(--surface-2);
}
.data-table tbody tr:hover { background: var(--row-hover); }
.data-table tbody td {
  padding: 10px 16px;
  vertical-align: middle;
  color: var(--text);
  transition: background-color .12s, color .3s;
}

/* Era separator rows */
.era-row td {
  background: linear-gradient(to right, var(--era-bg-1), var(--era-bg-2));
  color: var(--era-text);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 7px 16px;
  border-top: 2px solid var(--era-border);
  border-bottom: 1px solid var(--era-border);
}
.era-row:hover td {
  background: linear-gradient(to right, var(--era-bg-1), var(--era-bg-2)) !important;
}

/* Column widths */
.col-num    { width: 52px;  color: var(--text-3) !important; font-size: 12px !important; }
.col-dates  { width: 180px; color: var(--text-2); white-space: nowrap; }
.col-party  { width: 150px; }
.col-role   { width: 190px; color: var(--text-3); font-size: 12px; }
.col-reign  { width: 220px; color: var(--text-3); font-size: 12px; }

/* No results */
.no-results td {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-3);
}
.no-results td::before {
  content: "—";
  display: block;
  font-size: 24px;
  margin-bottom: 8px;
  opacity: .3;
}

/* ============================================================
   PARTY CHIPS
   ============================================================ */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .02em;
  white-space: nowrap;
  border: 1px solid transparent;
}
.chip-ERC          { background:#fff7ed; color:#c2410c; border-color:#fed7aa; }
.chip-PSC          { background:#fef2f2; color:#b91c1c; border-color:#fecaca; }
.chip-CDC          { background:#eff6ff; color:#1d4ed8; border-color:#bfdbfe; }
.chip-Junts        { background:#f0fdf4; color:#15803d; border-color:#bbf7d0; }
.chip-BEC          { background:#faf5ff; color:#7e22ce; border-color:#e9d5ff; }
.chip-FET          { background:#f3f4f6; color:#525252; border-color:#e5e5e5; }
.chip-LR           { background:#eff6ff; color:#1e40af; border-color:#bfdbfe; }
.chip-PLF          { background:#fff7ed; color:#9a3412; border-color:#fed7aa; }
.chip-PLC          { background:#f0fdf4; color:#166534; border-color:#bbf7d0; }
.chip-PRR          { background:#fef9c3; color:#854d0e; border-color:#fde68a; }
.chip-PRDF         { background:#fdf4ff; color:#86198f; border-color:#f0abfc; }
.chip-PRA          { background:#ecfeff; color:#0e7490; border-color:#a5f3fc; }
.chip-PP           { background:#fef3c7; color:#92400e; border-color:#fde68a; }
.chip-APC          { background:#ecfdf5; color:#065f46; border-color:#a7f3d0; }
.chip-UMN          { background:#f8fafc; color:#475569; border-color:#cbd5e1; }
.chip-CUP          { background:#1c1917; color:#fcd34d; border-color:#292524; }
.chip-ICV          { background:#f0fdf4; color:#166534; border-color:#86efac; }
.chip-CiU          { background:#dbeafe; color:#1e3a8a; border-color:#93c5fd; }
.chip-PSUC         { background:#fff1f2; color:#9f1239; border-color:#fecdd3; }
.chip-CNT          { background:#1c0a02; color:#fb923c; border-color:#431407; }
.chip-Progressista { background:#f0f9ff; color:#0369a1; border-color:#bae6fd; }
.chip-Liberal      { background:#fefce8; color:#92400e; border-color:#fde68a; }
.chip-Federal      { background:#ecfeff; color:#0e7490; border-color:#a5f3fc; }
.chip-Republica    { background:#fdf4ff; color:#7e22ce; border-color:#e9d5ff; }
.chip-Guanyem      { background:#fefce8; color:#3f6212; border-color:#bef264; }
.chip-AC           { background:#0f172a; color:#38bdf8; border-color:#1e3a5f; }
.chip-default      { background:#f3f4f6; color:#525252; border-color:#e5e5e5; }
.chip-PSPV         { background:#fff1f2; color:#be123c; border-color:#fecdd3; }
.chip-UCD          { background:#f1f5f9; color:#475569; border-color:#cbd5e1; }
.chip-Compromis    { background:#f0fdf4; color:#15803d; border-color:#86efac; }
.chip-PSOE         { background:#fef2f2; color:#dc2626; border-color:#fca5a5; }

/* Dark mode chip overrides — only fix chips that become unreadable */
[data-theme="dark"] .chip-FET,
[data-theme="dark"] .chip-default { background:#2a2826; color:#908880; border-color:#3a3530; }
[data-theme="dark"] .chip-UMN,
[data-theme="dark"] .chip-UCD     { background:#1c2030; color:#7088a8; border-color:#283048; }

/* L'Alguer – Itàlia chips */
.chip-DC  { background:#f0f9ff; color:#0369a1; border-color:#bae6fd; }   /* Democrazia Cristiana – blau clar */
.chip-PCI { background:#fff1f2; color:#9f1239; border-color:#fecdd3; }   /* PCI – carmesí */
.chip-FI  { background:#eff6ff; color:#2563eb; border-color:#93c5fd; }   /* Forza Italia / PDL – blau */
.chip-AVS { background:#f7fee7; color:#3f6212; border-color:#a3e635; }   /* Alleanza Verdi e Sinistra */
/* Dinasties medievals noves */
.chip-dGeno { background:#f1f5f9; color:#475569; border-color:#cbd5e1; } /* Gènova / Doria – pedra */
.chip-dSavo { background:#faf5ff; color:#6d28d9; border-color:#ddd6fe; } /* Casa de Savoia – lila */

/* França (Catalunya Nord) chips */
.chip-RPR  { background:#dbeafe; color:#1e40af; border-color:#93c5fd; }   /* RPR — Gaullisme, dreta */
.chip-UDF  { background:#eff6ff; color:#2563eb; border-color:#bfdbfe; }   /* UDF — Centre-dreta */
.chip-UMP  { background:#e0f2fe; color:#0369a1; border-color:#7dd3fc; }   /* UMP/LR — Dreta clàssica */
.chip-RN   { background:#1e293b; color:#93c5fd; border-color:#1e3a5f; }   /* RN — Ultradreta */
.chip-PCF  { background:#fff1f2; color:#9f1239; border-color:#fecdd3; }   /* PCF — Comunisme */

/* ---- Mini banderes CSS ---- */
.terr-flag {
  display: inline-block;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0,0,0,.18);
  flex-shrink: 0;
  overflow: hidden;
  vertical-align: middle;
}
/* Mides */
.flag-sm { width: 18px; height: 12px; }
.flag-md { width: 30px; height: 20px; }
.flag-lg { width: 42px; height: 28px; }

/* Senyera – 9 franges horitz. (5 daurades + 4 vermelles) */
.flag-cat, .flag-cno {
  background: repeating-linear-gradient(
    to bottom,
    #FCBF00 0% 11.11%, #C80015 11.11% 22.22%
  );
}
/* Valenciana – senyera + franja blava al pal (≈20%) */
.flag-pv {
  background:
    linear-gradient(90deg, #003DA5 20%, transparent 20%),
    repeating-linear-gradient(to bottom, #FCBF00 0% 11.11%, #C80015 11.11% 22.22%);
}
/* Balears – senyera + franja violeta al pal (≈18%) */
.flag-ib {
  background:
    linear-gradient(90deg, #6B21A8 18%, transparent 18%),
    repeating-linear-gradient(to bottom, #FCBF00 0% 11.11%, #C80015 11.11% 22.22%);
}
/* Andorra – 3 franges verticals: blau, groc, vermell */
.flag-and {
  background: linear-gradient(90deg, #003DA5 33.33%, #FEDF00 33.33% 66.66%, #C7192D 66.66%);
}
/* L'Alguer – bandera italiana: verd, blanc, vermell */
.flag-alg {
  background: linear-gradient(90deg, #009246 33.33%, #fff 33.33% 66.66%, #CE2B37 66.66%);
}
/* Mode fosc – reforça l'ombra de les banderes */
[data-theme="dark"] .terr-flag { box-shadow: 0 0 0 1px rgba(255,255,255,.12); }

/* ---- Etiquetes de territori al mapa d'inici ---- */
.home-map-label {
  display: inline-block;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #1f2937;
  text-shadow:
    0 0 4px #fff,
    0 0 8px #fff,
    0 1px 2px rgba(255,255,255,.9);
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
  opacity: .85;
}
[data-theme="dark"] .home-map-label {
  color: #f3f4f6;
  text-shadow:
    0 0 4px #000,
    0 0 8px #000,
    0 1px 2px rgba(0,0,0,.9);
}

/* ---- Ressaltat de fila (cerca global) ---- */
@keyframes row-flash {
  0%, 55% { background-color: #fef9c3; }
  100%     { background-color: transparent; }
}
@keyframes row-flash-dark {
  0%, 55% { background-color: #3b2900; }
  100%     { background-color: transparent; }
}
tr.row-hl { animation: row-flash 3s ease forwards; }
[data-theme="dark"] tr.row-hl { animation: row-flash-dark 3s ease forwards; }

/* ---- Placeholder "selecciona un municipi" ---- */
.muni-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 24px 64px;
  color: var(--text-3);
  gap: 14px;
  text-align: center;
}
.muni-placeholder svg { opacity: .2; }
.muni-placeholder p {
  font-size: 14px;
  max-width: 260px;
  line-height: 1.6;
}
.muni-placeholder[hidden] { display: none; }

/* ---- Titol de territori amb bandera ---- */
.view-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Illes Balears chips */
.chip-Mes  { background:#ecfdf5; color:#047857; border-color:#6ee7b7; }   /* Més per Mallorca/Menorca */

/* Andorra chips — partits principals */
.chip-AND  { background:#f5f3ff; color:#6d28d9; border-color:#ddd6fe; }  /* Agrupament Nacional Democràtic — viola */
.chip-PS   { background:#fef2f2; color:#b91c1c; border-color:#fecaca; }  /* Socialdemòcrates — roig */
.chip-DA   { background:#ecfdf5; color:#065f46; border-color:#a7f3d0; }  /* Demòcrates per Andorra — verd */
.chip-LdA  { background:#e0f2fe; color:#0284c7; border-color:#7dd3fc; }  /* Liberals d'Andorra — blau cel */
.chip-Conc { background:#f0fdfa; color:#0f766e; border-color:#99f6e4; }  /* Concòrdia — turquesa */
.chip-TV   { background:#f8fafc; color:#44403c; border-color:#a8a29e; }  /* Tercera Via — pedra */
.chip-AE   { background:#fffbeb; color:#b45309; border-color:#fcd34d; }  /* Andorra Endavant — ambre */
.chip-DL   { background:#f7fee7; color:#3f6212; border-color:#a3e635; }  /* Desperta Laurèdia — llima */
.chip-CC   { background:#fff7ed; color:#c2410c; border-color:#fed7aa; }  /* Ciutadans Compromesos — taronja */

/* Catalunya chips addicionals */
.chip-PDeCAT  { background:#dbeafe; color:#1e40af; border-color:#60a5fa; }  /* PDeCAT — blau fosc */
.chip-CatComu { background:#ede9fe; color:#4c1d95; border-color:#a78bfa; }  /* Catalunya en Comú — viola */
.chip-Cs      { background:#fff7ed; color:#ea580c; border-color:#fdba74; }  /* Ciutadans — taronja */

/* Dynasty chips */
.chip-dArag { background:#fefce8; color:#713f12; border-color:#fde047; }
.chip-dTras { background:#fff7ed; color:#9a3412; border-color:#fdba74; }
.chip-dHabs { background:#f5f3ff; color:#5b21b6; border-color:#c4b5fd; }
.chip-dBorb { background:#eff6ff; color:#1e3a8a; border-color:#93c5fd; }

/* Wikipedia link badge */
.wiki-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px; height: 15px;
  background: #000;
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  border-radius: 3px;
  margin-left: 6px;
  text-decoration: none;
  vertical-align: middle;
  opacity: 0.35;
  transition: opacity .15s;
  line-height: 1;
  font-family: 'Georgia', serif;
}
.wiki-link:hover { opacity: 0.85; }

/* ============================================================
   SUB-TABS
   ============================================================ */
.sub-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 4px;
  border-radius: 8px;
  width: fit-content;
  max-width: 100%;
  flex-wrap: wrap;
  transition: background-color .3s, border-color .3s;
}
.sub-tab {
  padding: 7px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-3);
  transition: background .15s, color .15s;
}
.sub-tab:hover { color: var(--text-2); }
.sub-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}
.sub-content { display: none; }
.sub-content.active { display: block; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state { text-align: center; padding: 80px 24px; color: var(--text-3); }
.empty-icon  { font-size: 40px; margin-bottom: 16px; opacity: .3; }
.empty-title { font-size: 18px; font-weight: 700; color: var(--text-2); margin-bottom: 8px; }
.empty-desc  { font-size: 14px; max-width: 380px; margin: 0 auto; line-height: 1.7; }

/* ============================================================
   MOBILE HEADER
   ============================================================ */
.mobile-header {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 52px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--sidebar-border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.menu-btn { display: flex; flex-direction: column; gap: 4.5px; padding: 4px; cursor: pointer; }
.menu-btn span {
  display: block;
  width: 20px; height: 2px;
  background: #ccc;
  border-radius: 1px;
  transition: transform .2s, opacity .2s;
}
.mobile-brand { font-size: 16px; font-weight: 600; color: #e8e0d8; }
.mobile-brand b { color: #c41a1a; font-weight: 700; }

.mobile-theme-btn {
  margin-left: auto;
  font-size: 17px;
  padding: 6px 8px;
  border-radius: 6px;
  color: rgba(255,255,255,.55);
  transition: color .15s, background .15s;
  line-height: 1;
  flex-shrink: 0;
}
.mobile-theme-btn:hover { color: #fff; background: rgba(255,255,255,.08); }

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 150;
  backdrop-filter: blur(2px);
}
.overlay.active { display: block; }

/* ============================================================
   FOOTER
   ============================================================ */

/* ---- Pàgina de presentació ---- */
.presentacio-body {
  max-width: 680px;
  line-height: 1.75;
  color: var(--text-2);
  font-size: 15px;
}
.presentacio-body p { margin-bottom: 1.15em; }
.presentacio-body a { color: var(--red); text-decoration: underline; text-underline-offset: 3px; }
.presentacio-body a:hover { opacity: .8; }
.presentacio-h2 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  margin: 2em 0 .6em;
  padding-left: 12px;
  border-left: 3px solid var(--red);
}

.site-footer {
  padding: 20px 40px;
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: 12px;
  background: var(--surface-2);
  transition: background-color .3s, border-color .3s, color .3s;
}

/* ============================================================
   HOME
   ============================================================ */
.global-search-wrap { padding: 4px 0 28px; }
.global-search-inner { position: relative; max-width: 580px; }
.global-search-icon {
  position: absolute;
  left: 16px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
  width: 18px; height: 18px;
  flex-shrink: 0;
}
.global-search-input {
  width: 100%;
  padding: 13px 18px 13px 46px;
  font-size: 14.5px;
  font-family: var(--font);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  outline: none;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s, background-color .3s, color .3s;
  color: var(--text);
}
.global-search-input::placeholder { color: var(--text-3); }
.global-search-input:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(185,28,28,.08), var(--shadow-sm);
}
.global-results {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 2000;
  transition: background-color .3s, border-color .3s;
}
.global-results.open { display: block; }
.global-result-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.global-result-item:last-child { border-bottom: none; }
.global-result-item:hover { background: var(--surface-2); }
.global-result-cat { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); }
.global-result-nom { font-size: 14px; font-weight: 500; color: var(--text); }
.global-result-sub { font-size: 12px; color: var(--text-3); }
.global-no-results { padding: 16px; text-align: center; color: var(--text-3); font-size: 13px; }

.home-hero { margin-bottom: 20px; }
.home-title {
  font-size: 36px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.8px;
  line-height: 1;
  margin-bottom: 8px;
}
.home-title span { color: var(--red); }
.home-subtitle { font-size: 15px; color: var(--text-3); max-width: 620px; line-height: 1.55; }

.home-map-wrap {
  width: 100%;
  height: 420px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  isolation: isolate;
  box-shadow: var(--shadow-sm);
  margin-bottom: 10px;
  position: relative;
  transition: border-color .3s;
}
#home-map { width: 100%; height: 100%; }
.home-map-legend {
  position: absolute;
  bottom: 30px; right: 10px;
  background: rgba(255,255,255,.93);
  backdrop-filter: blur(4px);
  border-radius: 8px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  pointer-events: none;
  transition: background-color .3s, border-color .3s;
}
[data-theme="dark"] .home-map-legend { background: rgba(28,26,23,.94); }
.legend-item { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-weight: 500; }
.legend-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid rgba(255,255,255,0.8);
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.legend-item--soon { opacity: 0.5; font-style: italic; font-size: 11px; }

.section-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3);
  letter-spacing: .07em;
  text-transform: uppercase;
  margin: 24px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-label::before {
  content: '';
  display: inline-block;
  width: 16px; height: 2px;
  background: var(--red);
  border-radius: 1px;
  flex-shrink: 0;
}

.map-caption {
  font-size: 12.5px;
  color: var(--text-3);
  margin: -6px 0 14px;
  font-style: italic;
}

/* Layout mapa + nav lateral per pàgina de territori */
.territory-hero {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  align-items: start;
  margin-bottom: 28px;
}

/* Mapa de territori (per pàgina de cada territori) */
.territory-map-wrap {
  width: 100%;
  height: 420px;
  border-radius: 18px;
  overflow: hidden;
  border: 1.5px solid var(--border);
  isolation: isolate; /* conté els z-index interns de Leaflet, evita que sobrepassin el header */
  box-shadow:
    0 2px 0 0 var(--border),
    0 6px 24px rgba(0,0,0,.08),
    0 1px 4px rgba(0,0,0,.04);
  position: relative;
  transition: box-shadow .3s, transform .3s;
}
.territory-map-wrap:hover {
  box-shadow:
    0 2px 0 0 var(--border),
    0 12px 40px rgba(0,0,0,.12),
    0 2px 8px rgba(0,0,0,.06);
  transform: translateY(-2px);
}

/* Franja de color per territori (dalt del marc) */
#view-alg-home .territory-map-wrap { border-top: 3px solid #0891b2; }
#view-cat-home .territory-map-wrap { border-top: 3px solid #b91c1c; }
#view-pv-home  .territory-map-wrap { border-top: 3px solid #d97706; }
#view-ib-home  .territory-map-wrap { border-top: 3px solid #1d4ed8; }
#view-cno-home .territory-map-wrap { border-top: 3px solid #059669; }
#view-and-home .territory-map-wrap { border-top: 3px solid #7c3aed; }

#cat-muni-map, #pv-muni-map, #ib-muni-map, #cno-muni-map, #and-muni-map, #alg-muni-map { width: 100%; height: 100%; }

/* La section-nav dins el hero no té marge inferior propi */
.territory-hero .section-nav { margin-bottom: 0; }

/* Accent de color per territori als títols de municipi */
#view-pv-home  .muni-sub-title { border-left-color: #d97706; }
#view-and-home .muni-sub-title { border-left-color: #7c3aed; }

/* Cercador de municipis */
.muni-search-box {
  position: relative;
  margin: 0 auto 20px;
  max-width: 520px;
}
.muni-search-box .search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.muni-search-box .search-icon {
  position: absolute;
  left: 13px;
  width: 16px; height: 16px;
  color: var(--text-3);
  pointer-events: none;
  flex-shrink: 0;
}
.muni-search-box input {
  width: 100%;
  padding: 10px 14px 10px 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  box-sizing: border-box;
}
.muni-search-box input:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(185,28,28,.1);
}
.muni-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  overflow-y: auto;
  max-height: 220px;
  z-index: 200;
}
.muni-drop-item {
  padding: 10px 14px;
  font-size: 13.5px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.muni-drop-item:last-child { border-bottom: none; }
.muni-drop-item:hover { background: var(--muni-hover); }
.muni-drop-empty {
  padding: 10px 14px;
  color: var(--text-3);
  font-size: 13px;
}

/* ============================================================
   MUNICIPALITIES
   ============================================================ */
.muni-comarca-label {
  font-size: 12px;
  color: var(--text-3);
  margin: 0 0 20px 17px;
  font-style: italic;
  letter-spacing: .02em;
}
.muni-sub-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  margin: 20px 0 10px;
  padding-left: 14px;
  border-left: 3px solid var(--red);
  line-height: 1.2;
  letter-spacing: -.3px;
}

/* ============================================================
   ETAPES JURÍDICO-POLÍTIQUES
   ============================================================ */
.etapes-timeline { max-width: 680px; padding-bottom: 16px; }
.etapa-item { display: grid; grid-template-columns: 68px 20px 1fr; gap: 0 14px; }
.etapa-year {
  text-align: right;
  font-weight: 700;
  font-size: 13px;
  color: var(--red);
  padding-top: 5px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.3px;
  line-height: 1;
}
.etapa-line { display: flex; flex-direction: column; align-items: center; padding-top: 5px; }
.etapa-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--red);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1.5px var(--red);
  flex-shrink: 0;
}
.etapa-connector {
  width: 1.5px;
  flex: 1;
  background: var(--border);
  min-height: 14px;
  margin-top: 3px;
}
.etapa-desc { font-size: 13.5px; line-height: 1.5; color: var(--text); padding: 2px 0 16px; }

/* ============================================================
   MUNICIPALITIES (list/map view)
   ============================================================ */
.muni-controls { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.muni-count { font-size: 12px; color: var(--text-3); white-space: nowrap; padding: 0 4px; }

.muni-layout { display: grid; grid-template-columns: 310px 1fr; gap: 14px; height: 560px; }
.muni-list-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  transition: background-color .3s, border-color .3s;
}
.muni-list {
  overflow-y: auto; flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.muni-list::-webkit-scrollbar { width: 5px; }
.muni-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.muni-item {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.muni-item:last-child { border-bottom: none; }
.muni-item:hover { background: var(--muni-hover); }
.muni-item.highlighted { background: var(--red-light); border-left: 3px solid var(--red); }
.muni-item-name { font-size: 13.5px; font-weight: 600; color: var(--text); }
.muni-item-meta { font-size: 11.5px; color: var(--text-3); }
.muni-item.highlighted .muni-item-name { color: var(--red); }
.muni-empty { padding: 32px 16px; text-align: center; color: var(--text-3); font-size: 13px; }

.muni-map-panel {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: relative;
  transition: border-color .3s;
}
#muni-map { width: 100%; height: 100%; }

/* Leaflet tooltips personalitzats (hover sobre marcadors) */
.muni-tooltip.leaflet-tooltip {
  background: rgba(16,14,12,.94);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 9px;
  color: #f0ece6;
  padding: 9px 13px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 4px 20px rgba(0,0,0,.45);
  white-space: nowrap;
  pointer-events: none;
}
.muni-tooltip.leaflet-tooltip-top::before    { border-top-color:    rgba(16,14,12,.94); }
.muni-tooltip.leaflet-tooltip-bottom::before { border-bottom-color: rgba(16,14,12,.94); }
.muni-tooltip.leaflet-tooltip-left::before   { border-left-color:   rgba(16,14,12,.94); }
.muni-tooltip.leaflet-tooltip-right::before  { border-right-color:  rgba(16,14,12,.94); }

/* Leaflet popup */
.leaflet-popup-content-wrapper {
  border-radius: 8px !important;
  box-shadow: var(--shadow-lg) !important;
  font-family: var(--font) !important;
}
.leaflet-popup-content { font-size: 13px !important; margin: 10px 14px !important; }
.leaflet-popup-content b { color: var(--red); }

/* ============================================================
   REIS DE VALÈNCIA
   ============================================================ */
.reis-table td { vertical-align: top; padding: 11px 14px; }
.col-bio      { width: 160px; }
.col-noces    { width: 210px; }
.col-dinastia { width: 110px; white-space: nowrap; }
.rei-nom      { font-weight: 700; font-size: 14px; line-height: 1.3; }
.rei-sobrenom { font-style: italic; color: var(--text-3); font-size: 12.5px; margin-top: 1px; }
.rei-regnat   { font-size: 11.5px; color: var(--text-2); margin-top: 5px; line-height: 1.4; }
.rei-durada   { font-size: 10.5px; color: var(--text-3); margin-top: 1px; }
.rei-naix-data, .rei-mort-data { font-size: 13px; color: var(--text); }
.rei-naix-lloc, .rei-mort-lloc { font-size: 12px; color: var(--text-3); }
.rei-pares    { font-size: 11px; color: var(--text-3); font-style: italic; margin-top: 4px; line-height: 1.4; }
.rei-noces-item  { font-size: 12px; color: var(--text-2); padding: 2px 0; line-height: 1.4; }
.rei-noces-num   { color: var(--text-3); font-weight: 600; margin-right: 3px; }
.rei-noces-dates { color: var(--text-3); font-size: 11px; }

.nota-historica td {
  background: linear-gradient(to right, var(--nota-bg-1), var(--nota-bg-2));
  color: var(--text-2);
  font-size: 12.5px;
  font-style: italic;
  padding: 10px 16px;
  border-top: 1px solid var(--nota-border);
  border-bottom: 1px solid var(--nota-border);
  line-height: 1.6;
}
.nota-historica:hover td {
  background: linear-gradient(to right, var(--nota-bg-1), var(--nota-bg-2)) !important;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .mobile-header { display: flex; }
  .main-wrapper { margin-left: 0; }
  .main { padding: 24px 16px 40px; }
  .site-footer { padding: 16px; }
  .cards-grid { grid-template-columns: 1fr; }
  .card--wide { grid-column: auto; }
  .col-role, .col-reign { display: none; }
  .muni-layout { grid-template-columns: 1fr; height: auto; }
  .muni-list-panel { height: 280px; }
  .muni-map-panel { height: 360px; }
  .home-map-wrap { height: 280px; }
  .home-map-legend { display: none; }
  .territory-hero { grid-template-columns: 1fr; }
  .territory-map-wrap { height: 280px; }
  .section-nav-item { padding: 11px 14px; gap: 11px; }
  .global-search-input { font-size: 14px; padding: 12px 16px 12px 44px; }
  .sub-tabs { width: 100%; }
  .sub-tab { flex: 1; text-align: center; font-size: 12px; }
  .filter-select { width: 100%; }
}
