:root {
    color-scheme: light;
    --background: #f3f5f8;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --text: #162033;
    --muted: #647084;
    --border: #dfe4eb;
    --primary: #1f5eff;
    --primary-hover: #174bd1;
    --success: #16825d;
    --danger: #b4233b;
    --shadow: 0 18px 60px rgba(24, 37, 61, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--background);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

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

a:hover {
    text-decoration: underline;
}

button,
input,
select,
textarea {
    font: inherit;
}

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 72px;
    padding: 0 32px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: var(--text);
    font-weight: 700;
    letter-spacing: -0.01em;
}

.brand:hover {
    text-decoration: none;
}

.brand-mark {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 11px;
    background: var(--primary);
    color: #fff;
    font-size: 13px;
    letter-spacing: 0.03em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 20px;
    font-size: 14px;
}

.header-actions form {
    margin: 0;
}

.account-name {
    color: var(--muted);
}

.link-button {
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--primary);
    cursor: pointer;
}

.link-button:hover {
    text-decoration: underline;
}

.page-shell {
    width: min(1180px, calc(100% - 48px));
    margin: 0 auto;
    padding: 56px 0 80px;
}

.page-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 32px;
}

.compact-heading {
    align-items: flex-start;
}

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

h1 {
    margin-bottom: 8px;
    font-size: clamp(30px, 4vw, 44px);
    line-height: 1.1;
    letter-spacing: -0.04em;
}

h2 {
    margin-bottom: 8px;
    font-size: 20px;
}

.eyebrow {
    margin-bottom: 10px;
    color: var(--primary);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

.muted,
.status-detail {
    color: var(--muted);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 0 14px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.status-shadow {
    background: #e9efff;
    color: #244eb8;
}

.status-ok {
    background: #e6f7f0;
    color: var(--success);
}

.status-warning {
    background: #fff4dd;
    color: #8a5a00;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.status-card,
.notice-panel,
.form-panel {
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: 0 4px 20px rgba(24, 37, 61, 0.04);
}

.status-card {
    display: flex;
    min-height: 172px;
    flex-direction: column;
    padding: 24px;
}

.status-label {
    margin-bottom: auto;
    color: var(--muted);
    font-size: 13px;
}

.status-card strong {
    margin-bottom: 5px;
    font-size: 20px;
}

.status-detail {
    font-size: 13px;
}

.ok {
    color: var(--success);
}

.error {
    color: var(--danger);
}

.notice-panel {
    margin-top: 20px;
    padding: 28px;
    background: var(--surface-muted);
}

.secondary-status-grid,
.source-summary {
    margin-top: 16px;
}

.panel-section {
    margin-top: 32px;
    padding: 28px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: 0 4px 20px rgba(24, 37, 61, 0.04);
}

.section-heading,
.source-card-heading,
.source-footer,
.query-row,
.inline-actions,
.inline-form,
.horizontal-form {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.section-heading {
    margin-bottom: 22px;
}

.section-heading p,
.source-card-heading p {
    margin-bottom: 0;
}

.count-badge {
    display: inline-grid;
    min-width: 38px;
    min-height: 34px;
    place-items: center;
    padding: 0 10px;
    border-radius: 999px;
    background: #edf1f7;
    color: #445069;
    font-size: 13px;
    font-weight: 750;
}

.form-grid {
    display: grid;
    gap: 16px;
}

.two-columns {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.compact-form {
    display: grid;
    width: 100%;
    gap: 16px;
    padding: 22px;
}

.compact-form h3 {
    margin: 0;
}

.compact-form label,
.source-settings label,
.horizontal-form label {
    display: grid;
    gap: 7px;
    color: #354055;
    font-size: 13px;
    font-weight: 650;
}

.compact-form input,
.source-settings input,
.source-settings select,
.source-settings textarea,
.horizontal-form input,
.inline-form input {
    width: 100%;
    min-height: 42px;
    padding: 8px 11px;
    border: 1px solid #cfd6e0;
    border-radius: 9px;
    background: #fff;
    color: var(--text);
}

.source-settings textarea {
    resize: vertical;
}

.secondary-button,
.small-button {
    border: 1px solid #cbd4e1;
    border-radius: 9px;
    background: #fff;
    color: #344058;
    font-weight: 700;
    cursor: pointer;
}

.secondary-button {
    min-height: 42px;
    padding: 0 16px;
}

.small-button {
    min-height: 34px;
    padding: 0 12px;
    font-size: 13px;
}

.small-button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 13px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: 14px;
}

th {
    color: var(--muted);
    font-size: 12px;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.table-action {
    text-align: right;
}

.empty-state {
    margin: 0;
    padding: 20px;
    border-radius: 12px;
    background: var(--surface-muted);
    color: var(--muted);
}

.source-list,
.query-list {
    display: grid;
    gap: 16px;
}

.source-card {
    padding: 22px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface-muted);
}

.source-card h3 {
    margin: 0 0 4px;
}

.source-meta {
    font-size: 13px;
}

.status-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
}

.dot-on {
    background: var(--success);
    box-shadow: 0 0 0 5px rgba(22, 130, 93, 0.12);
}

.dot-off {
    background: #9ca5b4;
}

.inline-error {
    margin: 14px 0;
    color: var(--danger);
    font-size: 13px;
}

.source-settings {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(120px, 0.5fr) minmax(120px, 0.5fr);
    gap: 14px;
    margin-top: 20px;
}

.wide-field {
    grid-column: 1 / -1;
}

.checkbox-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
}

.checkbox-field {
    display: inline-flex !important;
    align-items: center;
    gap: 7px !important;
    font-weight: 600 !important;
}

.checkbox-field input {
    width: 16px;
    min-height: 16px;
    margin: 0;
}

.source-footer {
    align-items: flex-end;
    flex-wrap: wrap;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
}

.source-footer form,
.query-row form {
    margin: 0;
}

.horizontal-form {
    max-width: none;
    margin-bottom: 18px;
}

.grow-field {
    flex: 1;
}

.query-row {
    padding: 15px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
}

.query-row > div {
    display: grid;
    gap: 4px;
    margin-right: auto;
}

.inline-form input[type="number"] {
    width: 80px;
}

code {
    padding: 2px 5px;
    border-radius: 5px;
    background: #e9edf3;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9em;
}

.notice-panel p {
    margin-bottom: 0;
    color: var(--muted);
}

.login-page {
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 12% 12%, rgba(31, 94, 255, 0.14), transparent 34%),
        var(--background);
}

.login-shell {
    width: min(100%, 440px);
}

.login-panel {
    padding: 42px;
    border: 1px solid rgba(223, 228, 235, 0.9);
    border-radius: 24px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

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

.form-panel {
    width: min(100%, 620px);
    padding: 32px;
}

.form-stack {
    display: grid;
    gap: 20px;
}

.form-stack label {
    display: grid;
    gap: 8px;
    color: #354055;
    font-size: 14px;
    font-weight: 650;
}

.form-stack input {
    width: 100%;
    min-height: 48px;
    padding: 10px 13px;
    border: 1px solid #cfd6e0;
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    outline: none;
}

.form-stack input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(31, 94, 255, 0.14);
}

.primary-button {
    min-height: 48px;
    padding: 0 20px;
    border: 0;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    font-weight: 750;
    cursor: pointer;
}

.primary-button:hover {
    background: var(--primary-hover);
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}

.secondary-link {
    font-size: 14px;
}

.alert {
    margin-bottom: 20px;
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 14px;
}

.alert-error {
    border: 1px solid #f3bac4;
    background: #fff1f3;
    color: #90243a;
}

.alert-success {
    border: 1px solid #a9dfca;
    background: #edfbf5;
    color: #116145;
}

@media (max-width: 900px) {
    .status-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .two-columns,
    .source-settings {
        grid-template-columns: 1fr;
    }

    .wide-field {
        grid-column: auto;
    }

    .query-row,
    .horizontal-form {
        align-items: stretch;
        flex-direction: column;
    }
}

@media (max-width: 640px) {
    .site-header {
        align-items: flex-start;
        gap: 20px;
        padding: 18px 20px;
    }

    .header-actions {
        align-items: flex-end;
        flex-direction: column;
        gap: 6px;
    }

    .account-name {
        display: none;
    }

    .page-shell {
        width: min(100% - 32px, 1180px);
        padding-top: 36px;
    }

    .page-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .section-heading,
    .source-card-heading,
    .source-footer {
        align-items: flex-start;
        flex-direction: column;
    }

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

    .login-panel,
    .form-panel {
        padding: 26px;
    }
}
