:root {
    color-scheme: dark;

    --bg: #0f1113;
    --bg-elevated: #161a1d;
    --bg-card: #1b2024;
    --bg-input: #101315;
    --border: #2a3136;
    --border-strong: #3a4248;

    --text: #e8e6e1;
    --text-muted: #9aa3a8;
    --text-faint: #6b7378;

    --gold: #d4af37;
    --gold-soft: rgba(212, 175, 55, 0.16);
    --red: #c0392b;
    --black: #1c1c1c;
    --green: #1e8a4c;
    --blue: #3a7bd5;

    --success: #2fa86a;
    --danger: #d1453b;
    --warning: #d9a441;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    --shadow-card: 0 4px 18px rgba(0, 0, 0, 0.35);
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

* {
    box-sizing: border-box;
}

/* .form-row/.page etc. set their own `display`, which otherwise ties with
   and can beat the UA [hidden] rule on specificity; force it to always win. */
[hidden] {
    display: none !important;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--gold);
}

h1,
h2,
h3,
h4 {
    margin: 0 0 0.5em;
    font-weight: 600;
    letter-spacing: 0.01em;
}

p {
    margin: 0 0 0.75em;
    color: var(--text-muted);
}

.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 24px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.app-header__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.05rem;
}

.app-header__brand-mark {
    font-size: 1.4rem;
}

.app-nav {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.app-nav__button {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 8px 14px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.app-nav__button:hover {
    color: var(--text);
    background: var(--bg-card);
}

.app-nav__button[aria-current='page'] {
    color: var(--bg);
    background: var(--gold);
    font-weight: 600;
}

.app-main {
    flex: 1;
    padding: 24px;
    max-width: 1280px;
    width: 100%;
    margin: 0 auto;
}

.page {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow-card);
}

.card__title {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
    margin-bottom: 6px;
}

.card__value {
    font-size: 1.6rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
}

.section-title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.section-title h2 {
    font-size: 1.1rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border: 1px solid var(--border-strong);
    color: var(--text-muted);
}

.badge--red {
    color: #ffb3a7;
    background: rgba(192, 57, 43, 0.18);
    border-color: rgba(192, 57, 43, 0.4);
}

.badge--black {
    color: #d7d7d7;
    background: rgba(28, 28, 28, 0.55);
    border-color: var(--border-strong);
}

.badge--green {
    color: #9de8bd;
    background: rgba(30, 138, 76, 0.18);
    border-color: rgba(30, 138, 76, 0.4);
}

.badge--observation {
    color: var(--text-muted);
}

.badge--weak {
    color: #f0d38a;
    background: var(--gold-soft);
    border-color: rgba(212, 175, 55, 0.4);
}

.badge--moderate {
    color: #f0b45a;
    background: rgba(217, 164, 65, 0.16);
    border-color: rgba(217, 164, 65, 0.4);
}

.badge--unusual {
    color: #f08a6a;
    background: rgba(209, 69, 59, 0.16);
    border-color: rgba(209, 69, 59, 0.4);
}

button,
input,
select {
    font-family: inherit;
    font-size: 0.92rem;
}

.btn {
    background: var(--gold);
    color: #1a1509;
    border: none;
    border-radius: var(--radius-md);
    padding: 10px 18px;
    font-weight: 700;
    cursor: pointer;
    transition: filter 0.15s ease;
}

.btn:hover {
    filter: brightness(1.08);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: none;
}

.btn--secondary {
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border-strong);
}

.btn--ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn:focus-visible,
.app-nav__button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.form-row label {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.form-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: end;
}

input[type='number'],
input[type='text'],
input[type='file'],
select {
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

th,
td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th {
    color: var(--text-faint);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    user-select: none;
}

tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.text-red {
    color: #ff8b7a;
}

.text-black {
    color: #d7d7d7;
}

.text-green {
    color: #7ee7a8;
}

.text-muted {
    color: var(--text-muted);
}

.insight-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.insight-list li {
    padding: 10px 12px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--gold);
    font-size: 0.9rem;
}

.chart-box {
    position: relative;
    height: 260px;
}

.pagination {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.disclaimer {
    font-size: 0.82rem;
    color: var(--text-faint);
    border-top: 1px dashed var(--border-strong);
    padding-top: 10px;
    margin-top: 6px;
}

.app-footer {
    padding: 16px 24px;
    text-align: center;
    color: var(--text-faint);
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 8px;
    background: var(--gold);
    color: #1a1509;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    z-index: 100;
}

.skip-link:focus {
    top: 8px;
}
