:root {
    --bg: #071016;
    --panel: #0e1b23;
    --panel-2: #142630;
    --line: rgba(148, 163, 184, .24);
    --text: #eff6ff;
    --muted: #91a6b8;
    --cyan: #22d3ee;
    --green: #34d399;
    --yellow: #fbbf24;
    --orange: #fb923c;
    --red: #fb7185;
    --violet: #a78bfa;
}

* {
    box-sizing: border-box;
}

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

a {
    color: inherit;
    text-decoration: none;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 clamp(1rem, 4vw, 2rem);
    background: rgba(7, 16, 22, .94);
    border-bottom: 1px solid var(--line);
}

.brand {
    font-weight: 850;
}

.topbar nav {
    display: flex;
    align-items: center;
    gap: .35rem;
    flex-wrap: wrap;
}

.topbar nav a {
    padding: .5rem .7rem;
    border-radius: 8px;
    color: var(--muted);
}

.topbar nav a:hover,
.topbar nav a.active {
    color: var(--text);
    background: rgba(255, 255, 255, .08);
}

.shell {
    width: min(1180px, calc(100% - 28px));
    margin: 0 auto;
    padding: clamp(1.25rem, 4vw, 2.4rem) 0 4rem;
}

.page-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 1rem;
    align-items: end;
    margin-bottom: 1rem;
}

.page-head h1,
.login-card h1 {
    margin: 0;
    font-size: clamp(2.1rem, 5vw, 3.4rem);
    line-height: 1;
    letter-spacing: 0;
}

.page-head p,
.panel p,
.muted {
    color: var(--muted);
}

.eyebrow {
    margin: 0 0 .4rem;
    color: var(--cyan);
    font-size: .8rem;
    font-weight: 850;
    text-transform: uppercase;
}

.panel,
.score-card,
.status-strip,
.login-card,
.score-badge {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.panel,
.login-card {
    padding: clamp(1rem, 3vw, 1.35rem);
    margin-bottom: 1rem;
}

.login-card {
    width: min(460px, 100%);
    margin: 8vh auto 0;
}

.alert {
    border-radius: 8px;
}

.score-badge {
    min-width: 210px;
    padding: 1rem;
    border-left-width: 4px;
}

.score-badge span,
.score-card span,
.status-strip small,
label span {
    display: block;
    color: var(--muted);
    font-size: .82rem;
    font-weight: 800;
}

.score-badge strong,
.score-card strong,
.status-strip strong {
    display: block;
    margin-top: .35rem;
    font-size: clamp(1.2rem, 2.4vw, 1.7rem);
    overflow-wrap: anywhere;
}

.status-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.status-strip div {
    padding: 1rem;
    background: rgba(255, 255, 255, .025);
}

.score-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: .85rem;
    margin-bottom: 1rem;
}

.dashboard-head {
    grid-template-columns: 1fr;
    align-items: start;
}

.dashboard-update-line {
    margin: .55rem 0 0;
    font-weight: 800;
}

.dashboard-warning {
    margin-bottom: 1rem;
    padding: .8rem 1rem;
    border: 1px solid rgba(251, 191, 36, .28);
    border-radius: 8px;
    background: rgba(251, 191, 36, .08);
    color: #fde68a;
    font-weight: 800;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .85rem;
    margin-bottom: 1rem;
}

.dashboard-card {
    min-height: 168px;
    display: grid;
    grid-template-rows: auto 1fr auto auto auto;
    gap: .45rem;
    padding: 1rem;
    border: 1px solid var(--line);
    border-left-width: 4px;
    border-radius: 8px;
    background: var(--panel);
}

.dashboard-card:hover {
    transform: translateY(-1px);
    background: var(--panel-2);
}

.dashboard-card-title,
.dashboard-quality,
.dashboard-data-status span {
    color: var(--muted);
    font-size: .82rem;
    font-weight: 850;
}

.dashboard-card strong {
    align-self: end;
    font-size: clamp(1.85rem, 5vw, 3rem);
    line-height: 1;
    overflow-wrap: anywhere;
}

.dashboard-card small {
    width: fit-content;
    padding: .26rem .52rem;
    border-radius: 8px;
    font-weight: 850;
}

.dashboard-card em {
    color: var(--muted);
    font-size: .9rem;
    font-style: normal;
    font-weight: 800;
}

.dashboard-card-rlusd {
    grid-template-rows: auto auto auto auto auto auto;
}

.dashboard-rlusd-metrics {
    display: grid;
    gap: .18rem;
    color: var(--muted);
    font-size: .78rem;
    line-height: 1.35;
}

.dashboard-rlusd-metrics span {
    font-size: inherit;
    font-weight: 750;
}

.dashboard-data-status {
    display: grid;
    grid-template-columns: minmax(0, .8fr) minmax(0, .8fr) minmax(0, 1.6fr);
    gap: 1px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.dashboard-data-status div {
    padding: .9rem 1rem;
    background: rgba(255, 255, 255, .025);
}

.dashboard-data-status strong {
    display: block;
    margin-top: .3rem;
    font-size: .95rem;
    overflow-wrap: anywhere;
}

.dashboard-update-status strong {
    white-space: normal;
    line-height: 1.45;
}

.dashboard-update-status a {
    display: inline-block;
    margin-top: .45rem;
    color: var(--accent);
    font-size: .88rem;
    font-weight: 850;
}

.score-unknown {
    border-left-color: #94a3b8;
}

.score-weak {
    border-left-color: #fb7185;
}

.score-observable {
    border-left-color: #fbbf24;
}

.score-relevant {
    border-left-color: #22d3ee;
}

.score-strong {
    border-left-color: #34d399;
}

.score-systemic {
    border-left-color: #8b5cf6;
}

.score-unknown small {
    background: rgba(148, 163, 184, .14);
    color: #e2e8f0;
}

.score-weak small {
    background: rgba(251, 113, 133, .14);
    color: #fecdd3;
}

.score-observable small {
    background: rgba(251, 191, 36, .15);
    color: #fde68a;
}

.score-relevant small {
    background: rgba(34, 211, 238, .14);
    color: #a5f3fc;
}

.score-strong small {
    background: rgba(52, 211, 153, .14);
    color: #bbf7d0;
}

.score-systemic small {
    background: rgba(139, 92, 246, .16);
    color: #ddd6fe;
}

.score-card {
    min-height: 148px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border-left-width: 4px;
}

.score-card:hover {
    transform: translateY(-1px);
    background: var(--panel-2);
}

.score-card small {
    align-self: flex-start;
    padding: .25rem .5rem;
    border-radius: 8px;
    font-weight: 850;
}

.score-card em {
    color: var(--muted);
    font-size: .82rem;
    font-style: normal;
    font-weight: 800;
}

.status-unknown {
    border-left-color: #94a3b8;
}

.status-weak {
    border-left-color: var(--red);
}

.status-observable {
    border-left-color: var(--yellow);
}

.status-relevant {
    border-left-color: var(--cyan);
}

.status-strong {
    border-left-color: var(--green);
}

.status-systemic {
    border-left-color: var(--violet);
}

.status-unknown small,
.status-unknown.score-badge {
    color: #d8e3ee;
}

.status-weak small {
    background: rgba(251, 113, 133, .14);
    color: #fecdd3;
}

.status-observable small {
    background: rgba(251, 191, 36, .15);
    color: #fde68a;
}

.status-relevant small {
    background: rgba(34, 211, 238, .14);
    color: #a5f3fc;
}

.status-strong small {
    background: rgba(52, 211, 153, .14);
    color: #bbf7d0;
}

.status-systemic small {
    background: rgba(167, 139, 250, .16);
    color: #ddd6fe;
}

.period-tabs,
.button-row {
    display: flex;
    gap: .6rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.period-tabs a {
    padding: .5rem .75rem;
    border-radius: 8px;
    border: 1px solid var(--line);
    color: var(--muted);
}

.period-tabs a.active,
.period-tabs a:hover {
    color: var(--text);
    background: var(--panel-2);
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.panel-head h2,
.panel h2 {
    margin: 0;
    font-size: 1.08rem;
}

.chart-box {
    position: relative;
    width: 100%;
    height: 320px;
    max-height: 42vh;
}

.chart-box canvas {
    width: 100% !important;
    height: 100% !important;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.detail-back {
    margin-bottom: .8rem;
}

.detail-back a {
    color: var(--muted);
    font-weight: 850;
}

.detail-back a:hover {
    color: var(--text);
}

.detail-back-bottom {
    margin: 1rem 0 0;
}

.detail-head {
    grid-template-columns: 1fr;
    align-items: start;
}

.score-detail-card {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1px;
    overflow: hidden;
    margin-bottom: 1rem;
    border: 1px solid var(--line);
    border-left-width: 4px;
    border-radius: 8px;
    background: var(--panel);
}

.score-detail-card > div {
    min-height: 92px;
    padding: 1rem;
    background: rgba(255, 255, 255, .025);
}

.score-detail-card span {
    display: block;
    color: var(--muted);
    font-size: .82rem;
    font-weight: 850;
}

.score-detail-card strong {
    display: block;
    margin-top: .35rem;
    overflow-wrap: anywhere;
}

.score-number-large {
    font-size: clamp(1.8rem, 4vw, 2.5rem);
    line-height: 1;
}

.score-status-badge,
.quality-badge {
    width: fit-content;
    padding: .26rem .52rem;
    border-radius: 8px;
    background: rgba(148, 163, 184, .14);
}

.range-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: .6rem;
    margin-bottom: 1rem;
}

.range-buttons a {
    padding: .5rem .75rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
    font-weight: 850;
}

.range-buttons a.active,
.range-buttons a:hover {
    color: var(--text);
    background: var(--panel-2);
}

.chart-card {
    margin-bottom: 1rem;
}

.chart-placeholder-notice {
    padding: 1rem;
    border: 1px solid rgba(251, 191, 36, .28);
    border-radius: 8px;
    background: rgba(251, 191, 36, .08);
    color: #fde68a;
    font-weight: 850;
}

.history-status {
    margin: .85rem 0 .35rem;
    color: var(--text);
    font-weight: 850;
}

.message-preview {
    margin-top: 1rem;
    padding: .85rem;
    border: 1px solid rgba(148, 163, 184, .18);
    border-radius: 8px;
    background: rgba(255, 255, 255, .025);
}

.message-preview span {
    display: block;
    color: var(--muted);
    font-size: .82rem;
    font-weight: 850;
    margin-bottom: .5rem;
}

.message-preview pre {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    color: var(--text);
    font: inherit;
    line-height: 1.45;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .85rem;
    margin-bottom: 1rem;
}

.form-grid.one-col {
    grid-template-columns: 1fr;
}

label {
    display: grid;
    gap: .25rem;
    color: var(--muted);
    font-weight: 800;
}

.checkline {
    display: flex;
    align-items: center;
    gap: .5rem;
    min-height: 2.4rem;
}

input,
select,
textarea {
    width: 100%;
    min-height: 40px;
    padding: .55rem .7rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-2);
    color: var(--text);
}

textarea {
    resize: vertical;
}

input[type="checkbox"] {
    width: auto;
    min-height: auto;
}

button {
    min-height: 40px;
    padding: .55rem .85rem;
    border: 0;
    border-radius: 8px;
    background: var(--cyan);
    color: #06252e;
    font-weight: 850;
    cursor: pointer;
}

button.secondary {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--line);
}

.admin-score-list,
.area-setup-list,
.data-source-list {
    display: grid;
    gap: .75rem;
    margin: 1rem 0;
}

.admin-score-list article,
.area-setup-list article,
.data-source-list article {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 120px minmax(220px, .8fr);
    gap: .85rem;
    align-items: end;
    padding: .85rem;
    border: 1px solid rgba(148, 163, 184, .18);
    border-radius: 8px;
    background: rgba(255, 255, 255, .025);
}

.area-setup-list article {
    grid-template-columns: minmax(180px, 1fr) 95px 120px 120px 130px;
}

.data-source-list article {
    grid-template-columns: minmax(190px, .8fr) minmax(260px, 1.4fr) 110px 90px minmax(130px, .7fr) minmax(180px, .9fr);
}

.data-source-list span {
    display: block;
    color: var(--muted);
    font-size: .82rem;
    font-weight: 800;
}

.data-source-list strong {
    display: block;
    margin-top: .3rem;
    color: var(--text);
    font-size: .9rem;
    overflow-wrap: anywhere;
}

.admin-score-list small {
    display: block;
    margin-top: .25rem;
    color: var(--muted);
}

.admin-score-list.manual-only article {
    grid-template-columns: minmax(260px, .9fr) minmax(320px, 1.1fr);
    align-items: start;
}

.manual-score-form {
    display: grid;
    grid-template-columns: 110px minmax(180px, 1fr) auto;
    gap: .85rem;
    align-items: end;
}

.check-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .45rem .85rem;
    margin: 1rem 0 1.25rem;
}

.setup-form section {
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(148, 163, 184, .18);
}

.setup-form section:last-of-type {
    border-bottom: 0;
}

code {
    display: inline-block;
    margin: .25rem 0;
    color: #a5f3fc;
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid rgba(148, 163, 184, .18);
    border-radius: 8px;
}

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

th,
td {
    padding: .7rem .8rem;
    border-bottom: 1px solid rgba(148, 163, 184, .14);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: .78rem;
    text-transform: uppercase;
}

@media (max-width: 980px) {
    .page-head,
    .status-strip,
    .score-grid,
    .dashboard-grid,
    .dashboard-data-status,
    .detail-grid,
    .score-detail-card,
    .form-grid,
    .check-grid,
    .admin-score-list article,
    .area-setup-list article,
    .data-source-list article,
    .admin-score-list.manual-only article,
    .manual-score-form {
        grid-template-columns: 1fr;
    }

    .score-badge {
        min-width: 0;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
        padding-top: .75rem;
        padding-bottom: .75rem;
    }

    .chart-box {
        height: 260px;
        max-height: 38vh;
    }
}

@media (min-width: 700px) and (max-width: 980px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
