/* =============================================
   PORTFOLIOAPP — Stili globali
   Tema: Frost
   ============================================= */

/* ---------------------------------------------
   CSS Variables — Light mode (default)
   --------------------------------------------- */
:root {
    --bg:           #F0F4FF;
    --surface:      #FFFFFF;
    --surface2:     #EEF2FF;
    --text:         #1E1B4B;
    --text2:        #6B7280;
    --accent:       #6366F1;
    --accent-light: #EEF2FF;
    --border:       #C7D2FE;
    --positive:     #10B981;
    --negative:     #EF4444;

    --radius-sm:    6px;
    --radius-md:    8px;
    --radius-lg:    12px;
}

/* ---------------------------------------------
   CSS Variables — Dark mode
   Applicate quando body ha classe .dark
   --------------------------------------------- */
body.dark {
    --bg:           #1C1C2E;
    --surface:      #2C2C3E;
    --surface2:     #3C3C5E;
    --text:         #E0E7FF;
    --text2:        #A5B4FC;
    --accent:       #818CF8;
    --accent-light: #2E2E5E;
    --border:       #383850;
    --positive:     #34D399;
    --negative:     #F87171;
}

/* ---------------------------------------------
   Reset e base
   --------------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow-x: hidden;
}

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
    font-size: 16px;
    font-weight: 400;
    line-height: 1.7;
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* ---------------------------------------------
   Tipografia
   --------------------------------------------- */
h1 { font-size: 22px; font-weight: 500; color: var(--text); }
h2 { font-size: 18px; font-weight: 500; color: var(--text); }
h3 { font-size: 16px; font-weight: 500; color: var(--text); }

p  { color: var(--text); line-height: 1.7; }

a  { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------
   Componenti base
   --------------------------------------------- */

/* Card */
.card {
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
}

/* KPI card */
.kpi-card {
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px;
}
.kpi-label {
    font-size: 11px;
    color: var(--text2);
    margin-bottom: 6px;
}
.kpi-value {
    font-size: 20px;
    font-weight: 500;
    color: var(--text);
}
.kpi-delta {
    font-size: 11px;
    margin-top: 4px;
}

/* Valori finanziari */
.positive { color: var(--positive); }
.negative { color: var(--negative); }

/* Label sezione */
.section-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text2);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-bottom: 10px;
}

/* Accent dot */
.accent-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    display: inline-block;
    margin-right: 6px;
}

/* Ticker badge */
.ticker-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 500;
    background: var(--accent-light);
    color: var(--accent);
}

/* ---------------------------------------------
   Chip selector
   --------------------------------------------- */
.chip-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    display: inline-flex;
    align-items: center;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    border: 0.5px solid var(--border);
    background: var(--surface);
    color: var(--text2);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    white-space: nowrap;
}

.chip:hover {
    background: var(--surface2);
    color: var(--text);
    border-color: var(--accent);
}

.chip-active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.chip-active:hover {
    background: var(--accent);
    color: #fff;
}

/* ---------------------------------------------
   Bottom sheet
   --------------------------------------------- */
.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 0.5px solid var(--border);
    border-radius: 16px 16px 0 0;
    padding: 1rem 1.5rem 2.5rem;
    z-index: 501;
    max-height: 60vh;
    overflow-y: auto;
}

.bottom-sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 1rem;
}

/* ---------------------------------------------
   Autocomplete
   --------------------------------------------- */
.autocomplete-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    z-index: 200;
    overflow: hidden;
}

.autocomplete-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 0.5px solid var(--border);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 2px;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover {
    background: var(--surface2);
}

/* ---------------------------------------------
   Form
   --------------------------------------------- */
.form-group {
    margin-bottom: 10px;
}

.form-label {
    display: block;
    font-size: 11px;
    color: var(--text2);
    margin-bottom: 4px;
}

input, select, textarea {
    width: 100%;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    border: 0.5px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s ease;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
}

/* ---------------------------------------------
   Bottoni
   --------------------------------------------- */
.btn-primary {
    background: var(--accent);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 7px 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    width: 100%;
    transition: opacity 0.15s ease;
}

.btn-primary:hover   { opacity: 0.9; }
.btn-primary:active  { opacity: 0.8; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
    background: transparent;
    color: var(--text);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 16px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.btn-secondary:hover { background: var(--surface2); }

/* ---------------------------------------------
   Griglie dati
   --------------------------------------------- */
.data-grid-header {
    font-size: 11px;
    color: var(--text2);
    padding-bottom: 6px;
    border-bottom: 0.5px solid var(--border);
    margin-bottom: 6px;
}

.data-grid-row {
    font-size: 12px;
    color: var(--text);
    padding: 6px 0;
    border-bottom: 0.5px solid var(--border);
    align-items: center;
}

/* ---------------------------------------------
   Alert e messaggi
   --------------------------------------------- */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 12px;
}

.alert-danger {
    background: #FEF2F2;
    color: #991B1B;
    border: 0.5px solid #FECACA;
}

body.dark .alert-danger {
    background: #3B1515;
    color: #FCA5A5;
    border-color: #7F1D1D;
}

.alert-success {
    background: #ECFDF5;
    color: #065F46;
    border: 0.5px solid #A7F3D0;
}

body.dark .alert-success {
    background: #052E16;
    color: #6EE7B7;
    border-color: #065F46;
}

/* ---------------------------------------------
   Layout helper grids
   --------------------------------------------- */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

/* ---------------------------------------------
   Pagine login e registrazione
   --------------------------------------------- */
.login-container {
    max-width: 400px;
    margin: 4rem auto;
    background: var(--surface);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
}

.login-container h2 {
    margin-bottom: 1.5rem;
}

/* ---------------------------------------------
   Card list — classi condivise per le card mobile
   --------------------------------------------- */
.list-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 0.5px solid var(--border);
}

.list-card-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.list-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 13px;
    color: var(--text);
}

.list-label {
    font-size: 11px;
    color: var(--text2);
}

.list-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 0.5px solid var(--border);
    justify-content: flex-end;
}

/* Toggle tabella/card per le varie pagine — default: tabella visibile */
.conti-saldi-cards,
.portafogli-cards,
.rendimenti-cards,
.tipologiche-cards,
.titoli-cards,
.prezzi-cards { display: none; }

/* ---------------------------------------------
   Posizioni aperte — layout responsivo
   --------------------------------------------- */
.posizioni-cards { display: none; }

.posizione-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 0.5px solid var(--border);
}

.posizione-card-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.posizione-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 13px;
    color: var(--text);
}

.posizione-label {
    font-size: 11px;
    color: var(--text2);
}

/* =============================================
   LAYOUT — Sidebar + Main content
   ============================================= */

.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 220px;
    min-height: 100vh;
    background: var(--surface);
    border-right: 0.5px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

/* Logo */
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 1.25rem 1rem;
    border-bottom: 0.5px solid var(--border);
}

.logo-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--accent);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 500;
    flex-shrink: 0;
}

.logo-text {
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
}

/* Navigazione */
.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
    overflow-y: auto;
}

.nav-list {
    list-style: none;
    padding: 0 0.5rem;
    margin: 0;
}

.nav-list li {
    margin-bottom: 2px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text2);
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-link:hover {
    background: var(--surface2);
    color: var(--text);
    text-decoration: none;
}

.nav-link.active {
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 500;
}

.nav-icon {
    font-size: 14px;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.nav-label {
    font-size: 14px;
}

/* Footer sidebar */
.sidebar-footer {
    padding: 0.75rem 0.5rem;
    border-top: 0.5px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text2);
    font-size: 14px;
    cursor: pointer;
    width: 100%;
    text-align: left;
    transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-btn:hover {
    background: var(--surface2);
    color: var(--text);
}

.sidebar-btn-logout:hover {
    color: var(--negative);
}

.sidebar-btn-icon {
    font-size: 14px;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-btn-label {
    font-size: 14px;
}

/* Main content */
.main-content {
    margin-left: 220px;
    flex: 1;
    min-height: 100vh;
    background: var(--bg);
}

/* =============================================
   MOBILE TOPBAR — visibile solo su mobile
   ============================================= */

.page-wrapper {
    min-height: 100vh;
    max-width: 100%;
    overflow-x: hidden;
}

.mobile-topbar {
    display: none;
}

/* Logo dentro la topbar mobile */
.mobile-topbar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mobile-overlay {
    position: fixed;
    inset: 0;
    top: 56px;
    background: rgba(0, 0, 0, 0.35);
    z-index: 140;
}

/* Burger button */
.burger-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    align-items: center;
    justify-content: center;
}

.burger-line {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: transform 0.2s ease, opacity 0.2s ease;
    transform-origin: center;
}

/* Animazione X quando menu aperto */
.burger-line--top-open { transform: translateY(7px) rotate(45deg); }
.burger-line--mid-open { opacity: 0; transform: scaleX(0); }
.burger-line--bot-open { transform: translateY(-7px) rotate(-45deg); }

/* =============================================
   RESPONSIVE — unica sezione consolidata
   ============================================= */

@media (max-width: 768px) {

    /* Tipografia ridotta */
    body { font-size: 14px; }
    h1   { font-size: 18px; }
    h2   { font-size: 16px; }

    /* Grids collassano a colonna singola */
    .grid-2, .grid-3, .grid-4, .charts-grid { grid-template-columns: 1fr; }

    /* Topbar fissa in cima */
    .mobile-topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 1rem;
        height: 56px;
        background: var(--surface);
        border-bottom: 0.5px solid var(--border);
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 200;
    }

    /* Layout: il contenuto scorre sotto la topbar fissa */
    .app-layout {
        display: block;
    }

    /* Sidebar: pannello a scomparsa da sinistra */
    .sidebar {
        width: 220px;
        min-height: auto;
        position: fixed;
        top: 56px;
        left: 0;
        bottom: 0;
        z-index: 150;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        border-right: 0.5px solid var(--border);
        flex-direction: column;
    }

    .sidebar.menu-open {
        transform: translateX(0);
    }

    /* Nasconde il logo nella sidebar mobile (già visibile nella topbar) */
    .sidebar .sidebar-logo {
        display: none;
    }

    /* Nav verticale (come desktop) */
    .sidebar-nav {
        flex: 1;
        padding: 0.75rem 0;
        overflow-y: auto;
    }

    .nav-list {
        display: flex;
        flex-direction: column;
        gap: 0;
        padding: 0 0.5rem;
    }

    .nav-list li {
        margin-bottom: 2px;
        flex-shrink: unset;
    }

    .nav-link {
        padding: 8px 12px;
        font-size: 14px;
        white-space: normal;
    }

    .nav-icon {
        display: inline-block;
    }

    /* Footer sidebar verticale */
    .sidebar-footer {
        flex-direction: column;
        padding: 0.75rem 0.5rem;
        border-top: 0.5px solid var(--border);
    }

    .sidebar-btn {
        padding: 8px 12px;
        font-size: 14px;
        width: 100%;
    }

    .sidebar-btn-label {
        display: inline;
    }

    /* Posizioni aperte (Dashboard) */
    .posizioni-table { display: none; }
    .posizioni-cards { display: flex; flex-direction: column; gap: 10px; }

    /* Conti: layout 2-col → 1-col, tabella saldi → card */
    .conti-layout { grid-template-columns: 1fr !important; }
    .conti-saldi-table { display: none; }
    .conti-saldi-cards { display: flex; flex-direction: column; gap: 10px; }

    /* Portafogli, Rendimenti, Titoli, Tipologiche */
    .portafogli-table { display: none; }
    .portafogli-cards { display: flex; flex-direction: column; gap: 10px; }

    .rendimenti-table { display: none; }
    .rendimenti-cards { display: flex; flex-direction: column; gap: 10px; }

    .tipologiche-table { display: none; }
    .tipologiche-cards { display: flex; flex-direction: column; gap: 10px; }

    .titoli-table { display: none; }
    .titoli-cards { display: flex; flex-direction: column; gap: 10px; }

    .prezzi-table { display: none; }
    .prezzi-cards { display: flex; flex-direction: column; gap: 10px; }

    /* Main content: offset per la topbar fissa */
    .main-content {
        margin-left: 0;
        padding-top: 56px;
        overflow-x: hidden;
        max-width: 100%;
    }
}