/* ═══════════════════════════════════════════════════════════════
   ControlPeso.it — Enterprise Mobile-First Design System v4
   
   Rules:
   · Mobile-first: everything designed for 390px first
   · No emoji in UI chrome — text labels only
   · Enterprise tone: precision, authority, calm
   · Touch targets: minimum 44px
   · Font: System stack — feels native on every device
   ═══════════════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    /* Brand */
    --navy:        #1B3A6B;
    --navy-d:      #0F2347;
    --navy-m:      #254D8A;
    --navy-l:      #5B82C0;
    --navy-xs:     #EEF3FB;
    --navy-xxs:    #F7FAFE;

    --coral:       #E8334A;
    --coral-d:     #C4253A;
    --coral-l:     #FF6B7A;
    --coral-xs:    #FFF1F2;

    /* Neutrals — Apple/Google enterprise */
    --white:  #FFFFFF;
    --n50:    #FAFAFA;
    --n100:   #F4F4F5;
    --n150:   #E4E4E7;
    --n200:   #D4D4D8;
    --n300:   #A1A1AA;
    --n400:   #71717A;
    --n500:   #52525B;
    --n600:   #3F3F46;
    --n700:   #27272A;
    --n800:   #18181B;

    /* Semantic */
    --bg:      var(--n100);
    --surface: var(--white);
    --border:  rgba(0,0,0,0.07);
    --border2: rgba(0,0,0,0.11);
    --text:    var(--n800);
    --text2:   var(--n400);
    --text3:   var(--n300);

    /* Status */
    --green:   #16A34A;
    --green-bg:#F0FDF4;
    --green-b: #BBF7D0;
    --red:     #DC2626;
    --red-bg:  #FEF2F2;
    --red-b:   #FECACA;
    --amber:   #D97706;
    --amber-bg:#FFFBEB;
    --amber-b: #FDE68A;

    /* Geometry */
    --r-sm: 8px;
    --r:    12px;
    --r-lg: 16px;
    --r-xl: 20px;
    --r-f:  100px;

    /* Shadows — understated */
    --sh-xs: 0 1px 2px rgba(0,0,0,.05);
    --sh-sm: 0 1px 4px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --sh-md: 0 4px 12px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.04);
    --sh-lg: 0 8px 24px rgba(0,0,0,.08), 0 4px 8px rgba(0,0,0,.04);

    /* Type scale — mobile-first */
    --text-xs:  0.70rem;   /* 11.2px */
    --text-sm:  0.813rem;  /* 13px  */
    --text-base:0.938rem;  /* 15px  */
    --text-md:  1.063rem;  /* 17px  */
    --text-lg:  1.25rem;   /* 20px  */
    --text-xl:  1.563rem;  /* 25px  */
    --text-2xl: 1.875rem;  /* 30px  */
    --text-3xl: 2.25rem;   /* 36px  */

    /* Spacing */
    --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
    --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;

    /* Touch target */
    --touch: 44px;
    --touch-lg: 52px;

    /* Font */
    --font: -apple-system, 'SF Pro Text', BlinkMacSystemFont,
            'Segoe UI', system-ui, Arial, sans-serif;
    --font-num: 'Helvetica Neue', 'Arial', sans-serif; /* clean numerics */

    /* Motion */
    --ease: cubic-bezier(.25,.46,.45,.94);
    --dur:  200ms;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior-y: none;
    height: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    display: flex; flex-direction: column;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    letter-spacing: -.01em;
    overflow-x: hidden;
    max-width: 100vw;
    overscroll-behavior-y: none;
    -webkit-overflow-scrolling: touch;
}

/* ═══════════════════════════
   SCROLLBAR
═══════════════════════════ */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--n200); border-radius: 4px; }

/* ═══════════════════════════
   NAVBAR
   44px height — compact, pro
═══════════════════════════ */
.navbar {
    position: sticky; top: 0; z-index: 200;
    /* height include safe area top (Dynamic Island, notch) */
    height: calc(52px + env(safe-area-inset-top, 0px)) !important;
    min-height: calc(52px + env(safe-area-inset-top, 0px)) !important;
    background: rgba(255,255,255,.94);
    backdrop-filter: blur(18px) saturate(180%);
    -webkit-backdrop-filter: blur(18px) saturate(180%);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    /* Padding top = safe area per Dynamic Island */
    padding: env(safe-area-inset-top, 0px) var(--sp-4) 0 !important;
}
.nav-brand { text-decoration: none; display: flex; align-items: center; }
.nav-logo  { height: 22px; width: auto; display: block; }

.nav-center {
    display: none; /* hidden on mobile, shown desktop */
    align-items: center; gap: var(--sp-1);
}
@media(min-width:768px){ .nav-center { display: flex; } }

.nav-link {
    display: flex; align-items: center;
    height: var(--touch); padding: 0 var(--sp-3);
    border-radius: var(--r-sm);
    text-decoration: none;
    font-size: var(--text-sm); font-weight: 500;
    color: var(--text2);
    transition: all var(--dur) var(--ease);
    white-space: nowrap;
}
.nav-link:hover  { background: var(--n100); color: var(--text); }
.nav-link.active { background: var(--navy-xs); color: var(--navy); font-weight: 600; }

.nav-add {
    display: none;
}
@media(min-width:768px){
    .nav-add {
        display: flex; align-items: center; gap: var(--sp-2);
        height: 36px; padding: 0 var(--sp-4);
        border-radius: var(--r-f);
        background: var(--navy); color: var(--white);
        font-size: var(--text-sm); font-weight: 600;
        text-decoration: none; margin-left: var(--sp-2);
        transition: all var(--dur) var(--ease);
    }
    .nav-add:hover { background: var(--navy-d); }
}

.nav-right { display: flex; align-items: center; gap: var(--sp-2); }

.nav-icon-btn {
    width: var(--touch); height: var(--touch);
    display: flex; align-items: center; justify-content: center;
    background: transparent; border: none;
    text-decoration: none; color: var(--text2);
    cursor: pointer; border-radius: var(--r-sm);
    transition: all var(--dur) var(--ease);
    position: relative;
}
.nav-icon-btn:hover { background: var(--n100); color: var(--text); }
.nav-icon-btn.has-badge::after {
    content: attr(data-badge); position: absolute; top: 4px; right: 4px;
    min-width: 16px; height: 16px; padding: 0 3px;
    background: var(--coral); color: var(--white);
    font-size: 9px; font-weight: 700; border-radius: var(--r-f);
    display: flex; align-items: center; justify-content: center;
    border: 2px solid var(--white); font-family: var(--font);
}

.nav-user {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px;
    padding: 0; flex-shrink: 0;
    background: transparent; border-radius: 50%;
    text-decoration: none; overflow: hidden;
}
/* Mobile: solo avatar tondo — immagine riempie il link */
.nav-user img {
    display: block;
    width: 34px; height: 34px;
    border-radius: 50%;
    object-fit: cover;
    border: none;
    pointer-events: none;
}
.nav-user-name { display: none; }

/* Desktop: pill con sfondo e nome */
@media(min-width:768px) {
    .nav-user {
        width: auto; height: var(--touch);
        border-radius: var(--r-f);
        padding: 0 var(--sp-3) 0 var(--sp-2);
        background: var(--n100); gap: var(--sp-2);
        overflow: visible;
    }
    .nav-user:hover { background: var(--n150); }
    .nav-user img { width: 28px; height: 28px; border-radius: 50%; }
    .nav-user-name { display: block; font-size: var(--text-sm); font-weight: 600; color: var(--text); }
}

.btn-nav-ghost {
    height: var(--touch); padding: 0 var(--sp-3);
    text-decoration: none; font-size: var(--text-sm); font-weight: 500;
    color: var(--text2); border-radius: var(--r-sm);
    transition: all var(--dur) var(--ease);
    display: flex; align-items: center;
}
.btn-nav-ghost:hover { background: var(--n100); color: var(--text); }

/* ═══════════════════════════
   PROGRESS BANNER
   Compact top strip
═══════════════════════════ */
.progress-banner {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: var(--sp-2) var(--sp-4);
    display: flex; align-items: center; gap: var(--sp-5);
    overflow-x: auto; white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.progress-banner::-webkit-scrollbar { display: none; }
.pb-sep   { width: 1px; height: 20px; background: var(--border2); flex-shrink: 0; }
.pb-item  { display: flex; flex-direction: column; gap: 1px; flex-shrink: 0; }
.pb-label { font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--text3); }
.pb-val   { font-size: var(--text-sm); font-weight: 700; color: var(--text); }
.pb-bar-section { display: flex; align-items: center; gap: var(--sp-2); flex-shrink: 0; margin-left: auto; }
.pb-bar-track   { width: 80px; height: 3px; background: var(--n150); border-radius: 10px; overflow: hidden; }
.pb-bar-fill    { height: 100%; background: var(--navy); border-radius: 10px; transition: width .8s var(--ease); }

/* Desktop: centra tutto il contenuto della banner */
@media (min-width: 768px) {
    .progress-banner {
        justify-content: center;
        gap: var(--sp-6);
    }
    .pb-bar-section {
        margin-left: var(--sp-4); /* piccolo offset invece di auto */
    }
}
.pb-pct { font-size: var(--text-xs); font-weight: 700; color: var(--navy); }

/* ═══════════════════════════
   LAYOUT
   Mobile: 16px padding
   Desktop: wider
═══════════════════════════ */
.main {
    flex: 1;
    padding: var(--sp-4) var(--sp-4);
    padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); /* tab bar + safe area */
    max-width: 1100px; margin: 0 auto;
    width: 100%;
    /* Pagine corte: occupa almeno tutto lo schermo → menu sempre in fondo */
    min-height: calc(100dvh - 52px - env(safe-area-inset-top, 0px));
    /* CRITICAL: prevent any child from overflowing */
    box-sizing: border-box;
}
@media(min-width:768px){
    .main   { padding: var(--sp-6); padding-bottom: var(--sp-6); max-width: 1020px !important; }
    .navbar { padding-right: calc((100% - 1020px) / 2); padding-left: calc((100% - 1020px) / 2); }
}

.container    { max-width: 560px; margin: 0 auto; }
.container-sm { max-width: 440px; margin: 0 auto; }

.site-footer {
    background: var(--n800); color: var(--n400);
    padding: var(--sp-6); text-align: center;
    font-size: var(--text-xs);
    display: none; /* hidden on mobile to save space */
}
@media(min-width:768px){ .site-footer { display: block; } }
.footer-brand { font-size: var(--text-sm); font-weight: 700; color: var(--white); margin-bottom: 4px; }
.footer-brand span { color: var(--coral-l); }

/* ═══════════════════════════
   TYPOGRAPHY
   No emoji in headings
═══════════════════════════ */
.page-title {
    font-size: var(--text-xl);
    font-weight: 700; letter-spacing: -.035em;
    color: var(--text); line-height: 1.15;
}
@media(min-width:768px){ .page-title { font-size: var(--text-2xl); } }
.page-title .accent { color: var(--navy); }
.page-subtitle { color: var(--text2); font-size: var(--text-sm); margin-top: 3px; }

.section-label {
    font-size: var(--text-xs); font-weight: 700;
    text-transform: uppercase; letter-spacing: .09em;
    color: var(--text3); margin-bottom: var(--sp-3);
}

/* ═══════════════════════════
   CARDS
═══════════════════════════ */
.card {
    background: var(--surface);
    border-radius: var(--r-lg);
    padding: var(--sp-4);
    border: 1px solid var(--border);
    box-shadow: var(--sh-xs);
    animation: upIn .22s var(--ease) both;
    /* Prevent overflow */
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}
@media(min-width:768px){ .card { padding: var(--sp-5); border-radius: var(--r-xl); } }

.card-hover { transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease); }
.card-hover:hover { box-shadow: var(--sh-md); transform: translateY(-1px); }

@keyframes upIn {
    from { opacity:0; transform:translateY(8px); }
    to   { opacity:1; transform:translateY(0); }
}
.grid > *:nth-child(1){animation-delay:.04s}
.grid > *:nth-child(2){animation-delay:.07s}
.grid > *:nth-child(3){animation-delay:.10s}
.grid > *:nth-child(4){animation-delay:.13s}

.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: var(--sp-4);
}
.card-title    { font-size: var(--text-base); font-weight: 700; color: var(--text); letter-spacing: -.02em; }
.card-subtitle { font-size: var(--text-sm); color: var(--text2); margin-top: 2px; }

/* ═══════════════════════════
   STAT CARDS
   2-col on mobile, auto on desktop
═══════════════════════════ */
.stats-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-3);
    margin-bottom: var(--sp-4);
}
@media(min-width:640px){ .stats-row { grid-template-columns: repeat(auto-fit, minmax(140px,1fr)); } }

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--sp-4);
    box-shadow: var(--sh-xs);
    animation: upIn .22s var(--ease) both;
    position: relative; overflow: hidden;
    min-width: 0;       /* prevent grid blowout */
    box-sizing: border-box;
}
.stat-card::before {
    content: ''; position: absolute;
    left: 0; top: 0; bottom: 0; width: 3px;
    border-radius: var(--r-lg) 0 0 var(--r-lg);
}
.sa-navy::before   { background: var(--navy); }
.sa-coral::before  { background: var(--coral); }
.sa-green::before  { background: var(--green); }
.sa-amber::before  { background: var(--amber); }
.sa-muted::before  { background: var(--n200); }

.stat-label {
    font-size: var(--text-xs); font-weight: 600;
    text-transform: uppercase; letter-spacing: .08em;
    color: var(--text3); margin-bottom: var(--sp-2);
}
.stat-value {
    font-size: var(--text-2xl); font-weight: 700;
    letter-spacing: -.05em; color: var(--text);
    line-height: 1; font-family: var(--font-num);
}
@media(max-width:380px){ .stat-value { font-size: var(--text-xl); } }
.stat-unit { font-size: var(--text-sm); font-weight: 400; color: var(--text2); margin-left: 1px; }
.stat-sub  { font-size: var(--text-xs); font-weight: 600; margin-top: 5px; }
.c-pos { color: var(--green); }
.c-neg { color: var(--red); }
.c-neu { color: var(--text3); }
.c-navy { color: var(--navy); }
.c-amber { color: var(--amber); }

/* ═══════════════════════════
   BUTTONS
   Min 44px touch target
═══════════════════════════ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
    min-height: var(--touch); padding: 0 var(--sp-5);
    border: none; border-radius: var(--r-f);
    font-family: var(--font); font-size: var(--text-sm); font-weight: 600;
    cursor: pointer; text-decoration: none; letter-spacing: -.01em;
    transition: all var(--dur) var(--ease); white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }

.btn-primary  { background: var(--navy);  color: var(--white); }
.btn-primary:hover  { background: var(--navy-d); }

.btn-coral    { background: var(--coral); color: var(--white); }
.btn-coral:hover    { background: var(--coral-d); }

.btn-secondary {
    background: var(--n100); color: var(--text);
    border: 1px solid var(--border2);
}
.btn-secondary:hover { background: var(--n150); }

.btn-ghost { background: transparent; color: var(--text2); }
.btn-ghost:hover { background: var(--n100); color: var(--text); }

.btn-sm { min-height: 36px; padding: 0 var(--sp-4); font-size: var(--text-xs); border-radius: var(--r-f); }
.btn-lg { min-height: var(--touch-lg); padding: 0 var(--sp-6); font-size: var(--text-base); }
.btn-full { width: 100%; }

/* ═══════════════════════════
   FORMS
   Large touch-friendly inputs
═══════════════════════════ */
.form-group { margin-bottom: var(--sp-4); }
.form-label {
    display: block; font-size: var(--text-xs); font-weight: 700;
    text-transform: uppercase; letter-spacing: .08em;
    color: var(--n500); margin-bottom: var(--sp-2);
}
.form-control {
    width: 100%;
    min-height: var(--touch-lg); /* larger on mobile */
    padding: 0 var(--sp-4);
    background: var(--n100);
    border: 1.5px solid transparent;
    border-radius: var(--r);
    font-family: var(--font); font-size: var(--text-base);
    font-weight: 400; color: var(--text);
    transition: all var(--dur) var(--ease); appearance: none;
    -webkit-appearance: none;
}
.form-control:focus {
    outline: none; border-color: var(--navy);
    background: var(--white);
    box-shadow: 0 0 0 3px rgba(27,58,107,.10);
}
.form-control::placeholder { color: var(--n300); }
textarea.form-control { min-height: 100px; padding: var(--sp-3) var(--sp-4); resize: vertical; }
select.form-control {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2371717A' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
@media(max-width:480px){ .form-row { grid-template-columns: 1fr; } }
.form-hint { font-size: var(--text-xs); color: var(--text3); margin-top: var(--sp-2); }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-suffix { position: absolute; right: var(--sp-4); font-size: var(--text-sm); font-weight: 600; color: var(--text3); pointer-events: none; }
.has-suffix { padding-right: 40px !important; }

/* ═══════════════════════════
   ALERTS
═══════════════════════════ */
.alert {
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--r);
    margin-bottom: var(--sp-3);
    font-size: var(--text-sm); font-weight: 500;
    display: flex; align-items: flex-start; gap: var(--sp-3);
    border-left: 3px solid;
}
.alert-success { background: var(--green-bg); color: #14532D; border-color: var(--green); }
.alert-error   { background: var(--red-bg);   color: #7F1D1D; border-color: var(--red); }
.alert-info    { background: var(--navy-xs);  color: var(--navy); border-color: var(--navy); }
.alert-warning { background: var(--amber-bg); color: #78350F; border-color: var(--amber); }

/* Toast */
#toast-container { position: fixed; bottom: 80px; left: var(--sp-4); right: var(--sp-4); z-index: 9999; display: flex; flex-direction: column; gap: var(--sp-2); }
@media(min-width:480px){ #toast-container { left:auto; right: var(--sp-5); width: 300px; } }
.toast {
    background: rgba(24,24,27,.94);
    backdrop-filter: blur(16px);
    color: var(--white); padding: var(--sp-3) var(--sp-4);
    border-radius: var(--r); box-shadow: var(--sh-lg);
    font-size: var(--text-sm); font-weight: 500;
    display: flex; align-items: center; gap: var(--sp-3);
    animation: toastUp .24s var(--ease);
}
@keyframes toastUp { from { opacity:0; transform:translateY(8px); } }

/* ═══════════════════════════
   STATUS PILLS
═══════════════════════════ */
.status-pill {
    display: inline-flex; align-items: center; gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-4);
    border-radius: var(--r-f);
    font-size: var(--text-sm); font-weight: 600;
}
.sp-under { background: var(--green-bg); color: #14532D; }
.sp-over  { background: var(--red-bg);   color: #7F1D1D; }
.sp-on    { background: var(--amber-bg); color: #78350F; }

/* Tags / chips */
.tag {
    display: inline-flex; align-items: center; gap: 3px;
    padding: 3px var(--sp-2); border-radius: var(--r-f);
    font-size: var(--text-xs); font-weight: 600;
    background: var(--n100); color: var(--text2);
}
.tag-navy  { background: var(--navy-xs);  color: var(--navy); }
.tag-coral { background: var(--coral-xs); color: var(--coral-d); }
.tag-green { background: var(--green-bg); color: #14532D; }
.tag-amber { background: var(--amber-bg); color: #78350F; }

/* ═══════════════════════════
   GRID
═══════════════════════════ */
.grid      { display: grid; gap: var(--sp-3); }
.grid-2    { grid-template-columns: 1fr 1fr; }
.grid-3    { grid-template-columns: 1fr 1fr 1fr; }
.grid-full { grid-column: 1/-1; }
@media(max-width:640px){ .grid-2,.grid-3 { grid-template-columns: 1fr; } }
@media(max-width:860px){ .grid-3 { grid-template-columns: 1fr 1fr; } }

.dash-layout { display: grid; grid-template-columns: 1fr; gap: var(--sp-4); }
@media(min-width:1024px){ .dash-layout { grid-template-columns: 1fr 280px; } }

/* ALL grid/flex children must not overflow */
.dash-layout > *, .grid > * {
    min-width: 0;
}

/* Column containers inside dash-layout */
.dash-layout > div {
    display: flex; flex-direction: column;
    gap: var(--sp-4); min-width: 0;
}

/* ═══════════════════════════
   TABS — pill style, scrollable
═══════════════════════════ */
.tabs {
    display: flex; gap: var(--sp-1);
    background: var(--n100); border-radius: var(--r);
    padding: 3px; width: fit-content; max-width: 100%;
    margin-bottom: var(--sp-4);
    overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
    min-height: 36px; padding: 0 var(--sp-4);
    background: transparent; border: none;
    border-radius: var(--r-sm); color: var(--text2);
    font-family: var(--font); font-size: var(--text-sm); font-weight: 600;
    cursor: pointer; white-space: nowrap;
    transition: all var(--dur) var(--ease);
    -webkit-tap-highlight-color: transparent;
}
.tab-btn.active { background: var(--white); color: var(--text); box-shadow: var(--sh-xs); }
.tab-panel { display: none !important; }
.tab-panel.active { display: block !important; }

/* ═══════════════════════════
   TABLE
═══════════════════════════ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--r); border: 1px solid var(--border); width: 100%; max-width: 100%; box-sizing: border-box; }
@media(max-width:480px){ table { font-size: 11px; } th, td { padding: 6px 8px; } }
table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
thead tr { background: var(--n50); }
th { padding: var(--sp-3) var(--sp-4); text-align: left; font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text3); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid rgba(0,0,0,.04); color: var(--text2); vertical-align: middle; }
tbody tr:hover { background: var(--n50); }
tbody tr:last-child td { border-bottom: none; }
td strong { color: var(--text); font-weight: 600; }

/* ═══════════════════════════
   AVATAR
═══════════════════════════ */
.avatar { border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.av-sm  { width: 32px; height: 32px; border: 1.5px solid var(--border2); }
.av-md  { width: 40px; height: 40px; border: 1.5px solid var(--border2); }
.av-lg  { width: 56px; height: 56px; border: 2px solid var(--navy-xs); }
.av-xl  { width: 72px; height: 72px; border: 2.5px solid var(--navy-xs); }

/* ═══════════════════════════
   CHART
═══════════════════════════ */
.chart-wrap { position: relative; height: 200px; width: 100%; max-width: 100%; overflow: hidden; }
@media(min-width:768px){ .chart-wrap { height: 260px; } }

/* ═══════════════════════════
   POSTS
═══════════════════════════ */
.post-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg); padding: var(--sp-4);
    box-shadow: var(--sh-xs);
    transition: box-shadow var(--dur) var(--ease);
    animation: upIn .22s var(--ease) both;
}
.post-header  { display: flex; align-items: flex-start; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.post-meta    { flex: 1; min-width: 0; }
.post-user    { font-size: var(--text-sm); font-weight: 700; color: var(--text); }
.post-info    { display: flex; align-items: center; gap: var(--sp-2); margin-top: 2px; flex-wrap: wrap; }
.post-time    { font-size: var(--text-xs); color: var(--text3); }
.post-body    { font-size: var(--text-sm); line-height: 1.65; color: var(--text2); margin-bottom: var(--sp-3); }

.post-type-tag {
    display: inline-flex; align-items: center; gap: 3px;
    padding: 2px 8px; border-radius: var(--r-f);
    font-size: var(--text-xs); font-weight: 700;
}
.ptt-peso        { background: var(--green-bg); color: #14532D; }
.ptt-pasto       { background: var(--amber-bg); color: #78350F; }
.ptt-esercizio   { background: var(--navy-xs);  color: var(--navy); }
.ptt-motivazione { background: #F5F0FF; color: #5B0DAF; }
.ptt-traguardo   { background: var(--coral-xs); color: var(--coral-d); }

.post-data-strip {
    background: var(--n100); border-radius: var(--r-sm);
    padding: var(--sp-3) var(--sp-4);
    display: flex; gap: var(--sp-5); flex-wrap: wrap;
    margin-bottom: var(--sp-3);
}
.pds-item  { display: flex; flex-direction: column; gap: 1px; }
.pds-label { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text3); }
.pds-val   { font-size: var(--text-sm); font-weight: 700; color: var(--text); }

.post-image { width: 100%; border-radius: var(--r-sm); margin-bottom: var(--sp-3); max-height: 280px; object-fit: cover; border: 1px solid var(--border); }

.post-actions { display: flex; align-items: center; gap: var(--sp-2); padding-top: var(--sp-3); border-top: 1px solid var(--border); }
.react-btn {
    display: flex; align-items: center; gap: 5px;
    min-height: 36px; padding: 0 var(--sp-3);
    border-radius: var(--r-f);
    background: var(--n100); border: none;
    color: var(--text2); font-size: var(--text-xs); font-weight: 600;
    cursor: pointer; transition: all var(--dur) var(--ease);
    text-decoration: none; font-family: var(--font);
    -webkit-tap-highlight-color: transparent;
}
.react-btn:hover, .react-btn.active { background: var(--navy-xs); color: var(--navy); }

.comment-area { margin-top: var(--sp-3); padding-top: var(--sp-3); border-top: 1px solid var(--border); display: none; }
.comment-area.open { display: block; }
.comment-item { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.comment-bubble { background: var(--n100); border-radius: var(--r-sm); padding: var(--sp-2) var(--sp-3); flex: 1; }
.comment-author { font-size: var(--text-xs); font-weight: 700; color: var(--text); margin-bottom: 2px; }
.comment-text   { font-size: var(--text-sm); color: var(--text2); }
.comment-input-row { display: flex; gap: var(--sp-2); margin-top: var(--sp-2); }
.comment-input-row input { flex: 1; border-radius: var(--r-f) !important; min-height: 40px; }

/* ═══════════════════════════
   CHALLENGE CARDS
═══════════════════════════ */
.ch-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r-lg); padding: var(--sp-4);
    text-decoration: none; display: block; box-shadow: var(--sh-xs);
    transition: all var(--dur) var(--ease);
    -webkit-tap-highlight-color: transparent;
}
.ch-card:active { transform: scale(.99); }
@media(min-width:768px){ .ch-card:hover { box-shadow: var(--sh-md); transform: translateY(-1px); } }

.ch-emoji-badge {
    width: 40px; height: 40px; border-radius: var(--r-sm);
    background: var(--n100); border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.35rem; margin-bottom: var(--sp-3);
}
.ch-name   { font-size: var(--text-base); font-weight: 700; color: var(--text); margin-bottom: 4px; letter-spacing: -.02em; }
.ch-desc   { font-size: var(--text-sm); color: var(--text2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; margin-bottom: var(--sp-3); }
.ch-footer { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.ch-members{ font-size: var(--text-xs); font-weight: 600; color: var(--text3); margin-left: auto; }

/* ═══════════════════════════
   MEMBER ROWS
═══════════════════════════ */
.member-row { display: flex; align-items: center; gap: var(--sp-3); min-height: var(--touch); border-bottom: 1px solid rgba(0,0,0,.05); }
.member-row:last-child { border-bottom: none; }
.member-rank { font-size: var(--text-sm); font-weight: 700; color: var(--text3); min-width: 20px; text-align: center; }
.member-info { flex: 1; min-width: 0; }
.member-name   { font-size: var(--text-sm); font-weight: 600; color: var(--text); }
.member-detail { font-size: var(--text-xs); color: var(--text3); font-weight: 500; }
.member-prog   { font-size: var(--text-xs); color: var(--text3); font-weight: 500; margin-top: 1px; }

/* ═══════════════════════════
   INVITE CODE
═══════════════════════════ */
.invite-code-box {
    display: flex; align-items: center; gap: var(--sp-3);
    background: var(--navy-xxs); border: 1px dashed var(--navy-l);
    border-radius: var(--r); padding: var(--sp-4);
}
.invite-code-box code {
    font-family: 'SF Mono', 'Courier New', monospace;
    font-size: 1.35rem; font-weight: 700;
    letter-spacing: .2em; color: var(--navy); flex: 1;
}

/* ═══════════════════════════
   MOOD PICKER
═══════════════════════════ */
.mood-row { display: flex; gap: var(--sp-2); }
.mood-opt {
    width: var(--touch); height: var(--touch);
    border-radius: var(--r-sm); border: 1.5px solid var(--n150);
    background: var(--n100); display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem; cursor: pointer;
    transition: all var(--dur) var(--ease);
    -webkit-tap-highlight-color: transparent;
}
.mood-opt:active { transform: scale(.92); }
.mood-opt.sel    { border-color: var(--navy); background: var(--navy-xs); box-shadow: 0 0 0 3px rgba(27,58,107,.12); }

/* ═══════════════════════════
   BADGE GRID
═══════════════════════════ */
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px,1fr)); gap: var(--sp-3); }
.badge-tile {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r); padding: var(--sp-4); text-align: center;
    box-shadow: var(--sh-xs); transition: all var(--dur) var(--ease);
}
.badge-tile.locked { opacity: .35; filter: grayscale(1); }
.badge-tile:not(.locked) { cursor: pointer; }
@media(min-width:768px){ .badge-tile:not(.locked):hover { box-shadow: var(--sh-md); transform: translateY(-1px); } }
.badge-emoji { font-size: 2rem; margin-bottom: 6px; }
.badge-name  { font-size: var(--text-xs); font-weight: 700; color: var(--text); margin-bottom: 3px; letter-spacing: -.01em; }
.badge-desc  { font-size: var(--text-xs); color: var(--text3); margin-bottom: var(--sp-2); line-height: 1.4; }
.badge-pts   { font-size: var(--text-xs); font-weight: 700; padding: 2px 8px; border-radius: var(--r-f); background: var(--navy-xs); color: var(--navy); }

/* ═══════════════════════════
   PROFILE
═══════════════════════════ */
.profile-hero { display: flex; align-items: flex-start; gap: var(--sp-4); padding: var(--sp-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-xs); margin-bottom: var(--sp-4); flex-wrap: wrap; }
.profile-stats { display: flex; gap: var(--sp-6); margin-top: var(--sp-3); flex-wrap: wrap; }
.ps-val { font-size: var(--text-xl); font-weight: 700; letter-spacing: -.04em; color: var(--text); display: block; }
.ps-lbl { font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text3); }
.profile-stat-item { text-align: center; }

/* ═══════════════════════════
   HERO (Landing)
═══════════════════════════ */
.hero-wrap {
    text-align: center; padding: 56px var(--sp-4) 48px;
    max-width: 640px; margin: 0 auto;
}
.hero-eyebrow {
    display: inline-block;
    background: var(--navy-xs); color: var(--navy);
    padding: 5px 14px; border-radius: var(--r-f);
    font-size: var(--text-xs); font-weight: 700; text-transform: uppercase;
    letter-spacing: .1em; margin-bottom: var(--sp-4);
}
.hero-h1 {
    font-size: clamp(2.4rem, 8vw, 4.5rem);
    font-weight: 700; letter-spacing: -.05em; line-height: 1.04;
    color: var(--text); margin-bottom: var(--sp-4);
}
.hero-h1 em     { font-style: normal; color: var(--coral); }
.hero-h1 strong { font-style: normal; color: var(--navy); font-weight: 700; }
.hero-sub       { font-size: var(--text-base); color: var(--text2); max-width: 420px; margin: 0 auto var(--sp-6); line-height: 1.7; }
.hero-cta { display: flex; gap: var(--sp-3); justify-content: center; flex-wrap: wrap; }

/* Auth */
.auth-wrap    { max-width: 380px; margin: var(--sp-8) auto; padding: 0 var(--sp-4); }
.auth-header  { text-align: center; margin-bottom: var(--sp-5); }
.auth-logo-img{ height: 28px; width: auto; display: block; margin: 0 auto var(--sp-3); }
.auth-sub     { font-size: var(--text-sm); color: var(--text2); }

/* ═══════════════════════════
   UTILITY
═══════════════════════════ */
.flex            { display: flex; }
.items-center    { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.gap-1{gap:var(--sp-2)} .gap-2{gap:var(--sp-3)} .gap-3{gap:var(--sp-4)}
.mt-1{margin-top:var(--sp-2)} .mt-2{margin-top:var(--sp-3)} .mt-3{margin-top:var(--sp-4)} .mt-4{margin-top:var(--sp-6)}
.mb-1{margin-bottom:var(--sp-2)} .mb-2{margin-bottom:var(--sp-3)} .mb-3{margin-bottom:var(--sp-4)}
.text-center{text-align:center} .text-right{text-align:right}
.text-sm  { font-size:var(--text-sm);  color:var(--text2); }
.text-xs  { font-size:var(--text-xs);  color:var(--text3); font-weight:500; }
.font-bold{ font-weight:700; }
.w-full   { width:100%; }
.flex-1   { flex:1; }
.truncate { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.nowrap   { white-space:nowrap; }
.divider  { border:none; border-top:1px solid var(--border); margin:var(--sp-4) 0; }
.diff-under { color:var(--green); font-weight:700; }
.diff-over  { color:var(--red);   font-weight:700; }
.diff-on    { color:var(--amber); font-weight:700; }

/* ═══════════════════════════
   MOBILE BOTTOM TAB BAR
   Primary navigation on mobile
═══════════════════════════ */
/* ── Mobile Tab Bar ──────────────────────────────────────── */
.mobile-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 9000;
    /* Sfondo completamente opaco — il testo non deve trasparire */
    background: #ffffff;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: flex-end;
    padding: 0 0 max(8px, env(safe-area-inset-bottom, 8px));
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}
/* Blocca qualsiasi contenuto che scorra sotto il menu */
.mobile-nav::before {
    content: '';
    position: absolute;
    bottom: -100px; left: 0; right: 0;
    height: 100px;
    background: #ffffff;
    pointer-events: none;
}

/* Ogni voce occupa 1 frazione uguale */
.mobile-nav a {
    flex: 1;
    display: flex; flex-direction: column; align-items: center;
    gap: 2px;
    padding: 8px 4px;
    text-decoration: none; color: var(--text3);
    font-size: 9px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .05em;
    transition: color var(--dur) var(--ease);
    -webkit-tap-highlight-color: transparent;
    min-width: 0;
}

.mobile-nav a .mn-icon {
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--r-sm);
    transition: background var(--dur) var(--ease);
    flex-shrink: 0;
}

.mobile-nav a.active          { color: var(--navy); }
.mobile-nav a.active .mn-icon { background: var(--navy-xs); }

.mobile-nav svg { width: 30px; height: 30px; }

/* ── Bottone centrale "Peso" — elevato e centrato ─────── */
.mobile-nav a.mn-center {
    /* Toglie il padding normale: l'icona sale sopra la barra */
    padding: 0 4px 8px;
    /* Allineamento verticale: allineato in basso come gli altri */
    align-self: flex-end;
    position: relative;
}

.mobile-nav a.mn-center .mn-icon {
    /* Icona bilancia quadrata con angoli arrotondati */
    width: 48px; height: 48px;
    border-radius: 14px;
    background: transparent !important;
    box-shadow: 0 4px 14px rgba(230,57,70,.35);
    margin-bottom: 4px;
    overflow: hidden;
    transform: translateY(-10px);
    transition: transform var(--dur) var(--ease),
                box-shadow var(--dur) var(--ease);
}

.mobile-nav a.mn-center .mn-icon svg {
    width: 48px; height: 48px;
}

.mobile-nav a.mn-center:active .mn-icon {
    transform: translateY(-8px) scale(.94);
    box-shadow: 0 2px 8px rgba(27,58,107,.25);
}

/* Il label "Peso" sotto il cerchio */
.mobile-nav a.mn-center .mn-label {
    display: block;
    font-size: 9px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .05em;
    color: var(--text3);
    margin-top: -6px; /* compensa il translateY del cerchio */
}
.mobile-nav a.mn-center.active .mn-label { color: var(--navy); }

/* On desktop: hide bottom nav */
@media(min-width:768px){ .mobile-nav { display: none; } }

/* ── Layout column helpers ── */
.dash-col {
    display: flex; flex-direction: column;
    gap: var(--sp-4); min-width: 0; width: 100%;
}

/* Ensure all direct children of flex/grid don't overflow */
* { box-sizing: border-box; }

/* Global overflow protection for mobile */
@media(max-width:767px) {
    .dash-layout { overflow: hidden; }
    .stats-row   { overflow: hidden; }
    /* Stat value text: truncate if too long */
    .stat-value  { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    /* Post cards */
    .post-card, .ch-card { overflow: hidden; }
    /* Tables */
    .table-wrap  { max-width: calc(100vw - 32px); }
    /* Chart */
    .chart-wrap  { max-width: 100%; }
    /* Any card inside flex */
    .card { max-width: 100%; box-sizing: border-box; }
}

/* Prevent any image overflow */
img { max-width: 100%; height: auto; }
canvas { max-width: 100%; }

/* ══════════════════════════════════════════════════
   CHART RANGE SLIDER
══════════════════════════════════════════════════ */
.chart-range-wrap {
    padding: 16px 4px 4px;
    user-select: none;
    -webkit-user-select: none;
}

/* Labels sopra: data inizio / data fine */
.chart-range-labels {
    display: flex;
    justify-content: space-between;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text3);
    margin-bottom: 10px;
    padding: 0 2px;
}

/* Track container — contiene la fill + i due input */
.chart-range-track {
    position: relative;
    height: 36px;
    display: flex;
    align-items: center;
}

/* Binario grigio di sfondo */
.chart-range-track::before {
    content: '';
    position: absolute;
    left: 0; right: 0;
    height: 4px;
    background: var(--n150);
    border-radius: 100px;
    pointer-events: none;
}

/* Fill colorata tra i due thumb */
.chart-range-fill {
    position: absolute;
    height: 4px;
    background: var(--navy);
    border-radius: 100px;
    pointer-events: none;
    transition: left .05s, width .05s;
}

/* Input range — sovrapposti, stessa larghezza */
.chart-range-track input[type=range] {
    position: absolute;
    left: 0; right: 0;
    width: 100%;
    height: 36px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
    pointer-events: none; /* solo il thumb è cliccabile */
    margin: 0;
    padding: 0;
}
.chart-range-track input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    pointer-events: all;
    width: 24px; height: 24px;
    border-radius: 50%;
    background: #fff;
    border: 2.5px solid var(--navy);
    box-shadow: 0 2px 8px rgba(27,58,107,.25);
    cursor: grab;
    transition: transform .1s, box-shadow .1s;
}
.chart-range-track input[type=range]::-webkit-slider-thumb:active {
    cursor: grabbing;
    transform: scale(1.15);
    box-shadow: 0 3px 14px rgba(27,58,107,.35);
}
.chart-range-track input[type=range]::-moz-range-thumb {
    pointer-events: all;
    width: 22px; height: 22px;
    border-radius: 50%;
    background: #fff;
    border: 2.5px solid var(--navy);
    box-shadow: 0 2px 8px rgba(27,58,107,.25);
    cursor: grab;
}
.chart-range-track input[type=range]:focus { outline: none; }
.chart-range-track input[type=range]:focus::-webkit-slider-thumb {
    box-shadow: 0 0 0 4px rgba(27,58,107,.15);
}

/* Info row sotto il track */
.chart-range-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    font-size: var(--text-xs);
    color: var(--text3);
    font-weight: 500;
    padding: 0 2px;
}
#range-today-marker { color: var(--navy); font-weight: 600; }

/* Mobile: thumb più grande, track più spessa */
@media (max-width: 767px) {
    .chart-range-track { height: 48px; }
    .chart-range-track::before { height: 5px; }
    .chart-range-fill { height: 5px; }
    .chart-range-track input[type=range]::-webkit-slider-thumb {
        width: 32px; height: 32px;
        border-width: 3px;
        box-shadow: 0 3px 12px rgba(27,58,107,.3);
    }
    .chart-range-labels { font-size: .72rem; margin-bottom: 12px; }
    .chart-range-info   { font-size: .72rem; margin-top: 12px; }
}


/* ═══════════════════════════════════════════════════════
   AGGIUNTE UTENTE — nav-brand, nav-logo, responsive fixes
═══════════════════════════════════════════════════════ */

/* Nav brand */
.nav-brand {
    text-decoration: none;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    margin-left: 14px;
}

/* Logo navbar */
.nav-logo {
    display: block;
    width: auto;
    height: 52px;
    max-width: none;
    object-fit: contain;
}
@media (max-width: 1024px) {
    .nav-logo { height: 46px; }
}
@media (max-width: 640px) {
    .navbar { height: calc(58px + env(safe-area-inset-top, 0px)); padding: env(safe-area-inset-top, 0px) var(--sp-3) 0; }
    .nav-logo { height: 34px; width: auto; }
    .nav-brand { margin-left: -25px; }
    .nav-brand img { width: 200px !important; height: 30px !important; } /* solo logo */
}
@media (max-width: 480px) {
    .navbar .nav-right .nav-user { width: 34px; height: 34px; }
}

/* Btn nav ghost — pill style */
.navbar .nav-right .btn-nav-ghost {
    background-color: rgba(0,0,0,.06);
    border-radius: 30px;
    border-color: rgba(17,17,17,.53);
}

/* ── Commenti: fix struttura e touch ── */
.comment-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    width: 100%;
}
.comment-bubble {
    background: var(--n100);
    border-radius: var(--r-sm);
    padding: var(--sp-2) var(--sp-3);
    flex: 1 1 auto;
    min-width: 0;
    position: relative;
}
.comment-bubble::after {
    content: '';
    position: absolute;
    right: -8px; top: 0; bottom: 0;
    width: 8px;
}
.comment-actions {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-start;
    position: relative;
    z-index: 10;
}
.cbtn-elimina {
    width: 44px; height: 44px;
    min-width: 44px; min-height: 44px;
    display: flex; align-items: center; justify-content: center;
    pointer-events: auto !important;
    position: relative; z-index: 20;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.comment-author {
    font-size: var(--text-xs); font-weight: 700;
    color: var(--text); margin-bottom: 2px;
}
.comment-text { font-size: var(--text-sm); color: var(--text2); }
.comment-input-row { display: flex; gap: var(--sp-2); margin-top: var(--sp-2); }
.comment-input-row input { flex: 1; border-radius: var(--r-f) !important; min-height: 40px; }

/* Form input font mobile */
.card .flex input[type=text] { font-size: 12px; }

/* Body background */
body { background-color: #ffffff; }

/* Linea chart */
.main .linea-section .linea-chart-wrap { height: 300px; }
.linea-section .linea-chart-wrap svg { height: 270px; }
@media (max-width: 640px) {
    .main .linea-section .linea-chart-wrap { height: 149px; }
    .linea-section .linea-chart-wrap svg  { height: 126px; }
}

/* Footer */
.site-footer p { color: #fafaff; }
footer { background-color: #0f2347 !important; }

/* Hero / landing colors */
.hp-section .hero-title strong { color: #1b3a6b; }
.main .hp-section h1 { transform: translateX(0) translateY(0); color: #1b3a6b; }
.main .section-header h2 { color: #1b3a6b; }
.stats-bar .stats-bar-item .stats-bar-num { color: #1b3a6b; }