:root {
  --bg: #fafaf7;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --bloc-EXG: #b91c1c;
  --bloc-GAU: #ef4444;
  --bloc-DIV: #a16207;
  --bloc-CENT: #d97706;
  --bloc-DTE: #2563eb;
  --bloc-EXD: #1e3a8a;
  --bloc-ECO: #16a34a;
  --bloc-abstention: #9ca3af;
  --bloc-blanc: #d1d5db;
  --bloc-nul: #6b7280;
  --bloc-blanc_nul: #9ca3af;
}
* { box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
       margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 24px; }
h1 { font-size: 28px; margin: 0 0 4px 0; font-weight: 700; }
h2 { font-size: 20px; margin: 0 0 16px 0; font-weight: 600; }
h3 { font-size: 16px; margin: 0 0 8px 0; font-weight: 600; }
.subtitle { color: var(--muted); margin-bottom: 32px; font-size: 14px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
         padding: 20px; margin-bottom: 24px; }
.panel-header { display: flex; justify-content: space-between; align-items: center;
                margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.muted { color: var(--muted); font-size: 13px; }
select { padding: 6px 10px; border: 1px solid var(--border); border-radius: 4px;
         background: white; font-size: 14px; cursor: pointer; }
.scenario-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
                 gap: 16px; }
@media (max-width: 900px) {
  .scenario-grid { grid-template-columns: 1fr; }
}
.scenario-card { background: #f9fafb; border-radius: 6px; padding: 14px; border-left: 3px solid var(--accent); }
.scenario-card h3 { color: var(--accent); }
.score-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 14px; }
.bar-track { flex: 1; height: 18px; background: #e5e7eb; border-radius: 3px;
             position: relative; overflow: hidden; }
.bar-cent { background: var(--bloc-CENT); height: 100%; transition: width .4s; }
.bar-exd  { background: var(--bloc-EXD);  height: 100%; transition: width .4s; }
.score-label { width: 80px; font-size: 13px; color: var(--muted); }
.score-value { width: 60px; text-align: right; font-weight: 600; }
.delta { font-size: 12px; padding: 2px 6px; border-radius: 3px; }
.delta-positive { background: #fef2f2; color: #991b1b; }
.delta-negative { background: #f0fdf4; color: #166534; }
.delta-small { background: #f3f4f6; color: var(--muted); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border);
     font-weight: 600; color: var(--muted); }
td { padding: 6px; border-bottom: 1px solid #f3f4f6; }
.bloc-pill { display: inline-block; padding: 2px 8px; border-radius: 10px;
             font-size: 11px; font-weight: 600; color: white; }
footer { text-align: center; color: var(--muted); font-size: 12px;
         padding: 24px 0; border-top: 1px solid var(--border); }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; flex-wrap: wrap; }
.tab { padding: 6px 14px; border: 1px solid var(--border); border-radius: 4px;
       background: var(--panel); cursor: pointer; font-size: 14px; }
.tab.active { background: var(--accent); color: white; border-color: var(--accent); }
.tooltip { position: absolute; background: rgba(0,0,0,.85); color: white;
           padding: 6px 10px; border-radius: 4px; font-size: 12px;
           pointer-events: none; opacity: 0; transition: opacity .2s; }
.svg-container { position: relative; }
.mtx-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 12px;
             font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.mtx-tools button { font-size: 12px; padding: 4px 10px; cursor: pointer;
                    border: 1px solid var(--border); background: white; border-radius: 4px; }
.mtx-tools button:hover { background: #f3f4f6; }
.mtx-status { margin-left: auto; }
.mtx-rows { display: flex; flex-direction: column; gap: 10px; }
.mtx-row  { display: flex; align-items: center; gap: 10px; }
.mtx-row-label { width: 64px; font-weight: 600; font-size: 13px; flex-shrink: 0;
                 text-align: right; }
.mtx-row-label.bad { color: #b91c1c; }
.mtx-row-bar { flex: 1 1 auto; position: relative; height: 26px;
               background: #f3f4f6; border-radius: 4px;
               overflow: visible; user-select: none; }
.mtx-seg { position: absolute; top: 0; bottom: 0; display: flex; align-items: center;
           justify-content: flex-start; padding: 0 6px; color: white;
           font-size: 11px; font-weight: 600; overflow: hidden; white-space: nowrap;
           transition: background .1s; }
.mtx-seg.light { color: #1f2937; }
.mtx-handle { position: absolute; top: -2px; bottom: -2px; width: 10px;
              transform: translateX(-50%); cursor: ew-resize;
              background: rgba(255,255,255,0.55);
              border-left: 1px solid rgba(0,0,0,0.35);
              border-right: 1px solid rgba(0,0,0,0.35);
              border-radius: 2px; z-index: 2; }
.mtx-handle:hover, .mtx-handle.active {
  background: rgba(37, 99, 235, 0.75);
  border-color: var(--accent); }
.mtx-row-total { width: 48px; font-size: 11px; color: var(--muted);
                 text-align: right; flex-shrink: 0; }
.mtx-row-total.bad { color: #b91c1c; font-weight: 600; }
.mtx-legend { display: flex; gap: 12px; flex-wrap: wrap; margin: 4px 0 10px;
              font-size: 11px; color: var(--muted); }
.mtx-legend .swatch { width: 10px; height: 10px; border-radius: 2px;
                       display: inline-block; vertical-align: middle; margin-right: 4px; }
.party-pick { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px 4px 10px;
              border-radius: 4px; color: white; font-size: 12px; font-weight: 600;
              white-space: nowrap; flex-shrink: 0; }
.party-pick select { font-size: 12px; padding: 2px 6px; border: none; border-radius: 3px;
                     background: white; color: var(--text); cursor: pointer; max-width: 220px; }
.legend-strip { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.legend-item { display: flex; align-items: center; gap: 4px; font-size: 12px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 2px; }
.live-badge { display: inline-flex; align-items: center; gap: 6px;
              font-size: 12px; padding: 3px 8px; border-radius: 10px;
              background: #ecfdf5; color: #065f46; border: 1px solid #6ee7b7; }
.live-badge.stale { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.live-badge.failed { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.live-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%;
                       background: #10b981; animation: pulse 2s ease-in-out infinite; }
.live-badge.stale::before  { background: #f59e0b; animation: none; }
.live-badge.failed::before { background: #ef4444; animation: none; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* Sankey + Matrix side-by-side grid */
.sankey-matrix-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 16px;
}

/* Portrait on mobile → show rotate prompt */
.rotate-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 9999;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  color: white;
  flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 32px;
}
.rotate-icon {
  font-size: 64px; margin-bottom: 16px;
  animation: rotate-hint 2s ease-in-out infinite;
}
@keyframes rotate-hint {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(90deg); }
}
@media (orientation: portrait) and (max-width: 900px) {
  .rotate-overlay { display: flex; }
}

/* ── App navigation bar ─────────────────────────────────────────────────── */
.app-nav {
  background: #0f172a;
  border-bottom: 1px solid #1e293b;
  position: sticky;
  top: 0;
  z-index: 200;
}
.app-nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  height: 44px;
  gap: 8px;
}
.app-nav-apps {
  display: flex;
  gap: 2px;
  flex: 1;
}
.app-nav-link {
  text-decoration: none;
  color: #94a3b8;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 4px;
  transition: all .15s;
}
.app-nav-link:hover { color: white; background: #1e293b; }
.app-nav-link.active { color: white; background: #1e40af; }
.lang-btn {
  background: none;
  border: 1px solid #334155;
  color: #94a3b8;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.lang-btn:hover { border-color: #64748b; color: white; }

/* ── Legislatives-specific layout ──────────────────────────────────────── */
/* 2-column grid used for hemicycle + seat table */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
@media (max-width: 680px) { .two-col { grid-template-columns: 1fr; } }

/* 50/50 Sankey+Matrix grid used in the legislatives panels */
.sankey-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
@media (max-width: 750px) { .sankey-grid { grid-template-columns: 1fr; } }

/* Horizontally scrollable matrix wrapper */
.matrix-wrap { overflow-x: auto; }

/* Legend as grid (better for many items) */
.legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 6px 14px;
  margin-bottom: 12px;
}
.ldot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}

/* Parliamentary-group seat table */
.seat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 8px;
}
.seat-table th {
  text-align: left;
  padding: 5px 9px;
  border-bottom: 2px solid var(--border);
  color: var(--muted);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.seat-table td { padding: 5px 9px; border-bottom: 1px solid #f1f5f9; }
.seat-table tr:last-child td { border-bottom: none; }

/* Coloured bullet in seat table */
.btag {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}

/* Methodology disclaimer box */
.disclaimer {
  background: #fffbeb;
  border: 1px solid #fbbf24;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 12px;
  color: #92400e;
  line-height: 1.6;
  margin-bottom: 24px;
}

/* ── Hemicycle + group-controls layout ──────────────────────────────────── */
.hemi-layout {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 700px) { .hemi-layout { grid-template-columns: 1fr; } }

/* ── Group controls panel ────────────────────────────────────────────────── */
.gc-reset-btn, .reset-btn {
  font-size: 11px;
  padding: 3px 10px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 4px;
  cursor: pointer;
  color: var(--muted);
  margin-top: 8px;
  display: inline-block;
}
.gc-reset-btn:hover, .reset-btn:hover { background: #f3f4f6; color: var(--text); }

/* Majority meter */
.majority-meter { margin-bottom: 12px; }
.majority-count-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}
.majority-num { font-size: 22px; font-weight: 700; color: var(--text); }
.maj-label { font-size: 11px; color: var(--muted); }
.majority-bar-wrap {
  position: relative;
  height: 10px;
  background: #e5e7eb;
  border-radius: 5px;
  overflow: visible;
  margin-bottom: 6px;
}
.majority-bar {
  height: 100%;
  border-radius: 5px;
  transition: width .35s;
  background: var(--accent);
}
.majority-bar.over { background: #16a34a; }
.majority-marker {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: #374151;
  border-radius: 1px;
}
.majority-verdict {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  display: inline-block;
}
.majority-verdict.has-majority { background: #dcfce7; color: #166534; }
.majority-verdict.no-majority  { background: #fef2f2; color: #991b1b; }

/* Group list rows */
.group-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 380px;
  overflow-y: auto;
}
.grp-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}
.grp-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 11.5px;
}
.grp-name.excluded { color: var(--muted); text-decoration: line-through; }
.grp-adj {
  display: flex;
  align-items: center;
  gap: 2px;
}
.adj-btn {
  width: 20px;
  height: 20px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 3px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--text);
}
.adj-btn:hover { background: #f3f4f6; }
.adj-btn:disabled { opacity: .35; cursor: default; }
.grp-count {
  width: 28px;
  text-align: right;
  font-weight: 600;
  font-size: 12px;
}
.grp-count.excluded { color: #9ca3af; }

/* CSS-only toggle switch */
.toggle-wrap {
  position: relative;
  width: 28px;
  height: 16px;
  flex-shrink: 0;
}
.toggle-wrap input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 8px;
  cursor: pointer;
  transition: background .2s;
}
.toggle-wrap input:checked + .toggle-track { background: var(--accent); }
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: white;
  transition: transform .2s;
  pointer-events: none;
}
.toggle-wrap input:checked + .toggle-track .toggle-thumb { transform: translateX(12px); }

/* Mobile landscape: tighten spacing */
@media (orientation: landscape) and (max-height: 520px) {
  .wrap { padding: 10px 12px; }
  h1 { font-size: 20px; }
  h2 { font-size: 15px; margin-bottom: 10px; }
  .panel { padding: 12px; margin-bottom: 12px; }
  .panel-header { margin-bottom: 10px; }
  .sankey-matrix-grid { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 10px; }
  .scenario-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
  footer { padding: 12px 0; }
}
