:root {
    --bg: #f6f7f9;
    --panel: #fff;
    --ink: #17212b;
    --muted: #66717d;
    --line: #dce2e8;
    --teal: #0f766e;
    --blue: #2454a6;
    --amber: #9a5b00;
    --red: #9b2c2c;
    --soft-teal: #e6f4f1;
    --soft-blue: #e9eefb;
    --soft-amber: #fff3d9;
    --shadow: 0 10px 30px rgba(23, 33, 43, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

a {
    color: var(--blue);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

header {
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}

.topbar,
main {
    width: min(1440px, 100%);
    margin: 0 auto;
    padding: 18px 22px;
}

.topbar {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) auto;
    gap: 18px;
    align-items: center;
}

h1,
h2,
h3,
h4,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 4px;
    font-size: 21px;
    line-height: 1.2;
    letter-spacing: 0;
}

.subtitle {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(88px, 1fr));
    gap: 8px;
}

.stat {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 11px;
    background: #fbfcfd;
}

.stat strong {
    display: block;
    font-size: 18px;
    line-height: 1.1;
}

.stat span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
    white-space: nowrap;
}

main {
    display: grid;
    grid-template-columns: 380px minmax(0, 1fr);
    gap: 18px;
    padding-top: 18px;
    padding-bottom: 30px;
}

.toolbar,
.detail-shell {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.toolbar {
    padding: 14px;
    display: grid;
    gap: 12px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 700;
    color: #34424f;
}

input[type="search"] {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px 12px;
    font: inherit;
    color: var(--ink);
    background: #fff;
    outline: none;
}

input[type="search"]:focus {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.segmented {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.segmented button {
    min-height: 38px;
    border: 0;
    border-right: 1px solid var(--line);
    background: #fff;
    color: var(--muted);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.segmented button:last-child {
    border-right: 0;
}

.segmented button.active {
    background: var(--soft-teal);
    color: var(--teal);
}

.municipality-list {
    margin-top: 14px;
    display: grid;
    gap: 8px;
    max-height: calc(100vh - 230px);
    overflow: auto;
    padding-right: 3px;
}

.municipality-button {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--ink);
    padding: 12px;
    text-align: left;
    cursor: pointer;
    display: grid;
    gap: 7px;
}

.municipality-button:hover,
.municipality-button.active {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.1);
}

.name-line,
.detail-title,
.meta-line,
.links {
    display: flex;
    gap: 8px;
}

.name-line,
.detail-title {
    align-items: flex-start;
    justify-content: space-between;
}

.meta-line,
.links {
    flex-wrap: wrap;
    align-items: center;
}

.province {
    color: var(--muted);
    font-size: 12px;
    flex: 0 0 auto;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 23px;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 12px;
    font-weight: 720;
    color: #34424f;
    background: #eef1f4;
}

.badge.official {
    color: var(--teal);
    background: var(--soft-teal);
}

.badge.public {
    color: var(--blue);
    background: var(--soft-blue);
}

.badge.missing {
    color: var(--red);
    background: #fae8e8;
}

.badge.money {
    color: var(--amber);
    background: var(--soft-amber);
}

.detail-shell {
    min-height: calc(100vh - 130px);
    overflow: hidden;
}

.detail-head {
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
}

.detail-title h2 {
    margin-bottom: 4px;
    font-size: 24px;
    line-height: 1.18;
    letter-spacing: 0;
}

.detail-body {
    padding: 16px 20px 22px;
    display: grid;
    gap: 14px;
}

.scheme {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    display: grid;
    gap: 13px;
    background: #fff;
}

.subsidy-card {
    border-left: 4px solid #10b981;
}

.subsidy-card-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 14px;
    align-items: start;
}

.subsidy-card-head h3 {
    margin-bottom: 7px;
}

.card-amount {
    color: #062960;
    text-align: right;
    min-width: 104px;
}

.card-amount strong {
    display: block;
    font-size: 17px;
    line-height: 1.2;
}

.card-amount span {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
}

.benefit-rows {
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    background: #f8fafc;
}

.benefit-row {
    min-height: 34px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 7px 10px;
    border-bottom: 1px solid var(--line);
}

.benefit-row:last-child {
    border-bottom: 0;
}

.benefit-row strong {
    color: #062960;
    white-space: nowrap;
}

.eligibility-panel {
    display: grid;
    gap: 8px;
}

.eligibility-status {
    border: 1px solid #86efac;
    border-radius: 8px;
    padding: 8px 10px;
    color: #047857;
    background: #ecfdf5;
    font-weight: 740;
}

.eligibility-status.neutral {
    color: var(--blue);
    border-color: #bfdbfe;
    background: #eff6ff;
}

.eligibility-status.warning {
    color: var(--amber);
    border-color: #facc15;
    background: #fffbeb;
}

.eligibility-status.blocked {
    color: var(--red);
    border-color: #fca5a5;
    background: #fff6f6;
}

.eligibility-status.success {
    color: #047857;
    border-color: #86efac;
    background: #ecfdf5;
}

.card-check-list {
    margin: 0;
    padding: 0;
    list-style: none;
    color: #34424f;
    display: grid;
    gap: 6px;
}

.card-check-list li {
    display: grid;
    grid-template-columns: 16px minmax(0, 1fr);
    gap: 6px;
    align-items: start;
}

.check-dot {
    width: 13px;
    height: 13px;
    margin-top: 3px;
    border: 1.5px solid #10b981;
    border-radius: 999px;
    position: relative;
}

.check-dot::after {
    content: "";
    position: absolute;
    left: 3px;
    top: 2px;
    width: 5px;
    height: 3px;
    border-left: 1.5px solid #10b981;
    border-bottom: 1.5px solid #10b981;
    transform: rotate(-45deg);
}

.card-check-list.neutral .check-dot,
.card-check-list.neutral .check-dot::after {
    border-color: var(--blue);
}

.card-check-list.warning .check-dot,
.card-check-list.warning .check-dot::after {
    border-color: var(--amber);
}

.card-check-list.blocked .check-dot,
.card-check-list.blocked .check-dot::after {
    border-color: var(--red);
}

.card-details {
    border-top: 1px solid var(--line);
    padding-top: 8px;
}

.card-details summary {
    color: var(--blue);
    cursor: pointer;
    font-weight: 720;
}

.card-details ul {
    margin: 8px 0 0;
    padding-left: 18px;
    color: #34424f;
}

.card-details li {
    margin: 5px 0;
}

.scheme h3 {
    margin-bottom: 8px;
    font-size: 17px;
    line-height: 1.3;
    letter-spacing: 0;
}

.scheme p {
    margin-bottom: 0;
    color: #293742;
}

.amount {
    color: #293742;
    background: #fbfcfd;
    border-left: 4px solid var(--amber);
    padding: 10px 12px;
    border-radius: 6px;
}

.quick-facts {
    margin-top: 12px;
    padding: 12px 14px;
    border-left: 4px solid var(--teal);
    border-radius: 6px;
    background: #f7fbfa;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 12px 20px;
}

.quick-fact {
    min-width: 0;
}

.quick-fact h4 {
    margin-bottom: 6px;
    font-size: 13px;
    color: #24443f;
}

.quick-fact ul {
    margin: 0;
    padding-left: 18px;
    color: #293742;
}

.quick-fact li {
    margin: 5px 0;
}

.source-note {
    margin-top: 10px;
    color: var(--muted);
    font-size: 13px;
}

.source-details {
    border-top: 1px solid var(--line);
    padding-top: 10px;
}

.source-details[open] {
    display: grid;
    gap: 10px;
}

.source-details summary {
    color: var(--blue);
    cursor: pointer;
    font-weight: 720;
}

.group h4 {
    margin-bottom: 6px;
    font-size: 13px;
    color: #34424f;
}

.condition-list {
    margin: 0;
    padding-left: 19px;
    color: #293742;
}

.condition-list li {
    margin: 6px 0;
}

.article {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.empty,
.error {
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 20px;
    color: var(--muted);
    background: #fbfcfd;
}

.error {
    color: var(--red);
    border-color: #f1c3c3;
    background: #fff6f6;
}

@media (max-width: 1020px) {
    .topbar,
    main {
        grid-template-columns: 1fr;
    }

    .stats {
        grid-template-columns: repeat(2, minmax(120px, 1fr));
    }

    .municipality-list {
        max-height: 42vh;
    }
}

@media (max-width: 560px) {
    .topbar,
    main {
        padding-left: 12px;
        padding-right: 12px;
    }

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

    .detail-title {
        display: grid;
    }

    .subsidy-card-head,
    .benefit-row {
        grid-template-columns: 1fr;
    }

    .card-amount {
        text-align: left;
    }

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

    .segmented button {
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }
}
