/* ==========================================================================
   site.css - the one shared stylesheet of the website
   ==========================================================================

   Used by every page (portfolio page, mortgage calculator, legal notice).
   It is organised in reusable building blocks, from general to specific:

     1.  Font (Montserrat, stored on this server - no Google Fonts)
     2.  Colours and sizes as variables ("design tokens")
     3.  Base rules for the whole page
     4.  Page container, header with navigation, footer
     5.  Two-column layout ("Werkstatt" left, results right)
     6.  Card (the dark boxes that hold content)
     7.  Buttons
     8.  Form inputs (text fields, checkboxes, range slider)
     9.  Tables (with horizontal scrolling inside their own box)
     10. Message box (errors / hints) and loading overlay
     11. Charts
     12. Pieces that only the portfolio page uses
     13. Helpers
     14. Mortgage calculator and text pages (Baufinanzierer, Impressum)

   No inline styles are used anywhere in the HTML or JavaScript, so that a
   strict Content-Security-Policy can forbid them. JavaScript only switches
   CSS classes or the "hidden" attribute.
   ========================================================================== */


/* --------------------------------------------------------------------------
   1. Font
   The two font files come from the @fontsource/montserrat package (see
   vendor/README.md). "font-display: swap" shows the text at once in a system
   font and switches to Montserrat as soon as the file is loaded.
   -------------------------------------------------------------------------- */

@font-face {
    font-family: "Montserrat";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/montserrat-latin-400-normal.woff2") format("woff2");
}

@font-face {
    font-family: "Montserrat";
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("../fonts/montserrat-latin-600-normal.woff2") format("woff2");
}


/* --------------------------------------------------------------------------
   2. Design tokens
   Change a colour here and it changes everywhere. The chart colours live in
   js/charts.js because Chart.js draws on a canvas and cannot read CSS.
   -------------------------------------------------------------------------- */

:root {
    --color-page: #1e1e1e;          /* page background (as on the old site) */
    --color-card: #2a2a2a;          /* background of the content boxes */
    --color-card-inner: #232323;    /* slightly darker areas inside a card */
    --color-border: #3d3d3d;
    --color-grid: #474747;          /* same grey as the chart grid lines */
    --color-text: #f2f2f2;
    --color-muted: #bdbdbd;         /* secondary text; still high contrast */
    --color-accent: #c72f2f;        /* red: ticked boxes, main button */
    --color-accent-hover: #a82626;
    --color-focus: #00bcd4;         /* keyboard focus ring */
    --color-link-hover: #00bcd4;

    --color-error-bg: #4a1f1f;
    --color-error-border: #c72f2f;
    --color-info-bg: #1f3340;
    --color-info-border: #647f98;
    --color-success-bg: #1f3a24;
    --color-success-border: #4caf50;

    --font-main: "Montserrat", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;

    --radius: 8px;
    --space-xs: 0.25rem;
    --space-s: 0.5rem;
    --space-m: 1rem;
    --space-l: 1.5rem;
    --space-xl: 2rem;

    --page-max-width: 1200px;
}


/* --------------------------------------------------------------------------
   3. Base rules
   -------------------------------------------------------------------------- */

/* Make width/height include padding and border - much easier to reason about. */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Elements with the "hidden" attribute must really disappear, even if one of
   the rules below gives them display: flex or grid. */
[hidden] {
    display: none !important;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background-color: var(--color-page);
    color: var(--color-text);
    font-family: var(--font-main);
    font-size: 1rem;
    line-height: 1.5;
    /* Safety net against horizontal scrolling on phones. Wide tables scroll
       inside their own box (see .table-scroll), not the whole page. */
    overflow-x: hidden;
}

h1, h2, h3, h4 {
    font-weight: 600;
    line-height: 1.25;
    margin: 0 0 var(--space-s);
}

h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

p {
    margin: 0 0 var(--space-s);
}

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

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

/* A clearly visible ring around whatever has the keyboard focus. */
:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}

/* Some explanations contain long words; let them break instead of
   pushing the page wider than the phone screen. (Not used for table cells:
   tables scroll sideways in their own box instead, see .table-scroll.) */
p, li, dd {
    overflow-wrap: anywhere;
}

/* Link that lets keyboard users jump straight to the content. It is only
   visible while it has the keyboard focus. */
.skip-link {
    position: absolute;
    left: var(--space-s);
    top: -3rem;
    padding: var(--space-s) var(--space-m);
    background: var(--color-card);
    border: 1px solid var(--color-focus);
    border-radius: var(--radius);
    z-index: 100;
}

.skip-link:focus {
    top: var(--space-s);
}


/* --------------------------------------------------------------------------
   4. Page container, header, footer
   -------------------------------------------------------------------------- */

/* Centres the content and limits its width on large screens. The 16px side
   gutter keeps text away from the screen edge on phones. */
.container {
    width: 100%;
    max-width: var(--page-max-width);
    margin: 0 auto;
    padding: 0 16px;
}

.site-header {
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-l);
}

.site-header__inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-s) var(--space-l);
    padding-top: var(--space-m);
    padding-bottom: var(--space-m);
}

/* Logo + site name, links to the home page. */
.site-title {
    display: inline-flex;
    align-items: center;
    gap: var(--space-s);
    font-size: 1.35rem;
    font-weight: 600;
    text-decoration: none;
}

.site-title__logo {
    width: 2rem;
    height: 2rem;
    /* The bull icon is drawn in black; invert() turns it white so it is
       visible on the dark background. */
    filter: invert(1);
}

.site-nav {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs) var(--space-m);
    list-style: none;
    margin: 0;
    padding: 0;
}

.site-nav a {
    display: inline-block;
    padding: var(--space-xs) 0;
    text-decoration: none;
    color: var(--color-muted);
    border-bottom: 2px solid transparent;
}

.site-nav a:hover {
    color: var(--color-text);
}

/* The link of the page currently shown (marked with aria-current="page"). */
.site-nav a[aria-current="page"] {
    color: var(--color-text);
    border-bottom-color: var(--color-accent);
}

.site-footer {
    margin-top: var(--space-xl);
    border-top: 1px solid var(--color-border);
    padding: var(--space-l) 0;
    color: var(--color-muted);
    font-size: 0.9rem;
}

.site-footer__inner {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-s) var(--space-l);
    justify-content: space-between;
}

.site-version {
    margin-left: var(--space-xs);
    font-size: 0.75rem;
    opacity: 0.8;
}

.site-footer a {
    color: var(--color-muted);
}

.site-footer a:hover {
    color: var(--color-text);
}

.footer-links {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs) var(--space-l);
    list-style: none;
    margin: 0;
    padding: 0;
}


/* --------------------------------------------------------------------------
   5. Two-column layout
   On phones and tablets everything is one column. From 992px width on, the
   controls ("Werkstatt") take one third on the left and stay in view while
   scrolling ("sticky"); the results take the right two thirds.
   -------------------------------------------------------------------------- */

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-l);
    align-items: start;
}

/* Stack of cards with even spacing in between. */
.stack {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-l);
}

@media (min-width: 992px) {
    .layout {
        /* minmax(0, ...) prevents wide content from stretching a column. */
        grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    }

    /* Shorter instrument list, so the search box and the main button still
       fit into the visible height of the sticky panel. */
    .layout__side .checklist {
        max-height: min(20rem, 32vh);
    }

    .layout__side {
        position: sticky;
        top: var(--space-m);
        max-height: calc(100vh - 2 * var(--space-m));
        overflow-y: auto;
    }
}


/* --------------------------------------------------------------------------
   6. Card
   -------------------------------------------------------------------------- */

.card {
    background-color: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-l);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    min-width: 0;
}

@media (max-width: 480px) {
    .card {
        padding: var(--space-m);
    }
}

.card__title {
    font-size: 1.2rem;
    margin-bottom: var(--space-m);
}

/* Smaller heading inside a card. */
.card__subtitle {
    font-size: 1rem;
    margin: var(--space-l) 0 var(--space-s);
}

/* Separator line between parts of a card. */
.card__divider {
    border: 0;
    border-top: 1px solid var(--color-border);
    margin: var(--space-l) 0;
}

/* Plain-language explanation shown under a card heading. */
.explain {
    color: var(--color-muted);
    font-size: 0.95rem;
    margin-bottom: var(--space-m);
}

.explain p:last-child {
    margin-bottom: 0;
}

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

.small {
    font-size: 0.875rem;
}


/* --------------------------------------------------------------------------
   7. Buttons
   -------------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-s);
    min-height: 2.5rem;
    padding: var(--space-s) var(--space-m);
    border: 1px solid var(--color-muted);
    border-radius: var(--radius);
    background: transparent;
    color: var(--color-text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
}

.btn:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

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

/* The main action of a page, e.g. "Get efficient portfolios". */
.btn--primary {
    background-color: var(--color-accent);
    border-color: var(--color-accent);
    color: #ffffff;
}

.btn--primary:hover:not(:disabled) {
    background-color: var(--color-accent-hover);
    border-color: var(--color-accent-hover);
}

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

.btn--small {
    min-height: 2rem;
    padding: var(--space-xs) var(--space-s);
    font-size: 0.875rem;
}

.btn--block {
    width: 100%;
}

/* Button that looks like a text link (e.g. "Clear selection"). */
.btn--link {
    border: 0;
    min-height: 0;
    padding: 0;
    font-weight: 400;
    text-decoration: underline;
    text-underline-offset: 2px;
    color: var(--color-muted);
}

.btn--link:hover {
    background: none;
    color: var(--color-text);
}


/* --------------------------------------------------------------------------
   8. Form inputs
   -------------------------------------------------------------------------- */

.field {
    margin-bottom: var(--space-m);
}

.field__label {
    display: block;
    font-weight: 600;
    margin-bottom: var(--space-xs);
}

.field__hint {
    display: block;
    color: var(--color-muted);
    font-size: 0.875rem;
    margin-top: var(--space-xs);
}

.input {
    width: 100%;
    min-height: 2.5rem;
    padding: var(--space-s) var(--space-s);
    border: 1px solid var(--color-muted);
    border-radius: var(--radius);
    background-color: var(--color-card-inner);
    color: var(--color-text);
    font: inherit;
}

.input::placeholder {
    color: #9a9a9a;
}

/* Text field with a button directly to its right. */
.input-group {
    display: flex;
    gap: var(--space-s);
}

.input-group .input {
    flex: 1 1 auto;
    min-width: 0;
}

.input-group .btn {
    flex: 0 0 auto;
}

/* Native checkboxes and sliders in the red accent colour of the old site. */
input[type="checkbox"],
input[type="radio"],
input[type="range"] {
    accent-color: var(--color-accent);
}

input[type="checkbox"] {
    width: 1.1rem;
    height: 1.1rem;
    margin: 0.15rem 0 0;
    flex: 0 0 auto;
    cursor: pointer;
}

/* One checkbox with its text; the whole row is clickable. */
.check {
    display: flex;
    align-items: flex-start;
    gap: var(--space-s);
    cursor: pointer;
    flex: 1 1 auto;
    min-width: 0;
}

.range {
    width: 100%;
    cursor: pointer;
}

/* Collapsible section (<details>). */
.details {
    margin-top: var(--space-m);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-s) var(--space-m);
    background-color: var(--color-card-inner);
}

.details > summary {
    cursor: pointer;
    font-weight: 600;
}

.details[open] > summary {
    margin-bottom: var(--space-s);
}


/* --------------------------------------------------------------------------
   9. Tables
   Wrap a table in <div class="table-scroll"> so that a wide table scrolls
   sideways inside its own box instead of making the whole page wider.
   -------------------------------------------------------------------------- */

.table-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.table th,
.table td {
    padding: var(--space-s);
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    vertical-align: top;
}

.table thead th {
    color: var(--color-muted);
    font-weight: 600;
    border-bottom-color: var(--color-grid);
}

.table tbody tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.03);
}

/* Numbers are right-aligned so their digits line up. */
.table .num {
    text-align: right;
    white-space: nowrap;
}

.table .nowrap {
    white-space: nowrap;
}

/* The first column holds names; give it room to stay readable on phones. */
.table td:first-child,
.table th:first-child {
    min-width: 9rem;
}


/* --------------------------------------------------------------------------
   10. Message box and loading overlay
   -------------------------------------------------------------------------- */

/* The message area is always in the page (screen readers announce what is
   put into it thanks to aria-live). When empty it takes no space. */
.message-area:empty {
    display: none;
}

.message-area {
    margin-bottom: var(--space-l);
}

.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-m);
    padding: var(--space-m);
    border: 1px solid var(--color-info-border);
    border-left-width: 4px;
    border-radius: var(--radius);
    background-color: var(--color-info-bg);
}

.alert__text {
    flex: 1 1 auto;
    margin: 0;
    min-width: 0;
}

.alert--error {
    background-color: var(--color-error-bg);
    border-color: var(--color-error-border);
}

.alert--success {
    background-color: var(--color-success-bg);
    border-color: var(--color-success-border);
}

/* Full-screen dark veil with a spinning ring while a request runs. */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.6);
}

.loading-overlay__box {
    display: flex;
    align-items: center;
    gap: var(--space-m);
    max-width: calc(100% - 32px);
    padding: var(--space-m) var(--space-l);
    background-color: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.spinner {
    width: 2rem;
    height: 2rem;
    flex: 0 0 auto;
    border: 4px solid var(--color-muted);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Visitors who asked their system for less motion get a slower spinner. */
@media (prefers-reduced-motion: reduce) {
    .spinner {
        animation-duration: 2.5s;
    }
}


/* --------------------------------------------------------------------------
   11. Charts
   Chart.js needs a box with a fixed height; the chart then fills it and
   redraws itself when the window size changes.
   -------------------------------------------------------------------------- */

.chart-box {
    position: relative;
    width: 100%;
    height: 380px;
}

/* For charts with a long legend (many instruments). */
.chart-box--tall {
    height: 520px;
}

.chart-box--short {
    height: 300px;
}

@media (max-width: 600px) {
    .chart-box {
        height: 320px;
    }

    .chart-box--tall {
        height: 480px;
    }

    .chart-box--short {
        height: 260px;
    }
}


/* --------------------------------------------------------------------------
   12. Portfolio page
   -------------------------------------------------------------------------- */

/* Header line of the instrument list: "3 selected" + "Clear selection". */
.list-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--space-xs) var(--space-m);
    margin: var(--space-s) 0;
    font-size: 0.9rem;
}

/* Scrollable list of checkboxes. */
.checklist {
    list-style: none;
    margin: 0;
    padding: var(--space-xs) 0;
    max-height: 20rem;
    overflow-y: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background-color: var(--color-card-inner);
}

.checklist__item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-s);
    padding: var(--space-xs) var(--space-s);
}

.checklist__item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.checklist__name {
    display: block;
}

.checklist__symbol {
    display: block;
    color: var(--color-muted);
    font-size: 0.8rem;
}

.checklist__empty {
    padding: var(--space-s);
    color: var(--color-muted);
}

/* Plain list (no bullets) e.g. for instruments without enough data. */
.plain-list {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 0.9rem;
}

.plain-list li {
    padding: var(--space-xs) 0;
}

/* Search results: each entry is a full-width button. */
.result-list {
    list-style: none;
    margin: var(--space-s) 0 0;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background-color: var(--color-card-inner);
    max-height: 18rem;
    overflow-y: auto;
}

.result-list__button {
    display: block;
    width: 100%;
    padding: var(--space-s);
    border: 0;
    border-bottom: 1px solid var(--color-border);
    background: transparent;
    color: var(--color-text);
    font: inherit;
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
}

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

.result-list__button:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

.result-list__meta {
    color: var(--color-muted);
}

/* Results heading row with the "selection changed" hint. */
.notice {
    padding: var(--space-s) var(--space-m);
    border: 1px dashed var(--color-muted);
    border-radius: var(--radius);
    color: var(--color-muted);
    font-size: 0.9rem;
}

.disclaimer {
    color: var(--color-muted);
    font-size: 0.85rem;
    margin: 0;
}

/* Slider with its two end labels. */
.slider {
    margin: var(--space-m) 0;
}

.slider__ends {
    display: flex;
    justify-content: space-between;
    gap: var(--space-m);
    color: var(--color-muted);
    font-size: 0.85rem;
}

.slider__value {
    text-align: center;
    font-weight: 600;
    margin-top: var(--space-xs);
}

/* Key figures of the chosen portfolio as label/value pairs. */
.key-figures {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
    gap: var(--space-s);
    margin: var(--space-m) 0;
}

.key-figures__item {
    padding: var(--space-s) var(--space-m);
    background-color: var(--color-card-inner);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.key-figures__item dt {
    color: var(--color-muted);
    font-size: 0.8rem;
}

.key-figures__item dd {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 600;
}

/* Composition list "name - weight %". */
.composition-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.composition-list li {
    display: flex;
    justify-content: space-between;
    gap: var(--space-m);
    padding: var(--space-xs) 0;
    border-bottom: 1px solid var(--color-border);
}

.composition-list__weight {
    font-weight: 600;
    white-space: nowrap;
}

.more-links {
    margin-top: var(--space-s);
    font-size: 0.9rem;
}

.more-links a + a {
    margin-left: var(--space-m);
}

/* Correlation table: a subtle colour scale from blue (opposite movement)
   over neutral grey to red (same movement). Classes are set by JavaScript
   depending on the value; see correlationClass() in js/portfolio.js. */
.corr-table td.num,
.corr-table th.num {
    text-align: center;
}

.corr-table tbody th {
    font-weight: 400;
    white-space: nowrap;
}

.corr--self      { background-color: #3a3a3a; color: var(--color-muted); }
.corr--very-high { background-color: #6b2a2a; }
.corr--high      { background-color: #553030; }
.corr--medium    { background-color: #433333; }
.corr--low       { background-color: transparent; }
.corr--negative  { background-color: #2e3d4d; }
.corr--very-neg  { background-color: #2a4560; }

.corr-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs) var(--space-m);
    list-style: none;
    margin: var(--space-s) 0 0;
    padding: 0;
    font-size: 0.8rem;
    color: var(--color-muted);
}

.corr-legend li {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
}

.corr-legend__swatch {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 1px solid var(--color-border);
    border-radius: 3px;
}


/* --------------------------------------------------------------------------
   13. Helpers
   -------------------------------------------------------------------------- */

/* Hidden on screen but still read out by screen readers. */
.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.mt-m { margin-top: var(--space-m); }
.mb-0 { margin-bottom: 0; }


/* --------------------------------------------------------------------------
   14. Mortgage calculator and text pages
   Used by baufinanzierer.html and impressum.html only. The calculator reuses
   the .layout grid (inputs left, chart right), .card, .input, .range, .table
   and .chart-box from the sections above.
   -------------------------------------------------------------------------- */

/* A slider with its number field directly below it. */
.range + .input {
    margin-top: var(--space-s);
}

/* Running text with headings, numbered lists and paragraphs (explanations,
   legal notice). */
.prose h1 {
    font-size: 1.6rem;
    margin-bottom: var(--space-m);
}

.prose h2 {
    margin-top: var(--space-l);
}

.prose h3 {
    margin-top: var(--space-l);
}

.prose > :first-child {
    margin-top: 0;
}

.prose ol,
.prose ul {
    margin: 0 0 var(--space-m);
    padding-left: 1.5rem;
}

.prose li {
    margin-bottom: var(--space-s);
}

/* Visible marker for text the site owner still has to fill in. */
.todo {
    background-color: #5c4a00;
    border-radius: 3px;
    padding: 0 var(--space-xs);
}

.mb-m { margin-bottom: var(--space-m); }
