/* ═══ 16. CSV MAPPING MODAL ═══ */

/* ─── CSV Mapping Modal ──────────────────────────────── */

.mapping-modal-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.import-modal-intro {
    font-size: 13px;
    line-height: 1.5;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid transparent;
}
.import-modal-intro.intro-ok {
    background: rgba(34, 197, 94, 0.07);
    border-color: rgba(34, 197, 94, 0.18);
    color: var(--text);
}
.import-modal-intro.intro-warn {
    background: rgba(234, 179, 8, 0.07);
    border-color: rgba(234, 179, 8, 0.18);
    color: var(--text);
}
.import-modal-intro.intro-error {
    background: rgba(239, 68, 68, 0.07);
    border-color: rgba(239, 68, 68, 0.18);
    color: var(--text);
}

.mapping-auto-btn {
    background: none;
    border: none;
    padding: 0;
    font-size: inherit;
    color: var(--accent);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.mapping-auto-btn:hover {
    color: var(--text);
}

.mapping-quality-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 7px;
    font-size: 13px;
    margin-bottom: 8px;
    border: 1px solid transparent;
}
.mapping-quality-bar.ok {
    background: rgba(34, 197, 94, 0.08);
    border-color: rgba(34, 197, 94, 0.2);
    color: #4ade80;
}
.mapping-quality-bar.warn {
    background: rgba(234, 179, 8, 0.08);
    border-color: rgba(234, 179, 8, 0.2);
    color: #facc15;
}
.mapping-quality-bar.error {
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.2);
    color: #f87171;
}
.mapping-quality-bar .quality-icon {
    flex-shrink: 0;
}

.mapping-fields {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.mapping-section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    margin: 8px 0 4px;
}

.field-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.field-row label {
    width: 90px;
    font-size: 13px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.field-row label .required-star {
    color: var(--accent);
    margin-left: 2px;
}

.mapping-select {
    flex: 1;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 6px;
    color: var(--text);
    padding: 6px 10px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.15s;
}

.mapping-select:focus {
    outline: none;
    border-color: var(--accent);
}

/* Fehlende Pflichtfelder — visuell hervorheben */
.field-unmatched .mapping-select {
    border-color: rgba(234, 179, 8, 0.55);
    background: rgba(234, 179, 8, 0.04);
}
.field-unmatched label {
    color: var(--text);
}
.field-unmatched .mapping-select:focus {
    border-color: var(--accent);
    background: var(--input-bg);
}

.mapping-preview {
    margin-top: 20px;
}

.mapping-preview h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.preview-table-wrap {
    overflow-x: auto;
    border-radius: 6px;
    border: 1px solid var(--input-border);
}

.preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.preview-table th {
    background: var(--card-bg);
    color: var(--text-secondary);
    font-weight: 600;
    padding: 7px 10px;
    text-align: left;
    border-bottom: 1px solid var(--input-border);
    white-space: nowrap;
}

.preview-table td {
    padding: 6px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    color: var(--text);
    white-space: nowrap;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.preview-table tr:last-child td {
    border-bottom: none;
}

.preview-table .empty-cell {
    color: var(--text-secondary);
    font-style: italic;
}

.preview-table .auto-price-cell {
    color: var(--green);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

#csvMappingModal .modal-content {
    max-width: 580px;
    max-height: 90vh;
    overflow-y: auto;
}

.import-errors-list {
    margin-top: 8px;
    padding: 10px 12px;
    background: rgba(255, 80, 80, 0.08);
    border-radius: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    max-height: 160px;
    overflow-y: auto;
}

.import-errors-list li {
    list-style: none;
    padding: 2px 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}

.import-errors-list li:last-child {
    border-bottom: none;
}

.import-price-missing-note {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-top: 12px;
    padding: 12px 14px;
    border-radius: 8px;
    background: var(--yellow-bg);
    border: 1px solid var(--yellow);
    color: var(--yellow);
    font-size: 13px;
    line-height: 1.5;
    text-align: left;
}

.import-price-missing-title {
    font-weight: 600;
    margin-bottom: 4px;
}

.import-price-missing-sub {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.tx-no-price-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: 1px solid var(--red);
    border-radius: 4px;
    padding: 2px 7px;
    font-size: 11px;
    font-weight: 600;
    color: var(--red);
    cursor: pointer;
    letter-spacing: 0.2px;
    transition: background 0.15s;
}

.tx-no-price-btn:hover {
    background: var(--red-bg);
}

/* ─── Mapping Analyzer / Hints ───────────────────── */

#mappingHints {
    margin: 14px 0 4px;
}


/* ═══ 17. WIDGET DASHBOARD ═══ */

/* ═══════════════════════════════════════════
   Widget-Dashboard
   ═══════════════════════════════════════════ */

/* ─── Dashboard Header ─── */
.dashboard-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ─── Asset-Typ-Filter (Alle / Krypto / Aktien) ─── */
.asset-filter-group {
    display: flex;
    align-items: center;
    gap: 4px;
}
.page-header .asset-filter-group {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}
.asset-filter-btn {
    background: var(--input-bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    font-family: var(--font-body);
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}
.asset-filter-btn:hover { background: var(--surface-hover); color: var(--text); }
.asset-filter-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    font-weight: 600;
}

.btn-icon {
    padding: 10px 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* ─── GridStack Container ─── */
.grid-stack {
    background: transparent;
    min-height: 100px;
}

.grid-stack-placeholder > .placeholder-content {
    border-radius: 14px;
    background: rgba(0,212,170,0.06);
    border: 1px dashed rgba(0,212,170,0.25);
}

/* ─── Widget Card ─── */
/* Identisch zu .card — gleiche Farbe, gleicher Radius, gleicher Shadow.
   KEIN Multi-Layer-Background mit var() — bricht in Firefox/Safari. */
.widget-card {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    overflow: hidden !important;
    transition: background 0.3s, box-shadow 0.2s;
    box-sizing: border-box;
    container-type: inline-size;
}

.widget-card:hover {
    box-shadow: var(--card-shadow), 0 0 0 1px rgba(0,212,170,0.15);
}

.grid-stack-item.ui-draggable-dragging .widget-card {
    box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 2px 8px rgba(0,0,0,0.4);
    opacity: 0.95;
}

.widget-highlight {
    animation: widgetPulse 0.8s ease;
}

@keyframes widgetPulse {
    0%   { box-shadow: var(--card-shadow), 0 0 0 0 rgba(0,212,170,0.5); }
    50%  { box-shadow: var(--card-shadow), 0 0 0 8px rgba(0,212,170,0); }
    100% { box-shadow: var(--card-shadow); }
}

/* ─── Widget Header ─── */
.widget-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    user-select: none;
    cursor: grab;
}
.grid-stack-item.ui-draggable-dragging .widget-header { cursor: grabbing; }

/* Multi-Select: Shift+Klick selektiert Widgets */
.grid-stack-item.gs-selected > .grid-stack-item-content > .widget-card {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    box-shadow: 0 0 0 5px rgba(0,212,170,0.15);
}
.grid-stack-item.gs-selected > .grid-stack-item-content > .widget-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 12px;
    background: rgba(0,212,170,0.04);
    pointer-events: none;
    z-index: 1;
}

/* Drag-Handle: erscheint sanft bei Hover */
.widget-drag-handle {
    cursor: grab;
    color: var(--text-secondary);
    font-size: 12px;
    letter-spacing: -1px;
    opacity: 0;
    flex-shrink: 0;
    transition: opacity 0.18s;
}

.widget-card:hover .widget-drag-handle { opacity: 0.4; }
.widget-drag-handle:hover { opacity: 0.85 !important; }
.grid-stack-item.ui-draggable-dragging .widget-drag-handle { cursor: grabbing; opacity: 1; }

/* Titel-Gruppe: Titel + optionaler ?-Button direkt daneben */
.widget-title-group {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
}

/* Titel wie .card-title */
.widget-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.widget-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

/* Remove-Button — schlicht, erscheint erst bei Card-Hover */
.widget-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 15px;
    padding: 5px 7px;
    border-radius: 6px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
    font-family: var(--font-body);
    flex-shrink: 0;
}

.widget-card:hover .widget-remove { opacity: 0.45; }
.widget-remove:hover {
    opacity: 1 !important;
    background: var(--red-bg);
    color: var(--red);
}

/* ─── Widget Body ─── */
.widget-body {
    flex: 1;
    overflow: auto;
    padding: 14px 20px 18px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.08) transparent;
}

/* Chart-Widget: kein Padding (chart füllt Body) */
.widget-body:has(#chartArea) {
    padding: 0;
}

#wb_chart_portfolio .chart-container {
    flex: 1;
    height: auto;
    min-height: 140px;
    flex-direction: row;       /* Desktop: SVG links, Stats rechts */
    align-items: stretch;
    justify-content: flex-start;
}

/* Desktop: SVG-Wrapper nimmt flex-Platz ein, SVG füllt ihn */
#wb_chart_portfolio .chart-container > .chart-svg-wrap {
    flex: 1;
    min-height: 80px;
    min-width: 0;
    order: 1;
    overflow: hidden;
}
#wb_chart_portfolio .chart-container > .chart-svg-wrap > svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* Investiert-Toggle — Legend-Entry-Style (wie TradingView/Highcharts Legende) */
.chart-cost-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    background: none;
    border: none;
    padding: 2px 0;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 500;
    opacity: 0.38;
    transition: opacity 0.15s;
    white-space: nowrap;
    letter-spacing: 0.2px;
}
.chart-cost-toggle:hover { opacity: 0.7; }
.chart-cost-toggle.active { opacity: 1; color: var(--text); }
.chart-cost-toggle-line {
    width: 18px;
    height: 0;
    border-top: 2px dashed var(--text-secondary);
    flex-shrink: 0;
}

/* Desktop: Stats rechts, FESTE Breite (verhindert Layout-Shift durch JetBrains Mono font-display:swap).
   Font-Swap ändert sonst wrap.clientWidth nach erstem Render → falscher SVG-viewBox → Zoom-Effekt. */
#wb_chart_portfolio .chart-container .chart-stats {
    order: 2;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    padding: 10px 16px;
    gap: 8px;
    flex-shrink: 0;
    width: 160px;          /* Feste Breite: gleich wie .bench-sidebar, stabil vor/nach Font-Load */
    overflow: hidden;      /* Sehr große Werte clipped statt zu brechen */
}

/* Desktop: Wert oben, Prozent darunter → Chart bekommt mehr Breite */
#wb_chart_portfolio .chart-container .chart-stat-change {
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

/* Chart-Widget: Placeholder-States füllen den flex-row Container vollständig */
#wb_chart_portfolio .chart-container > .chart-single-point,
#wb_chart_portfolio .chart-container > .loading-placeholder {
    flex: 1;
    height: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

/* Range-Buttons + BTC in Widget-Header */
.widget-header-btns {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* Mehr-Button am unteren Rand von Listen-Widgets */
.widget-more-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    margin-top: 12px;
    padding: 9px 14px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
    font-family: var(--font-body);
}
.widget-more-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
}

/* Alle Resize-Handles außer SE verstecken */
.grid-stack-item > .ui-resizable-handle:not(.ui-resizable-se) {
    display: none !important;
}

/* ─── GridStack Resize Handle — elegantes L-Eck (SE only) ─── */
.grid-stack-item > .ui-resizable-se {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 22px;
    height: 22px;
    background: none !important;
    background-image: none !important;
    cursor: se-resize;
    opacity: 1;
    z-index: 10;
}

.grid-stack-item > .ui-resizable-se::after {
    content: '';
    position: absolute;
    right: 6px;
    bottom: 6px;
    width: 9px;
    height: 9px;
    border-right: 1.5px solid transparent;
    border-bottom: 1.5px solid transparent;
    border-radius: 0 0 2px 0;
    transition: border-color 0.15s;
}

/* Nur beim direkten Hover über den Resize-Handle sichtbar */
.grid-stack-item > .ui-resizable-se:hover::after {
    border-color: rgba(0,212,170,0.6);
}

.grid-stack-item > .ui-resizable-se:active::after {
    border-color: var(--accent);
}

/* ─── Chart-Widget Toolbar ─── */
.widget-chart-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px 8px;
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 6px;
}

/* ─── Listen-Widget Header ─── */
.widget-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
    flex-shrink: 0;
}

/* ─── Metrik-Widgets — Stat-Box Stil (wie Transaktions-Seite) ─── */

/* Kompakter Body-Padding + kein Scroll für Metrik-Widgets */
#wb_portfolio_value,
#wb_performance,
#wb_risk_volatility,
#wb_risk_drawdown,
#wb_risk_sharpe {
    padding: 10px 12px;
    overflow: hidden;
}

#wb_portfolio_value {
    display: flex;
    flex-direction: column;
}

/* Allokations-Widget: kompakteres Padding */
#wb_allocation_chart {
    padding: 8px 12px 12px;
}

/* Holdings: kein Scroll — resizeHoldingsToFit passt die Widget-Höhe an */
#wb_holdings_table {
    overflow: hidden;
}

/* Innerhalb Holdings: kein vertikaler Scroll in der Tabelle selbst */
#wb_holdings_table .table-container {
    overflow-x: auto;
    overflow-y: hidden;
}

/* Holdings-Count-Badge im Widget-Header (neben dem Titel) */
.widget-count-badge {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 400;
    flex-shrink: 0;
    margin-left: 6px;
}


/* Outlined Box — exakt wie .stat-box auf der Transaktions-Seite,
   aber füllt den Body vollständig aus (flex: 1) */
/* Portfolio Gesamtwert Widget — spiegelt den ehemaligen Dashboard-Header */
.wgt-pl-stripe {
    height: 3px;
    border-radius: 2px;
    margin: -14px -20px 12px; /* passend zu widget-body padding: 14px 20px */
    flex-shrink: 0;
}
.wgt-pl-stripe.pos { background: var(--green); }
.wgt-pl-stripe.neg { background: var(--red); }

.wgt-value-main {
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex: 1;
    gap: 4px;
    min-height: 0;
}
.wgt-value-main .total-value { font-size: 32px; }
.wgt-value-main .total-pl    { margin-top: 2px; }

/* Container-Queries: Portfolio-Wert-Widget bei schmalen Breiten (iPad Portrait, kleine Widgets) */
@container (max-width: 520px) {
    .wgt-value-main .total-value { font-size: 26px; letter-spacing: -0.5px; }
    .total-pl-amount { font-size: 18px; }
    .total-pl { gap: 6px; }
    .pv-range-badge { padding: 2px 8px; font-size: 11px; }
}

@container (max-width: 320px) {
    .wgt-value-main .total-value { font-size: 20px; letter-spacing: 0; }
    .total-pl-amount { font-size: 14px; }
    .total-pl { flex-wrap: wrap; gap: 4px; }
    .wgt-cost-hint { font-size: 10px; }
}

/* ─── Container Queries: alle Widgets ───────────────────────────── */

/* Perf-Widget: Zahlen ab ~500px runterskalieren — früher Einstieg = sanftere Kurve */
@container (max-width: 500px) {
    .wgt-perf-num     { font-size: clamp(16px, 7.5cqi, 38px); }
    .wgt-perf-num--sm { font-size: clamp(12px, 4.5cqi, 22px); }
}

/* Perf-Widget (Niete/Überflieger/Performance): mittlere Breite */
@container (max-width: 360px) {
    .wgt-perf-lbl   { font-size: 10px; }
    .wgt-perf-side  { gap: 3px; }
    .wgt-perf-row   { font-size: 11px; gap: 5px; }
    .wgt-perf-val   { font-size: 10px; }
    .wgt-perf-sym   { font-size: 11px; }
    .wgt-perf-tag   { font-size: 9px; min-width: 22px; }
    .wgt-perf-icon img,
    .wgt-perf-logo  { width: 18px !important; height: 18px !important; }
}

/* Perf-Widget: sehr schmal — nur komprimieren, KEIN Stacking (würde in flex:1 brechen) */
@container (max-width: 240px) {
    .wgt-perf-split { gap: 0; }
    .wgt-perf-side  { gap: 1px; padding: 4px 2px; }
    .wgt-perf-lbl   { font-size: 8px; letter-spacing: 0; }  /* klein aber sichtbar */
    .wgt-perf-vsep  { margin: 0 4px; }
    .wgt-perf-row   { font-size: 10px; gap: 3px; }
    .wgt-perf-tag   { display: none; }
}

/* Top-Performer-Liste: schmal */
@container (max-width: 300px) {
    .top-perf-values { flex-direction: column; gap: 1px; align-items: flex-end; }
    .top-perf-abs    { font-size: 10px; }
    .top-perf-ticker { font-size: 11px; }
    .top-perf-icon img { width: 18px !important; height: 18px !important; }
}

/* KV-Widget (Steuerstatus etc.): sehr schmal */
@container (max-width: 220px) {
    .wgt-kv-row { flex-direction: column; gap: 2px; padding: 8px 0; }
    .wgt-kv-val { font-size: 12px; text-align: left; }
}

/* Chart-Widget Header: schmal */
@container (max-width: 340px) {
    .chart-stats     { flex-wrap: wrap; gap: 6px; }
    .chart-stat-val  { font-size: 14px; }
    .range-btn       { padding: 4px 8px; font-size: 11px; }
}

.wgt-hint-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
    gap: 8px;
}

.wgt-cost-hint {
    font-size: 11px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.wgt-updated-at {
    font-size: 10px;
    color: var(--text-secondary);
    opacity: 0.45;
    flex-shrink: 0;
    white-space: nowrap;
}

/* Meta-Hint — kleine graue Zeile ("X Coins · N Transaktionen") */
.wgt-meta-hint {
    font-size: 11px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    margin-bottom: 2px;
}

/* ─── Widget: Performance (Plus/Minus Split + Top/Flop) ─── */
.wgt-perf-box {
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: 100%;
}

.wgt-perf-split {
    display: flex;
    flex: 1;
    align-items: center;
    min-height: 0;
}

.wgt-perf-side {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-width: 0;
    gap: 5px;
}
.wgt-perf-side--link {
    cursor: pointer;
    transition: opacity 0.15s;
}
.wgt-perf-side--link:hover { opacity: 0.75; }

.wgt-perf-num {
    font-size: 38px;
    font-weight: 700;
    font-family: var(--font-mono);
    line-height: 1;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    max-width: 100%;
}
.wgt-perf-num.pos { color: var(--green); }
.wgt-perf-num.neg { color: var(--red); }

.wgt-perf-lbl {
    font-size: 11px;
    color: var(--text-secondary);
    letter-spacing: 0.04em;
}



.wgt-perf-vsep {
    width: 1px;
    height: auto;
    align-self: stretch;
    background: var(--border);
    flex-shrink: 0;
}

.wgt-perf-rows {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    padding-top: 8px;
}

.wgt-perf-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.wgt-perf-row--link {
    cursor: pointer;
    border-radius: 6px;
    padding: 3px 5px;
    margin: -3px -5px;
    transition: background 0.15s;
}
.wgt-perf-row--link:hover { background: var(--surface-hover); }

.wgt-perf-tag {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    min-width: 28px;
}

.wgt-perf-sym {
    font-weight: 600;
    font-family: var(--font-mono);
    flex: 1;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.wgt-perf-val {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
}
.wgt-perf-val.pos { color: var(--green); }
.wgt-perf-val.neg { color: var(--red); }

.wgt-perf-icon {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.wgt-perf-logo {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    object-fit: contain;
    display: block;
    background: #fff;
}

.wgt-perf-logo-fb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--border);
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.wgt-perf-num--sm {
    font-size: 22px;
    letter-spacing: -0.03em;
    white-space: nowrap;
    overflow: hidden;
    max-width: 100%;
}

.wgt-niete-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 5px;
    min-height: 0;
    text-align: center;
}

/* ─── Transaktions-Formular Validierung ─── */
.input--error {
    border-color: var(--red) !important;
    box-shadow: 0 0 0 2px rgba(255, 77, 106, 0.15);
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%       { transform: translateX(-5px); }
    40%       { transform: translateX(5px); }
    60%       { transform: translateX(-3px); }
    80%       { transform: translateX(3px); }
}
.btn-shake { animation: shake 0.35s ease; }

.wgt-metric-box {
    flex: 1;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-align: center;
    min-height: 0;
}

/* Variante für KV-Listen (Performance): linksbündig, Zeilen-Trenner */
.wgt-metric-box.wgt-metric-kv {
    align-items: stretch;
    justify-content: center;
    text-align: left;
    gap: 0;
    padding: 4px 16px;
}

/* Wert — groß, Mono */
.wgt-metric-val {
    font-family: var(--font-mono);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
    white-space: nowrap;
}
.wgt-metric-val.pos { color: var(--green); }
.wgt-metric-val.neg { color: var(--red);   }
.wgt-metric-val.na  { color: var(--text-secondary); font-size: 19px; }

/* Delta-Zeile (P&L-Betrag + Prozent) */
.wgt-metric-delta {
    display: flex;
    gap: 5px;
    align-items: center;
    font-size: 11px;
    font-weight: 600;
}
.wgt-metric-delta.pos { color: var(--green); }
.wgt-metric-delta.neg { color: var(--red);   }
.wgt-metric-delta-pct { opacity: 0.75; font-size: 10px; }

.wgt-metric-hint {
    font-size: 10px;
    color: var(--text-secondary);
    opacity: 0.6;
}

/* KV-Zeilen (Performance-Widget) */
.wgt-kv-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.wgt-kv-row:last-child { border-bottom: none; }

.wgt-kv-lbl { color: var(--text-secondary); font-size: 12px; }

.wgt-kv-val {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
}
.wgt-kv-val.pos { color: var(--green); }
.wgt-kv-val.neg { color: var(--red); }

.widget-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;          /* füllt flex-column .widget-body vollständig */
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    opacity: 0.6;
    padding: 12px;
}

/* UX-015: Widget error state — visually distinct from empty */
.widget-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    color: var(--red);
    font-size: 13px;
    opacity: 0.8;
    padding: 12px;
}

/* ─── Tax Widget ─── */
.tax-totals {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}
.tax-total-item {
    flex: 1;
    text-align: center;
}
.tax-total-label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
}
.tax-total-val {
    font-size: clamp(13px, 3cqi, 20px);
    font-weight: 700;
    font-family: var(--font-mono, monospace);
    word-break: break-all;
}
.tax-total-val.pos  { color: var(--green); }
.tax-total-val.warn { color: var(--yellow); }
.tax-total-sub {
    font-size: 10px;
    color: var(--text-secondary);
    margin-top: 2px;
}
.tax-total-divider {
    width: 1px;
    height: 40px;
    background: var(--border);
    flex-shrink: 0;
}
.tax-main-bar {
    height: 6px;
    background: var(--green);
    border-radius: 3px;
    margin-bottom: 10px;
    overflow: hidden;
}
.tax-main-bar .tax-bar-taxable,
.tax-bar .tax-bar-taxable {
    height: 100%;
    background: var(--yellow);
    border-radius: 3px;
    transition: width 0.4s ease;
}
.tax-list-header {
    display: grid;
    grid-template-columns: 40px 1fr minmax(0, 1fr) minmax(0, 1fr);
    gap: 4px;
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0 0 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
}
.tax-list-header span:nth-child(3),
.tax-list-header span:nth-child(4) {
    text-align: right;
}
.tax-rows {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.tax-row {
    display: grid;
    grid-template-columns: 40px 1fr minmax(0, 1fr) minmax(0, 1fr);
    align-items: center;
    gap: 4px;
    font-size: 12px;
}
.tax-sym {
    font-weight: 600;
    font-size: 11px;
    color: var(--text);
}
.tax-bar-wrap { padding: 0 4px; }
.tax-bar {
    height: 4px;
    background: var(--green);
    border-radius: 2px;
    overflow: hidden;
}
.tax-col {
    text-align: right;
    font-family: var(--font-mono, monospace);
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.tax-col.pos  { color: var(--green); }
.tax-col.warn { color: var(--yellow); }
.tax-clickable {
    cursor: pointer;
    transition: opacity 0.15s;
}
.tax-clickable:hover { opacity: 0.75; }
.tax-footnote {
    font-size: 10px;
    color: var(--text-secondary);
    margin-top: 8px;
    opacity: 0.6;
    text-align: center;
}
.tax-freigrenze {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.tax-freigrenze-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.tax-freigrenze-bar-wrap {
    height: 6px;
    background: var(--surface2);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}
.tax-freigrenze-bar {
    height: 100%;
    background: var(--green);
    border-radius: 3px;
    transition: width 0.4s ease;
}
.tax-freigrenze-vals {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
}
.tax-frei-limit {
    color: var(--text-secondary);
}
.tax-frei-badge {
    margin-left: auto;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(0, 212, 170, 0.15);
    color: var(--green);
}
.tax-warn-badge {
    margin-left: auto;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(255, 193, 7, 0.15);
    color: var(--yellow);
}
.widget-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    font-size: 13px;
    opacity: 0.6;
}

/* ─── Widget-Picker Modal ─── */
.modal-wide .modal-content,
.modal-content-wide {
    max-width: 620px;
    width: 100%;
}

.picker-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.picker-category-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.picker-items {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
}

.picker-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    padding: 12px 14px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    text-align: left;
    font-family: var(--font-body);
}

.picker-item:hover {
    border-color: var(--accent);
    background: var(--surface-hover);
}

.picker-item-active {
    border-color: rgba(0,212,170,0.35);
    background: var(--accent-bg);
}

.picker-item-icon {
    font-size: 15px;
    color: var(--text-secondary);
    line-height: 1;
}

.picker-item-title {
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
    line-height: 1.3;
}

.picker-active-badge {
    position: absolute;
    top: 7px;
    right: 8px;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--accent);
    opacity: 0.75;
}

/* ─── Light Theme Overrides ─── */
[data-theme="light"] .widget-card {
    /* var(--surface) = #ffffff im Light-Mode — kein Override nötig */
}

[data-theme="light"] .widget-card:hover {
    box-shadow: var(--card-shadow), 0 0 0 1px rgba(14,163,113,0.18);
}

[data-theme="light"] .widget-header {
    border-bottom-color: rgba(0,0,0,0.10);
    background: rgba(0,0,0,0.015);
}

[data-theme="light"] .grid-stack-item > .ui-resizable-se::after {
    border-color: rgba(0,0,0,0.12);
}

[data-theme="light"] .grid-stack-item:hover > .ui-resizable-se::after {
    border-color: rgba(14,163,113,0.5);
}

[data-theme="light"] .picker-item:hover {
    border-color: rgba(14,163,113,0.4);
}

[data-theme="light"] .picker-item-active {
    background: rgba(14,163,113,0.06);
    border-color: rgba(14,163,113,0.22);
}

/* ─── Mobile — Widget-Grid-Overrides ─── */
@media (max-width: 768px) {

    /* GridStack setzt per JS: position:absolute auf Items + feste Höhe auf Container.
       Alles überschreiben, damit Widgets als normale Block-Elemente fließen.           */
    .grid-stack {
        display: flex !important;
        flex-direction: column !important;
        height: auto !important;       /* GridStack setzt per JS eine feste Höhe — entfernen  */
        gap: 12px;
        margin-left: -4px;             /* Widgets näher an Bildschirmrand */
        margin-right: -4px;
    }

    /* Explizite Reihenfolge per CSS order — unabhängig von GridStack DOM-Sortierung.
       DOM-Reihenfolge ≠ visuelle Reihenfolge bei flex; order erzwingt gewünschte Sequenz. */
    [data-gs-id="portfolio_value"]    { order: 1; }
    [data-gs-id="top_performer"]      { order: 2; }
    [data-gs-id="chart_portfolio"]    { order: 3; }
    [data-gs-id="allocation_chart"]   { order: 4; }
    [data-gs-id="performance"]        { order: 5; }
    [data-gs-id="recent_transactions"]{ order: 6; }
    [data-gs-id="holdings_table"]     { order: 7; }

    .grid-stack-item {
        position: static !important;
        width: 100% !important;
        height: auto !important;       /* GridStack setzt per JS feste Höhe — entfernen       */
        transform: none !important;
    }

    /* KRITISCHER FIX: grid-stack-item-content ist normalerweise position:absolute
       (top:0 left:0 right:0 bottom:0 innerhalb des Items). Mit position:static
       auf dem Item würde der Content zum nächsten positioned ancestor escapen.
       → Auch den Content auf static setzen, damit er normal im Flow bleibt.         */
    .grid-stack-item-content {
        position: static !important;
        height: auto !important;
    }

    /* Widget-Karte auf Mobile: auto-Höhe, Mindestgröße für Lesbarkeit */
    .widget-card {
        min-height: 180px;
    }

    /* Widget-Body auf Mobile: kein interner Scroll — die Seite scrollt */
    .widget-body {
        padding: 8px 8px 12px;
        overflow: visible;
    }

    /* Spezifische Widget-Body-Overrides die overflow:hidden setzen */
    #wb_portfolio_value,
    #wb_performance,
    #wb_holdings_table {
        overflow: visible;
    }

    /* Performance-Widget: Split-Layout braucht feste Mindesthöhe */
    .wgt-perf-box  { height: auto; }
    .wgt-perf-split { flex: 0 0 auto; min-height: 110px; }

    /* Portfolio-Wert: Wert-Block soll nicht kollabieren */
    .wgt-value-main { flex: 0 0 auto; }

    /* Chart-Widget: vernünftige Mindesthöhe für Mobile */
    #wb_chart_portfolio { min-height: 260px; }

    /* Auf Mobile: Stats über den Chart (column), SVG darunter */
    #wb_chart_portfolio .chart-container {
        flex-direction: column;
        align-items: stretch;
    }
    #wb_chart_portfolio .chart-container > .chart-svg-wrap { order: 2; }
    #wb_chart_portfolio .chart-container .chart-stats   {
        order: 1;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        padding: 8px 12px 4px;
        gap: 12px;
    }
    /* Mobile: Wert + Prozent wieder nebeneinander (chart-stats ist Row) */
    #wb_chart_portfolio .chart-container .chart-stat-change {
        flex-direction: row;
        align-items: center;
        gap: 8px;
    }

    /* Handles ausblenden */
    .widget-drag-handle,
    .grid-stack-item > .ui-resizable-se {
        display: none !important;
    }

    .dashboard-header-actions {
        flex-wrap: wrap;
        gap: 6px;
    }

    .picker-items {
        grid-template-columns: repeat(2, 1fr);
    }

    /* ── Mobile: chart_portfolio in mob-chart-area ──────────────────────── */
    /* Stats-Panel ausblenden — Chart bekommt volle Breite                   */
    #mob-chart-area .chart-stats { display: none !important; }
    /* Container füllt den Eltern-div vollständig (100% der 240px)           */
    #mob-chart-area .chart-container {
        height: 100%;
        flex-direction: row;
        align-items: stretch;
        justify-content: flex-start;
    }
    /* SVG-Wrapper füllt den flex-Container vollständig                      */
    #mob-chart-area .chart-container > .chart-svg-wrap {
        flex: 1;
        min-width: 0;
        overflow: hidden;
    }
    #mob-chart-area .chart-container > .chart-svg-wrap > svg {
        width: 100%;
        height: 100%;
        display: block;
    }
    /* Placeholder/loading-State zentriert im Container                      */
    #mob-chart-area .chart-container > .chart-single-point,
    #mob-chart-area .chart-container > .loading-placeholder {
        flex: 1;
        height: auto;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }
    /* Range-Badge im Portfolio-Wert-Widget ausblenden — Range-Buttons unten
       übernehmen die Steuerung für beide Widgets                             */
    #mob-value .pv-range-badge { display: none !important; }
    /* Portfolio-Value-Widget auf Mobile: Padding anpassen                   */
    #mob-value .wgt-value-main { padding: 4px 0; }
}

