/* Puoluevertailu — editorial style */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --text:        #111;
    --text-muted:  #6b7280;
    --text-faint:  #9ca3af;
    --bg:          #f5f5f2;
    --bg-card:     #fff;
    --border:      #e5e5e5;
    --border-dark: #c8c8c8;
    --header-bg:   #13213a;
    --accent:      #1a56db;
    --font:        "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono:   "Tabular", "Roboto Mono", ui-monospace, monospace;
}

html { font-size: 16px; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ─── HEADER ─── */

header {
    background: var(--header-bg);
    color: #fff;
    padding: 0;
    border-bottom: 3px solid #2563eb;
}

.header-inner {
    max-width: 1440px;
    margin: 0 auto;
    padding: 1.4rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-brand {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.header-eyebrow {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #93c5fd;
    line-height: 1;
}

header h1 {
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    color: #fff;
    line-height: 1.15;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.kompassi-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 1rem;
    background: transparent;
    color: #93c5fd;
    text-decoration: none;
    border: 1px solid #334d80;
    border-radius: 4px;
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.kompassi-link:hover {
    background: rgba(147, 197, 253, 0.12);
    border-color: #93c5fd;
    color: #fff;
}

/* ─── MAIN ─── */

main {
    flex: 1;
    max-width: 1440px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem 2rem 3rem;
}

/* ─── CONTROLS ─── */

.controls-wrap {
    margin-bottom: 1.75rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1.25rem;
}

.search-wrap { flex: 1; min-width: 180px; max-width: 380px; }

.search-input {
    width: 100%;
    padding: 0.5rem 0.9rem;
    border: 1px solid var(--border-dark);
    border-radius: 4px;
    font-family: var(--font);
    font-size: 0.9rem;
    background: #fff;
    color: var(--text);
    outline: none;
    transition: border-color 0.15s;
}

.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-faint); }

.sorting-controls {
    display: flex;
    align-items: center;
    gap: 0;
    border: 1px solid var(--border-dark);
    border-radius: 4px;
    overflow: hidden;
    background: #fff;
}

.sort-label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0 0.75rem;
    border-right: 1px solid var(--border);
    white-space: nowrap;
    align-self: stretch;
    display: flex;
    align-items: center;
}

.sort-button {
    padding: 0.45rem 0.9rem;
    background: transparent;
    border: none;
    border-right: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 500;
    transition: background 0.12s, color 0.12s;
    line-height: 1;
    white-space: nowrap;
}

.sort-button:last-child { border-right: none; }

.sort-button:hover {
    background: #f0f4ff;
    color: var(--text);
}

.sort-button.active {
    background: var(--header-bg);
    color: #fff;
    font-weight: 600;
}

/* ─── GRID ─── */

.parties-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1.25rem;
}

.no-results {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-muted);
    font-size: 1rem;
    padding: 3rem 0;
}

/* ─── PARTY CARD ─── */

.party-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-top: 3px solid;          /* color set inline per party */
    border-radius: 2px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.15s;
}

.party-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}

/* ─── CARD HEADER ─── */

.party-header {
    padding: 1rem 1.1rem 0.75rem;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}

.party-name-block { flex: 1; min-width: 0; }

.party-name {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
    display: block;
    line-height: 1.3;
}

.party-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.party-color-swatch {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ─── BADGES ─── */

.party-badges {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.3rem;
    flex-shrink: 0;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border-radius: 2px;
    white-space: nowrap;
}

.badge-hallitus {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.badge-oppositio {
    background: #fafafa;
    color: #78350f;
    border: 1px solid #e5e7eb;
}

.badge-ideologia {
    background: transparent;
    border: 1px solid var(--border-dark);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: none;
    font-size: 0.7rem;
    letter-spacing: 0;
}

/* ─── KANNATUS BAR ─── */

.kannatus-bar-wrap {
    height: 3px;
    background: #f0f0ee;
    margin: 0;
}

.kannatus-bar {
    height: 100%;
    transition: width 0.5s ease;
}

/* ─── STATS ─── */

.party-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.stat {
    padding: 0.85rem 1.1rem;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.stat:last-child { border-right: none; }

.stat-value {
    font-size: 1.45rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.stat-trend {
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1;
}

.trend-up     { color: #15803d; }
.trend-down   { color: #b91c1c; }
.trend-neutral { color: var(--text-muted); }

.stat-label {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-faint);
    margin-top: 0.15rem;
}

/* ─── PARTY INFO ─── */

.party-info {
    padding: 0.9rem 1.1rem 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    flex: 1;
}

.info-section {}

.info-label {
    display: block;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-faint);
    margin-bottom: 0.2rem;
}

.leader-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
}

.eu-ryhma-name {
    font-size: 0.88rem;
    color: #374151;
}

.ohjelma-tavoite {
    font-size: 0.85rem;
    font-style: italic;
    color: #4b5563;
    line-height: 1.5;
    margin-bottom: 0.5rem;
    border-left: 2px solid var(--border-dark);
    padding-left: 0.65rem;
}

.painopisteet {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.painopisteet li {
    font-size: 0.83rem;
    color: #374151;
    padding-left: 1rem;
    position: relative;
    line-height: 1.4;
}

.painopisteet li::before {
    content: "–";
    position: absolute;
    left: 0;
    color: var(--text-faint);
}

.puolue-linkki {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
    color: var(--accent);
    margin-top: auto;
    transition: opacity 0.15s;
}

.puolue-linkki:hover { opacity: 0.7; text-decoration: underline; }

/* ─── FOOTER ─── */

footer {
    background: var(--header-bg);
    color: #6b7280;
    border-top: 1px solid #1e3a5f;
    padding: 1.5rem 2rem;
}

.footer-inner {
    max-width: 1440px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    font-size: 0.8rem;
}

.footer-inner a {
    color: #93c5fd;
    text-decoration: none;
}

.footer-inner a:hover { text-decoration: underline; }

.footer-source {
    color: #4b5563;
    font-size: 0.75rem;
}

/* ─── HALLITUKSEN RAKENTAJA ─── */

.builder-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 1rem;
    background: transparent;
    color: #93c5fd;
    border: 1px solid #334d80;
    border-radius: 4px;
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.builder-toggle-btn:hover {
    background: rgba(147, 197, 253, 0.12);
    border-color: #93c5fd;
    color: #fff;
}

.builder-toggle-btn.active {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

.builder-panel {
    max-width: 1440px;
    width: 100%;
    margin: 0 auto;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease, padding 0.35s ease;
    background: #fff;
    border-bottom: 1px solid var(--border);
}

.builder-panel.open {
    max-height: 2000px;
    padding: 1.5rem 2rem 2rem;
}

.builder-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.builder-header h2 {
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text);
}

.builder-subtitle {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

.builder-close {
    background: none;
    border: none;
    font-size: 1.6rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 0.3rem;
    line-height: 1;
    transition: color 0.15s;
}

.builder-close:hover { color: var(--text); }

.builder-parties {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.builder-party-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.85rem;
    background: #fff;
    border: 2px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.builder-party-btn:hover {
    border-color: var(--party-color);
    background: #fafafa;
}

.builder-party-btn.selected {
    border-color: var(--party-color);
    background: color-mix(in srgb, var(--party-color) 8%, #fff);
    transform: scale(1.03);
}

.builder-party-swatch {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.builder-party-name {
    font-weight: 700;
}

.builder-party-seats {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-left: 0.15rem;
}

.builder-party-btn.selected .builder-party-seats {
    color: var(--text);
}

/* Meter */

.builder-meter {
    margin-bottom: 1rem;
}

.meter-bar {
    position: relative;
    height: 10px;
    background: #f0f0ee;
    border-radius: 2px;
    overflow: visible;
}

.meter-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.4s ease, background 0.3s;
}

.meter-fill.majority {
    background: #15803d;
}

.meter-majority-line {
    position: absolute;
    top: -4px;
    bottom: -4px;
    width: 2px;
    background: #b91c1c;
    z-index: 1;
}

.meter-majority-label {
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.65rem;
    font-weight: 700;
    color: #b91c1c;
    white-space: nowrap;
}

.meter-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
}

.meter-seats {
    font-size: 1.1rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.meter-seats.has-majority { color: #15803d; }
.meter-seats.no-majority { color: var(--text); }

.meter-status {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* Seat bar */

.seat-bar-wrap {
    margin-bottom: 1.25rem;
}

.seat-bar {
    display: flex;
    height: 24px;
    border-radius: 3px;
    overflow: hidden;
    gap: 1px;
}

.seat-segment {
    transition: width 0.4s ease;
    min-width: 2px;
}

/* Builder hint */

.builder-hint {
    color: var(--text-muted);
    font-size: 0.88rem;
    font-style: italic;
    padding: 1rem 0;
}

/* Analysis */

.analysis {
    border-top: 1px solid var(--border);
    padding-top: 1.25rem;
}

.analysis-title {
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: -0.01em;
    margin-bottom: 1rem;
    color: var(--text);
}

.analysis-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.analysis-card {
    background: #fafafa;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1rem;
}

.analysis-label {
    display: block;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-faint);
    margin-bottom: 0.35rem;
}

.analysis-verdict {
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1.4;
    margin-bottom: 0.5rem;
}

.verdict-ok   { color: #15803d; }
.verdict-warn { color: #b45309; }
.verdict-bad  { color: #b91c1c; }

.analysis-detail {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.analysis-conflicts,
.analysis-tensions {
    margin-bottom: 1rem;
}

.conflict-pair,
.tension-pair {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.3rem 0;
}

.conflict-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.conflict-x {
    color: #b91c1c;
    font-weight: 800;
    font-size: 0.9rem;
}

.tension-dash {
    color: #b45309;
    font-weight: 800;
}

.conflict-desc { color: #b91c1c; font-weight: 500; font-size: 0.8rem; }
.tension-desc  { color: #b45309; font-weight: 500; font-size: 0.8rem; }

.analysis-ideologies {
    margin-bottom: 0.5rem;
}

.ideology-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.35rem;
}

.ideology-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.6rem;
    border: 1px solid;
    border-radius: 3px;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text);
    background: #fff;
}

/* ─── RESPONSIVE ─── */

@media (max-width: 900px) {
    .parties-container {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }
}

@media (max-width: 640px) {
    .header-inner { padding: 1rem; }

    header h1 { font-size: 1.3rem; }

    main { padding: 1rem 1rem 2rem; }

    .builder-panel.open { padding: 1rem; }

    .analysis-grid { grid-template-columns: 1fr; }

    .controls-wrap { flex-direction: column; align-items: stretch; gap: 0.75rem; }

    .search-wrap { max-width: 100%; }

    .sorting-controls { width: 100%; }

    .sort-label { display: none; }

    .parties-container { grid-template-columns: 1fr; gap: 1rem; }
}

@media (max-width: 360px) {
    .party-stats {
        grid-template-columns: 1fr 1fr;
    }
    .party-stats .stat:nth-child(2) { border-right: none; }
    .party-stats .stat:nth-child(3) {
        grid-column: 1 / -1;
        border-right: none;
        border-top: 1px solid var(--border);
    }
}
