:root {
    --bg: #0f172a;
    --panel: #1e293b;
    --panel-border: #334155;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --accent: #38bdf8;
    --match: #16a34a;
    --nomatch: #475569;
    --info: #ca8a04;
    font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    overflow-x: hidden; /* Sicherheitsnetz: einzelne Elemente scrollen selbst horizontal (z. B. Tabelle), die Seite als Ganzes nie */
}

header.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--panel);
    border-bottom: 1px solid var(--panel-border);
}

header.app-header a { color: var(--text); text-decoration: none; }
.header-title { display: flex; align-items: baseline; gap: 8px; }
.version-badge { color: var(--muted); font-size: 12px; font-weight: 400; text-decoration: underline; text-decoration-style: dotted; }
.version-badge:hover { color: var(--accent); }
header.app-header nav a { margin-right: 16px; color: var(--muted); }
header.app-header nav a:hover { color: var(--accent); }

/* Aufklappbare Menügruppe (z. B. "Daten & Import") */
.nav-group { position: relative; display: inline-block; margin-right: 16px; }
.nav-group-toggle {
    background: none;
    border: none;
    padding: 0;
    border-radius: 0;
    color: var(--muted);
    font: inherit;
    font-weight: 400;
    cursor: pointer;
}
.nav-group-toggle:hover, .nav-group.open .nav-group-toggle { color: var(--accent); opacity: 1; }
.nav-submenu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    min-width: 230px;
    padding: 6px 0;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    z-index: 60;
}
.nav-group.open .nav-submenu { display: block; }
@media (hover: hover) and (min-width: 641px) {
    .nav-group:hover .nav-submenu { display: block; }
}
header.app-header nav .nav-submenu a { display: block; margin: 0; padding: 8px 14px; white-space: nowrap; }
header.app-header nav .nav-submenu a:hover { background: rgba(255, 255, 255, 0.05); }

/* Aktualisieren-Knopf der Kopfzeile (siehe nav.js): mobil und in der Homebildschirm-App sichtbar, am Desktop nicht nötig */
.refresh-btn {
    display: none;
    margin-left: auto;
    margin-right: 8px;
    background: transparent;
    border: 1px solid var(--panel-border);
    color: var(--text);
    border-radius: 6px;
    font-size: 20px;
    line-height: 1;
    padding: 6px 10px;
    cursor: pointer;
}
.refresh-btn.spinning { animation: refresh-spin 0.8s linear infinite; }
@keyframes refresh-spin { to { transform: rotate(360deg); } }
@media (max-width: 640px), (display-mode: standalone) {
    .refresh-btn { display: inline-block; }
}
/* Hinweis beim Herunterziehen (nur App-Modus) */
.pull-hint {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translate(-50%, -100%);
    padding: 8px 16px;
    border-radius: 0 0 12px 12px;
    background: var(--accent);
    color: #0f172a;
    font-size: 13px;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    z-index: 100;
    white-space: nowrap;
}
.nav-toggle {
    display: none;
    background: transparent;
    border: 1px solid var(--panel-border);
    color: var(--text);
    font-size: 20px;
    line-height: 1;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
}

main { padding: 24px; max-width: 1400px; margin: 0 auto; }

.card {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--panel-border); white-space: nowrap; }
td.signal-cell { white-space: normal; min-width: 320px; max-width: 420px; }

/* white-space:normal am <td> selbst nötig, sonst erzwingt das automatische
   Tabellen-Spaltenlayout die Spaltenbreite am längsten unumbrochenen Namen in
   der ganzen Tabelle (ließ die farbige Hinterlegung bei kurzen Namen sichtbar
   in die Kaufdatum-Spalte hineinragen). Die feste Breite steckt bewusst am
   inneren .name-truncate-Element (nicht am <td> als max-width) - sonst hat der
   Browser keinen verlässlichen Anhaltspunkt für die Spaltenbreite und
   kollabiert die Spalte stattdessen auf wenige Pixel. */
td.name-cell { white-space: normal; }
/* Die feste Breite steckt bewusst am äußeren .name-cell-header (nicht mehr am
   .name-truncate selbst) - so bleibt der Spaltenanker für das Tabellenlayout
   immer gleich groß, egal ob 0, 1 oder 2 Kauf/Verkaufsziel-Badges daneben
   stehen; .name-truncate schrumpft stattdessen flexibel (min-width:0 nötig,
   sonst verhindert Flexbox das Schrumpfen unter die Textbreite). */
.name-cell-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; width: 160px; }
.name-truncate {
    display: block;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
    cursor: default;
    font-weight: 700;
}
/* Depot als Kürzel in Markenfarbe bzw. Logo (siehe depotMark() in index.php); der volle Name steht nur mobil dahinter */
.depot-badge {
    display: inline-block;
    min-width: 30px;
    padding: 3px 6px;
    border-radius: 6px;
    background: var(--brand, #94a3b8);
    color: #0f172a;
    font-weight: 700;
    font-size: 11px;
    line-height: 1.2;
    text-align: center;
    letter-spacing: 0.02em;
    cursor: default;
}
.depot-logo { height: 22px; width: auto; max-width: 56px; vertical-align: middle; border-radius: 4px; }
.depot-full { display: none; }
td.depot-cell { width: 1%; }
.target-badges { display: flex; gap: 4px; flex-shrink: 0; }
.target-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    line-height: 1;
}
.target-badge-buy { background: var(--match); }
.target-badge-sell { background: #dc2626; }
.signal-source { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.zone-row { margin-bottom: 8px; }
.zone-detail { color: var(--muted); font-size: 12px; }
th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); }
tbody tr:hover { background: rgba(255,255,255,0.03); }

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.badge-match { background: var(--match); color: white; }
.badge-sell { background: #2563eb; color: white; }
.badge-verkauf { background: #dc2626; color: white; }
.badge-nomatch { background: var(--nomatch); color: var(--muted); }

/* Seite "Gesendete E-Mails": Vorschau des Mailtexts beim Überfahren/Antippen einer Zeile */
tr.mail-row { cursor: pointer; }
tr.mail-row.pinned td { background: rgba(56, 189, 248, 0.12); }
.mail-body-store { display: none !important; }
.mail-preview {
    position: fixed;
    z-index: 200;
    max-width: min(760px, calc(100vw - 32px));
    max-height: 70vh;
    overflow: auto;
    padding: 14px 16px;
    background: var(--bg);
    border: 1px solid var(--accent);
    border-radius: 8px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
    font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    pointer-events: none;
}
/* Festgehalten (Klick/Antippen): bedienbar, damit lange Mails scrollbar sind */
.mail-preview.interactive { pointer-events: auto; }
.mail-preview[hidden] { display: none; }
.badge-info { background: var(--info); color: #1c1917; }
.badge-none { background: transparent; color: var(--muted); border: 1px dashed var(--panel-border); }

.pos { color: #4ade80; }
.neg { color: #f87171; }

form.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

input, button {
    background: #0f172a;
    border: 1px solid var(--panel-border);
    color: var(--text);
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 14px;
}

button {
    background: var(--accent);
    color: #0f172a;
    font-weight: 600;
    border: none;
    cursor: pointer;
}
button:hover { opacity: 0.9; }

.btn-buy { background: #86efac; color: #14532d; }
.btn-sell { background: #fca5a5; color: #7f1d1d; }

.row-toggle-btn {
    background: transparent;
    border: none;
    color: var(--accent);
    font-size: 20px;
    line-height: 1;
    padding: 4px 8px 4px 0;
    cursor: pointer;
    vertical-align: middle;
}
.row-toggle-btn:hover { opacity: 0.75; }

.name-cell-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2px;
}

a.link { color: var(--accent); }
a.btn-link {
    display: inline-block;
    padding: 8px 14px;
    border-radius: 6px;
    background: var(--accent);
    color: #0f172a;
    font-weight: 600;
    font-size: 14px;
    text-decoration: none;
}
a.btn-link:hover { opacity: 0.9; }

.errors { color: #f87171; }
.notice { color: #4ade80; }
/* Statuszeile oben im Dashboard (Kurse/FX/Marktübersicht): bewusst klein, nur Information */
.status-line { font-size: 12px; }

.login-box {
    max-width: 360px;
    margin: 80px auto;
}

.summary-grid {
    display: grid;
    grid-template-columns: 230px 190px 180px 180px 180px 1fr;
    gap: 24px;
    align-items: start;
}
.summary-grid .chart-caption { margin-bottom: 4px; }
.summary-grid canvas { max-height: 130px; }
.summary-label { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.summary-value { font-size: 28px; font-weight: 700; white-space: nowrap; }
/* Zeile unter dem Gesamtwert: investiertes Kapital und Gewinn/Verlust, bewusst kleiner als der Gesamtwert */
.summary-sub { font-size: 13px; color: var(--muted); margin-top: 4px; line-height: 1.5; }
.summary-sub .pos, .summary-sub .neg { font-weight: 600; }
.summary-depots { font-size: 14px; line-height: 1.6; }
.summary-signal-count { font-size: 13px; color: var(--muted); margin-top: 8px; }
.top3-widget {
    margin-top: 10px;
    padding: 6px 8px;
    border-radius: 6px;
    border: 3px solid #fde047;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.6;
    display: grid;
    grid-template-columns: auto auto;
    justify-content: start;
    column-gap: 10px;
    row-gap: 2px;
}
.top3-label, .top3-value { text-align: left; }
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.modal-overlay.open { display: flex; }
.modal-card {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 20px;
    width: 100%;
    max-width: 1000px;
}
.modal-chart-body { height: 55vh; position: relative; }
.modal-close {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}
.modal-close:hover { color: var(--text); }

.chart-caption { color: var(--muted); font-size: 13px; margin-bottom: 8px; text-align: center; }

.summary-chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.chart-toggle { display: flex; gap: 6px; }
.chart-toggle-btn {
    background: transparent;
    border: 1px solid var(--panel-border);
    color: var(--muted);
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 999px;
    cursor: pointer;
}
.chart-mode-note { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* Depot-Auswahl als Buttons in Broker-Markenfarben (statt Dropdown) */
.depot-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.depot-btn {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 999px;
    border: 2px solid var(--brand, var(--panel-border));
    color: var(--brand, var(--text));
    background: transparent;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    user-select: none;
}
.depot-btn.active,
input.depot-radio:checked + .depot-btn {
    background: var(--brand);
    color: #0f172a;
}
input.depot-radio { position: absolute; opacity: 0; width: 0; height: 0; }
.depot-btn.depot-all { border-color: var(--panel-border); color: var(--muted); }
.depot-btn.depot-all.active { background: var(--panel-border); color: var(--text); }
.chart-toggle-btn.active {
    background: var(--accent);
    color: #0f172a;
    border-color: var(--accent);
    font-weight: 600;
}
.chart-toggle-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Schiebeschalter für binäre An/Aus-Filter (Watchlist, Details, EUR-Werte, ...) -
   bewusst optisch von den Depot/Klasse-Auswahlpillen abgesetzt, da dort "eine von
   mehreren wählen" statt "an/aus" gilt. */
.toggle-switch-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}
.toggle-track {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    border-radius: 999px;
    background: var(--panel-border);
    flex-shrink: 0;
    transition: background 0.15s ease;
}
.toggle-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text);
    transition: transform 0.15s ease;
}
.toggle-switch-btn.active .toggle-track { background: var(--brand, var(--accent)); }
.toggle-switch-btn.active .toggle-knob { transform: translateX(16px); background: #0f172a; }
.toggle-switch-btn.active .toggle-text { color: var(--text); }
.toggle-switch-btn:disabled { cursor: not-allowed; opacity: 0.4; }

.filter-bar {
    display: flex;
    gap: 24px;
    align-items: center;
    flex-wrap: wrap;
}
.filter-bar label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    color: var(--muted);
}
.filter-bar select { min-width: 160px; }

/* "Wert (EUR)"-Spalte + Summe ausblenden/ausgrauen */
body.eur-hidden .eur-value {
    filter: blur(5px);
    user-select: none;
}

.signal-row td { background: rgba(255,255,255,0.015); padding-top: 4px; padding-bottom: 12px; }
.sell-target { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--panel-border); }
.sell-target label { color: var(--muted); font-size: 13px; }
.sell-target input, .sell-target button { padding: 4px 8px; font-size: 13px; }
/* Notiz-Feld der Ziel-Formulare: nimmt am Desktop den restlichen Platz der Zeile ein, am iPhone die ganze Breite
   (wie der Speichern-Knopf, siehe @media unten) */
.sell-target input.target-note { flex: 1 1 280px; min-width: 200px; width: 280px; }
/* Nach Klick auf einen Namen im Gewinn/Verlust-Chart: Zeile/Kachel kurz hervorheben */
tr.position-row.row-flash { outline: 2px solid var(--accent); outline-offset: -2px; }
tr.position-row.row-flash td { animation: row-flash 2.6s ease-out; }
@keyframes row-flash {
    0%, 35% { background-color: rgba(56, 189, 248, 0.28); }
    100% { background-color: transparent; }
}

/* Mobil (iPhone & Co.): Kopfzeilen-Grid, Nav und Formulare brechen bei fester Breite
   um - hier auf einspaltiges/stapelndes Layout umschalten statt horizontal zu scrollen.
   Die Positions-Tabelle wird zu einer Karten-Liste (Label: Wert je Zeile) statt einer
   horizontal scrollenden Tabelle mit 12 Spalten - auf einem Handy nicht sinnvoll bedienbar. */
@media (max-width: 640px) {
    header.app-header {
        flex-wrap: wrap;
        padding: 12px 16px;
    }
    .nav-toggle { display: block; }
    header.app-header nav {
        display: none;
        flex-direction: column;
        align-items: stretch;
        gap: 2px;
        width: 100%;
        margin-top: 10px;
        white-space: normal;
    }
    header.app-header nav.open { display: flex; }
    header.app-header nav a {
        margin-right: 0;
        padding: 10px 4px;
        border-top: 1px solid var(--panel-border);
    }
    /* Menügruppe: in der Hamburger-Ansicht als aufklappbare Zeile mit eingerückten Unterpunkten */
    .nav-group { display: block; margin-right: 0; }
    .nav-group-toggle {
        width: 100%;
        text-align: left;
        padding: 10px 4px;
        border-top: 1px solid var(--panel-border);
    }
    .nav-submenu {
        position: static;
        min-width: 0;
        padding: 0 0 0 14px;
        background: transparent;
        border: none;
        border-radius: 0;
        box-shadow: none;
    }
    header.app-header nav .nav-submenu a { padding: 10px 4px; white-space: normal; }

    main { padding: 12px; }
    .card { padding: 14px; }

    .summary-grid { grid-template-columns: 1fr; gap: 18px; }
    .summary-value { font-size: 24px; }

    .filter-bar { gap: 12px 16px; }
    .filter-bar select { min-width: 0; width: 100%; }

    .modal-overlay { padding: 8px; }
    .modal-card { padding: 12px; }
    .modal-chart-body { height: 42vh; }

    table { font-size: 13px; }
    td.signal-cell { min-width: 0; max-width: none; }

    /* Positions-Tabelle -> Karten-Liste */
    .mobile-card-table thead { display: none; }
    .mobile-card-table, .mobile-card-table tbody, .mobile-card-table tr { display: block; width: 100%; }
    .mobile-card-table td {
        display: block;
        white-space: normal;
        border-bottom: none;
        padding: 3px 6px;
    }
    .mobile-card-table td.name-cell { max-width: none; }
    .mobile-card-table .depot-full { display: inline; margin-left: 6px; }
    .mobile-card-table td.depot-cell { width: auto; }
    .mobile-card-table .name-truncate { white-space: normal; width: auto; flex: initial; }
    .mobile-card-table .name-cell-header { width: auto; }
    /* Auf dem Desktop zweizeilig (spart Spaltenbreite), in der Kartenansicht dagegen
       nebeneinander, damit die Karten niedriger werden. */
    .mobile-card-table td[data-label="52w tief/hoch"] br,
    .mobile-card-table td[data-label="Wert (EUR)"] br { display: none; }
    .mobile-card-table td[data-label]:not([data-label=""])::before {
        content: attr(data-label) ": ";
        color: var(--muted);
        font-size: 11px;
        font-weight: 600;
    }
    .mobile-card-table tr.position-row {
        border: 1px solid var(--panel-border);
        border-radius: 8px 8px 0 0;
        padding: 8px 4px;
        margin-top: 12px;
    }
    .mobile-card-table tr.signal-row {
        border: 1px solid var(--panel-border);
        border-top: none;
        border-radius: 0 0 8px 8px;
    }
    .mobile-card-table tr.signal-row td { padding: 8px 10px; }
    /* Einfache Tabellen ohne position-row/signal-row-Aufteilung (z. B. Positionen verwalten):
       jede Zeile bekommt ihre eigene Karte. */
    .mobile-card-table tbody tr:not(.position-row):not(.signal-row) {
        border: 1px solid var(--panel-border);
        border-radius: 8px;
        padding: 8px 4px;
        margin-top: 12px;
    }

    form.inline { flex-direction: column; align-items: stretch; }
    .sell-target form.inline > * { width: 100%; }
    /* Notiz-Feld: volle Breite wie der Speichern-Knopf (flex-basis würde in der Spalte zur Höhe) */
    .sell-target form.inline > input.target-note { flex: none; width: 100%; min-width: 0; }

    .login-box { margin: 40px auto; padding: 0 16px; }
}
