:root {
    --bg: #f5f1e8;
    --bg-accent: #e7dccb;
    --surface: rgba(255, 252, 245, 0.88);
    --surface-strong: #fffaf0;
    --text: #1f1a17;
    --muted: #6d6258;
    --border: rgba(78, 56, 35, 0.16);
    --primary: #8c4f2b;
    --primary-dark: #64351c;
    --danger: #b23a30;
    --success: #376d32;
    --shadow: 0 22px 40px rgba(58, 36, 21, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(140, 79, 43, 0.12), transparent 30%),
        linear-gradient(180deg, var(--bg) 0%, #fbf8f2 100%);
    min-height: 100vh;
}

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

a {
    color: inherit;
    text-decoration: none;
    transition: color 120ms ease, background 120ms ease, border-color 120ms ease, box-shadow 120ms ease, text-decoration-color 120ms ease;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 0;
    box-shadow: 0 0 0 3px rgba(140, 79, 43, 0.18);
}

a:not(.button):not(.button-secondary):not(.button-danger):not(.icon-button):not(.tag):not(.brand):hover,
a:not(.button):not(.button-secondary):not(.button-danger):not(.icon-button):not(.tag):not(.brand):focus-visible {
    color: var(--primary-dark);
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 0.18em;
    text-decoration-color: rgba(140, 79, 43, 0.65);
}

button {
    cursor: pointer;
}

.shell {
    width: min(1120px, calc(100vw - 2rem));
    margin: 0 auto;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(14px);
    background: rgba(245, 241, 232, 0.9);
    border-bottom: 1px solid var(--border);
}

.header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 0;
    font-size: 1.1rem;
}

.brand {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--primary);
}

.nav-links,
.auth-box,
.actions,
.toolbar,
.summary-row,
.inline-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.auth-box {
    justify-content: flex-end;
}

.auth-box form {
    margin: 0;
}

.nav-links a,
.auth-box,
.auth-box a,
.auth-box button {
    font-size: 1.05rem;
}

.nav-links a {
    padding: 0.2rem 0.35rem;
    border-radius: 10px;
}

.nav-links a:hover,
.nav-links a:focus-visible {
    background: rgba(140, 79, 43, 0.1);
    color: var(--primary-dark);
    text-decoration: none;
}

.auth-status {
    color: var(--muted);
    font-size: 0.95rem;
}

.page-content {
    padding: 2rem 0 4rem;
}

.hero {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.hero-panel,
.panel,
.stat-card,
.flash,
.data-table,
.form-grid,
.empty-state {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.hero-panel,
.panel,
.empty-state {
    padding: 1.5rem;
}

.eyebrow {
    margin: 0 0 0.5rem;
    color: var(--primary);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-size: 0.8rem;
}

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

.lead {
    max-width: 42rem;
    color: var(--muted);
    line-height: 1.6;
}

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

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

.stats-panel-header,
.stats-select-form,
.stats-select-form label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.stats-panel-header {
    justify-content: space-between;
    margin-bottom: 0.65rem;
}

.stats-panel-header h2 {
    margin-bottom: 0;
}

.stats-select-form select {
    width: auto;
    min-width: 4.5rem;
    height: 2.25rem;
    padding: 0.3rem 2rem 0.3rem 0.7rem;
}

.stats-overview {
    margin-bottom: 1rem;
}

.ranking-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.ranking-list li {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--border);
}

.ranking-list li:last-child {
    border-bottom: 0;
}

.ranking-list a {
    font-weight: 600;
}

.ranking-count {
    color: var(--muted);
    white-space: nowrap;
}

.chart-shell {
    overflow-x: auto;
    padding-bottom: 0.25rem;
}

.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 0.28rem;
    min-height: 17rem;
    min-width: max-content;
    padding: 1rem 0.25rem 0;
}

.bar-column {
    width: 1.7rem;
    display: grid;
    justify-items: center;
    align-content: end;
    gap: 0.35rem;
}

.bar-value,
.bar-label {
    color: var(--muted);
    font-size: 0.74rem;
}

.bar-track {
    width: 100%;
    height: 12rem;
    display: flex;
    align-items: flex-end;
}

.bar-link {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: flex-end;
    border-radius: 0.45rem 0.45rem 0 0;
}

.bar-link:hover,
.bar-link:focus-visible {
    text-decoration: none;
}

.bar {
    width: 100%;
    min-height: 2px;
    border-radius: 0.45rem 0.45rem 0 0;
    background: linear-gradient(180deg, #c98957 0%, var(--primary) 100%);
    transition: filter 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

.bar-link:hover .bar,
.bar-link:focus-visible .bar {
    filter: saturate(1.1) brightness(1.03);
    transform: translateY(-1px);
    box-shadow: 0 0 0 3px rgba(140, 79, 43, 0.14);
}

.excluded-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

.excluded-item {
    padding: 0.9rem 1rem;
    border-radius: 14px;
    background: rgba(140, 79, 43, 0.06);
    border: 1px solid var(--border);
}

.excluded-item strong {
    display: block;
    margin-top: 0.25rem;
    font-size: 1.05rem;
}

.stat-card {
    padding: 1.2rem 1.4rem;
}

.stat-card strong {
    display: block;
    font-size: 1.55rem;
    margin-top: 0.35rem;
}

.stat-label,
.help-text,
.meta,
.summary-text,
.table-note {
    color: var(--muted);
}

.section-heading {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: end;
    margin-bottom: 1rem;
}

.section-heading h1 {
    font-size: 1.75rem;
    line-height: 1.15;
    margin-bottom: 0;
}

.button,
.button-secondary,
.button-danger,
.link-button,
.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.7rem 1rem;
    border-radius: 999px;
    border: 1px solid transparent;
    transition: transform 120ms ease, background 120ms ease, border-color 120ms ease, box-shadow 120ms ease, color 120ms ease;
}

.button {
    background: var(--primary);
    color: #fff9f3;
}

.button:hover,
.button-secondary:hover,
.button-danger:hover,
.link-button:hover,
.icon-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 0 0 3px rgba(140, 79, 43, 0.14);
}

.button-secondary {
    background: #ffffff;
    border-color: var(--border);
    color: #000;
}

.button-danger {
    background: var(--danger);
    color: white;
}

.link-button {
    background: transparent;
    padding-inline: 0;
    color: var(--primary-dark);
}

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

.icon-button {
    width: 1.9rem;
    height: 1.9rem;
    padding: 0;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: #ffffff;
    color: var(--primary-dark);
}

.icon-button:hover {
    background: rgba(140, 79, 43, 0.08);
    border-color: rgba(140, 79, 43, 0.35);
}

.icon-button-primary {
    background: var(--primary);
    color: #fff9f3;
    border-color: transparent;
}

.icon-button-secondary {
    background: #ffffff;
    color: var(--primary-dark);
}

.icon-button-danger {
    background: #ffffff;
    color: var(--danger);
    border-color: rgba(178, 58, 48, 0.22);
}

.icon-button-danger:hover {
    background: rgba(178, 58, 48, 0.08);
    border-color: rgba(178, 58, 48, 0.35);
}

.icon-svg {
    width: 0.9rem;
    height: 0.9rem;
    flex: 0 0 auto;
}

.actions.icon-actions,
.inline-actions.icon-actions {
    gap: 0.45rem;
}

.flash-stack {
    display: grid;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.flash {
    padding: 1rem 1.2rem;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
}


.toolbar {
    justify-content: space-between;
    margin-bottom: 1rem;
}

.filter-form {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
    align-items: end;
}

label,
.field {
    display: grid;
    gap: 0.4rem;
}

input,
select,
textarea {
    width: 100%;
    padding: 0.75rem 0.85rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #ffffff;
}

input,
select {
    height: 2.85rem;
}

select[multiple] {
    min-height: 14rem;
}

textarea {
    min-height: 9rem;
    resize: vertical;
}

.form-shell.narrow {
    width: min(34rem, 100%);
    margin: 0 auto;
}

.form-grid {
    padding: 1.4rem;
    display: grid;
    gap: 1rem;
}

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

.form-grid .full-width {
    grid-column: 1 / -1;
}

.data-table {
    overflow: hidden;
}

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

.data-table th,
.data-table td {
    text-align: left;
    padding: 0.52rem 0.72rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    line-height: 1.3;
}

.data-table th a {
    color: var(--primary-dark);
}

.data-table th a:hover,
.data-table th a:focus-visible {
    color: var(--primary);
}

.data-table tbody tr:hover {
    background: rgba(140, 79, 43, 0.05);
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.tag {
    padding: 0.12rem 0.45rem;
    border-radius: 999px;
    background: rgba(140, 79, 43, 0.1);
    border: 1px solid transparent;
    color: var(--primary-dark);
    font-size: 0.92rem;
}

a.tag:hover,
a.tag:focus-visible {
    background: rgba(140, 79, 43, 0.18);
    border-color: rgba(140, 79, 43, 0.28);
    box-shadow: 0 0 0 3px rgba(140, 79, 43, 0.12);
    text-decoration: none;
}

.data-table .inline-actions {
    gap: 0.45rem;
    justify-content: flex-end;
    flex-wrap: nowrap;
}

.data-table .link-button {
    font-size: 0.95rem;
}

.data-table th:last-child,
.data-table td:last-child {
    text-align: right;
    white-space: nowrap;
}

.definition-list {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.8rem 1rem;
}

.definition-list dt {
    font-weight: 700;
}

.empty-state {
    text-align: center;
}

@media (max-width: 900px) {
    .hero,
    .stats-grid,
    .stats-overview,
    .stats-lists,
    .excluded-summary,
    .filter-form,
    .form-grid.two-column {
        grid-template-columns: 1fr;
    }

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

    .auth-box {
        justify-content: flex-start;
    }

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