:root {
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #101828;
    --muted: #4b5563;
    --line: #dbe4ef;
    --brand-blue: #1e3a8a;
    --brand-blue-soft: #dbeafe;
    --brand-orange: #9a3412;
    --brand-orange-soft: #fef2e8;
    --brand-green: #166534;
    --brand-green-soft: #dcfce7;
    --brand-red: #be485d;
    --brand-red-soft: #fdecef;
    --shadow: 0 12px 32px rgba(15, 23, 42, 0.07);
    --shadow-soft: 0 6px 18px rgba(15, 23, 42, 0.05);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    background:
        radial-gradient(circle at top right, rgba(30, 58, 138, 0.11), transparent 30%),
        radial-gradient(circle at top left, rgba(154, 52, 18, 0.06), transparent 22%),
        linear-gradient(180deg, #f8fbff 0%, #f2f6fb 100%);
    color: var(--text);
}

.page-shell {
    width: min(1080px, calc(100% - 48px));
    margin: 24px auto 40px;
}

.hero-card,
.card,
.actions-card {
    position: relative;
    overflow: hidden;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
}

.hero-card {
    padding: 22px 24px;
    margin-bottom: 20px;
    border-color: rgba(30, 58, 138, 0.14);
    background: linear-gradient(180deg, rgba(246, 250, 255, 0.98) 0%, #ffffff 100%);
}

.hero-card::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 4px;
    background: linear-gradient(90deg, rgba(30, 58, 138, 0.96), rgba(30, 58, 138, 0.42) 58%, rgba(154, 52, 18, 0.3));
}

.hero-card::after {
    content: "";
    position: absolute;
    right: -64px;
    top: -82px;
    width: 280px;
    height: 280px;
    background: radial-gradient(circle, rgba(30, 58, 138, 0.11) 0%, rgba(30, 58, 138, 0) 72%);
    pointer-events: none;
}

.card {
    padding: 20px;
    margin-bottom: 18px;
    background: linear-gradient(180deg, rgba(252, 253, 255, 0.98) 0%, #ffffff 100%);
}

.actions-card {
    display: flex;
    gap: 12px;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
    padding: 16px 20px;
    border-color: rgba(30, 58, 138, 0.14);
    background: linear-gradient(180deg, rgba(244, 248, 255, 0.98) 0%, #ffffff 100%);
    box-shadow: var(--shadow-soft);
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    margin: 0 0 12px;
    padding: 6px 11px;
    border-radius: 999px;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--brand-blue);
    font-weight: 700;
    background: rgba(219, 234, 254, 0.76);
}

h1 {
    margin: 0 0 12px;
    font-size: clamp(26px, 3.2vw, 34px);
    line-height: 1.08;
    letter-spacing: -0.03em;
    max-width: none;
}

h2 {
    margin: 0 0 6px;
    font-size: 20px;
    color: var(--brand-blue);
    letter-spacing: -0.02em;
}

.intro,
.card-heading p {
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}

.intro {
    max-width: 44rem;
    font-size: 15px;
    color: #41536b;
}

.card-heading p {
    color: #566273;
}

.card-heading {
    margin-bottom: 18px;
}

.note {
    margin: 14px 0 0;
    padding: 13px 15px;
    border-radius: 10px;
    border: 1px solid rgba(30, 58, 138, 0.12);
    font-size: 14px;
    line-height: 1.5;
    background: linear-gradient(180deg, rgba(235, 244, 255, 0.92) 0%, rgba(255, 255, 255, 0.96) 100%);
    color: var(--brand-blue);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.note.is-hidden {
    display: none;
}

.note-warm {
    border-color: rgba(154, 52, 18, 0.14);
    background: linear-gradient(180deg, rgba(254, 242, 232, 0.94) 0%, rgba(255, 255, 255, 0.96) 100%);
    color: var(--brand-orange);
}

.is-hidden {
    display: none !important;
}

.top-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 20px 0 0;
    padding: 12px 14px;
    border: 1px solid rgba(30, 58, 138, 0.12);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(245, 248, 255, 0.96) 0%, rgba(255, 255, 255, 0.92) 100%);
}

.top-action-buttons {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    padding: 7px 12px;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
}

.status-pill-active {
    color: var(--brand-green);
    background: rgba(220, 252, 231, 0.82);
    border-color: rgba(22, 101, 52, 0.14);
}

.status-pill-inactive {
    color: var(--brand-red);
    background: rgba(253, 236, 239, 0.84);
    border-color: rgba(190, 72, 93, 0.16);
}

.flow-banner {
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 16px;
    margin: 15px 0 0;
    padding: 15px 17px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(248, 250, 252, 0.96) 0%, rgba(255, 255, 255, 0.96) 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.flow-banner.is-hidden {
    display: none;
}

.flow-banner-copy strong {
    display: block;
    margin-bottom: 6px;
    font-size: 15px;
}

.flow-banner-copy p {
    margin: 0;
    color: var(--muted);
    line-height: 1.5;
}

.flow-banner-warm {
    background: linear-gradient(180deg, rgba(254, 242, 232, 0.94) 0%, rgba(255, 255, 255, 0.96) 100%);
    border-color: rgba(154, 52, 18, 0.16);
    color: var(--brand-orange);
}

.flow-banner-warm .flow-banner-copy p {
    color: #7c2d12;
}

.flow-banner-success {
    background: linear-gradient(180deg, rgba(220, 252, 231, 0.94) 0%, rgba(255, 255, 255, 0.96) 100%);
    border-color: rgba(22, 101, 52, 0.16);
    color: var(--brand-green);
}

.flow-banner-success .flow-banner-copy p {
    color: #166534;
}

.toggle-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 12px;
}

.toggle-card,
.source-card {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    padding: 16px;
    border: 1px solid rgba(219, 228, 239, 0.92);
    border-radius: 12px;
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.toggle-card input {
    flex: 0 0 auto;
    margin-top: 2px;
    width: 24px;
    height: 24px;
    accent-color: var(--brand-blue);
}

.source-card input {
    flex: 0 0 auto;
    margin-top: 3px;
    width: 18px;
    height: 18px;
    accent-color: var(--brand-blue);
}

.toggle-card strong,
.source-card strong {
    display: block;
    margin-bottom: 4px;
}

.toggle-card > span,
.source-card > span {
    min-width: 0;
    flex: 1;
}

.toggle-card small,
.source-card small {
    color: var(--muted);
}

.sources-root {
    display: grid;
    gap: 22px;
}

.category-card {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 18px;
    background: linear-gradient(180deg, rgba(249, 251, 255, 0.98) 0%, #ffffff 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.78);
}

.category-card h3 {
    margin: 0;
    font-size: 18px;
}

.category-card p {
    margin: 0 0 18px;
    color: #5d6777;
    font-size: 14px;
}

.category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 8px;
}

.category-title {
    color: var(--brand-blue);
}

.category-card-authorities {
    border-color: rgba(154, 52, 18, 0.1);
    background: linear-gradient(180deg, rgba(255, 252, 248, 0.76) 0%, #ffffff 100%);
}

.category-card-authorities::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 2px;
    background: linear-gradient(90deg, rgba(154, 52, 18, 0.46), rgba(154, 52, 18, 0.16) 72%, rgba(154, 52, 18, 0));
}

.category-card-authorities .category-title {
    color: var(--brand-orange);
}

.category-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.category-action {
    appearance: none;
    border: 1px solid rgba(148, 163, 184, 0.2);
    padding: 6px 10px;
    background: rgba(248, 250, 252, 0.88);
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.category-action-select {
    color: var(--brand-green);
}

.category-action-clear {
    color: var(--brand-red);
}

.category-action:hover {
    text-decoration: none;
    background: rgba(241, 245, 249, 0.96);
}

.sources-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 22px;
    padding: 0 9px;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.02em;
}

.source-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 5px;
}

.source-name {
    display: inline-block;
    line-height: 1.35;
}

.source-badges {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
}

.toggle-card input:checked + span strong,
.source-card input:checked + span .source-name {
    color: var(--brand-blue);
}

.category-card-authorities .source-card input:checked + span .source-name {
    color: var(--brand-orange);
}

.pill-format {
    color: #1d4ed8;
    background: rgba(219, 234, 254, 0.56);
    border-color: rgba(30, 58, 138, 0.12);
}

.pill-authorities {
    color: var(--brand-orange);
    background: rgba(254, 242, 232, 0.72);
    border-color: rgba(154, 52, 18, 0.1);
}

.button {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.button:disabled {
    cursor: wait;
    opacity: 0.65;
}

.button-primary {
    background: var(--brand-blue);
    color: #ffffff;
    box-shadow: 0 10px 22px rgba(30, 58, 138, 0.18);
}

.button-success {
    background: var(--brand-green);
    color: #ffffff;
}

.button-success-soft {
    background: rgba(220, 252, 231, 0.84);
    color: var(--brand-green);
    border-color: rgba(22, 101, 52, 0.14);
}

.button-danger {
    background: rgba(253, 236, 239, 0.78);
    color: var(--brand-red);
    border-color: rgba(190, 72, 93, 0.16);
}

.button-secondary {
    background: rgba(241, 245, 249, 0.92);
    color: #475569;
    border-color: rgba(100, 116, 139, 0.18);
    box-shadow: none;
}

.actions-card .button-primary {
    min-width: 168px;
}

.actions-card .button-danger {
    background: rgba(255, 255, 255, 0.72);
    color: #a24a5e;
    border-color: rgba(190, 72, 93, 0.14);
    box-shadow: none;
}

@supports selector(:has(*)) {
    .toggle-card:has(input:checked),
    .source-card:has(input:checked) {
        border-color: rgba(30, 58, 138, 0.28);
        background: linear-gradient(180deg, rgba(239, 246, 255, 0.88) 0%, #ffffff 100%);
        box-shadow: 0 10px 24px rgba(30, 58, 138, 0.1);
    }

    .category-card-authorities .source-card:has(input:checked) {
        border-color: rgba(154, 52, 18, 0.16);
        background: linear-gradient(180deg, rgba(254, 242, 232, 0.56) 0%, #ffffff 100%);
        box-shadow: 0 8px 20px rgba(154, 52, 18, 0.06);
    }
}

@media (min-width: 641px) {
    .hero-card h1 {
        white-space: nowrap;
    }
}

@media (hover: hover) {
    .toggle-card:hover,
    .source-card:hover {
        border-color: rgba(30, 58, 138, 0.2);
        box-shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
        transform: translateY(-1px);
    }

    .category-action:hover {
        border-color: rgba(30, 58, 138, 0.2);
    }

    .button:not(:disabled):hover {
        transform: translateY(-1px);
    }
}

@media (max-width: 640px) {
    .page-shell {
        width: min(100% - 20px, 1080px);
        margin-top: 20px;
    }

    .hero-card,
    .card,
    .actions-card {
        padding: 18px;
        border-radius: 12px;
    }

    .hero-card::after {
        right: -92px;
        top: -102px;
        width: 220px;
        height: 220px;
    }

    .actions-card {
        flex-direction: column;
        align-items: stretch;
    }

    .top-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .category-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .source-title-row {
        align-items: flex-start;
        flex-direction: column;
    }

    .flow-banner {
        align-items: stretch;
        flex-direction: column;
    }

    h1 {
        max-width: none;
        white-space: normal;
    }
}
