/*
 * ═══════════════════════════════════════════════════════════
 * FolioTrack — style.css
 * Table of Contents
 * ═══════════════════════════════════════════════════════════
 *
 *   1. Variables / Tokens          (line ~12)
 *   2. Reset / Base                (line ~65)
 *   3. Layout / Navigation         (line ~80)
 *   4. Cards                       (line ~587)
 *   5. Buttons                     (line ~610)
 *   6. Grid / Layout Helpers       (line ~734)
 *   7. Holdings & Tables           (line ~955)
 *   8. Transactions                (line ~1051)
 *   9. Import                      (line ~1271)
 *  10. Settings / Admin            (line ~1324)
 *  11. Modals                      (line ~1557)
 *  12. Forms / Inputs              (line ~1681)
 *  13. Charts                      (line ~1918)
 *  14. Utilities / Empty States    (line ~2228)
 *  15. Auth / Login Overlay        (line ~2441)
 *  16. Widget Dashboard            (line ~3163)
 *  17. Maintenance Overlay         (line ~4415)
 *  18. Transaction Modal Variants  (line ~4556)
 *  19. Import Magic Animation      (line ~4620)
 *  20. Toast Notifications         (line ~4340)
 *  21. Widget Extras               (line ~4872)
 *  22. Mobile Fixed Layout         (line ~5529)
 *  23. Lock Overlay / PIN          (line ~5782)
 *  24. Accessibility               (line ~5915)
 *
 * TODO: Split into separate files when a build system is added.
 * ═══════════════════════════════════════════════════════════
 */

/* ═══════════════════════════════════════════
   FolioTrack — Stylesheet
   Dark/Light Theme via CSS Variables
   ═══════════════════════════════════════════ */

/* Sicherstellen dass [hidden] immer greift, auch wenn display durch andere Regeln überschrieben wird */
[hidden] { display: none !important; }

/* iOS Safari: Tap-Highlight für alle Elemente deaktivieren */
* { -webkit-tap-highlight-color: transparent; }

:root {
    /* Dark Theme (Default) */
    --bg: #0B0E11;
    --surface: #151921;
    --surface-hover: #1C2230;
    --border: rgba(255,255,255,0.06);
    --text: #E8ECF1;
    --text-secondary: #7A8599;
    --accent: #00D4AA;
    --accent-bg: rgba(0,212,170,0.1);
    --red: #FF4D6A;
    --red-bg: rgba(255,77,106,0.1);
    --green: #00D4AA;
    --green-bg: rgba(0,212,170,0.1);
    --sidebar-bg: #0F1218;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.4);
    --input-bg: #1C2230;
    --input-border: rgba(255,255,255,0.12);
    --modal-backdrop: rgba(0,0,0,0.6);
    --yellow: #f5a623;
    --yellow-bg: rgba(245,166,35,0.12);
    --bitcoin: #f7931a;
    --teal: #2dd4bf;
    --teal-bg: rgba(45,212,191,0.12);
    --violet: #a78bfa;
    --violet-bg: rgba(167,139,250,0.14);

    --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;

    --sidebar-width: 220px;
    --color-scheme: dark;
}

[data-theme="light"] {
    --bg: #F4F5F7;
    --surface: #FFFFFF;
    --surface-hover: #F8F9FB;
    --border: rgba(0,0,0,0.08);
    --text: #1A1D23;
    --text-secondary: #6B7280;
    --accent: #0EA371;
    --accent-bg: rgba(14,163,113,0.08);
    --red: #E5334B;
    --red-bg: rgba(229,51,75,0.08);
    --green: #0EA371;
    --green-bg: rgba(14,163,113,0.08);
    --sidebar-bg: #FFFFFF;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 0 0 1px rgba(0,0,0,0.04);
    --input-bg: #F4F5F7;
    --input-border: rgba(0,0,0,0.15);
    --modal-backdrop: rgba(0,0,0,0.3);
    --yellow: #d4820a;
    --yellow-bg: rgba(212,130,10,0.1);
    --teal: #0d9488;
    --teal-bg: rgba(13,148,136,0.1);
    --violet: #7c3aed;
    --violet-bg: rgba(124,58,237,0.1);
    --color-scheme: light;
}

/* ═══ 1. VARIABLES / TOKENS ═══ */

/* ─── Reset & Base ──────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    transition: background 0.3s, color 0.3s;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* ═══ 2. RESET / BASE ═══ */

/* ─── App Layout ────────────────────────── */
#app {
    display: flex;
    height: 100vh;
}

/* ═══ 3. LAYOUT / NAVIGATION ═══ */

/* ─── Sidebar ───────────────────────────── */
#sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 0;
    transition: width 0.25s ease, background 0.3s;
    flex-shrink: 0;
    overflow: hidden;
}

#sidebar.collapsed {
    width: 60px;
}

#sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 6px;
    transition: background 0.2s, color 0.2s;
    margin-left: auto;
    flex-shrink: 0;
}

#sidebar-toggle:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px 24px;
    white-space: nowrap;
}

#sidebar.collapsed .sidebar-logo {
    padding: 0 0 24px;
    justify-content: center;
}

/* Collapsed: hide logo content, keep only toggle button */
#sidebar.collapsed .logo-icon,
#sidebar.collapsed .logo-text {
    display: none;
}

#sidebar.collapsed #sidebar-toggle {
    margin-left: 0;
    font-size: 22px;
}

#sidebar.collapsed .sidebar-footer {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 0;
    gap: 6px;
}

#sidebar.collapsed .theme-toggle {
    padding: 6px;
    background: none;
    gap: 0;
    justify-content: center;
    width: 40px;
}

#sidebar.collapsed .theme-label {
    display: none;
}

#sidebar.collapsed .toggle-track {
    flex-shrink: 0;
}

#sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 12px;
    gap: 0;
}

#sidebar.collapsed .nav-label {
    display: none;
}

#sidebar.collapsed .nav-icon {
    width: auto;
}

.logo-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--accent), #627EEA);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
}

.logo-text {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

#main-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 400;
    color: var(--text-secondary);
    text-decoration: none;
    border-right: 2px solid transparent;
    transition: all 0.2s;
}

.nav-item:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.nav-item.active {
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-bg);
    border-right-color: var(--accent);
}

/* Mobile-only action buttons (Theme + Logout) — auf Desktop versteckt */
.nav-mob-action {
    display: none;
    background: none;
    border: none;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    font: inherit;
    line-height: normal;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    margin: 0;
}
.nav-mob-action:hover { color: var(--text); background: var(--surface-hover); }

.nav-icon {
    width: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.nav-label {
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.btn-logout {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.btn-logout:hover { background: var(--red-bg); color: var(--red); }


/* Theme Toggle */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 8px;
    background: var(--input-bg);
    transition: background 0.2s;
}

.theme-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.toggle-track {
    width: 36px;
    height: 20px;
    border-radius: 10px;
    background: var(--accent);
    position: relative;
    transition: background 0.3s;
}

[data-theme="light"] .theme-toggle .toggle-track {
    background: #ccc;
}

.toggle-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    position: absolute;
    top: 2px;
    left: 18px;
    transition: left 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

[data-theme="light"] .theme-toggle .toggle-thumb {
    left: 2px;
}

/* ─── Main Content ──────────────────────── */
#main-content {
    flex: 1;
    overflow-y: auto;
    overflow-anchor: none; /* Verhindert automatisches Re-Scroll beim Widget-Rendering */
    padding: 24px 32px;
}

/* ─── Pages ─────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

/* ─── Page Header ───────────────────────── */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
    position: relative;
}
.page-header-end { justify-content: flex-end; }
.page-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.form-group-end  { align-self: flex-end; flex: 0 0 auto; }

/* ── Preis-Alert Banner ──────────────────────────── */
#dashboard-price-alert { margin-bottom: 16px; }

/* Demo-Portfolio Banner Modifier */
.price-alert-banner--demo {
    background: var(--accent-bg);
    border-color: var(--accent);
}
.price-alert-banner--demo .price-alert-icon { color: var(--accent); }
.price-alert-banner--demo .price-alert-title { color: var(--accent); }
.price-alert-banner--demo .price-alert-btn {
    background: var(--accent);
    box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 30%, transparent);
}

.price-alert-banner--info {
    background: color-mix(in srgb, var(--accent) 8%, var(--surface));
    border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
}
.price-alert-banner--info .price-alert-icon,
.price-alert-banner--info .price-alert-title { color: var(--accent); }

.price-alert-banner--stale {
    background: color-mix(in srgb, var(--yellow) 8%, var(--surface));
}

.price-alert-banner--danger {
    background: var(--red-bg);
    border-color: color-mix(in srgb, var(--red) 60%, var(--border));
}
.price-alert-banner--danger .price-alert-icon,
.price-alert-banner--danger .price-alert-title { color: var(--red); }

.price-alert-banner {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    background: var(--yellow-bg);
    border: 1.5px solid var(--yellow);
    border-radius: 12px;
    color: var(--text);
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
}
.price-alert-icon {
    flex-shrink: 0;
    color: var(--yellow);
    display: flex;
    align-items: center;
}
.price-alert-body { flex: 1; min-width: 0; }
.price-alert-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--yellow);
    margin-bottom: 3px;
}
.price-alert-title strong { font-weight: 700; }
.price-alert-sub {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.45;
}
.price-alert-sub strong { color: var(--text); font-weight: 600; }
.price-alert-sym-btn {
    display: inline-block;
    padding: 1px 7px;
    margin: 0 2px;
    background: var(--yellow-bg);
    border: 1px solid var(--yellow);
    border-radius: 5px;
    color: var(--yellow);
    font-size: 0.78rem;
    font-weight: 700;
    font-family: var(--font-mono);
    cursor: pointer;
    transition: opacity 0.15s;
}
.price-alert-sym-btn:hover { opacity: 0.75; }
.price-alert-btn {
    flex-shrink: 0;
    padding: 8px 16px;
    background: var(--yellow);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font-body);
    cursor: pointer;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    box-shadow: 0 2px 8px color-mix(in srgb, var(--yellow) 30%, transparent);
    transition: opacity 0.2s;
}
.price-alert-btn:hover:not(:disabled) { opacity: 0.9; }
.price-alert-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.price-alert-btn-sec {
    flex-shrink: 0;
    padding: 8px 16px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font-body);
    cursor: pointer;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    transition: color 0.15s, border-color 0.15s;
}
.price-alert-btn-sec:hover { color: var(--text); border-color: var(--text-secondary); }

.price-alert-close {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    opacity: 0.6;
    transition: opacity 0.15s;
}
.price-alert-close:hover { opacity: 1; background: rgba(255,255,255,0.08); }

.page-header h2 {
    font-size: 22px;
    font-weight: 700;
}

.label-uppercase {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 4px;
}

.total-value {
    font-size: 36px;
    font-weight: 700;
    letter-spacing: -1px;
    font-family: var(--font-mono);
}

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

.btn-refresh-prices,
.btn-privacy {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px 7px;
    border-radius: 6px;
    color: var(--text-secondary);
    opacity: 0.55;
    transition: color 0.15s, background 0.15s, opacity 0.15s;
    line-height: 1;
}

.btn-refresh-prices:hover {
    opacity: 1;
    color: var(--accent);
    background: var(--accent-bg);
}

.btn-refresh-prices.spinning,
.mob-refresh-btn.spinning {
    animation: spin 0.8s linear infinite;
    opacity: 0.8;
    color: var(--accent);
}

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

.btn-privacy:hover {
    opacity: 1;
    color: var(--text);
    background: var(--surface-hover);
}

[data-privacy="on"] .btn-privacy {
    opacity: 0.85;
    color: var(--accent);
}

.total-pl {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}

.total-pl-amount {
    font-size: 22px;
    font-weight: 700;
    font-family: var(--font-mono);
    letter-spacing: -0.5px;
    line-height: 1;
}

.total-pl-pct {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    font-family: var(--font-mono);
}

.total-pl-amount.positive { color: var(--green); }
.total-pl-amount.negative { color: var(--red); }
.total-pl-pct.positive { background: var(--green-bg); color: var(--green); }
.total-pl-pct.negative { background: var(--red-bg); color: var(--red); }

/* badge-pl bleibt für Transaktionen/Holdings-Liste */
.badge-pl {
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font-mono);
    white-space: nowrap;
}

.badge-pl.positive { color: var(--green); background: var(--green-bg); }
.badge-pl.negative { color: var(--red); background: var(--red-bg); }
.badge-pl.dividend { color: var(--teal); background: var(--teal-bg); }
.badge-pl.staking  { color: var(--violet); background: var(--violet-bg); }


.pl-amount {
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font-mono);
}

.pl-amount.positive { color: var(--green); }
.pl-amount.negative { color: var(--red); }
