/* ============================================================
   PosteInvest Monitor — Stile principale
   ============================================================ */

:root {
    --sidebar-width: 240px;
    --sidebar-bg:    #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active:#FFD700;
    --topbar-height: 56px;
    --bottom-nav-h:  62px;
    --primary:       #FFD700;
    --primary-dark:  #e6c200;
    --accent:        #3B82F6;
    --bg-page:       #f1f5f9;
    --bg-card:       #ffffff;
    --text-main:     #1e293b;
    --text-muted:    #64748b;
    --border:        #e2e8f0;
    --success:       #22c55e;
    --danger:        #ef4444;
    --warning:       #f59e0b;
}

* { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-page);
    color: var(--text-main);
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform 0.28s cubic-bezier(.4,0,.2,1);
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    min-height: var(--topbar-height);
}

.sidebar-logo {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: #000;
    flex-shrink: 0;
}

.sidebar-brand-text .brand-main {
    display: block;
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    line-height: 1.2;
}
.sidebar-brand-text .brand-sub {
    display: block;
    color: rgba(255,255,255,0.5);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
}

.nav-section-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: rgba(255,255,255,0.35);
    padding: 0 6px;
    margin-bottom: 6px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 8px;
    color: rgba(255,255,255,0.7) !important;
    text-decoration: none !important;
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
    margin-bottom: 2px;
}
.nav-link i { font-size: 16px; width: 18px; }
.nav-link:hover {
    background: var(--sidebar-hover);
    color: #fff !important;
}
.nav-link.active {
    background: rgba(255,215,0,0.12);
    color: var(--primary) !important;
    font-weight: 600;
}
.nav-link.active i { color: var(--primary); }

.sidebar-footer {
    padding: 16px 14px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

/* ============================================================
   BOTTOM NAVIGATION (mobile only)
   ============================================================ */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-h);
    background: var(--sidebar-bg);
    border-top: 1px solid rgba(255,255,255,0.08);
    z-index: 1000;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: rgba(255,255,255,0.45);
    text-decoration: none !important;
    font-size: 10px;
    font-weight: 500;
    padding: 6px 10px;
    border-radius: 10px;
    transition: color 0.15s;
    min-width: 52px;
}
.bottom-nav-item i { font-size: 20px; line-height: 1; }
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item:hover { color: rgba(255,255,255,0.8); }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.28s cubic-bezier(.4,0,.2,1);
}

.topbar {
    height: var(--topbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 500;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.sidebar-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 5px 9px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    flex-shrink: 0;
}

.topbar-title {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-main);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.page-content {
    padding: 24px;
    flex: 1;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.card-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: transparent;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    row-gap: 8px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.stat-body .stat-value {
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
}

.stat-body .stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ============================================================
   TABELLA FONDI
   ============================================================ */
.fund-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13.5px;
}

.fund-table thead th {
    background: #f8fafc;
    border-bottom: 2px solid var(--border);
    padding: 10px 12px;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.fund-table tbody td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.fund-table tbody tr:hover td { background: #f8fafc; }
.fund-table tbody tr:last-child td { border-bottom: none; }

.fund-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 8px;
    flex-shrink: 0;
}

.fund-name {
    font-weight: 500;
    color: var(--text-main);
    font-size: 13px;
}

.fund-isin {
    font-size: 11px;
    color: var(--text-muted);
}

.nav-value {
    font-weight: 600;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

.perf-badge {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px 7px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    min-width: 60px;
    justify-content: center;
    white-space: nowrap;
}

.perf-up   { background: rgba(34,197,94,0.12);  color: #15803d; }
.perf-down { background: rgba(239,68,68,0.12);   color: #b91c1c; }
.perf-flat { background: rgba(100,116,139,0.12); color: #475569; }

/* ============================================================
   PERIODO SELECTOR
   ============================================================ */
.period-selector {
    display: flex;
    gap: 3px;
    background: #f1f5f9;
    padding: 3px;
    border-radius: 8px;
    flex-wrap: nowrap;
}

.period-btn {
    padding: 5px 10px;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.period-btn:hover { background: #fff; color: var(--text-main); }
.period-btn.active { background: #fff; color: var(--text-main); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }

/* ============================================================
   GRAFICO CONTENITORE
   ============================================================ */
.chart-container    { min-height: 300px; }
.chart-container-lg { min-height: 420px; }

/* ============================================================
   CONFRONTO
   ============================================================ */
.fund-checkbox-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 8px;
}

.fund-checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    user-select: none;
}

.fund-checkbox-item:hover  { border-color: var(--accent); background: #f8fafc; }
.fund-checkbox-item.selected { border-color: var(--accent); background: rgba(59,130,246,0.05); }
.fund-checkbox-item input  { display: none; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
    padding: 16px;
}

.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 36px 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
    width: 64px;
    height: 64px;
    background: var(--primary);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    margin: 0 auto 20px;
}

/* ============================================================
   ALERT PAGE
   ============================================================ */
.alert-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

/* ============================================================
   RESPONSIVE — TABLET (≤ 992px)
   ============================================================ */
@media (max-width: 992px) {
    .chart-container-lg { min-height: 340px; }

    /* Nascondi alcune colonne performance nella tabella */
    .fund-table .col-hide-md,
    .fund-table thead th.col-hide-md,
    .fund-table tbody td.col-hide-md { display: none; }
}

/* ============================================================
   RESPONSIVE — MOBILE (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {

    /* Sidebar: slide-in da sinistra */
    .sidebar {
        transform: translateX(-100%);
        box-shadow: none;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0,0,0,0.3);
    }

    /* Bottom navigation visibile */
    .bottom-nav { display: flex; }

    /* Contenuto principale */
    .main-content { margin-left: 0; }
    .sidebar-toggle { display: block; }

    .page-content {
        padding: 12px;
        padding-bottom: calc(var(--bottom-nav-h) + 12px + env(safe-area-inset-bottom, 0px));
    }

    /* Topbar compatta */
    .topbar { padding: 0 12px; gap: 10px; }
    .topbar-title { font-size: 14px; }
    .topbar-badge-text { display: none; } /* nasconde testo badge, lascia icona */

    /* Stat cards: 2 colonne su mobile */
    .stat-card { padding: 12px 14px; gap: 10px; }
    .stat-icon { width: 38px; height: 38px; font-size: 17px; }
    .stat-body .stat-value { font-size: 18px; }
    .stat-body .stat-label { font-size: 11px; }

    /* Card header: stacked su mobile */
    .card-header {
        padding: 10px 12px;
        font-size: 13px;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .card-header .ms-auto { margin-left: 0 !important; width: 100%; }
    .card-header .period-selector { width: 100%; justify-content: space-between; }
    .card-header .d-flex.gap-2 { width: 100%; }

    /* Period buttons più compatti */
    .period-btn { padding: 5px 8px; font-size: 11px; flex: 1; text-align: center; }

    /* Grafici meno alti */
    .chart-container    { min-height: 220px; }
    .chart-container-lg { min-height: 260px; }

    /* Tabella: mostra solo colonne essenziali */
    .fund-table { font-size: 12.5px; }
    .fund-table thead th,
    .fund-table tbody td { padding: 10px 8px; }

    /* Nascondi ISIN, 3M, 6M, 3A dalla tabella su mobile */
    .fund-table .col-hide-sm,
    .fund-table thead th.col-hide-sm,
    .fund-table tbody td.col-hide-sm { display: none; }

    /* Perf badge compatto */
    .perf-badge { padding: 2px 5px; font-size: 11px; min-width: 50px; }

    /* Confronto: griglia 1 colonna */
    .fund-checkbox-list { grid-template-columns: 1fr 1fr; }

    /* Login card: meno padding */
    .login-card { padding: 28px 20px; }

    /* Alert row: stacked */
    .alert-row { flex-direction: column; align-items: flex-start; }
}

/* ============================================================
   RESPONSIVE — SMALL MOBILE (≤ 480px)
   ============================================================ */
@media (max-width: 480px) {
    .fund-checkbox-list { grid-template-columns: 1fr; }
    .bottom-nav-item { font-size: 9px; min-width: 44px; padding: 6px 6px; }
    .bottom-nav-item i { font-size: 18px; }
}

/* ============================================================
   UTILITIES
   ============================================================ */
.text-success { color: var(--success) !important; }
.text-danger  { color: var(--danger)  !important; }
.text-warning { color: var(--warning) !important; }

.bg-primary-soft { background: rgba(255,215,0,0.1); }
.bg-success-soft { background: rgba(34,197,94,0.1); }
.bg-danger-soft  { background: rgba(239,68,68,0.1); }

.font-mono { font-family: 'Courier New', monospace; }

.spinner-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: 12px;
}

/* Scrollbar personalizzata */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); }
