/* Colour tokens come from themes.css (generated from src/Settings/ThemeRegistry.php); fonts from fonts.css. */

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

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

h1,
h2,
h3,
.stat-value,
.auth-brand {
    font-family: "Bricolage Grotesque", "Figtree", system-ui, sans-serif;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.placeholder {
    max-width: 32rem;
    margin: 0 auto;
    padding: 6rem 1rem;
    text-align: center;
}

/* Logo: the image itself, never recoloured by theme (DESIGN.md "Logo") */
.placeholder .logo {
    display: inline-block;
    width: 4.5rem;
    height: 4.5rem;
}

.placeholder h1 {
    margin: 1rem 0 0.5rem;
}

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

/* Buttons and forms (DESIGN.md §1: pill buttons, 44-48 px touch targets) */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 0 1.5rem;
    border: 1px solid transparent;
    border-radius: 999px;
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.btn:disabled {
    opacity: 0.6;
    cursor: progress;
}

.btn-primary {
    background: var(--accent);
    color: var(--on-accent);
}

.btn-secondary {
    background: var(--accent-soft);
    color: var(--on-accent-soft);
}

.btn:focus-visible,
input:focus-visible,
.link:focus-visible,
a:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

a,
.link {
    color: var(--accent);
}

.link {
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    font-weight: 600;
    text-decoration: underline;
    cursor: pointer;
}

/* Sign-in pages */
body.auth {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 3rem 1rem;
}

.auth-card {
    width: 100%;
    max-width: 26rem;
    padding: 2rem;
    border: 1px solid var(--border);
    border-radius: 28px;
    background: var(--surface);
}

.auth-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.625rem;
    color: var(--text);
    font-size: 1.375rem;
    font-weight: 800;
    letter-spacing: -0.01em;
    text-decoration: none;
}

.auth-brand .logo {
    width: 2.5rem;
    height: 2.5rem;
}

.auth-card h1 {
    margin: 1.5rem 0 1rem;
    font-size: 1.75rem;
}

.auth-card form {
    display: flex;
    flex-direction: column;
}

.auth-card label {
    margin-top: 0.75rem;
    font-weight: 600;
}

.auth-card input[type="email"],
.auth-card input[type="password"],
.auth-card input[type="text"] {
    min-height: 48px;
    margin-top: 0.25rem;
    padding: 0 1rem;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

.auth-card input[aria-invalid="true"] {
    border-color: var(--negative);
}

.auth-card label.check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
    font-weight: 500;
}

.auth-card .btn {
    margin-top: 1rem;
}

.field-error,
.form-error {
    margin: 0.25rem 0 0;
    color: var(--negative);
    font-size: 0.875rem;
}

.field-error:empty,
.form-error:empty {
    display: none;
}

.hint {
    margin: 0.25rem 0 0;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.notice {
    padding: 0.75rem 1rem;
    border-radius: 14px;
    background: var(--accent-soft);
    color: var(--on-accent-soft);
}

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

.auth-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 1.5rem;
    font-size: 0.9375rem;
}

@media (max-width: 480px) {
    body.auth {
        padding: 1rem;
    }

    .auth-card {
        padding: 1.5rem 1.25rem;
        border-radius: 22px;
    }
}

[hidden] {
    display: none !important;
}

/* Settings pages (until the app shell and sidebar arrive in Phase 6) */
.page {
    max-width: 44rem;
    margin: 0 auto;
    padding: 2rem 1rem 4rem;
}

.card {
    margin-top: 1.25rem;
    padding: 1.5rem;
    border: 1px solid var(--border);
    border-radius: 28px;
    background: var(--surface);
}

.card h2 {
    margin: 0 0 0.25rem;
    font-size: 1.25rem;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 24rem;
}

.stack input,
.field input[type="text"],
.field input[type="date"],
.field input[type="password"],
.field input[type="number"],
.field input[type="time"],
.auth-card input[inputmode="numeric"],
.auth-card input[name="recovery_code"] {
    min-height: 48px;
    padding: 0 1rem;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

.auth-card input[inputmode="numeric"] {
    margin-top: 0.25rem;
    font-size: 1.25rem;
    letter-spacing: 0.2em;
    font-variant-numeric: tabular-nums;
}

.row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.btn-small {
    min-height: 44px;
    padding: 0 1rem;
}

.badge {
    display: inline-block;
    margin-left: 0.5rem;
    padding: 0.125rem 0.625rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--on-accent-soft);
    font-size: 0.8125rem;
    font-weight: 600;
}

.badge:first-child {
    margin-left: 0;
}

.badge-on {
    background: var(--accent);
    color: var(--on-accent);
}

.item-list {
    margin: 1rem 0 0;
    padding: 0;
    list-style: none;
}

.item-list li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    padding: 0.75rem 0;
    border-top: 1px solid var(--border);
}

/* The text keeps at least ~14rem; on a narrow phone the buttons drop below it instead of squeezing it. */
.item-list li > div:first-child {
    flex: 1 1 14rem;
    min-width: 0;
}

.secret,
.codes {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-variant-numeric: tabular-nums;
}

.secret {
    padding: 0.5rem 0.75rem;
    border-radius: 10px;
    background: var(--accent-soft);
    color: var(--on-accent-soft);
    word-break: break-all;
}

.codes {
    columns: 2;
    padding-left: 1.5rem;
}

.qr {
    display: block;
    width: 200px;
    height: 200px;
    margin: 0.5rem 0;
    border: 1px solid var(--border);
    border-radius: 16px; /* the SVG brings its own white quiet zone, so it scans in every theme */
}

/* On a phone the QR code would be on the same screen as the app, so only the key is shown. */
@media (max-width: 600px) {
    .qr {
        display: none;
    }
}

.auth-card [data-code-field],
.auth-card [data-recovery-field] {
    display: flex;
    flex-direction: column;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.passkey-login .btn {
    width: 100%;
}

.divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1rem 0 0;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.divider::before,
.divider::after {
    flex: 1;
    height: 1px;
    background: var(--border);
    content: "";
}

.row-tight {
    flex-wrap: nowrap;
    margin-top: 0;
}

.btn-block {
    display: flex;
    width: 100%;
    margin-top: 0.75rem;
}

/* Tabs wrap onto a second line on narrow screens, so none is hidden off the edge */
.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 1.25rem 0 0;
}

.tabs a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 1rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--on-accent-soft);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.tabs a[aria-current="page"] {
    background: var(--accent);
    color: var(--on-accent);
}

.stack select,
.field select,
.item-list select {
    min-height: 48px;
    padding: 0 0.75rem;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-top: 0.75rem;
}

.field label {
    font-weight: 600;
}

.field .source {
    color: var(--text-muted);
    font-size: 0.8125rem;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
}

.danger {
    border-color: var(--negative);
}

/* Admin */
.page-wide {
    max-width: 60rem;
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
    gap: 0.75rem;
}

.stat {
    padding: 1rem;
    border-radius: 18px;
    background: var(--accent-soft);
}

.stat-value {
    color: var(--on-accent-soft);
    font-size: 1.75rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.error-message {
    margin: 0.25rem 0;
    overflow-wrap: anywhere;
}

.item-list .muted {
    overflow-wrap: anywhere;
}

/* A list item's name with its badges on one line; details go on the next. */
.item-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.5rem;
}

.item-title .badge {
    margin: 0;
}

input[type="search"] {
    min-height: 48px;
    padding: 0 1rem;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

/* Visually hidden, still read by screen readers (labels for controls whose meaning is shown nearby). */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* Wide tables scroll inside their own box, so the page never scrolls sideways on a phone. */
.table-scroll {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
    padding: 0.5rem 0.625rem;
    border-top: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

.data-table th {
    color: var(--text-muted);
    font-weight: 600;
}

.data-table .num {
    text-align: right;
}

.data-table .row-skipped td,
.data-table .row-already_imported td {
    color: var(--text-muted);
}

.data-table .row-error td {
    color: var(--negative);
}

details > summary {
    display: flex;
    align-items: center;
    min-height: 44px;
    cursor: pointer;
    font-weight: 600;
}

/* Filter controls side by side where there is room, stacked on a phone. */
.filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
    gap: 0.75rem 1rem;
    align-items: end;
}

.filters .field {
    margin: 0;
}

.amount {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    white-space: nowrap;
}

.amount-in {
    color: var(--positive, var(--accent));
}

.item-list li.is-removed {
    opacity: 0.6;
}

/* A checkbox with a 44 px tap area. */
.select-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
}

.select-box input {
    width: 1.25rem;
    height: 1.25rem;
}

/* Grouped choices (the import's "the file holds" radios). */
fieldset {
    border: 0;
    margin: 0;
    padding: 0;
    min-width: 0;
}

legend {
    font-weight: 600;
    padding: 0;
    margin-bottom: 0.25rem;
}

/* KPI tiles (DESIGN.md §1, §3): tile 1 is the strong one, all its text in --on-accent; tiles 2-4 use --on-tile-*. */
.tile {
    padding: 1rem;
    border-radius: 18px;
    font-weight: 600;
}

.tile-1 {
    background: var(--tile-1);
    color: var(--on-accent);
}

.tile-2 {
    background: var(--tile-2);
    color: var(--on-tile-2);
}

.tile-3 {
    background: var(--tile-3);
    color: var(--on-tile-3);
}

.tile-4 {
    background: var(--tile-4);
    color: var(--on-tile-4);
}

.tile .stat-value {
    color: inherit;
    font-size: 1.5rem;
}

/* A badge in a row of buttons keeps its own height instead of stretching to theirs. */
.row > .badge {
    align-self: center;
}

.amount-up {
    color: var(--positive);
    font-weight: 600;
}

.amount-down {
    color: var(--negative);
    font-weight: 600;
}

/* Gains and losses inside tiles keep the tile's own text colour (their contrast is checked against the tile). */
.tile .amount-up,
.tile .amount-down {
    color: inherit;
}

/* Space above a heading that follows a table or list inside a card. */
.section-gap {
    margin-top: 1.5rem;
}

/* Admin → Data sources: one line per capability (name, priority, on), and forms folded away until needed. */
.cap-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 5.5rem 44px;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.25rem;
}

.cap-row input[type="number"] {
    min-height: 44px;
    width: 100%;
    padding: 0 0.5rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

.cap-head {
    font-size: 0.8125rem;
    margin-top: 0.75rem;
}

.item-list details > summary {
    display: flex;
    align-items: center;
    min-height: 44px;
    color: var(--accent);
    font-weight: 600;
    cursor: pointer;
}

/* ---- App shell (DESIGN.md §4; views/partials/shell.php, lib/shell.js) ----------------------------------------
   <html data-nav> is the nav_mode preference: expanded (240 px, icons + labels), collapsed (72 px icon rail) or
   auto_hide (no sidebar; the menu button opens it over the page). Tablets show "expanded" as the rail; phones
   have no sidebar, only the tab bar, whose More opens it over the page. [data-nav-open] = the overlay is open. */
html {
    --nav-w: 240px;
}

html[data-nav="collapsed"] {
    --nav-w: 72px;
}

html[data-nav="auto_hide"] {
    --nav-w: 0px;
}

body.has-shell {
    padding-left: var(--nav-w);
    transition: padding-left 0.2s ease;
}

.skip-link {
    position: absolute;
    left: 1rem;
    top: -4rem;
    z-index: 60;
    padding: 0.75rem 1rem;
    border-radius: 14px;
    background: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
}

.skip-link:focus {
    top: 0.5rem;
}

main:focus {
    outline: none;
}

.sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: var(--nav-w);
    padding: 1rem 0.75rem;
    overflow-x: hidden;
    overflow-y: auto;
    border-right: 1px solid var(--border);
    background: var(--surface);
    transition: width 0.2s ease, transform 0.2s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    min-height: 44px;
    padding: 0 0.25rem;
    color: var(--text);
    font-family: "Bricolage Grotesque", "Figtree", system-ui, sans-serif;
    font-size: 1.25rem;
    font-weight: 800;
    text-decoration: none;
}

.sidebar-brand .logo {
    flex: none;
    width: 36px;
    height: 36px;
}

.topbar-portfolio select {
    min-height: 44px;
    max-width: 100%;
    padding: 0 0.75rem;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
    font-size: 1rem;
}

.nav-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    min-height: 44px;
    padding: 0 0.75rem;
    border: 0;
    border-radius: 14px;
    background: none;
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-align: left;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.nav-link:hover {
    background: var(--accent-soft);
    color: var(--on-accent-soft);
}

.nav-link[aria-current="page"] {
    background: var(--accent);
    color: var(--on-accent);
}

.nav-link:focus-visible,
.icon-btn:focus-visible,
.tab:focus-visible,
select:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.icon {
    flex: none;
}

.sidebar-foot {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-top: auto;
}

.sidebar-user {
    display: flex;
    flex-direction: column;
    margin: 0 0 0.5rem;
    padding: 0 0.75rem;
    font-weight: 600;
    overflow-wrap: anywhere;
}

/* The rail: labels kept for screen readers (and as tooltips via title), not shown. */
html[data-nav="collapsed"]:not([data-nav-open]) .sidebar .nav-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

html[data-nav="collapsed"]:not([data-nav-open]) .sidebar :is(.nav-link, .sidebar-brand) {
    justify-content: center;
    padding: 0;
}

html[data-nav="auto_hide"] [data-nav-toggle] {
    display: none;
}

html[data-nav="collapsed"]:not([data-nav-open]) [data-nav-toggle] .icon {
    transform: rotate(180deg);
}

/* Hidden until opened: auto-hide on any screen (phones: see below). */
html[data-nav="auto_hide"]:not([data-nav-open]) .sidebar {
    transform: translateX(-100%);
    visibility: hidden;
}

html[data-nav-open] .sidebar {
    z-index: 50;
    width: min(280px, 85vw);
    transform: none;
    visibility: visible;
    box-shadow: 0 12px 40px rgb(0 0 0 / 0.25);
}

.nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgb(0 0 0 / 0.4);
}

.nav-backdrop[hidden] {
    display: none;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 60px;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.topbar-spacer {
    flex: 1;
}

.topbar-portfolio {
    min-width: 0;
}

.topbar-portfolio select {
    width: 100%;
    max-width: 16rem;
}

.icon-btn {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: none;
    color: var(--text);
    cursor: pointer;
}

.icon-btn:hover {
    background: var(--accent-soft);
    color: var(--on-accent-soft);
}

.icon-btn[hidden],
.topbar-portfolio[hidden] {
    display: none;
}

/* Two icons per toggle; aria-pressed (set by lib/shell.js) picks one. */
[aria-pressed="true"] > .icon-off,
:not([aria-pressed="true"]) > .icon-on {
    display: none;
}

.topbar-menu {
    display: none;
}

html[data-nav="auto_hide"] .topbar-menu {
    display: inline-flex;
}

.tabbar {
    display: none;
}

/* Tablets: "expanded" shows as the rail; its toggle opens the full menu over the page. */
@media (max-width: 1023px) {
    html[data-nav="expanded"] {
        --nav-w: 72px;
    }

    html[data-nav="expanded"]:not([data-nav-open]) .sidebar .nav-label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    html[data-nav="expanded"]:not([data-nav-open]) .sidebar :is(.nav-link, .sidebar-brand) {
        justify-content: center;
        padding: 0;
    }
}

/* Phones: no sidebar; the tab bar along the bottom, its More opens the menu. */
@media (max-width: 767px) {
    html[data-nav] {
        --nav-w: 0px;
    }

    html:not([data-nav-open]) .sidebar {
        transform: translateX(-100%);
        visibility: hidden;
    }

    html[data-nav-open] .sidebar .nav-label {
        position: static;
        width: auto;
        height: auto;
        clip: auto;
    }

    html[data-nav-open] .sidebar :is(.nav-link, .sidebar-brand) {
        justify-content: flex-start;
        padding: 0 0.75rem;
    }

    [data-nav-toggle],
    html[data-nav="auto_hide"] .topbar-menu {
        display: none;
    }

    body.has-shell {
        padding-bottom: calc(64px + env(safe-area-inset-bottom));
    }

    .topbar {
        padding: 0.5rem 0.75rem;
    }

    .tabbar {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 30;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        padding-bottom: env(safe-area-inset-bottom);
        border-top: 1px solid var(--border);
        background: var(--surface);
    }

    .tab {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.125rem;
        min-height: 64px;
        padding: 0.25rem;
        border: 0;
        background: none;
        color: var(--text-muted);
        font: inherit;
        font-size: 0.75rem;
        font-weight: 600;
        text-decoration: none;
        cursor: pointer;
    }

    .tab[aria-current="page"] {
        color: var(--accent);
    }
}

@media (prefers-reduced-motion: reduce) {
    body.has-shell,
    .sidebar {
        transition: none;
    }
}

/* Hide amounts: money becomes a plain bar the size of the figure (layout unchanged, nothing to read). */
html[data-hide-amounts] .amount {
    border-radius: 6px;
    background: var(--border);
    color: transparent;
    user-select: none;
}

html[data-hide-amounts] .amount * {
    visibility: hidden;
}

/* Playful headlines (DESIGN.md §5): the page carries both versions; Hide amounts shows the one without figures. */
html[data-hide-amounts] [data-headline-full],
html:not([data-hide-amounts]) [data-headline-hidden] {
    display: none;
}

.eyebrow {
    margin: 1rem 0 -0.75rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* A headline is a sentence, so it is set smaller than a page title. */
h1:has([data-headline-full]) {
    font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.25rem);
    line-height: 1.2;
}

.eyebrow[hidden] {
    display: none;
}

/* ---- Dashboard (Overview; DESIGN.md §4: KPI tiles in an auto-fit grid, then 2 : 1 card rows) ---------------- */
.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(13.75rem, 1fr));
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.kpis .tile {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-height: 8.5rem;
}

.tile-label {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.tile-sub {
    margin-top: auto;
    font-size: 0.875rem;
    font-weight: 500;
}

.tile-loading {
    opacity: 0.6;
}

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

@media (max-width: 860px) {
    .dash-row {
        grid-template-columns: minmax(0, 1fr);
    }
}

.card-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.card-head h2 {
    margin: 0;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.chip {
    min-width: 44px;
    min-height: 44px;
    padding: 0 0.875rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.chip[aria-pressed="true"] {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--on-accent);
}

.chip:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

/* Inside a tile the chips take the tile's own colours (contrast is checked for text on each tile). */
.tile .chip {
    min-height: 44px;
    padding: 0 0.625rem;
    border-color: transparent;
    background: none;
    color: inherit;
    font-size: 0.8125rem;
}

.tile .chip[aria-pressed="true"] {
    border-color: currentColor;
    background: none;
    color: inherit;
}

.chart {
    width: 100%;
    height: 18rem;
    margin-top: 0.5rem;
}

.gain-list {
    margin: 0.5rem 0 0;
    padding: 0;
    list-style: none;
}

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

.gain-list .gain-total {
    border-bottom: 0;
    font-weight: 700;
}

.gain-name {
    overflow-wrap: anywhere;
}

.gain-figures {
    display: inline-flex;
    gap: 0.5rem;
    font-variant-numeric: tabular-nums;
}

.chart-short {
    height: 14rem;
}

/* Allocation: the donut beside its legend, stacked on narrow cards. The legend is the readable version. */
.alloc {
    display: grid;
    grid-template-columns: minmax(10rem, 14rem) minmax(0, 1fr);
    align-items: center;
    gap: 1.25rem;
    margin-top: 0.75rem;
}

@media (max-width: 560px) {
    .alloc {
        grid-template-columns: minmax(0, 1fr);
    }

    .donut {
        max-width: 11rem;
    }
}

.donut {
    width: 100%;
    max-width: 14rem;
    aspect-ratio: 1;
    margin: 0 auto;
}

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

.legend li {
    display: flex;
    align-items: baseline;
    gap: 0.625rem;
    padding: 0.375rem 0;
    border-bottom: 1px solid var(--border);
}

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

.legend .gain-name {
    flex: 1;
}

.swatch {
    flex: none;
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 3px;
    align-self: center;
}

/* Performance: Gain / Value beside the note. */
.perf-kind {
    margin-top: 0.75rem;
}

/* Data-quality alerts: one line each, with where to fix it. */
.alert-list {
    margin: 0.5rem 0 0;
    padding: 0;
    list-style: none;
}

.alert-list li {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.25rem 1rem;
    padding: 0.625rem 0 0.625rem 0.875rem;
    border-bottom: 1px solid var(--border);
    border-left: 3px solid var(--negative);
}

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

.alert-list .alert-info {
    border-left-color: var(--accent);
}

.alert-list a {
    font-weight: 600;
    white-space: nowrap;
}

/* Where the gain came from: a name, a bar for the size, the amount. */
.source-list {
    margin: 0.5rem 0 0;
    padding: 0;
    list-style: none;
}

.source-list li {
    display: grid;
    grid-template-columns: minmax(8rem, 14rem) minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
}

.source-list .source-total {
    border-bottom: 0;
    font-weight: 700;
}

.source-track {
    display: block;
    height: 0.625rem;
}

.source-bar {
    display: block;
    height: 100%;
    border-radius: 3px;
    background: var(--positive);
}

.source-bar-down {
    background: var(--negative);
}

@media (max-width: 560px) {
    .source-list li {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .source-track {
        grid-column: 1 / -1;
        grid-row: 2;
    }
}

.income-totals {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    margin: 0.5rem 0 0;
    font-size: 0.875rem;
}

/* Holdings: a sortable table; a security in several accounts opens to show each. On phones each row is a card. */
.table-wrap {
    margin-top: 0.75rem;
    overflow-x: auto;
}

.holdings {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9375rem;
    font-variant-numeric: tabular-nums;
}

.holdings th,
.holdings td {
    padding: 0.5rem 0.375rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.holdings th {
    font-size: 0.8125rem;
    font-weight: 600;
    white-space: nowrap;
}

.holdings .col-num {
    text-align: right;
    white-space: nowrap;
}

.holdings .sort {
    min-height: 44px;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
}

.holdings .sort:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.sort-mark {
    display: inline-block;
    min-width: 1em;
    font-size: 0.6875rem;
}

.col-security {
    text-align: left;
    min-width: 10rem;
}

.holdings .holding-name .muted {
    display: -webkit-box;
    max-width: 16rem;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
}

.holding-name {
    display: inline-flex;
    flex-direction: column;
    vertical-align: middle;
}

.holding-name .muted,
.holding-in {
    font-size: 0.8125rem;
}

.holding-in {
    display: block;
}

.holding-child td {
    background: var(--bg);
    font-size: 0.875rem;
}

.holding-account {
    padding-left: 3.25rem;
}

.expand {
    width: 44px;
    height: 44px;
    margin-right: 0.375rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 700;
    vertical-align: middle;
    cursor: pointer;
}

.cell-pair {
    display: inline-flex;
    gap: 0.5rem;
}

.columns-picker {
    align-self: end;
}

.columns-picker fieldset {
    margin: 0.5rem 0 0;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}

@media (max-width: 760px) {
    .holdings thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
    }

    .holdings,
    .holdings tbody,
    .holdings tr,
    .holdings td {
        display: block;
        width: 100%;
    }

    .holdings tr {
        padding: 0.5rem 0;
        border-bottom: 1px solid var(--border);
    }

    .holdings td {
        display: flex;
        justify-content: space-between;
        gap: 1rem;
        padding: 0.25rem 0;
        border: 0;
    }

    .holdings td.col-security {
        padding-bottom: 0.5rem;
    }

    .holdings td[data-label]::before {
        content: attr(data-label);
        color: var(--text-muted);
        font-size: 0.875rem;
    }

    .holding-child td {
        background: none;
    }

    .holding-account {
        padding-left: 0;
        font-weight: 600;
    }
}

.cell-stack {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-end;
}

.cell-note {
    font-size: 0.75rem;
}

/* A portfolio's name that switches the page to it, like the shell's selector. */
.link-button {
    min-height: 44px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent);
    font: inherit;
    font-weight: 600;
    text-align: left;
    text-decoration: underline;
    cursor: pointer;
}

.link-button:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

/* Holding detail */
.holding-link {
    color: inherit;
    text-decoration: none;
}

.holding-link:hover strong,
.holding-link:focus-visible strong {
    text-decoration: underline;
}

.holding-sub {
    margin-top: -0.5rem;
}

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

[data-note] {
    width: 100%;
    min-height: 7rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 1rem;
    resize: vertical;
}

.link-small {
    min-height: 32px;
    font-size: 0.875rem;
    font-weight: 500;
}

/* Performance: returns by period (a .holdings table), the chosen period's figures, and the month grid. */
.small {
    font-size: 0.8125rem;
}

.perf-table .perf-unavailable td {
    color: var(--text-muted);
}

.perf-figures {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 2rem;
    margin: 0.75rem 0 0.5rem;
}

.perf-figure {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.perf-figure-value {
    font-family: "Bricolage Grotesque", Figtree, system-ui, sans-serif;
    font-size: 1.375rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.perf-figure-value .cell-stack {
    align-items: flex-start;
}

.perf-figure-value .small {
    font-family: Figtree, system-ui, sans-serif;
    font-weight: 400;
}

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

.month-grid {
    width: 100%;
    border-collapse: separate;
    border-spacing: 3px;
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
}

.month-grid th {
    padding: 0.25rem 0.375rem;
    color: var(--text-muted);
    font-weight: 600;
    text-align: left;
}

.month-grid .col-num {
    text-align: right;
    white-space: nowrap;
}

.month-grid td {
    padding: 0.375rem;
    border-radius: 4px;
}

.month-grid .month-year {
    font-weight: 700;
}

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

.heat-up-1 { background: color-mix(in srgb, var(--positive) 10%, var(--surface)); }
.heat-up-2 { background: color-mix(in srgb, var(--positive) 20%, var(--surface)); }
.heat-up-3 { background: color-mix(in srgb, var(--positive) 30%, var(--surface)); }
.heat-down-1 { background: color-mix(in srgb, var(--negative) 10%, var(--surface)); }
.heat-down-2 { background: color-mix(in srgb, var(--negative) 20%, var(--surface)); }
.heat-down-3 { background: color-mix(in srgb, var(--negative) 30%, var(--surface)); }
.heat-flat { background: color-mix(in srgb, var(--text-muted) 8%, var(--surface)); }

/* Phones: each year is a block of 4 × 3 months with the year's figures under them. */
@media (max-width: 760px) {
    .month-grid thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
    }

    .month-grid,
    .month-grid tbody {
        display: block;
    }

    .month-grid tr {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 3px;
        padding-bottom: 0.75rem;
    }

    .month-grid tr th {
        grid-column: 1 / -1;
        padding-left: 0;
    }

    .month-grid td {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        min-height: 2.75rem;
    }

    .month-grid td[data-label]::before {
        content: attr(data-label);
        color: var(--text-muted);
        font-size: 0.75rem;
    }

    .month-grid .month-year,
    .month-grid .month-bench {
        grid-column: span 2;
    }
}

/* A filter form that folds away on phones (Transactions): open on wider screens, where the toggle is hidden. */
.filter-box > summary {
    display: none;
}

@media (max-width: 760px) {
    .filter-box > summary {
        display: inline-flex;
        list-style: none;
    }

    .filter-box > summary::-webkit-details-marker {
        display: none;
    }

    .filter-box[open] > summary {
        margin-bottom: 0.75rem;
    }

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

    .filter-box .filters .field:has(input[type="search"]),
    .filter-box .filters .check-row {
        grid-column: 1 / -1;
    }

    /* Account actions wrap rather than run off a narrow card. */
    .item-list .row-tight {
        flex-wrap: wrap;
    }

    /* A period without enough history: one line. */
    .perf-table .perf-unavailable {
        display: flex;
        justify-content: space-between;
        gap: 1rem;
    }

    .perf-table .perf-unavailable td {
        width: auto;
        padding: 0;
    }
}

/*
 * Loading states (lib/states.js). A region with aria-busy="true" shows soft placeholders where its charts, lists
 * and tables are still empty, and dims what it already shows under a thin moving bar while it reloads. Both wait
 * a moment first, so a quick load does not flicker. No movement with reduced motion.
 */
@keyframes busy-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes shimmer {
    from { background-position: 100% 0; }
    to { background-position: 0 0; }
}

@keyframes busy-bar {
    from { background-position: 150% 0; }
    to { background-position: -50% 0; }
}

[aria-busy="true"] .chart:empty,
[aria-busy="true"] .donut:empty,
[aria-busy="true"] ul:empty,
[aria-busy="true"] .table-wrap:has(tbody:empty),
[aria-busy="true"] .perf-figures:empty,
[aria-busy="true"][data-portfolios]:empty,
ul[aria-busy="true"]:empty {
    border-radius: 10px;
    background: linear-gradient(90deg, color-mix(in srgb, var(--text-muted) 8%, transparent) 30%, color-mix(in srgb, var(--text-muted) 16%, transparent) 50%, color-mix(in srgb, var(--text-muted) 8%, transparent) 70%);
    background-size: 300% 100%;
    animation: busy-in 0.2s ease 0.25s both, shimmer 1.4s linear 0.25s infinite;
}

[aria-busy="true"] ul:empty,
ul[aria-busy="true"]:empty,
[aria-busy="true"] .perf-figures:empty {
    min-height: 6rem;
}

[aria-busy="true"] .table-wrap:has(tbody:empty) {
    min-height: 10rem;
}

[aria-busy="true"][data-portfolios]:empty {
    min-height: 14rem;
}

.tile-loading {
    background-image: linear-gradient(90deg, transparent 30%, color-mix(in srgb, var(--surface) 30%, transparent) 50%, transparent 70%);
    background-size: 300% 100%;
    animation: shimmer 1.4s linear infinite;
}

/* Reloading what is already there (a period chip, the portfolio selector): dimmed, with a bar along the top. */
[data-dashboard],
[data-details],
[data-holdings],
[data-holding],
[data-performance],
[data-detail] {
    position: relative;
    transition: opacity 0.2s ease;
}

[aria-busy="true"]:is([data-dashboard], [data-details], [data-holdings], [data-holding], [data-performance], [data-detail]):has(canvas, tbody tr, .stat-value .amount) {
    opacity: 0.6;
    transition-delay: 0.2s;
}

[aria-busy="true"]:is([data-dashboard], [data-holdings], [data-holding], [data-performance], [data-detail])::before {
    content: "";
    position: absolute;
    z-index: 2;
    top: -0.5rem;
    right: 0;
    left: 0;
    height: 3px;
    border-radius: 3px;
    background: linear-gradient(90deg, transparent 0 35%, var(--accent) 35% 65%, transparent 65%) no-repeat;
    background-size: 60% 100%;
    animation: busy-in 0.2s ease 0.3s both, busy-bar 1.1s ease-in-out 0.3s infinite;
}

/* A part that did not load: what happened and Try again. */
.load-failed {
    border-left: 4px solid var(--negative);
}

.load-failed p {
    margin: 0;
}

.load-failed-region > :not([data-load-failed]) {
    display: none;
}

.load-failed-region > [data-load-failed] {
    margin-bottom: 0;
}

.load-failed-inline {
    margin: 0.75rem 0;
    padding: 0.5rem 0 0.5rem 0.75rem;
}

/* "Recalculating…": a small spinner before the text; "updated" afterwards. */
.notice-busy::before {
    content: "";
    display: inline-block;
    width: 0.875em;
    height: 0.875em;
    margin-right: 0.5rem;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    vertical-align: -0.1em;
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    [aria-busy="true"] .chart:empty,
    [aria-busy="true"] .donut:empty,
    [aria-busy="true"] ul:empty,
    [aria-busy="true"] .table-wrap:has(tbody:empty),
    [aria-busy="true"] .perf-figures:empty,
    [aria-busy="true"][data-portfolios]:empty,
    ul[aria-busy="true"]:empty,
    .tile-loading,
    .notice-busy::before {
        animation: none;
    }

    [aria-busy="true"]:is([data-dashboard], [data-holdings], [data-holding], [data-performance], [data-detail])::before {
        animation: busy-in 0.2s ease 0.3s both;
        background: var(--accent);
        opacity: 0.4;
    }
}

/* An empty list that says why, with the way forward beside it. */
.item-list .empty-state {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
}

/* Admin → Logs: one line per entry, newest first; details open to the context. */
.log-list {
    margin: 0.75rem 0 0;
    padding: 0;
    list-style: none;
    font-size: 0.875rem;
}

.log-line {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.log-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 0.75rem;
}

.log-head time {
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
}

.log-message {
    overflow-wrap: anywhere;
}

.log-request {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 0.8125rem;
}

.log-level-warning {
    background: color-mix(in srgb, var(--chart-4) 25%, var(--surface));
    color: var(--text);
}

.log-level-error,
.log-level-critical {
    background: color-mix(in srgb, var(--negative) 22%, var(--surface));
    color: var(--text);
}

.log-context {
    max-height: 20rem;
    margin: 0.5rem 0 0;
    padding: 0.75rem;
    overflow: auto;
    border-radius: 8px;
    background: color-mix(in srgb, var(--text-muted) 8%, var(--surface));
    font-size: 0.8125rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* Dividend calendar: received solid, declared outlined, expected faint; the holding column stays put. */
.calendar-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    justify-content: space-between;
    gap: 0.75rem 1.5rem;
    margin-bottom: 1rem;
}

.calendar-bar .field {
    margin: 0;
    min-width: 12rem;
}

.calendar-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 0.875rem;
}

.calendar-legend li {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
}

.cal-swatch {
    display: inline-block;
    flex: none;
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 3px;
}

.cal-swatch.cal-received { background: var(--chart-1); }
.cal-swatch.cal-declared { background: var(--chart-3); }
.cal-swatch.cal-projected { background: var(--chart-5); }

.calendar-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 2px;
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
}

.calendar-table th {
    padding: 0.25rem;
    color: var(--text-muted);
    font-weight: 600;
    text-align: left;
}

.calendar-table .col-num {
    text-align: right;
    white-space: nowrap;
}

.calendar-table .col-security {
    position: sticky;
    left: 0;
    z-index: 1;
    min-width: 7rem;
    background: var(--surface);
    color: var(--text);
}

.calendar-table .cal-name {
    display: block;
    max-width: 9rem;
    overflow: hidden;
    font-weight: 400;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cal-cell {
    padding: 0.375rem 0.25rem;
    border-radius: 4px;
}

.cal-cell.cal-received { background: color-mix(in srgb, var(--chart-1) 18%, var(--surface)); }
.cal-cell.cal-declared { background: color-mix(in srgb, var(--chart-3) 12%, var(--surface)); box-shadow: inset 0 0 0 1.5px var(--chart-3); }
.cal-cell.cal-projected { background: color-mix(in srgb, var(--chart-5) 14%, var(--surface)); color: var(--text-muted); }

.calendar-table tfoot th,
.calendar-table tfoot td,
.cal-row-total {
    font-weight: 700;
}

.calendar-table tfoot .cal-cell:not(.cal-empty) {
    border-top: 2px solid var(--border);
}

.cal-detail td {
    padding: 0 0 0.75rem 0.5rem;
}

.cal-detail .cal-payments {
    position: sticky;
    left: 0;
    max-width: min(48rem, calc(100vw - 4rem));
}

@media (max-width: 760px) {
    /* the card's padding and the page gutter: the list fits what is visible */
    .cal-detail .cal-payments {
        max-width: calc(100vw - 7rem);
    }
}

.gain-list .cal-payment {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: baseline;
    gap: 0.25rem 0.5rem;
}

.cal-payment .gain-name {
    text-align: left;
}

.month-list .cal-month-empty > summary {
    color: var(--text-muted);
    font-weight: 400;
}



.cal-payment-projected .amount {
    color: var(--text-muted);
}

.month-list .cal-month {
    border-bottom: 1px solid var(--border);
}

.month-list .cal-month > summary {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.625rem 0;
    cursor: pointer;
    font-weight: 600;
}

.month-list .cal-month > summary::-webkit-details-marker {
    display: none;
}

.month-list .cal-month > summary::before {
    content: "▸";
    margin-right: 0.5rem;
    color: var(--text-muted);
}

.month-list .cal-month[open] > summary::before {
    content: "▾";
}

.month-list .cal-month > summary > span:first-child {
    flex: 1;
}

/* Fee audit: a fund's name, and an expense ratio's source, on a line of their own under it. */
.fees-cell {
    display: flex;
    flex-direction: column;
    align-items: inherit;
    min-width: 0;
}

.fees-table .col-num .fees-cell {
    align-items: flex-end;
}

.fees-table .holding-sub {
    display: block;
    max-width: 16rem;
    margin-top: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Income: each holding's share of what is expected, as a bar beside the figure. */
.income-table .holding-sub {
    display: block;
    max-width: 16rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.income-table .income-total-cell {
    font-weight: 700;
}

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

.share-cell {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
}

.share-track {
    display: inline-block;
    width: 4rem;
    height: 0.5rem;
    border-radius: 3px;
    background: color-mix(in srgb, var(--text-muted) 12%, transparent);
}

.share-bar {
    display: block;
    height: 100%;
    border-radius: 3px;
    background: var(--chart-1);
}

/* ETF X-ray: the funds a holding comes through as small tags; overlap tinted by how much two funds share. */
.dash-row-even {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (max-width: 900px) {
    .dash-row-even {
        grid-template-columns: minmax(0, 1fr);
    }
}

.xray-search {
    margin: 0;
    min-width: 14rem;
}

.chip-row {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.chip.chip-static {
    min-width: 0;
    min-height: 0;
    padding: 0.125rem 0.5rem;
    border-color: transparent;
    background: color-mix(in srgb, var(--accent) 10%, var(--surface));
    color: var(--text);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: default;
}

.xray-table td:last-child {
    min-width: 10rem;
}

.overlap-pct {
    min-width: 3.5rem;
    padding: 0.125rem 0.5rem;
    border-radius: 6px;
    font-weight: 700;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.overlap-grid {
    margin-top: 1rem;
    border-collapse: separate;
    border-spacing: 2px;
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
}

.overlap-grid th {
    padding: 0.25rem 0.375rem;
    color: var(--text-muted);
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
}

.overlap-grid thead th {
    text-align: center;
}

.overlap-grid td {
    min-width: 2.75rem;
    padding: 0.375rem 0.25rem;
    border-radius: 4px;
    text-align: center;
}

.ov-0 { background: color-mix(in srgb, var(--text-muted) 6%, var(--surface)); color: var(--text-muted); }
.ov-1 { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.ov-2 { background: color-mix(in srgb, var(--accent) 24%, var(--surface)); }
.ov-3 { background: color-mix(in srgb, var(--accent) 40%, var(--surface)); }
.ov-4 { background: color-mix(in srgb, var(--accent) 52%, var(--surface)); color: var(--text); font-weight: 700; }
.ov-self { background: color-mix(in srgb, var(--text-muted) 15%, var(--surface)); }

.xray-country {
    white-space: nowrap;
}

.chip.chip-more {
    display: none;
}

@media (max-width: 760px) {
    .xray-search {
        width: 100%;
    }

    .chip-row .chip:nth-child(n+4):not(.chip-more) {
        display: none;
    }

    .chip.chip-more {
        display: inline-flex;
        background: color-mix(in srgb, var(--text-muted) 12%, var(--surface));
    }
}

/* Growth simulator: the assumptions beside the chart where there is room, stacked on a phone. */
.sim-layout {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    gap: 0 1.25rem;
    align-items: start;
}

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

.sim-form {
    display: grid;
    gap: 0.875rem;
}

.sim-slider label {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    font-weight: 600;
}

.sim-slider output {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.sim-slider input[type="range"] {
    width: 100%;
    min-height: 44px;
    margin: 0;
    accent-color: var(--accent);
}

.sim-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
    font-weight: 600;
}

.sim-toggle input {
    width: 1.25rem;
    height: 1.25rem;
    accent-color: var(--accent);
}

.sim-form .is-changed output {
    color: var(--accent);
}

details > summary h2 {
    margin: 0;
}
