:root {
    color-scheme: light dark;
    --bg: #f6f7f9;
    --text: #20242a;
    --muted: #626b77;
    --line: #dfe3e8;
    --panel: #ffffff;
    --accent: #0b6bcb;
    --accent-dark: #084f99;
    --green-bg: #e6f4ec;
    --green-text: #126038;
    --yellow-bg: #fff5d6;
    --yellow-text: #7a4d00;
    --red-bg: #fde8e8;
    --red-text: #9b1c1c;
    --gray-bg: #edf0f3;
    --gray-text: #3f4650;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #101418;
        --text: #edf1f5;
        --muted: #a7b0bb;
        --line: #2a323b;
        --panel: #171c22;
        --accent: #73b7ff;
        --accent-dark: #4da2f4;
        --green-bg: #133324;
        --green-text: #8ee3b2;
        --yellow-bg: #3a2d10;
        --yellow-text: #f3ca67;
        --red-bg: #3b171b;
        --red-text: #f4a0a8;
        --gray-bg: #29313a;
        --gray-text: #c2cad3;
    }
}

:root[data-theme="light"] {
    --bg: #f6f7f9;
    --text: #20242a;
    --muted: #626b77;
    --line: #dfe3e8;
    --panel: #ffffff;
    --accent: #0b6bcb;
    --accent-dark: #084f99;
    --green-bg: #e6f4ec;
    --green-text: #126038;
    --yellow-bg: #fff5d6;
    --yellow-text: #7a4d00;
    --red-bg: #fde8e8;
    --red-text: #9b1c1c;
    --gray-bg: #edf0f3;
    --gray-text: #3f4650;
}

:root[data-theme="dark"] {
    --bg: #101418;
    --text: #edf1f5;
    --muted: #a7b0bb;
    --line: #2a323b;
    --panel: #171c22;
    --accent: #73b7ff;
    --accent-dark: #4da2f4;
    --green-bg: #133324;
    --green-text: #8ee3b2;
    --yellow-bg: #3a2d10;
    --yellow-text: #f3ca67;
    --red-bg: #3b171b;
    --red-text: #f4a0a8;
    --gray-bg: #29313a;
    --gray-text: #c2cad3;
}

* {
    box-sizing: border-box;
}

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

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

a:hover {
    text-decoration: underline;
}

.topbar {
    align-items: center;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    padding: 18px 28px;
}

.topbar h1 {
    font-size: 24px;
    line-height: 1.1;
    margin: 0;
}

.topbar p {
    color: var(--muted);
    margin: 5px 0 0;
}

.topbar nav {
    align-items: center;
    display: flex;
    gap: 16px;
}

.theme-toggle,
.notification-toggle {
    align-items: center;
    background: transparent;
    border: 1px solid var(--line);
    color: var(--muted);
    display: inline-flex;
    gap: 8px;
    margin: 0;
    padding: 5px 8px;
}

.theme-toggle:hover,
.notification-toggle:hover {
    background: var(--gray-bg);
}

.notification-toggle[aria-pressed="true"] {
    background: var(--green-bg);
    color: var(--green-text);
}

.notification-toggle.notification-blocked {
    background: var(--red-bg);
    color: var(--red-text);
}

.theme-toggle-track {
    background: var(--gray-bg);
    border-radius: 999px;
    display: inline-flex;
    height: 18px;
    padding: 2px;
    width: 34px;
}

.theme-toggle-thumb {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 999px;
    height: 14px;
    transform: translateX(0);
    transition: transform 0.16s ease;
    width: 14px;
}

.theme-toggle[aria-pressed="true"] .theme-toggle-thumb {
    transform: translateX(16px);
}

.theme-toggle-label {
    font-size: 12px;
    font-weight: 700;
}

.brand,
.login-brand {
    align-items: center;
    display: flex;
    gap: 12px;
}

.brand img,
.login-brand img {
    border-radius: 8px;
    flex: 0 0 auto;
}

main {
    margin: 0 auto;
    max-width: 1500px;
    padding: 24px;
}

.flash {
    border: 1px solid var(--line);
    margin-bottom: 14px;
    padding: 10px 12px;
}

.flash-success {
    background: var(--green-bg);
    color: var(--green-text);
}

.flash-error {
    background: var(--red-bg);
    color: var(--red-text);
}

.toolbar {
    align-items: center;
    display: flex;
    justify-content: space-between;
    margin-bottom: 14px;
}

.legend {
    display: flex;
    gap: 8px;
}

.filters {
    align-items: end;
    background: var(--panel);
    border: 1px solid var(--line);
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 14px;
    padding: 14px;
}

.filters label {
    color: var(--muted);
    display: grid;
    font-size: 12px;
    font-weight: 700;
    gap: 5px;
    text-transform: uppercase;
}

.filters input,
.filters select {
    min-width: 170px;
}

.filters input[type="search"] {
    min-width: 280px;
}

.pagination {
    align-items: center;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-bottom: 14px;
}

.pagination-bottom {
    margin-bottom: 0;
    margin-top: 14px;
}

.pagination a,
.pagination span,
.secondary-button {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    display: inline-block;
    padding: 7px 10px;
}

.pagination span {
    color: var(--muted);
}

.pagination strong {
    color: var(--muted);
    font-size: 13px;
}

.table-wrap {
    background: var(--panel);
    border: 1px solid var(--line);
    overflow-x: auto;
}

table {
    border-collapse: collapse;
    min-width: 1460px;
    width: 100%;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 12px 14px;
    text-align: left;
    vertical-align: top;
}

th {
    background: var(--gray-bg);
    color: var(--muted);
    font-size: 12px;
    letter-spacing: 0;
    text-transform: uppercase;
}

td strong {
    display: block;
    margin-bottom: 4px;
}

small,
.secondary-link,
.muted {
    color: var(--muted);
    display: block;
    font-size: 12px;
}

.secondary-link {
    align-items: center;
    display: inline-flex;
    gap: 4px;
}

.metrics-table {
    min-width: 360px;
    width: 100%;
}

.metrics-table th,
.metrics-table td {
    border-bottom: 0;
    font-size: 12px;
    padding: 3px 6px;
    text-align: right;
    white-space: nowrap;
}

.metrics-table th:first-child,
.metrics-table td:first-child {
    color: var(--muted);
    text-align: left;
}

.metrics-table thead th {
    background: transparent;
    color: var(--muted);
    text-transform: none;
}

.metric-change-positive {
    color: var(--green-text);
    font-weight: 700;
}

.metric-change-negative {
    color: var(--red-text);
    font-weight: 700;
}

.metric-change-neutral,
.metric-change-empty {
    color: var(--muted);
}

.score-badge {
    align-items: center;
    border-radius: 999px;
    display: inline-flex;
    font-size: 13px;
    font-weight: 800;
    justify-content: center;
    min-width: 36px;
    padding: 5px 8px;
}

.score-label {
    display: block;
    font-size: 13px;
    margin: 6px 0 4px;
}

.score-strong,
.score-interesting {
    background: var(--green-bg);
    color: var(--green-text);
}

.score-maybe {
    background: var(--yellow-bg);
    color: var(--yellow-text);
}

.score-low {
    background: var(--gray-bg);
    color: var(--gray-text);
}

.nowrap {
    white-space: nowrap;
}

.pill {
    border-radius: 999px;
    display: inline-block;
    font-size: 12px;
    font-weight: 700;
    margin: 0 0 6px;
    padding: 4px 8px;
    white-space: nowrap;
}

.status-not_analyzed,
.doc-missing,
.doc-pending,
.news-unknown {
    background: var(--gray-bg);
    color: var(--gray-text);
}

.status-queued,
.status-analyzing,
.news-maybe {
    background: var(--yellow-bg);
    color: var(--yellow-text);
}

.status-analyzed,
.doc-extracted,
.news-interesting {
    background: var(--green-bg);
    color: var(--green-text);
}

.status-failed,
.doc-failed,
.news-not_interesting {
    background: var(--red-bg);
    color: var(--red-text);
}

button,
input,
select {
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
}

button {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    cursor: pointer;
    margin-top: 6px;
    padding: 7px 10px;
}

.gemini-workflow-button {
    display: block;
    font-size: 12px;
    margin: 8px 0 4px;
    padding: 5px 8px;
}

.ai-action-form {
    margin: 8px 0 0;
}

.ai-generate-button {
    display: block;
    font-size: 12px;
    margin: 0;
    padding: 5px 8px;
}

.copy-ai-button {
    display: inline-block;
    font-size: 12px;
    margin: 8px 0 0;
    padding: 5px 8px;
}

.ai-draft {
    border-top: 1px solid var(--line);
    margin-top: 10px;
    padding-top: 8px;
}

.ai-draft summary {
    color: var(--accent);
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
}

.ai-article-body {
    background: var(--gray-bg);
    border: 1px solid var(--line);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    margin: 8px 0;
    max-height: 420px;
    overflow: auto;
    padding: 10px;
}

.ai-article-body h1 {
    font-size: 20px;
    line-height: 1.2;
    margin: 0 0 10px;
}

.ai-article-body h2 {
    border-top: 1px solid var(--line);
    font-size: 14px;
    line-height: 1.25;
    margin: 14px 0 7px;
    padding-top: 10px;
}

.ai-article-body h2:first-child {
    border-top: 0;
    margin-top: 0;
    padding-top: 0;
}

.ai-article-body p {
    margin: 0 0 9px;
}

.ai-article-body ul {
    margin: 0 0 10px 18px;
    padding: 0;
}

.ai-article-body li {
    margin-bottom: 5px;
}

.popup-hint {
    display: none;
    max-width: 260px;
}

.popup-hint.is-visible {
    display: block;
}

.popup-hint-warning {
    color: var(--yellow-text);
    font-weight: 700;
}

button:hover {
    background: var(--accent-dark);
}

button:disabled {
    background: var(--gray-bg);
    border-color: var(--line);
    color: var(--muted);
    cursor: not-allowed;
}

select {
    background: var(--panel);
    color: var(--text);
    min-width: 140px;
    padding: 7px 8px;
}

input {
    background: var(--panel);
    color: var(--text);
    padding: 7px 8px;
}

.empty {
    color: var(--muted);
    padding: 32px;
    text-align: center;
}

.login-page {
    background: var(--bg);
}

.login-shell {
    align-items: center;
    display: flex;
    min-height: 100vh;
    max-width: none;
    padding: 24px;
}

.login-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    margin: 0 auto;
    max-width: 560px;
    padding: 32px;
    width: 100%;
}

.login-panel h1 {
    font-size: 30px;
    line-height: 1.1;
    margin: 0;
}

.login-brand {
    margin-bottom: 14px;
}

.login-lede {
    color: var(--text);
    font-size: 18px;
    line-height: 1.45;
    margin: 0 0 22px;
}

.login-copy {
    color: var(--muted);
    line-height: 1.55;
    margin-bottom: 24px;
}

.login-copy p {
    margin: 0 0 10px;
}

.login-button {
    align-items: center;
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 6px;
    color: #fff;
    display: inline-flex;
    gap: 9px;
    font-weight: 700;
    padding: 10px 14px;
}

.login-button:hover {
    background: var(--accent-dark);
    text-decoration: none;
}

.google-mark {
    align-items: center;
    background: #fff;
    border-radius: 999px;
    color: #4285f4;
    display: inline-flex;
    font-family: Arial, sans-serif;
    font-weight: 700;
    height: 20px;
    justify-content: center;
    width: 20px;
}

.login-credit {
    color: var(--muted);
    font-size: 11px;
    margin: 12px 0 0;
}

.page-credit {
    color: var(--muted);
    font-size: 11px;
    margin: 22px 0 0;
    text-align: center;
}

.login-notice {
    background: var(--green-bg);
    color: var(--green-text);
    display: inline-block;
    font-size: 13px;
    font-weight: 700;
    margin: 0 0 16px;
    padding: 6px 9px;
}

@media (max-width: 760px) {
    body {
        font-size: 14px;
    }

    .topbar,
    .toolbar,
    .pagination {
        align-items: flex-start;
        flex-direction: column;
        gap: 12px;
    }

    .filters {
        align-items: stretch;
        padding: 12px;
    }

    .filters label,
    .filters input,
    .filters select,
    .filters button,
    .secondary-button {
        width: 100%;
    }

    main {
        padding: 14px;
    }

    .login-shell {
        min-height: 100vh;
        padding: 14px;
    }

    .login-panel {
        padding: 22px;
    }

    .login-panel h1 {
        font-size: 25px;
    }

    .login-lede {
        font-size: 16px;
    }

    .topbar {
        padding: 14px;
    }

    .topbar nav {
        flex-wrap: wrap;
    }

    .topbar h1 {
        font-size: 21px;
    }

    .table-wrap {
        background: transparent;
        border: 0;
        overflow-x: visible;
    }

    table {
        border-collapse: separate;
        border-spacing: 0;
        min-width: 0;
    }

    thead {
        display: none;
    }

    tbody,
    tr,
    td {
        display: block;
        width: 100%;
    }

    tr {
        background: var(--panel);
        border: 1px solid var(--line);
        margin-bottom: 12px;
        padding: 12px;
    }

    td {
        border-bottom: 0;
        padding: 0;
    }

    td + td {
        border-top: 1px solid var(--line);
        margin-top: 10px;
        padding-top: 10px;
    }

    td:nth-child(2),
    td:nth-child(3) {
        align-items: baseline;
        display: flex;
        justify-content: space-between;
        gap: 12px;
    }

    td:nth-child(2)::before {
        color: var(--muted);
        content: "Kommune";
        font-size: 12px;
        font-weight: 700;
        text-transform: uppercase;
    }

    td:nth-child(3)::before {
        color: var(--muted);
        content: "År";
        font-size: 12px;
        font-weight: 700;
        text-transform: uppercase;
    }

    .metrics-table {
        min-width: 0;
    }

    .metrics-table thead {
        display: table-header-group;
    }

    .metrics-table tbody {
        display: table-row-group;
    }

    .metrics-table tr {
        background: transparent;
        border: 0;
        display: table-row;
        margin: 0;
        padding: 0;
    }

    .metrics-table th,
    .metrics-table td {
        display: table-cell;
        padding: 4px 3px;
        width: auto;
    }

    .metrics-table td + td {
        border-top: 0;
        margin-top: 0;
        padding-top: 4px;
    }

    .metrics-table th {
        font-size: 11px;
    }

    .metrics-table td {
        font-size: 11px;
    }

    .metrics-table td:nth-child(2)::before,
    .metrics-table td:nth-child(3)::before {
        content: none;
    }
}
