/* =====================================================
   MUECKINVEST WIKIPERFORMANCE FRONTEND
   Brand-Farbe wird zentral aus dem globalen Designsystem
   uebernommen. Fallback: #3776FF.
===================================================== */

:root {
    --mi-blue: var(--color-bg-table-head, #3776FF);
    --mi-blue-dark: var(--color-brand-dark, #6EA8FF);
    --mi-blue-soft: rgba(55, 118, 255, 0.09);
}

/* =====================================================
   CARD / GRUNDAUFBAU
===================================================== */

.miwp-card {
    --bg: #FFFFFF;
    --text: #172033;
    --muted: #64748B;
    --line: #DBE2EA;
    --head: var(--color-bg-table-head, #3776FF);

    margin: 18px 0;
    padding: 18px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 14px;
}

html.dark-mode .miwp-card {
    --bg: #0B1424;
    --text: #F8FAFC;
    --muted: #CBD5E1;
    --line: #314158;
    --head: var(--color-bg-table-head, #3776FF);
}

/* =====================================================
   JAHRESAUSWAHL
===================================================== */

.miwp-year {
    margin: 0 0 14px;
}

.miwp-year select {
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
}

/* =====================================================
   TABELLEN
===================================================== */

.miwp-scroll {
    width: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--line);
    border-radius: 10px;
}

.miwp-scroll table {
    width: 100%;
    min-width: 980px;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    border-top: 1px solid var(--line) !important;
    border-left: 1px solid var(--line) !important;
}

.miwp-scroll th,
.miwp-scroll td {
    padding: 10px;
    border-right: 1px solid var(--line) !important;
    border-bottom: 1px solid var(--line) !important;
    text-align: right;
    white-space: nowrap;
}

/*
 * Alle Tabellenkoepfe beziehen ihre Farbe direkt aus dem
 * globalen Mueckinvest Designsystem.
 */
.miwp-card .miwp-scroll table thead,
.miwp-card .miwp-scroll table thead tr,
.miwp-card .miwp-scroll table thead th,
.miwp-card .miwp-scroll table thead tr th,
.miwp-card .miwp-scroll thead th,
.miwp-card .miwp-scroll th {
    background-color: var(--head) !important;
    background-image: none !important;
    color: #FFFFFF !important;
}

.miwp-card .miwp-scroll table thead th,
.miwp-card .miwp-scroll table thead tr th,
.miwp-card .miwp-scroll thead th,
.miwp-card .miwp-scroll th {
    position: sticky;
    top: 0;
    z-index: 4;
    border-color: rgba(255, 255, 255, 0.28) !important;
}

/* Erste Spalte bleibt beim horizontalen Scrollen sichtbar. */
.miwp-scroll tbody td:first-child {
    position: sticky;
    left: 0;
    z-index: 5;
    text-align: left;
    background: var(--bg);
    color: var(--text);
    border-right: 1px solid var(--line) !important;
}

/* Linke obere Ecke muss ueber Kopf und erster Spalte liegen. */
.miwp-card .miwp-scroll table thead th:first-child,
.miwp-card .miwp-scroll table thead tr th:first-child,
.miwp-card .miwp-scroll thead th:first-child,
.miwp-card .miwp-scroll th:first-child {
    position: sticky;
    top: 0;
    left: 0;
    z-index: 10;
    text-align: left;
    background-color: var(--head) !important;
    background-image: none !important;
    color: #FFFFFF !important;
}

.miwp-scroll tbody td {
    border-color: var(--line) !important;
}

.miwp-scroll small {
    display: block;
}

/* =====================================================
   PERFORMANCE-FARBEN
===================================================== */

.pos {
    color: #078743;
    font-weight: 700;
}

.neg {
    color: #C62828;
    font-weight: 700;
}

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

/* =====================================================
   DIAGRAMME
===================================================== */

.miwp-chart {
    position: relative;
    height: 460px;
    padding: 10px;
    background: #FFFFFF;
    border: 1px solid var(--line);
    border-radius: 12px;
}

.miwp-chart canvas {
    display: block;
    width: 100%;
    height: calc(100% - 42px);
}

.miwp-legend {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    color: #334155;
    font-size: 12px;
    padding: 8px;
}

html.light-mode .miwp-chart {
    background: #FFFFFF;
}

html.light-mode .miwp-legend {
    color: #334155;
}

html.dark-mode .miwp-chart {
    background: #0F1115;
    border-color: #2A2D33;
}

html.dark-mode .miwp-legend {
    color: #E5EDF7;
}

.miwp-single-wrap > .miwp-year {
    margin-bottom: 10px;
}

/* =====================================================
   ZEITRAUM-TABS
===================================================== */

.miwp-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.miwp-tabs button {
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
}

.miwp-tabs button.active {
    background: var(--mi-blue);
    border-color: var(--mi-blue);
    color: #FFFFFF;
}

.miwp-note {
    font-size: 12px;
    color: var(--muted);
}

/* =====================================================
   ASSET-AUSWAHL
===================================================== */

.miwp-selector {
    margin: 10px 0 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg);
}

.miwp-selector > summary {
    padding: 12px 14px;
    font-weight: 800;
    cursor: pointer;
    list-style-position: inside;
}

.miwp-selector[open] > summary {
    border-bottom: 1px solid var(--line);
}

.miwp-selector-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin: 12px 0 8px;
}

.miwp-selector-head button {
    padding: 7px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
}

.miwp-selector-head button:hover,
.miwp-selector-head button:focus {
    border-color: var(--mi-blue);
    color: var(--mi-blue);
}

.miwp-selector .miwp-selector-head,
.miwp-selector .miwp-asset-selector {
    margin-left: 12px;
    margin-right: 12px;
}

.miwp-asset-selector {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 8px;
    max-height: 220px;
    overflow: auto;
    margin-bottom: 14px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg);
}

.miwp-asset-selector label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
}

.miwp-asset-selector label:has(input:checked) {
    border-color: var(--mi-blue);
    background: var(--mi-blue-soft);
}

/* =====================================================
   RANKING
===================================================== */

.miwp-ranking {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 12px;
    margin-top: 18px;
}

.miwp-ranking article {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.miwp-ranking article[hidden] {
    display: none;
}

.miwp-ranking h4 {
    margin: 0 0 3px;
    font-size: 16px;
}

.miwp-ranking small {
    color: var(--muted);
}

.miwp-ranking strong {
    font-size: 18px;
}

.miwp-rank {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--mi-blue);
    color: #FFFFFF;
    font-weight: 800;
}

.miwp-rank-name {
    font-size: 16px;
    font-weight: 800;
}

/* =====================================================
   ASSET-LINKS
===================================================== */

.miwp-asset-link {
    color: inherit;
    text-decoration: none;
    font-weight: 800;
    border-bottom: 1px dashed currentColor;
}

.miwp-asset-link:hover,
.miwp-asset-link:focus,
html.dark-mode .miwp-asset-link:hover,
html.dark-mode .miwp-asset-link:focus {
    color: var(--mi-blue);
    border-bottom-style: solid;
}

.miwp-ranking .miwp-asset-link {
    border: 0;
    font-size: 16px;
    line-height: 1.3;
}

/* =====================================================
   MOBILE HILFSZEILEN
===================================================== */

.miwp-mobile-asset-name {
    display: none;
}

/* =====================================================
   DARK MODE TABELLEN
===================================================== */

html.dark-mode .miwp-scroll table {
    border-color: #2A2D33 !important;
}

html.dark-mode .miwp-scroll tbody td {
    border-color: #2A2D33 !important;
}

html.dark-mode .miwp-card .miwp-scroll table thead,
html.dark-mode .miwp-card .miwp-scroll table thead tr,
html.dark-mode .miwp-card .miwp-scroll table thead th,
html.dark-mode .miwp-card .miwp-scroll table thead tr th,
html.dark-mode .miwp-card .miwp-scroll thead th,
html.dark-mode .miwp-card .miwp-scroll th {
    background-color: var(--head) !important;
    background-image: none !important;
    color: #FFFFFF !important;
    border-color: rgba(255, 255, 255, 0.20) !important;
}

/* =====================================================
   RESPONSIVE BIS 768 PX
===================================================== */

@media (max-width: 768px) {
    .miwp-card {
        padding: 8px;
        margin: 10px 0;
        border-radius: 10px;
    }

    .miwp-chart,
    .miwp-chart[style] {
        height: 260px !important;
        padding: 5px;
    }

    .miwp-chart canvas {
        height: 210px !important;
    }

    .miwp-legend {
        max-height: 42px;
        overflow: auto;
        padding: 5px;
        font-size: 10px;
        line-height: 1.2;
    }

    .miwp-note {
        margin: 8px 2px 12px;
        line-height: 1.35;
    }

    .miwp-ranking {
        margin-top: 10px;
        gap: 8px;
    }

    .miwp-ranking article {
        padding: 11px;
        grid-template-columns: auto 1fr auto;
    }

    .miwp-scroll {
        position: relative;
        width: 100%;
        overflow-x: auto !important;
        overflow-y: visible;
        overscroll-behavior-x: contain;
        scroll-behavior: smooth;
    }

    .miwp-scroll table {
        width: max-content !important;
        min-width: max-content !important;
        border-collapse: separate !important;
        border-spacing: 0 !important;
    }

    .miwp-scroll .miwp-mobile-asset-name {
        display: none !important;
    }

    .miwp-scroll thead th:first-child,
    .miwp-scroll .miwp-asset-data-row .miwp-desktop-asset-name {
        display: table-cell !important;
        position: sticky !important;
        left: 0 !important;
        width: 118px !important;
        min-width: 118px !important;
        max-width: 118px !important;
        padding: 7px 8px !important;
        font-size: 12px !important;
        white-space: normal !important;
        text-align: left !important;
        box-shadow: 2px 0 0 var(--line);
    }

    .miwp-scroll .miwp-asset-data-row .miwp-desktop-asset-name {
        z-index: 8 !important;
        background: var(--bg) !important;
        color: var(--text) !important;
    }

    .miwp-card .miwp-scroll thead th:first-child {
        z-index: 10 !important;
        background-color: var(--head) !important;
        background-image: none !important;
        color: #FFFFFF !important;
    }

    .miwp-scroll th:not(:first-child),
    .miwp-scroll td:not(:first-child) {
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
        padding: 7px 9px !important;
    }

    .miwp-scroll td small {
        font-size: 10px;
    }
}

/* =====================================================
   RESPONSIVE BIS 600 PX
===================================================== */

@media (max-width: 600px) {
    .miwp-selector-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .miwp-asset-selector {
        grid-template-columns: 1fr;
    }

    .miwp-ranking {
        grid-template-columns: 1fr;
    }
}

/* =====================================================
   LETZTE PRIORITAET: TABELLENKOPF ERZWINGEN
   Dieser Block steht absichtlich am Dateiende.
===================================================== */

.miwp-card .miwp-scroll table > thead > tr > th,
.miwp-card .miwp-scroll table > thead > tr > th:first-child,
html.dark-mode .miwp-card .miwp-scroll table > thead > tr > th,
html.dark-mode .miwp-card .miwp-scroll table > thead > tr > th:first-child {
    background-color: var(--color-bg-table-head, #3776FF) !important;
    background-image: none !important;
    color: #FFFFFF !important;
}