*, *::before, *::after {
    box-sizing: border-box;
}

:root {
    --color-bg: #fff;
    --color-text: #1a1a1a;
    --color-muted: #666;
    --color-link: #1a5fb4;
    --color-link-hover: #0d3d6b;
    --color-border: #ddd;
    --color-header-bg: #1a5fb4;
    --color-header-text: #fff;
    --max-width: 820px;
    --spacing: 1.5rem;
}

html {
    font-size: 16px;
    line-height: 1.6;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, sans-serif;
    color: var(--color-text);
    background: var(--color-bg);
}

a {
    color: var(--color-link);
    text-decoration: underline;
    text-underline-offset: 2px;
}

a:hover {
    color: var(--color-link-hover);
}

header {
    background: var(--color-header-bg);
    color: var(--color-header-text);
    padding: 0.75rem var(--spacing);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

header h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

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

header h1 a:hover {
    color: inherit;
    text-decoration: underline;
}

main, .content {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: var(--spacing) var(--spacing) calc(var(--spacing) * 3);
}

h1 { font-size: 1.75rem; margin: 0 0 0.5rem; }
h2 { font-size: 1.25rem; margin: 1.5rem 0 0.5rem; border-bottom: 1px solid var(--color-border); padding-bottom: 0.25rem; }

p {
    margin: 0.5rem 0 1rem;
}

ul {
    margin: 0.25rem 0 1rem;
    padding-left: 1.25rem;
}

li {
    margin-bottom: 0.35rem;
}

dl {
    display: grid;
    grid-template-columns: 9rem 1fr;
    gap: 0.25rem 1.25rem;
    margin: 0.5rem 0 1rem;
}

dt {
    color: var(--color-muted);
    font-size: 0.875rem;
    font-weight: 600;
    padding-top: 0.1rem;
}

dd {
    margin: 0;
}

form {
    margin: 1rem 0;
}

header form {
    margin: 0;
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex: 1;
    min-width: 0;
}

header form input[type="search"] {
    flex: 1;
    min-width: 0;
    max-width: 220px;
    background: rgba(255,255,255,0.15);
    border-color: rgba(255,255,255,0.4);
    color: #fff;
}

header form input[type="search"]::placeholder {
    color: rgba(255,255,255,0.7);
}

header form button {
    background: rgba(255,255,255,0.2);
    white-space: nowrap;
}

header form button:hover {
    background: rgba(255,255,255,0.35);
}

input[type="search"], input[type="text"] {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 1rem;
    width: 100%;
    max-width: 400px;
}

button, input[type="submit"] {
    padding: 0.4rem 1rem;
    background: var(--color-link);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
}

button:hover, input[type="submit"]:hover {
    background: var(--color-link-hover);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    margin: 0.5rem 0 1rem;
}

th, td {
    padding: 0.4rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

th {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-muted);
    white-space: nowrap;
}

.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

tbody tr:hover {
    background: #f5f7fa;
}

.muted {
    color: var(--color-muted);
    font-size: 0.875rem;
}

.other-names {
    color: var(--color-muted);
    font-size: 0.9rem;
    margin: -0.5rem 0 1rem;
}

/* Charity detail two-column layout */
.charity-layout {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 0 2.5rem;
    align-items: start;
}

.charity-sidebar {
    position: sticky;
    top: 1.5rem;
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
}

.charity-nav {
    display: flex;
    flex-direction: column;
    margin-top: 0.75rem;
}

.charity-nav a {
    display: block;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    text-decoration: none;
    color: var(--color-muted);
    font-size: 0.875rem;
    transition: color 0.15s;
}

.charity-nav a:hover {
    color: var(--color-text);
    background: #f5f7fa;
}

.charity-nav a.active {
    color: var(--color-link);
    font-weight: 600;
    background: #eef3fc;
}

.charity-section {
    scroll-margin-top: 1.5rem;
}

.data-links {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.data-links a {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    font-size: 0.875rem;
    text-decoration: none;
    color: var(--color-link);
    transition: background 0.15s, border-color 0.15s;
}

.data-links a:hover {
    background: #eef3fc;
    border-color: var(--color-link);
    color: var(--color-link-hover);
}

/* Search sidebar layout */
.search-layout {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 0 2.5rem;
    align-items: start;
}

.search-sidebar {
    position: sticky;
    top: 1.5rem;
}

.filter-form {
    margin: 0;
}

.filter-fields {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.filter-fields label {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-muted);
}

.filter-fields select,
.filter-fields input[type="number"] {
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 0.875rem;
    width: 100%;
    background: var(--color-bg);
}

.filter-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.filter-actions button {
    font-size: 0.875rem;
    padding: 0.35rem 0.9rem;
}

.filter-actions a {
    font-size: 0.875rem;
}

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

@media (max-width: 640px) {
    .charity-layout,
    .search-layout {
        display: block;
    }

    .charity-sidebar,
    .search-sidebar {
        position: static;
        margin-bottom: 1.5rem;
    }

    .charity-nav {
        display: none;
    }
}
